/* * 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 {querySelectTraceStats, queryTraceMetaData,} from "../database/SqlLite.js"; import {LitTable} from "../../base-ui/table/lit-table.js"; import "../../base-ui/table/lit-table.js"; import {info} from "../../log/Log.js"; import {LitProgressBar} from "../../base-ui/progress-bar/LitProgressBar.js"; @element('sp-info-and-stats') export class SpInfoAndStats extends BaseElement { private metaData: Array = []; private infoData: Array = []; private metaTableEl: LitTable | undefined; private infoTableEl: LitTable | undefined; private th: HTMLElement | undefined; private backgroundMetaTable: HTMLDivElement | undefined; private backgroundInfoTable: HTMLDivElement | undefined; private progressLoad: LitProgressBar | undefined; static get observedAttributes() { return [] } initElements(): void { this.progressLoad = this.shadowRoot?.querySelector(".load-metric") as LitProgressBar; this.metaTableEl = this.shadowRoot!.querySelector('#metaData-table') as LitTable; this.infoTableEl = this.shadowRoot!.querySelector('#stats-table') as LitTable; this.infoTableEl.style.overflow = 'visible' this.metaTableEl.style.overflow = 'visible' this.infoTableEl.style.width = 'auto' this.metaTableEl.style.width = 'auto' this.th = this.shadowRoot!.querySelector('.th') as HTMLElement; } initInfoAndStatsData() { this.progressLoad!.loading = true let time = new Date().getTime(); this.initMetricItemData().then(() => { let durTime = new Date().getTime() - time; info("InfoAndStatsData query time is: " + durTime + "ms") if (this.metaData.length > 0) { this.metaTableEl!.recycleDataSource = this.metaData; } else { this.metaTableEl!.recycleDataSource = []; } new ResizeObserver(() => { if (this.parentElement?.clientHeight != 0) { this.metaTableEl!.style.height = '100%' this.metaTableEl!.reMeauseHeight() } }).observe(this.parentElement!) info("metaData(metric) size is: ", this.metaData.length) if (this.infoData.length > 0) { this.infoTableEl!.recycleDataSource = this.infoData; } else { this.infoTableEl!.recycleDataSource = [] } new ResizeObserver(() => { if (this.parentElement?.clientHeight != 0) { this.infoTableEl!.reMeauseHeight() } }).observe(this.parentElement!) info("infoData(metric) size is: ", this.infoData.length) let metaDataStyle: HTMLDivElement | undefined | null = this.shadowRoot?.querySelector('#metaData-table')?.shadowRoot?.querySelector('div.body') as HTMLDivElement let metaDataHeadStyle: HTMLDivElement | undefined | null = this.shadowRoot?.querySelector('#metaData-table')?.shadowRoot?.querySelector('div.thead') as HTMLDivElement let statsStyle: HTMLDivElement | undefined | null = this.shadowRoot?.querySelector('#stats-table')?.shadowRoot?.querySelector('div.body') as HTMLDivElement let statsHeadStyle: HTMLDivElement | undefined | null = this.shadowRoot?.querySelector('#stats-table')?.shadowRoot?.querySelector('div.thead') as HTMLDivElement setTimeout(()=>{ this.initDataTableStyle(metaDataStyle!); this.initDataTableStyle(metaDataHeadStyle!); this.initDataTableStyle(statsStyle!); this.initDataTableStyle(statsHeadStyle!); }, 20) this.progressLoad!.loading = false }); } initDataTableStyle(styleTable: HTMLDivElement): void { for (let index = 0; index < styleTable.children.length; index++) { // @ts-ignore styleTable.children[index].style.backgroundColor = 'var(--dark-background5,#F6F6F6)' } this.metaTableEl!.style.height = 'auto' this.metaTableEl!.style.minHeight = '80%' this.metaTableEl!.style.borderRadius = '16' this.infoTableEl!.style.height = 'auto' this.infoTableEl!.style.minHeight = '80%' this.infoTableEl!.style.borderRadius = '16' } async initMetricItemData() { this.metaData = [] this.infoData = [] let mete = await queryTraceMetaData(); if (mete) { for (let index = 0; index < mete.length; index++) { this.metaData.push({name: mete[index].name, value: mete[index].valueText}) } } let info = await querySelectTraceStats(); if (info) { for (let index = 0; index < info.length; index++) { this.infoData.push({ event_name: info[index].event_name, stat_type: info[index].stat_type, count: info[index].count }) } } } connectedCallback() { } disconnectedCallback() { } attributeChangedCallback(name: string, oldValue: string, newValue: string) { } initHtml(): string { return `
`; } } export class MetaDataTable { name: string | undefined; value: string | undefined; type?: string | undefined; } export class InfoDataTable { event_name: string | undefined; stat_type: string | undefined; count: number | undefined; source?: string | undefined; serverity?: string | undefined; }