• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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';
17import LitSwitch, { LitSwitchChangeEvent } from '../../../base-ui/switch/lit-switch.js';
18import '../../../base-ui/select/LitAllocationSelect.js';
19
20import '../../../base-ui/switch/lit-switch.js';
21import { LitAllocationSelect } from '../../../base-ui/select/LitAllocationSelect.js';
22import { SpRecordTrace } from '../SpRecordTrace.js';
23import { Cmd } from '../../../command/Cmd.js';
24import { CmdConstant } from '../../../command/CmdConstant.js';
25import { HdcDeviceManager } from '../../../hdc/HdcDeviceManager.js';
26
27@element('sp-vm-tracker')
28export class SpVmTracker extends BaseElement {
29  private vmTrackerProcessInput: LitAllocationSelect | undefined | null;
30  private vmTrackerSelectProcess: HTMLInputElement | undefined | null;
31  private configList: Array<any> = [];
32
33  set startSamp(start: boolean) {
34    if (start) {
35      this.setAttribute('startSamp', '');
36    } else {
37      this.removeAttribute('startSamp');
38      let input = this.vmTrackerProcessInput?.shadowRoot?.querySelector<HTMLInputElement>('#singleInput');
39      input!.value = '';
40    }
41  }
42
43  get process(): string {
44    if (this.vmTrackerProcessInput!.value.length > 0) {
45      let result = this.vmTrackerProcessInput!.value.match(/\((.+?)\)/g);
46      if (result) {
47        return result.toString().replace('(', '').replace(')', '');
48      } else {
49        return this.vmTrackerProcessInput!.value;
50      }
51    }
52    return '';
53  }
54
55  get startSamp(): boolean {
56    return this.hasAttribute('startSamp');
57  }
58
59  initElements(): void {
60    this.initConfigList();
61    let configList = this.shadowRoot?.querySelector<HTMLDivElement>('.configList');
62    this.configList.forEach((config) => {
63      let vmTrackerDiv = document.createElement('div');
64      if (config.hidden) {
65        vmTrackerDiv.className = 'vm-config-div hidden';
66      } else {
67        vmTrackerDiv.className = 'vm-config-div';
68      }
69      let headDiv = document.createElement('div');
70      vmTrackerDiv.appendChild(headDiv);
71      let vmTrackerTitle = document.createElement('span');
72      vmTrackerTitle.className = 'title';
73      vmTrackerTitle.textContent = config.title;
74      headDiv.appendChild(vmTrackerTitle);
75      let des = document.createElement('span');
76      des.textContent = config.des;
77      des.className = 'des';
78      headDiv.appendChild(des);
79      switch (config.type) {
80        case 'select':
81          let html1 = '';
82          html1 += `<lit-allocation-select style="width: 100%;" rounded="" default-value="" class="select config" placement="bottom" title="${config.title}"  placeholder="${config.selectArray[0]}">`;
83          html1 += `</lit-allocation-select>`;
84          vmTrackerDiv.innerHTML = vmTrackerDiv.innerHTML + html1;
85          break;
86        case 'switch':
87          let vmTrackerSwitch = document.createElement('lit-switch') as LitSwitch;
88          vmTrackerSwitch.className = 'config';
89          vmTrackerSwitch.title = config.title;
90          if (config.value) {
91            vmTrackerSwitch.checked = true;
92          } else {
93            vmTrackerSwitch.checked = false;
94          }
95          if (config.title == 'Start VM Tracker Record') {
96            vmTrackerSwitch.addEventListener('change', (event: CustomEventInit<LitSwitchChangeEvent>) => {
97              let detail = event.detail;
98              if (detail!.checked) {
99                this.startSamp = true;
100                this.unDisable();
101              } else {
102                this.startSamp = false;
103                this.disable();
104              }
105            });
106          }
107          headDiv.appendChild(vmTrackerSwitch);
108          break;
109        default:
110          break;
111      }
112      configList!.appendChild(vmTrackerDiv);
113    });
114    this.vmTrackerProcessInput = this.shadowRoot?.querySelector<LitAllocationSelect>(
115      "lit-allocation-select[title='Process']"
116    );
117    let vmTrackerMul = this.vmTrackerProcessInput?.shadowRoot?.querySelector('.multipleSelect') as HTMLDivElement;
118    this.vmTrackerSelectProcess = this.vmTrackerProcessInput!.shadowRoot?.querySelector('input') as HTMLInputElement;
119    vmTrackerMul!.addEventListener('mousedown', (ev) => {
120      if (SpRecordTrace.serialNumber == '') {
121        this.vmTrackerProcessInput!.processData = [];
122        this.vmTrackerProcessInput!.initData();
123      }
124    });
125    vmTrackerMul!.addEventListener('mouseup', () => {
126      if (SpRecordTrace.serialNumber == '') {
127        this.vmTrackerProcessInput!.processData = [];
128        this.vmTrackerProcessInput!.initData();
129      } else {
130        Cmd.getProcess().then((processList) => {
131          this.vmTrackerProcessInput!.processData = processList;
132          this.vmTrackerProcessInput!.initData();
133        });
134      }
135    });
136    this.disable();
137  }
138
139  private unDisable() {
140    let configVal = this.shadowRoot?.querySelectorAll<HTMLElement>('.config');
141    configVal!.forEach((configVal1) => {
142      configVal1.removeAttribute('disabled');
143    });
144  }
145
146  private disable() {
147    let configVal = this.shadowRoot?.querySelectorAll<HTMLElement>('.config');
148    configVal!.forEach((configVal1) => {
149      if (configVal1.title != 'Start VM Tracker Record') {
150        configVal1.setAttribute('disabled', '');
151      }
152    });
153  }
154
155  initConfigList(): void {
156    this.configList = [
157      {
158        title: 'Start VM Tracker Record',
159        des: '',
160        hidden: false,
161        type: 'switch',
162        value: false,
163      },
164      {
165        title: 'Process',
166        des: 'Record process',
167        hidden: false,
168        type: 'select',
169        selectArray: [''],
170      },
171    ];
172  }
173
174  initHtml(): string {
175    return `
176        <style>
177        :host{
178            background: var(--dark-background3,#FFFFFF);
179            border-radius: 0px 16px 16px 0px;
180            display: inline-block;
181            width: 100%;
182            height: 100%;
183        }
184
185        .vm-tracker {
186            font-size:16px;
187            margin-bottom: 30px;
188            padding-top: 30px;
189            padding-left: 54px;
190            margin-right: 30px;
191        }
192
193        .title {
194          text-align: center;
195          line-height: 40px;
196          font-weight: 700;
197          margin-right: 10px;
198          opacity: 0.9;
199          font-family: Helvetica-Bold;
200          font-size: 18px;
201        }
202
203        .vm-config-div {
204           width: 80%;
205           display: flex;
206           flex-direction: column;
207           margin-top: 5vh;
208           margin-bottom: 5vh;
209           gap: 25px;
210        }
211
212        .des {
213          text-align: center;
214          line-height: 35px;
215          font-weight: 400;
216          opacity: 0.6;
217          font-family: Helvetica;
218          font-size: 14px;
219        }
220
221        .select {
222          border-radius: 15px;
223        }
224
225        lit-switch {
226          display:inline;
227          float: right;
228          height: 38px;
229          margin-top: 10px;
230        }
231
232        input::-webkit-input-placeholder{
233            color:var(--bark-prompt,#999999);
234        }
235
236        .input {
237            text-align: left;
238            line-height: 20px;
239            font-weight: 400;
240            border: 1px solid var(--dark-background5,#ccc);
241            font-family: Helvetica;
242            font-size: 14px;
243            color: var(--dark-color1,#212121);
244        }
245
246        :host([startSamp]) .input {
247            background: var(--dark-background5,#FFFFFF);
248        }
249
250        input {
251           outline:none;
252           border-radius: 16px;
253           height: 25px;
254           text-indent:2%
255        }
256
257        :host(:not([startSamp])) .input {
258            color: #999999;
259        }
260        </style>
261        <div class="root vm-tracker">
262            <div class="configList">
263            </div>
264        </div>
265        `;
266  }
267}
268