From 180ff3a9b49e3c4c6787a99f896184ee7dec65e4 Mon Sep 17 00:00:00 2001 From: ElonH Date: Mon, 1 Jun 2020 17:42:28 +0800 Subject: [PATCH] fix(manager): paste only trigger copy and move, not include delete --- .../manager/clipboard/clipboard.service.ts | 10 ++++++-- src/app/pages/manager/manager.component.ts | 2 +- src/app/pages/manager/tasks/task.service.ts | 23 +++++++++++-------- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/app/pages/manager/clipboard/clipboard.service.ts b/src/app/pages/manager/clipboard/clipboard.service.ts index 1854b4d..5fdb542 100644 --- a/src/app/pages/manager/clipboard/clipboard.service.ts +++ b/src/app/pages/manager/clipboard/clipboard.service.ts @@ -62,8 +62,14 @@ export class Clipboard { return this.data.size; } - public clear() { - this.data.clear(); + public clear(...opers: IManipulate[]) { + if (opers.length === 0) this.data.clear(); + else + this.values + .filter((x) => opers.some((y) => x.oper === y)) + .forEach((x) => { + this.data.delete(x.key); + }); } public static genKey(remote: string, path: string) { diff --git a/src/app/pages/manager/manager.component.ts b/src/app/pages/manager/manager.component.ts index 0b71a7d..f720546 100644 --- a/src/app/pages/manager/manager.component.ts +++ b/src/app/pages/manager/manager.component.ts @@ -250,7 +250,7 @@ export class ManagerComponent implements OnInit { private pasteDeploy() { this.pasteTrigger.pipe(withLatestFrom(this.nav$.getOutput())).subscribe(([, dstNode]) => { if (dstNode[1].length !== 0) throw Error("can't not get destination."); - this.taskService.createTask(dstNode[0]); + this.taskService.createTask(dstNode[0], 'copy', 'move'); }); } diff --git a/src/app/pages/manager/tasks/task.service.ts b/src/app/pages/manager/tasks/task.service.ts index 2288536..5bcd8fc 100644 --- a/src/app/pages/manager/tasks/task.service.ts +++ b/src/app/pages/manager/tasks/task.service.ts @@ -6,7 +6,12 @@ import { OperationsMovefileFlow, OperationsMovefileFlowInNode, } from 'src/app/@dataflow/rclone'; -import { ClipboardService, Clipboard, ClipboardItem } from '../clipboard/clipboard.service'; +import { + ClipboardService, + Clipboard, + ClipboardItem, + IManipulate, +} from '../clipboard/clipboard.service'; import { Subject, from, Observable } from 'rxjs'; import { withLatestFrom, @@ -33,20 +38,20 @@ export abstract class TasksPoolFlow extends NothingFlow {} providedIn: 'root', }) export class TaskService { - private createTrigger = new Subject(); - public createTask(dst: NavigationFlowOutNode) { - this.createTrigger.next(dst); + private createTrigger = new Subject<[NavigationFlowOutNode, IManipulate[]]>(); + public createTask(dst: NavigationFlowOutNode, ...opers: IManipulate[]) { + this.createTrigger.next([dst, opers]); } private deployCreate() { this.createTrigger .pipe(withLatestFrom(this.cbService.clipboard$.getOutput())) - .subscribe(([dst, cbNode]) => { + .subscribe(([[dst, opers], cbNode]) => { if (cbNode[1].length !== 0) return; - cbNode[0].clipboard.values.forEach((x) => - this.tasksPool.add(x.oper, x.srcRemote, x.srcItem, dst) - ); - this.cbService.clear(); + cbNode[0].clipboard.values + .filter((x) => opers.some((y) => y === x.oper)) + .forEach((x) => this.tasksPool.add(x.oper, x.srcRemote, x.srcItem, dst)); + this.cbService.clear(...opers); this.cbService.commit(); this.postTrigger.next(1); });