/* * Copyright (C) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { BaseElement, element } from '../../../base-ui/BaseElement.js'; import LitSwitch, { LitSwitchChangeEvent } from '../../../base-ui/switch/lit-switch.js'; import '../../../base-ui/select/LitAllocationSelect.js'; import '../../../base-ui/switch/lit-switch.js'; import { LitAllocationSelect } from '../../../base-ui/select/LitAllocationSelect.js'; import { SpRecordTrace } from '../SpRecordTrace.js'; import { Cmd } from '../../../command/Cmd.js'; import { CmdConstant } from '../../../command/CmdConstant.js'; import { HdcDeviceManager } from '../../../hdc/HdcDeviceManager.js'; @element('sp-vm-tracker') export class SpVmTracker extends BaseElement { private vmTrackerProcessInput: LitAllocationSelect | undefined | null; private vmTrackerSelectProcess: HTMLInputElement | undefined | null; private configList: Array = []; set startSamp(start: boolean) { if (start) { this.setAttribute('startSamp', ''); } else { this.removeAttribute('startSamp'); let input = this.vmTrackerProcessInput?.shadowRoot?.querySelector('#singleInput'); input!.value = ''; } } get process(): string { if (this.vmTrackerProcessInput!.value.length > 0) { let result = this.vmTrackerProcessInput!.value.match(/\((.+?)\)/g); if (result) { return result.toString().replace('(', '').replace(')', ''); } else { return this.vmTrackerProcessInput!.value; } } return ''; } get startSamp(): boolean { return this.hasAttribute('startSamp'); } initElements(): void { this.initConfigList(); let configList = this.shadowRoot?.querySelector('.configList'); this.configList.forEach((config) => { let vmTrackerDiv = document.createElement('div'); if (config.hidden) { vmTrackerDiv.className = 'vm-config-div hidden'; } else { vmTrackerDiv.className = 'vm-config-div'; } let headDiv = document.createElement('div'); vmTrackerDiv.appendChild(headDiv); let vmTrackerTitle = document.createElement('span'); vmTrackerTitle.className = 'title'; vmTrackerTitle.textContent = config.title; headDiv.appendChild(vmTrackerTitle); let des = document.createElement('span'); des.textContent = config.des; des.className = 'des'; headDiv.appendChild(des); switch (config.type) { case 'select': let html1 = ''; html1 += ``; html1 += ``; vmTrackerDiv.innerHTML = vmTrackerDiv.innerHTML + html1; break; case 'switch': let vmTrackerSwitch = document.createElement('lit-switch') as LitSwitch; vmTrackerSwitch.className = 'config'; vmTrackerSwitch.title = config.title; if (config.value) { vmTrackerSwitch.checked = true; } else { vmTrackerSwitch.checked = false; } if (config.title == 'Start VM Tracker Record') { vmTrackerSwitch.addEventListener('change', (event: CustomEventInit) => { let detail = event.detail; if (detail!.checked) { this.startSamp = true; this.unDisable(); } else { this.startSamp = false; this.disable(); } }); } headDiv.appendChild(vmTrackerSwitch); break; default: break; } configList!.appendChild(vmTrackerDiv); }); this.vmTrackerProcessInput = this.shadowRoot?.querySelector( "lit-allocation-select[title='Process']" ); let vmTrackerMul = this.vmTrackerProcessInput?.shadowRoot?.querySelector('.multipleSelect') as HTMLDivElement; this.vmTrackerSelectProcess = this.vmTrackerProcessInput!.shadowRoot?.querySelector('input') as HTMLInputElement; vmTrackerMul!.addEventListener('mousedown', (ev) => { if (SpRecordTrace.serialNumber == '') { this.vmTrackerProcessInput!.processData = []; this.vmTrackerProcessInput!.initData(); } }); vmTrackerMul!.addEventListener('mouseup', () => { if (SpRecordTrace.serialNumber == '') { this.vmTrackerProcessInput!.processData = []; this.vmTrackerProcessInput!.initData(); } else { Cmd.getProcess().then((processList) => { this.vmTrackerProcessInput!.processData = processList; this.vmTrackerProcessInput!.initData(); }); } }); this.disable(); } private unDisable() { let configVal = this.shadowRoot?.querySelectorAll('.config'); configVal!.forEach((configVal1) => { configVal1.removeAttribute('disabled'); }); } private disable() { let configVal = this.shadowRoot?.querySelectorAll('.config'); configVal!.forEach((configVal1) => { if (configVal1.title != 'Start VM Tracker Record') { configVal1.setAttribute('disabled', ''); } }); } initConfigList(): void { this.configList = [ { title: 'Start VM Tracker Record', des: '', hidden: false, type: 'switch', value: false, }, { title: 'Process', des: 'Record process', hidden: false, type: 'select', selectArray: [''], }, ]; } initHtml(): string { return `
`; } }