/* * 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 {LitTable} from "../../../../../base-ui/table/lit-table.js"; import {SelectionParam} from "../../../../bean/BoxSelection.js"; import "../../../../../base-ui/slicer/lit-slicer.js"; import {LitProgressBar} from "../../../../../base-ui/progress-bar/LitProgressBar.js"; import {procedurePool} from "../../../../database/Procedure.js"; import {FileSysEvent} from "../../../../database/logic-worker/ProcedureLogicWorkerFileSystem.js"; import {FilterData, TabPaneFilter} from "../TabPaneFilter.js"; import "../TabPaneFilter.js"; @element('tabpane-filesystem-event') export class TabPaneFileSystemEvents extends BaseElement { private tbl: LitTable | null | undefined; private tblData: LitTable | null | undefined; private progressEL:LitProgressBar | null | undefined; private filter: TabPaneFilter | null | undefined; private loadingList:number[] = [] private loadingPage:any; private source: Array = []; private filterSource: Array = []; private sortKey: string = "startTs"; private sortType: number = 0; private currentSelection: SelectionParam | undefined | null private filterEventType: string = "0"; private filterProcess: string = "0"; private eventList:string[] | null |undefined; private processList:string[] | null |undefined; set data(val: SelectionParam | null | undefined) { if (val == this.currentSelection) { return } this.currentSelection = val // @ts-ignore this.tbl?.shadowRoot.querySelector(".table").style.height = (this.parentElement.clientHeight - 20 - 31) + "px" // @ts-ignore this.tblData?.shadowRoot.querySelector(".table").style.height = (this.parentElement.clientHeight - 20 - 31) + "px" this.tbl!.recycleDataSource = []; this.tblData!.recycleDataSource = []; if (val) { this.loadingList.push(1) this.progressEL!.loading = true this.loadingPage.style.visibility = "visible" this.source = []; procedurePool.submitWithName("logic0","fileSystem-queryFileSysEvents", {leftNs:val.leftNs,rightNs:val.rightNs,typeArr:val.fileSystemType,tab:"events"},undefined,(res:any)=>{ this.source = this.source.concat(res.data) res.data = null; if(!res.isSending){ this.tbl!.recycleDataSource = this.source; this.filterSource = this.source; this.setProcessFilter(); this.loadingList.splice(0,1) if(this.loadingList.length == 0) { this.progressEL!.loading = false this.loadingPage.style.visibility = "hidden" } } }) } } setProcessFilter(){ this.processList = ["All Process"]; this.source.map(it => { if(this.processList!.findIndex(a => a === it.process) == -1){ this.processList!.push(it.process); } }) this.filter!.setSelectList(this.eventList,this.processList,"",""); this.filter!.firstSelect = "0"; this.filter!.secondSelect = "0"; } filterData(){ let pfv = parseInt(this.filterProcess) if(this.filterEventType == "0"){ this.filterSource = pfv === 0 ? this.source : this.source.filter((it) => it.process === this.processList![pfv]); }else{ let eventType = parseInt(this.filterEventType) - 1 this.filterSource = this.source.filter((it) => it.type == eventType && ( pfv === 0 ? true : it.process === this.processList![pfv])); } this.tblData!.recycleDataSource = []; this.sortTable(this.sortKey,this.sortType); } initElements(): void { this.loadingPage = this.shadowRoot?.querySelector('.loading'); this.progressEL = this.shadowRoot?.querySelector('.progress') as LitProgressBar; this.tbl = this.shadowRoot?.querySelector('#tbl'); this.tblData = this.shadowRoot?.querySelector('#tbr'); this.tbl!.addEventListener('row-click', (e) => { // @ts-ignore let data = (e.detail.data as FileSysEvent); (data as any).isSelected = true; // @ts-ignore if ((e.detail as any).callBack) { // @ts-ignore (e.detail as any).callBack(true) } procedurePool.submitWithName("logic0","fileSystem-queryStack", { callchainId : data.callchainId },undefined,(res:any)=>{ this.tblData!.recycleDataSource = res; }) }); this.tbl!.addEventListener('column-click', (evt) => { // @ts-ignore this.sortKey = evt.detail.key // @ts-ignore this.sortType = evt.detail.sort // @ts-ignore this.sortTable(evt.detail.key,evt.detail.sort) }) this.filter = this.shadowRoot?.querySelector("#filter"); this.eventList = ['All Event','All Open Event','All Close Event','All Read Event','All Write Event']; this.processList = ['All Process']; this.filter!.setSelectList(this.eventList,this.processList,"",""); this.filter!.firstSelect = "0"; this.filter!.getFilterData((data: FilterData) => { this.filterEventType = data.firstSelect || "0"; this.filterProcess = data.secondSelect || "0"; this.filterData(); }) } connectedCallback() { super.connectedCallback(); new ResizeObserver((entries) => { if (this.parentElement?.clientHeight != 0) { // @ts-ignore this.tbl?.shadowRoot.querySelector(".table").style.height = (this.parentElement.clientHeight) - 10 - 33 + "px"; this.tbl?.reMeauseHeight(); // @ts-ignore this.tblData?.shadowRoot.querySelector(".table").style.height = (this.parentElement.clientHeight) - 10 -33 + "px" this.tblData?.reMeauseHeight() this.loadingPage.style.height = (this.parentElement!.clientHeight - 24) + "px" } }).observe(this.parentElement!); } sortTable(key: string,type:number){ if(type == 0){ this.tbl!.recycleDataSource = this.filterSource }else{ let arr = Array.from(this.filterSource) arr.sort((a,b):number=>{ if(key == "startTsStr"){ if(type == 1){ return a.startTs - b.startTs ; }else{ return b.startTs - a.startTs ; } }else if(key == "durStr"){ if(type == 1){ return a.dur - b.dur ; }else{ return b.dur - a.dur ; } }else if(key == "process"){ if (a.process > b.process) { return type === 2 ? 1 : -1; } else if (a.process == b.process) { return 0; } else { return type === 2 ? -1 : 1; } }else if(key == "thread"){ if (a.thread > b.thread) { return type === 2 ? 1 : -1; } else if (a.thread == b.thread) { return 0; } else { return type === 2 ? -1 : 1; } } else if(key == "typeStr"){ if (a.typeStr > b.typeStr) { return type === 2 ? 1 : -1; } else if (a.typeStr == b.typeStr) { return 0; } else { return type === 2 ? -1 : 1; } } else{ return 0; } }) this.tbl!.recycleDataSource = arr; } } initHtml(): string { return `
`; } }