1/* 2 * Copyright (C) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import {BaseElement, element} from "../../../base-ui/BaseElement.js"; 17 18@element('sp-allocations') 19export class SpAllocations extends BaseElement { 20 private processId: HTMLInputElement | null | undefined; 21 private unwindEL: HTMLInputElement | null | undefined; 22 private shareMemory: HTMLInputElement | null | undefined; 23 private shareMemoryUnit: HTMLSelectElement | null | undefined; 24 private filterMemory: HTMLInputElement | null | undefined; 25 private filterMemoryUnit: HTMLSelectElement | null | undefined; 26 27 get pid(): number { 28 return Number(this.processId!.value) || -1; 29 } 30 31 get unwind(): number { 32 return Number(this.unwindEL!.value) || 10; 33 } 34 35 get shared(): number { 36 let value = this.shareMemory?.value || ""; 37 if (value != "") { 38 let unit = this.shareMemoryUnit?.value || ""; 39 return this.convertToValue(value, unit); 40 } 41 return 1024; 42 } 43 44 get filter(): number { 45 let value = this.filterMemory?.value || ""; 46 if (value != "") { 47 let unit = this.filterMemoryUnit?.value || ""; 48 return this.convertToValue(value, unit); 49 } 50 return 0; 51 } 52 53 initElements(): void { 54 this.processId = this.shadowRoot?.getElementById("pid") as HTMLInputElement 55 this.unwindEL = this.shadowRoot?.getElementById("unwind") as HTMLInputElement 56 this.shareMemory = this.shadowRoot?.getElementById("shareMemory") as HTMLInputElement 57 this.shareMemoryUnit = this.shadowRoot?.getElementById("shareMemoryUnit") as HTMLSelectElement 58 this.filterMemory = this.shadowRoot?.getElementById("filterSized") as HTMLInputElement 59 this.filterMemoryUnit = this.shadowRoot?.getElementById("filterSizedUnit") as HTMLSelectElement 60 } 61 62 initHtml(): string { 63 return ` 64<style> 65:host{ 66 display: block; 67 width: 100%; 68 height: 100%; 69 border-radius: 0px 16px 16px 0px; 70} 71.root { 72 display: grid; 73 grid-template-columns: repeat(2, 1fr); 74 grid-template-rows: min-content 1fr min-content; 75 padding-top: 45px; 76 margin-left: 40px; 77 width: 90%; 78 border-radius: 0px 16px 16px 0px; 79} 80.title { 81 grid-column: span 2 / auto; 82} 83 84.font-style{ 85 font-family: Helvetica-Bold; 86 font-size: 1em; 87 color: var(--dark-color1,#000000); 88 line-height: 28px; 89 font-weight: 700; 90} 91.inner-font-style { 92 font-family: Helvetica,serif; 93 font-size: 1em; 94 color: var(--dark-color1,#000000); 95 text-align: left; 96 line-height: 20px; 97 font-weight: 400; 98} 99input { 100 width: 72%; 101 height: 25px; 102 border:0; 103 outline:none; 104 border-radius: 10px; 105 106} 107input::-webkit-input-placeholder{ 108 color:var(--bark-prompt,#999999); 109} 110.select { 111 height: 30px; 112 border:0; 113 border-radius: 3px; 114 outline:none; 115 border: 1px solid var(--dark-border,#B3B3B3); 116 width: 60px; 117 background-color:var(--dark-background5, #FFFFFF) 118 font-family: Helvetica; 119 font-size: 14px; 120 color:var(--dark-color,#212121) 121 text-align: left; 122 line-height: 16px; 123 font-weight: 400; 124 border-radius: 10px; 125} 126.application{ 127 display: flex; 128 flex-direction: column; 129 grid-gap: 15px; 130 margin-top: 40px; 131} 132.inputstyle{ 133 background: var(--dark-background5,#FFFFFF); 134 border: 1px solid var(--dark-background5,#999999); 135 font-family: Helvetica; 136 font-size: 14px; 137 color: var(--dark-color1,#212121); 138 text-align: left; 139 line-height: 16px; 140 font-weight: 400; 141} 142.inputstyle::-webkit-input-placeholder { 143 background: var(--dark-background5,#FFFFFF); 144} 145#one_mb{ 146 background-color:var(--dark-background5, #FFFFFF) 147} 148#one_kb{ 149 background-color:var(--dark-background5, #FFFFFF) 150} 151#two_mb{ 152 background-color:var(--dark-background5, #FFFFFF) 153} 154#two_kb{ 155 background-color:var(--dark-background5, #FFFFFF) 156} 157</style> 158<div class="root"> 159 <div class = "title"> 160 <span class="font-style">Allocations</span> 161 </div> 162 <div class="application"> 163 <span class="inner-font-style">Process Identifier :</span> 164 <input id= "pid" class="inputstyle" type="text" placeholder="Enter the pid" oninput="if(this.value > 2147483647) this.value = ''" onkeyup="this.value=this.value.replace(/\\D/g,'')"> 165 </div> 166 <div class="application"> 167 <span class="inner-font-style" >Max unwind level :</span> 168 <input id= "unwind" class="inputstyle" type="text" placeholder="Enter the Max Unwind Level" oninput="if(this.value > 2147483647) this.value = ''" onkeyup="this.value=this.value.replace(/\\D/g,'')" value="10"> 169 </div> 170 <div class="application"> 171 <span class="inner-font-style">Shared Memory Size :</span> 172 <div> 173 <input id = "shareMemory" class="inputstyle" type="text" placeholder="Enter the Shared Memory Size" oninput="if(this.value > 2147483647) this.value = ''" onkeyup="this.value=this.value.replace(/\\D/g,'')" value="4"> 174 <select class="select" id="shareMemoryUnit" > 175 <option id= "one_mb" class="select" value="MB">MB</option> 176 <option id= "one_kb" class="select" value="KB">KB</option> 177 </select> 178 </div> 179 </div> 180 <div class="application"> 181 <span class="inner-font-style" >Filter Memory Size :</span> 182 <div> 183 <input id = "filterSized" class="inputstyle" type="text" placeholder="Enter the Filter Memory Size" oninput="if(this.value > 2147483647) this.value = ''" onkeyup="this.value=this.value.replace(/\\D/g,'')" value="0"> 184 <select class="select" id="filterSizedUnit"> 185 <option id= "two_mb" class="select" value="MB">MB</option> 186 <option id= "two_mb" class="select" value="KB">KB</option> 187 </select> 188 </div> 189 </div> 190</div>`; 191 } 192 193 private convertToValue(input: string, unit: string): number { 194 let value: number; 195 switch (unit) { 196 case "MB": 197 value = Number(input) * 1024 * 1024; 198 break; 199 case "KB": 200 value = Number(input) * 1024; 201 break; 202 default: 203 value = 0; 204 } 205 let number = value / 4096; 206 if (number > 0 && number < 1) { 207 return 1; 208 } 209 return parseInt(String(number)); 210 } 211 212} 213