Skip to content

Commit

Permalink
feat(delete-file-flow): enable delete file now
Browse files Browse the repository at this point in the history
  • Loading branch information
ElonH committed Jun 1, 2020
1 parent 180ff3a commit 9cefd41
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/app/@dataflow/rclone/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export * from './operations-mkdir-flow';
export * from './async-post-flow';
export * from './operations-copyfile-flow';
export * from './operations-movefile-flow';
export * from './operations-deletefile-flow';
39 changes: 39 additions & 0 deletions src/app/@dataflow/rclone/operations-deletefile-flow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { IRcloneServer } from '../extra';
import { CombErr } from '../core';
import { AsyncPostFlow, AsyncPostFlowParamsNode } from './async-post-flow';

export interface OperationsDeletefileFlowParamsNode extends AsyncPostFlowParamsNode {
/** a remote name string eg "drive:" */
srcFs: string;
/** a path within that remote eg "dir" */
srcRemote: string;
}

export interface OperationsDeletefileFlowInNode
extends OperationsDeletefileFlowParamsNode,
IRcloneServer {}

interface OperationsDeletefileFlowInnerParamsNode extends AsyncPostFlowParamsNode {
/** a remote name string eg "drive:" */
fs: string;
/** a path within that remote eg "dir" */
remote: string;
}

export abstract class OperationsDeletefileFlow extends AsyncPostFlow<
OperationsDeletefileFlowInNode,
OperationsDeletefileFlowInnerParamsNode
> {
// public prerequest$: Observable<CombErr<OperationsDeletefileFlowInNode>>;
protected cmd: string = 'operations/deletefile';
protected params = (
pre: CombErr<OperationsDeletefileFlowInNode>
): OperationsDeletefileFlowInnerParamsNode => {
if (pre[1].length !== 0) return {} as any;
return {
fs: pre[0].srcFs,
remote: pre[0].srcRemote,
};
};
protected cacheSupport: boolean = false;
}
10 changes: 9 additions & 1 deletion src/app/pages/manager/clipboard/clipboard.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnInit } from '@angular/core';
import { Component, OnInit, Output, EventEmitter } from '@angular/core';
import { ClipboardService, IManipulate } from './clipboard.service';

@Component({
Expand All @@ -12,6 +12,12 @@ import { ClipboardService, IManipulate } from './clipboard.service';
[badgeText]="tab.len"
badgeStatus="primary"
>
<ng-container *ngIf="tab.oper === 'del'">
<button nbButton status="danger" (click)="onDeleteConfirm.emit()">
<nb-icon icon="alert-triangle"></nb-icon>
Confirm
</button>
</ng-container>
<clipboard-remotes-table [oper]="tab.oper"> </clipboard-remotes-table>
</nb-tab>
</nb-tabset>
Expand All @@ -32,4 +38,6 @@ export class ClipboardComponent implements OnInit {
this.data.forEach((x) => (x.len = node[0].clipboard.countManipulation(x.oper)));
});
}

@Output() onDeleteConfirm = new EventEmitter();
}
16 changes: 10 additions & 6 deletions src/app/pages/manager/manager.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { OperationsMkdirFlow, OperationsMkdirFlowInNode } from 'src/app/@dataflo
import { ConnectionService } from '../connection.service';
import { NbToastrService } from '@nebular/theme';
import { FileModeComponent } from './fileMode/fileMode.component';
import { ClipboardService } from './clipboard/clipboard.service';
import { ClipboardService, IManipulate } from './clipboard/clipboard.service';
import { TaskService } from './tasks/task.service';

@Component({
Expand Down Expand Up @@ -83,7 +83,7 @@ import { TaskService } from './tasks/task.service';
Clipboard
</nb-card-header>
<nb-card-body>
<manager-clipboard> </manager-clipboard>
<manager-clipboard (onDeleteConfirm)="del()"> </manager-clipboard>
</nb-card-body>
</nb-card>
</ng-template>
Expand Down Expand Up @@ -246,16 +246,20 @@ export class ManagerComponent implements OnInit {
});
}

private pasteTrigger = new Subject<number>();
private pasteTrigger = new Subject<IManipulate[]>();
private pasteDeploy() {
this.pasteTrigger.pipe(withLatestFrom(this.nav$.getOutput())).subscribe(([, dstNode]) => {
this.pasteTrigger.pipe(withLatestFrom(this.nav$.getOutput())).subscribe(([opers, dstNode]) => {
if (dstNode[1].length !== 0) throw Error("can't not get destination.");
this.taskService.createTask(dstNode[0], 'copy', 'move');
this.taskService.createTask(dstNode[0], ...opers);
});
}

paste() {
this.pasteTrigger.next(1);
this.pasteTrigger.next(['copy', 'move']);
}

del() {
this.pasteTrigger.next(['del']);
}

public orderCnt = 0;
Expand Down
36 changes: 35 additions & 1 deletion src/app/pages/manager/tasks/task.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import {
OperationsCopyfileFlowInNode,
AsyncPostFlowOutNode,
OperationsMovefileFlow,
OperationsMovefileFlowInNode,
OperationsMovefileFlowInNode,
OperationsDeletefileFlowInNode,
OperationsDeletefileFlow,
} from 'src/app/@dataflow/rclone';
import {
ClipboardService,
Expand Down Expand Up @@ -152,6 +154,37 @@ export class TaskService {
});
}

private deleteFile$: OperationsDeletefileFlow;
private deployDeleteFile() {
const outer = this;
const taskReal$ = outer.post$.pipe(filter((x) => x.oper === 'del' && !x.srcItem.IsDir));
this.deleteFile$ = new (class extends OperationsDeletefileFlow {
public prerequest$ = taskReal$.pipe(
withLatestFrom(outer.connectService.listCmd$.verify(this.cmd)),
map(
([item, cmdNode]): CombErr<OperationsDeletefileFlowInNode> => {
if (cmdNode[1].length !== 0) return [{}, cmdNode[1]] as any;
return [
{
...cmdNode[0],
srcFs: `${item.srcRemote}:`,
srcRemote: item.srcItem.Path,
},
[],
];
}
)
);
})();
this.deleteFile$.deploy();
this.deleteFile$
.getOutput()
.pipe(zip(taskReal$))
.subscribe((x) => {
this.postAfter(...x);
});
}

private detailTrigger = new Subject<number>();
public detail$: TasksPoolFlow;
private deployDetail() {
Expand Down Expand Up @@ -189,6 +222,7 @@ export class TaskService {
this.deployPost();
this.deployCopyFile();
this.deployMoveFile();
this.deployDeleteFile();
this.deployDetail();
}
}

0 comments on commit 9cefd41

Please sign in to comment.