Skip to content

Commit

Permalink
feat(mounts-manager): add button to unmount all mounts
Browse files Browse the repository at this point in the history
  • Loading branch information
ElonH committed Jul 7, 2020
1 parent 922ebab commit d736533
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/app/@dataflow/rclone/index.ts
Expand Up @@ -29,3 +29,4 @@ export * from './navigation-flow';
export * from './list-mounts-flow';
export * from './mount-mount-flow';
export * from './mount-unmount-flow';
export * from './mount-unmount-all-flow';
18 changes: 18 additions & 0 deletions src/app/@dataflow/rclone/mount-unmount-all-flow.ts
@@ -0,0 +1,18 @@
import { CombErr, FlowOutNode, AjaxFlowInteralNode } from '../core';
import { IRcloneServer, PostFlow } from './post-flow';

/**
* @description Unmount all active mounts.
* @abstract
* @class MountUnmountAllFlow
*/
export abstract class MountUnmountAllFlow extends PostFlow<IRcloneServer, FlowOutNode> {
// public prerequest$: Observable<CombErr<IRcloneServer>>;
protected cmd = 'mount/unmountall';
protected cacheSupport = false;
protected params: unknown = {};
protected reconstructAjaxResult(x: CombErr<AjaxFlowInteralNode>): CombErr<FlowOutNode> {
if (x[1].length !== 0) return x;
return [{}, []];
}
}
44 changes: 41 additions & 3 deletions src/app/pages/mounts/mounts.component.ts
Expand Up @@ -4,6 +4,7 @@ import { NbToastrService } from '@nebular/theme';
import * as moment from 'moment';
import { Observable, of, Subscription } from 'rxjs';
import { map } from 'rxjs/operators';
import { Modal } from 'ngx-modialog-7/plugins/vex';
import {
ListMountsOutItemNode,
IMountType,
Expand All @@ -17,7 +18,10 @@ import { MountsService } from './mounts.service';
<nb-card>
<nb-card-header>
Mount Point Manager
<nb-icon icon="sync" (click)="refresh()"></nb-icon>
<nb-actions class="push-to-right">
<nb-action icon="trash-2-outline" (click)="unmountAll()"></nb-action>
<nb-action icon="sync" (click)="refresh()"></nb-action>
</nb-actions>
</nb-card-header>
<nb-card-body>
<ngx-table
Expand Down Expand Up @@ -90,7 +94,7 @@ import { MountsService } from './mounts.service';
nb-card-header {
display: flex;
}
nb-card-header > nb-icon {
.push-to-right {
margin-left: auto;
}
`,
Expand All @@ -110,7 +114,11 @@ export class MountsComponent implements OnInit, OnDestroy {
MountedTimeHumanReadable: string;
})[] = [];

constructor(private mountService: MountsService, private toastr: NbToastrService) {}
constructor(
private mountService: MountsService,
private toastr: NbToastrService,
public modal: Modal
) {}

options: IMountType[];
filteredOptions$: Observable<IMountType[]>;
Expand Down Expand Up @@ -151,6 +159,22 @@ export class MountsComponent implements OnInit, OnDestroy {
this.mountService.unmount({ mountPoint: item.MountPoint });
}

unmountAll() {
this.modal
.confirm()
.className('flat-attack')
.message(`Unmount all activated mounts?`)
.isBlocking(false)
.open()
.result.then(
ok => {
if (!ok) return;
this.mountService.unmountAll();
},
() => {}
);
}

ngOnInit() {
this.configuration = { ...DefaultConfig };
this.configuration.searchEnabled = false;
Expand Down Expand Up @@ -208,6 +232,20 @@ export class MountsComponent implements OnInit, OnDestroy {
});
})
);

this.scrb.push(
this.mountService.unmountAll$.getOutput().subscribe(node => {
if (node[1].length !== 0) {
this.toastr.danger(node[1].join(' \n'), 'Unmount all mounts failure', {
icon: 'alert-triangle-outline',
});
return;
}
this.toastr.success('', 'Unmount all mounts successfully', {
icon: 'checkmark-circle-outline',
});
})
);
this.refresh();
}

Expand Down
2 changes: 2 additions & 0 deletions src/app/pages/mounts/mounts.module.ts
Expand Up @@ -8,6 +8,7 @@ import {
NbInputModule,
NbAutocompleteModule,
NbButtonModule,
NbActionsModule,
} from '@nebular/theme';
import { FormsModule } from '@angular/forms';
import { MountsRoutingModule } from './mounts-routing.module';
Expand All @@ -25,6 +26,7 @@ import { MountsComponent } from './mounts.component';
NbAutocompleteModule,
NbButtonModule,
FormsModule,
NbActionsModule,
],
})
export class MountsModule {}
20 changes: 20 additions & 0 deletions src/app/pages/mounts/mounts.service.ts
Expand Up @@ -9,6 +9,7 @@ import {
MountUnmountFlow,
MountUnmountFlowInNode,
MountUnmountFlowParamsNode,
MountUnmountAllFlow,
} from '../../@dataflow/rclone';
import { CombErr } from '../../@dataflow/core';
import { ConnectionService } from '../connection.service';
Expand All @@ -26,6 +27,9 @@ export class MountsService {
private unmountTrigger = new Subject<MountUnmountFlowParamsNode>();
unmount$: MountUnmountFlow;

private unmountAllTrigger = new Subject<number>();
unmountAll$: MountUnmountAllFlow;

constructor(private connectService: ConnectionService) {
const outer = this;
this.list$ = new (class extends ListMountsFlow {
Expand Down Expand Up @@ -58,6 +62,18 @@ export class MountsService {
if (node[1].length !== 0) return;
this.refreshList();
});

this.unmountAll$ = new (class extends MountUnmountAllFlow {
public prerequest$: Observable<CombErr<IRcloneServer>> = combineLatest(
[outer.unmountAllTrigger, outer.connectService.listCmd$.verify(this.cmd)],
(_, node) => node
);
})();
this.unmountAll$.deploy();
this.unmountAll$.getOutput().subscribe(node => {
if (node[1].length !== 0) return;
this.refreshList();
});
}
refreshList() {
this.list$.clearCache();
Expand All @@ -71,4 +87,8 @@ export class MountsService {
unmount(params: MountUnmountFlowParamsNode) {
this.unmountTrigger.next(params);
}

unmountAll() {
this.unmountAllTrigger.next(1);
}
}

0 comments on commit d736533

Please sign in to comment.