/* * 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'; import { LitMainMenu, MenuItem } from '../../base-ui/menu/LitMainMenu'; @element('sp-third-party') export class SpThirdParty extends BaseElement { private uploadJsonBtn: HTMLElement | undefined | null; private inputJsonEl: HTMLInputElement | undefined | null; private uploadCsvBtn: HTMLElement | undefined | null; private inputCsvEl: HTMLInputElement | undefined | null; initElements(): void { let parentElement = this.parentNode as HTMLElement; parentElement.style.overflow = 'hidden'; this.uploadJsonBtn = this.shadowRoot?.querySelector('.upload-json-btn')?.shadowRoot?.querySelector('#custom-button'); this.inputJsonEl = this.shadowRoot?.querySelector('#file'); this.addUploadEvent(this.uploadJsonBtn!, this.inputJsonEl!); this.uploadCsvBtn = this.shadowRoot?.querySelector('.upload-csv-btn')?.shadowRoot?.querySelector('#custom-button'); this.inputCsvEl = this.shadowRoot?.querySelector('#csv-file'); this.addUploadEvent(this.uploadCsvBtn!, this.inputCsvEl!); } initHtml(): string { return ` ${this.initHtmlStyle()}
Open bpftrace file
Open gpu counter file
`; } private initHtmlStyle(): string { return ` `; } addUploadEvent(uploadBtn: HTMLElement, uploadEl: HTMLInputElement): void { uploadBtn?.addEventListener('click', () => { uploadEl?.click(); }); uploadEl!.addEventListener('change', () => { let files = uploadEl!.files; if (files && files.length > 0) { let main = this.parentNode!.parentNode!.querySelector('lit-main-menu') as LitMainMenu; let children = main.menus!; let child = children[0].children as Array; let fileHandler = child[0].fileHandler!; fileHandler({ detail: files[0] }); } if (uploadEl) { uploadEl.value = ''; } }); } }