move operation added
This commit is contained in:
parent
e5b9f99b56
commit
cb74165073
|
@ -1,11 +1,12 @@
|
|||
import { Action } from "./action";
|
||||
import { CopyAction } from "./copy-item";
|
||||
import { DeleteAction } from "./delete-item";
|
||||
import { MoveAction } from "./move-item";
|
||||
import { RenameAction } from "./rename-item";
|
||||
|
||||
export class Actions {
|
||||
|
||||
private static actions: Action[] = [new CopyAction(),new RenameAction(), new DeleteAction()];
|
||||
private static actions: Action[] = [new MoveAction(), new CopyAction(),new RenameAction(), new DeleteAction()];
|
||||
public static getActionsPerType(type: string): Action[] {
|
||||
/*switch (type) {
|
||||
case 'SharedFolder':
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { AlertOptions, ModalOptions } from "@ionic/angular";
|
||||
import { ModalOptions } from "@ionic/angular";
|
||||
import { Observable } from "rxjs";
|
||||
import { StoragehubService } from "src/app/storagehub.service";
|
||||
import { WsViewerComponent } from "src/app/ws-viewer/ws-viewer.component";
|
||||
|
@ -8,19 +8,26 @@ import { Action } from "./action";
|
|||
export class CopyAction extends Action {
|
||||
|
||||
|
||||
override getModalOptions(item: WSItem, storagehub: StoragehubService, postOp?: Function): ModalOptions | undefined {
|
||||
override getModalOptions(item: WSItem, storagehub: StoragehubService, reload: Function): ModalOptions | undefined {
|
||||
return {
|
||||
component: WsViewerComponent,
|
||||
componentProps: {
|
||||
finishLabel: "Copy here",
|
||||
title: "Copy "+item.getTitle()
|
||||
title: "Select destination folder for "+item.getTitle(),
|
||||
notClickableIds: [item.item.id],
|
||||
notSelectableIds: [item.item.parentId],
|
||||
onSelected: (destinationItem:WSItem) =>{
|
||||
this.actionHandler({item: item, destinationItem: destinationItem}, storagehub).subscribe(
|
||||
() => reload()
|
||||
)
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
actionHandler(data: {item: WSItem, newName : string}, storagehub: StoragehubService): Observable<any> {
|
||||
return storagehub.renameItem(data.item.item.id, data.newName);
|
||||
actionHandler(data: {item: WSItem, destinationItem : WSItem}, storagehub: StoragehubService): Observable<any> {
|
||||
return storagehub.copyItem(data.destinationItem.item.id, data.item.item.id, data.item.item.name);
|
||||
}
|
||||
|
||||
getName(): string {
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
import { ModalOptions } from "@ionic/angular";
|
||||
import { Observable } from "rxjs";
|
||||
import { StoragehubService } from "src/app/storagehub.service";
|
||||
import { WsViewerComponent } from "src/app/ws-viewer/ws-viewer.component";
|
||||
import { WSItem } from "../ws-item";
|
||||
import { Action } from "./action";
|
||||
|
||||
export class MoveAction extends Action {
|
||||
|
||||
|
||||
override getModalOptions(item: WSItem, storagehub: StoragehubService, reload: Function): ModalOptions | undefined {
|
||||
return {
|
||||
component: WsViewerComponent,
|
||||
componentProps: {
|
||||
finishLabel: "Move here",
|
||||
title: "Select destination folder for "+item.getTitle(),
|
||||
notClickableIds: [item.item.id],
|
||||
notSelectableIds: [item.item.parentId],
|
||||
onSelected: (destinationItem:WSItem) =>{
|
||||
this.actionHandler({item: item, destinationItem: destinationItem}, storagehub).subscribe(
|
||||
() => reload()
|
||||
)
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
actionHandler(data: {item: WSItem, destinationItem : WSItem}, storagehub: StoragehubService): Observable<any> {
|
||||
return storagehub.moveItem(data.destinationItem.item.id, data.item.item.id);
|
||||
}
|
||||
|
||||
getName(): string {
|
||||
return "Move";
|
||||
}
|
||||
getActionType(): string | undefined {
|
||||
return undefined;
|
||||
}
|
||||
}
|
|
@ -105,6 +105,22 @@ export class StoragehubService {
|
|||
);
|
||||
}
|
||||
|
||||
copyItem(destinationId: string, itemId: string, name:string) : Observable<any> {
|
||||
let copyItemUrl = `${shURL}/items/${itemId}/copy?gcube-token=${token}`;
|
||||
let body = `destinationId=${destinationId}&fileName=${name}`;
|
||||
return this.http.put(copyItemUrl,body,{observe: 'body', responseType: 'text' ,headers: { 'Content-Type' : 'application/x-www-form-urlencoded' }}).pipe(
|
||||
catchError(this.error)
|
||||
);
|
||||
}
|
||||
|
||||
moveItem(destinationId: string, itemId: string) : Observable<any> {
|
||||
let copyItemUrl = `${shURL}/items/${itemId}/move?gcube-token=${token}`;
|
||||
let body = `destinationId=${destinationId}`;
|
||||
return this.http.put(copyItemUrl,body,{observe: 'body', responseType: 'text' ,headers: { 'Content-Type' : 'application/x-www-form-urlencoded' }}).pipe(
|
||||
catchError(this.error)
|
||||
);
|
||||
}
|
||||
|
||||
error(error: HttpErrorResponse) {
|
||||
let errorMessage = '';
|
||||
if (error.error instanceof ErrorEvent) {
|
||||
|
|
|
@ -1,29 +1,39 @@
|
|||
<ion-header>
|
||||
<ion-toolbar>
|
||||
<ion-buttons slot="start">
|
||||
<ion-button color="medium" (click)="cancel()">Cancel</ion-button>
|
||||
<ion-button (click)="cancel()"><mat-icon>close</mat-icon></ion-button>
|
||||
</ion-buttons>
|
||||
<ion-title class="ion-text-center">{{ title }}</ion-title>
|
||||
</ion-toolbar>
|
||||
</ion-header>
|
||||
<ion-content class="ion-padding">
|
||||
<ion-text color="medium" *ngIf="items.length == 0" class="ion-padding ion-text-center">
|
||||
<p>Empty folder</p>
|
||||
</ion-text>
|
||||
<ion-list>
|
||||
<ion-item *ngFor="let i of items" (click)="itemClicked(i)" [disabled]="!i.isFolder()">
|
||||
<mat-icon slot="start">{{ i.getIconInfo() }}</mat-icon>
|
||||
<ion-label text-wrap>
|
||||
{{ i.getTitle() }}
|
||||
</ion-label>
|
||||
<mat-icon *ngIf="i.isFolder()" slot="end">keyboard_arrow_right</mat-icon>
|
||||
</ion-item>
|
||||
</ion-list>
|
||||
<ion-progress-bar *ngIf="!items; else showItems" type="indeterminate"></ion-progress-bar>
|
||||
<ng-template #showItems>
|
||||
<p *ngIf="!anchestors"></p>
|
||||
<p *ngIf="anchestors">
|
||||
<ion-buttons slot="start">
|
||||
<ion-button (click)="backClicked()"><mat-icon>arrow_back_ios</mat-icon></ion-button>
|
||||
<ion-title class="ion-text-center">{{ currentItem?.getTitle() }}</ion-title>
|
||||
</ion-buttons>
|
||||
</p>
|
||||
<ion-text color="medium" *ngIf="items?.length == 0" class="ion-padding ion-text-center">
|
||||
<p>Empty folder</p>
|
||||
</ion-text>
|
||||
<ion-list>
|
||||
<ion-item *ngFor="let i of items" (click)="itemClicked(i)" [disabled]="!isItemClickable(i)">
|
||||
<mat-icon slot="start">{{ i.getIconInfo() }}</mat-icon>
|
||||
<ion-label text-wrap>
|
||||
{{ i.getTitle() }}
|
||||
</ion-label>
|
||||
<mat-icon *ngIf="i.isFolder()" slot="end">keyboard_arrow_right</mat-icon>
|
||||
</ion-item>
|
||||
</ion-list>
|
||||
</ng-template>
|
||||
</ion-content>
|
||||
<ion-footer>
|
||||
<ion-toolbar>
|
||||
<ion-buttons slot="end">
|
||||
<ion-button (click)="confirm()">{{ finishLabel }}</ion-button>
|
||||
<ion-button [disabled]="!items || !isCurrentItemSelectable()" (click)="confirm()">{{ finishLabel }}</ion-button>
|
||||
</ion-buttons>
|
||||
</ion-toolbar>
|
||||
</ion-footer>
|
|
@ -1,7 +1,7 @@
|
|||
import { CommonModule } from '@angular/common';
|
||||
import { Component, Input, OnInit } from '@angular/core';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { IonicModule, ModalController } from '@ionic/angular';
|
||||
import { IonicModule, LoadingController, ModalController } from '@ionic/angular';
|
||||
import { WSItem } from '../model/ws-item';
|
||||
import { StoragehubService } from '../storagehub.service';
|
||||
|
||||
|
@ -17,20 +17,27 @@ import { StoragehubService } from '../storagehub.service';
|
|||
})
|
||||
export class WsViewerComponent implements OnInit {
|
||||
|
||||
constructor(private storagehub: StoragehubService, private modalCtrl: ModalController) { }
|
||||
constructor(private storagehub: StoragehubService, private modalCtrl: ModalController,
|
||||
private loadingCtrl: LoadingController) { }
|
||||
|
||||
@Input() toExcludeOnOperation: string[] = [];
|
||||
@Input() notClickableIds: string[] = [];
|
||||
@Input() notSelectableIds: string[] = [];
|
||||
@Input() finishLabel: string = "Confirm";
|
||||
@Input() title: string = "Operation";
|
||||
|
||||
@Input() onSelected :Function = () => {};
|
||||
|
||||
currentItem: WSItem | undefined;
|
||||
|
||||
items: WSItem[] = []
|
||||
anchestors: WSItem[] | undefined ;
|
||||
|
||||
items: WSItem[] | undefined = undefined;
|
||||
|
||||
|
||||
ngOnInit() {
|
||||
this.loadDocuments();
|
||||
this.loadDocuments();
|
||||
}
|
||||
|
||||
|
||||
loadDocuments() {
|
||||
if (this.currentItem) {
|
||||
this.storagehub.getChildren(this.currentItem.item.id).subscribe(
|
||||
|
@ -43,7 +50,6 @@ export class WsViewerComponent implements OnInit {
|
|||
this.storagehub.getWsRoot().subscribe(
|
||||
(res) => this.addVresToWs(new WSItem(res))
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
addVresToWs(wsRoot: WSItem) {
|
||||
|
@ -55,24 +61,49 @@ export class WsViewerComponent implements OnInit {
|
|||
})
|
||||
}
|
||||
|
||||
isCurrentItemSelectable(){
|
||||
return this.currentItem && !this.notSelectableIds.includes(this.currentItem.item.id);
|
||||
}
|
||||
|
||||
isItemClickable(item: WSItem){
|
||||
return item.isFolder() && !this.notClickableIds.includes(item.item.id);
|
||||
}
|
||||
|
||||
itemClicked(item: WSItem) {
|
||||
this.items = undefined;
|
||||
if (this.currentItem)
|
||||
this.anchestors?.push(this.currentItem);
|
||||
else this.anchestors =[]
|
||||
this.currentItem = item;
|
||||
this.ngOnInit();
|
||||
}
|
||||
|
||||
backClicked() {
|
||||
this.items = undefined;
|
||||
if (this.anchestors?.length == 0){
|
||||
this.anchestors = undefined;
|
||||
this.currentItem = undefined;
|
||||
} else {
|
||||
var tmpitem = this.anchestors?.pop();
|
||||
this.currentItem = tmpitem;
|
||||
}
|
||||
this.ngOnInit();
|
||||
}
|
||||
|
||||
cancel() {
|
||||
return this.modalCtrl.dismiss(null, 'cancel');
|
||||
}
|
||||
|
||||
confirm() {
|
||||
this.onSelected(this.currentItem);
|
||||
return this.modalCtrl.dismiss(null, 'confirm');
|
||||
}
|
||||
|
||||
sort(item1: WSItem, item2: WSItem) {
|
||||
if (item1.isFolder() && !item2.isFolder()) return -1;
|
||||
if (!item1.isFolder() && item2.isFolder()) return 1;
|
||||
if (item1.item.title > item2.item.title) return -1;
|
||||
if (item1.item.title < item2.item.title) return 1;
|
||||
if (item1.item.title > item2.item.title) return 1;
|
||||
if (item1.item.title < item2.item.title) return -1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue