1/* 2 * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development 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 { TrashUserFileDataItem } from '../base/TrashUserFileDataItem'; 17import { Log } from '../utils/Log'; 18import { ItemDataSource } from '../common/ItemDataSource'; 19import { MenuContext } from './MenuContext' 20import { ProcessMenuOperation } from './ProcessMenuOperation'; 21import { BroadcastConstants } from '../constants/BroadcastConstants'; 22 23const TAG = 'BatchRecoverMenuOperation'; 24 25export class BatchRecoverMenuOperation extends ProcessMenuOperation { 26 constructor(menuContext: MenuContext) { 27 super(menuContext); 28 } 29 30 doAction(): void { 31 Log.info(TAG, 'delete doAction'); 32 if (this.menuContext == null) { 33 Log.warn(TAG, 'menuContext is null, return'); 34 return; 35 } 36 37 let dataSource: ItemDataSource = this.menuContext.dataSource; 38 if (dataSource == null) { 39 this.count = this.menuContext.items.length; 40 } else { 41 this.count = dataSource.getSelectedCount(); 42 } 43 if (this.count <= 0) { 44 Log.warn(TAG, 'count <= 0, return'); 45 return; 46 } 47 48 this.onOperationEnd = this.menuContext.onOperationEnd; 49 let onOperationStart = this.menuContext.onOperationStart; 50 if (onOperationStart != null) onOperationStart(); 51 52 this.menuContext.broadCast.emit(BroadcastConstants.DELETE_PROGRESS_DIALOG, 53 [$r('app.string.action_recover'), this.count]); 54 55 if (dataSource == null) { 56 this.items = this.menuContext.items; 57 } else { 58 this.items = dataSource.getSelectedItems(); 59 } 60 this.processOperation(); 61 } 62 63 // Delete a batch of data 64 requestOneBatchOperation(): void { 65 let item = this.items[this.currentBatch] as TrashUserFileDataItem; 66 item.onRecover().then<void, void>((): void => { 67 this.currentBatch++; 68 this.menuContext.broadCast.emit(BroadcastConstants.UPDATE_PROGRESS, [this.getExpectProgress(), this.currentBatch]); 69 this.cyclicOperation(); 70 }) 71 } 72} 73