• 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';
17import LitSwitch from '../../../base-ui/switch/lit-switch';
18import '../../../base-ui/select/LitAllocationSelect';
19
20import '../../../base-ui/switch/lit-switch';
21import { SpRecordTrace } from '../SpRecordTrace';
22import { Cmd } from '../../../command/Cmd';
23import { LitAllocationSelect } from '../../../base-ui/select/LitAllocationSelect';
24import { LitSelect } from '../../../base-ui/select/LitSelect';
25import { SpHiLogRecordHtml } from './SpHilogRecord.html';
26
27@element('sp-hi-log')
28export class SpHilogRecord extends BaseElement {
29  private vmTrackerSwitch: LitSwitch | undefined | null;
30  private processSelectEl: LitAllocationSelect | undefined | null;
31  private logsSelectEl: LitSelect | undefined | null;
32
33  get recordHilog(): boolean {
34    return this.vmTrackerSwitch!.checked;
35  }
36
37  get appProcess(): string {
38    return this.processSelectEl!.value || '';
39  }
40
41  get appLogLevel(): string {
42    if (this.logsSelectEl!.value.trim() === '' || this.logsSelectEl!.value === 'ALL-Level') {
43      return 'LEVEL_UNSPECIFIED';
44    }
45    return this.logsSelectEl!.value || '';
46  }
47
48  initElements(): void {
49    this.vmTrackerSwitch = this.shadowRoot?.querySelector('.hilog-switch') as LitSwitch;
50    this.processSelectEl = this.shadowRoot?.querySelector('.record-process-select') as LitAllocationSelect;
51    this.logsSelectEl = this.shadowRoot?.querySelector('.record-logs-select') as LitSelect;
52    let hiLogConfigList = this.shadowRoot?.querySelectorAll<HTMLDivElement>('.hilog-config-top');
53    this.vmTrackerSwitch.addEventListener('change', () => {
54      let configVisibility = 'none';
55      if (this.vmTrackerSwitch?.checked) {
56        configVisibility = 'block';
57      }
58      if (hiLogConfigList) {
59        console.log(configVisibility);
60        hiLogConfigList!.forEach((configEl) => {
61          configEl.style.display = configVisibility;
62        });
63      }
64    });
65    let processInputEl = this.processSelectEl.shadowRoot?.querySelector('.multipleSelect') as HTMLInputElement;
66    processInputEl.addEventListener('mousedown', () => {
67      if (SpRecordTrace.serialNumber === '') {
68        this.processSelectEl!.processData = [];
69        this.processSelectEl!.initData();
70      } else {
71        Cmd.getProcess().then((processList) => {
72          if (processList.length > 0 && this.recordHilog) {
73            processInputEl!.setAttribute('readonly', 'readonly');
74          }
75          processList.unshift('ALL-Process');
76          this.processSelectEl!.processData = processList;
77          this.processSelectEl!.initData();
78        });
79      }
80    });
81  }
82
83  attributeChangedCallback(name: string, oldValue: string, newValue: string): void {
84    super.attributeChangedCallback(name, oldValue, newValue);
85  }
86
87  initHtml(): string {
88    return SpHiLogRecordHtml;
89  }
90}
91