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.js'; 17import { LitTable } from '../../../../../base-ui/table/lit-table.js'; 18import { MemoryConfig } from '../../../../bean/MemoryConfig.js'; 19import { SelectionParam } from '../../../../bean/BoxSelection.js'; 20import { queryProcessPurgeableSelectionTab, querySysPurgeableSelectionTab } from '../../../../database/SqlLite.js'; 21import { ns2s } from '../../../../database/ui-worker/ProcedureWorkerCommon.js'; 22import { Utils } from '../../base/Utils.js'; 23import { resizeObserver } from '../SheetUtils.js'; 24 25@element('tabpane-purg-pin-selection') 26export class TabPanePurgPinSelection extends BaseElement { 27 private purgeableSelectionTable: LitTable | null | undefined; 28 private purgeableSelectionSource: Array<any> = []; 29 30 set data(selection: SelectionParam | any) { 31 if (selection && selection.type) { 32 this.queryTableData(selection.type, selection.startNs); 33 } 34 } 35 36 async queryTableData(type: string, startNs: number) { 37 if (type === 'ability') { 38 await querySysPurgeableSelectionTab(startNs, true).then((purgePinSelectResults) => { 39 this.purgeableSelectionSource = []; 40 this.purgeableSelectionSource.push({ name: 'TimeStamp', value: ns2s(startNs) }); 41 for (let i = 0; i < purgePinSelectResults.length; i++) { 42 purgePinSelectResults[i].value = Utils.getBinaryByteWithUnit(purgePinSelectResults[i].value); 43 this.purgeableSelectionSource.push(purgePinSelectResults[i]); 44 this.purgeableSelectionTable!.recycleDataSource = this.purgeableSelectionSource; 45 } 46 }); 47 } else if (type === 'VM') { 48 await queryProcessPurgeableSelectionTab(startNs, MemoryConfig.getInstance().iPid, true).then((results) => { 49 this.purgeableSelectionSource = []; 50 this.purgeableSelectionSource.push({ name: 'TimeStamp', value: ns2s(startNs) }); 51 for (let i = 0; i < results.length; i++) { 52 results[i].value = Utils.getBinaryByteWithUnit(results[i].value); 53 this.purgeableSelectionSource.push(results[i]); 54 this.purgeableSelectionTable!.recycleDataSource = this.purgeableSelectionSource; 55 } 56 }); 57 } 58 } 59 60 initElements(): void { 61 this.purgeableSelectionTable = this.shadowRoot?.querySelector<LitTable>('#selectionTbl'); 62 } 63 64 connectedCallback(): void { 65 super.connectedCallback(); 66 resizeObserver(this.parentElement!, this.purgeableSelectionTable!); 67 } 68 69 initHtml(): string { 70 return ` 71 <style> 72 :host{ 73 display: flex; 74 flex-direction: column; 75 padding: 10px 10px; 76 } 77 </style> 78 <lit-table id="selectionTbl" no-head> 79 <lit-table-column title="name" data-index="name" key="name" align="flex-start" width="180px"> 80 <template><div>{{name}}</div></template> 81 </lit-table-column> 82 <lit-table-column title="value" data-index="value" key="value" align="flex-start" > 83 <template><div style="display: flex;">{{value}}</div></template> 84 </lit-table-column> 85 </lit-table> 86 `; 87 } 88} 89