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 { SelectionParam } from '../../../../bean/BoxSelection.js'; 19import { MemoryConfig } from '../../../../bean/MemoryConfig.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-total-selection') 26export class TabPanePurgTotalSelection 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).then((purgeTotalSelectResults) => { 39 this.purgeableSelectionSource = []; 40 if (purgeTotalSelectResults.length > 0) { 41 this.purgeableSelectionSource.push({ name: 'TimeStamp', value: ns2s(startNs) }); 42 for (let i = 0; i < purgeTotalSelectResults.length; i++) { 43 purgeTotalSelectResults[i].value = Utils.getBinaryByteWithUnit(purgeTotalSelectResults[i].value); 44 this.purgeableSelectionSource.push(purgeTotalSelectResults[i]); 45 } 46 this.purgeableSelectionTable!.recycleDataSource = this.purgeableSelectionSource; 47 } 48 }); 49 } else if (type === 'VM') { 50 await queryProcessPurgeableSelectionTab(startNs, MemoryConfig.getInstance().iPid).then((results) => { 51 this.purgeableSelectionSource = []; 52 if (results.length > 0) { 53 this.purgeableSelectionSource.push({ name: 'TimeStamp', value: ns2s(startNs) }); 54 for (let i = 0; i < results.length; i++) { 55 results[i].value = Utils.getBinaryByteWithUnit(results[i].value); 56 this.purgeableSelectionSource.push(results[i]); 57 } 58 this.purgeableSelectionTable!.recycleDataSource = this.purgeableSelectionSource; 59 } 60 }); 61 } 62 } 63 64 initElements(): void { 65 this.purgeableSelectionTable = this.shadowRoot?.querySelector<LitTable>('#selectionTbl'); 66 } 67 68 connectedCallback(): void { 69 super.connectedCallback(); 70 resizeObserver(this.parentElement!, this.purgeableSelectionTable!); 71 } 72 73 initHtml(): string { 74 return ` 75 <style> 76 :host{ 77 display: flex; 78 flex-direction: column; 79 padding: 10px 10px; 80 } 81 </style> 82 <lit-table id="selectionTbl" no-head> 83 <lit-table-column title="name" data-index="name" key="name" align="flex-start" width="180px"> 84 <template><div>{{name}}</div></template> 85 </lit-table-column> 86 <lit-table-column title="value" data-index="value" key="value" align="flex-start" > 87 <template><div style="display: flex;">{{value}}</div></template> 88 </lit-table-column> 89 </lit-table> 90 `; 91 } 92} 93