move operation added

This commit is contained in:
Lucio Lelii 2023-02-26 13:10:00 +01:00
parent e5b9f99b56
commit cb74165073
6 changed files with 133 additions and 29 deletions

View File

@ -1,11 +1,12 @@
import { Action } from "./action"; import { Action } from "./action";
import { CopyAction } from "./copy-item"; import { CopyAction } from "./copy-item";
import { DeleteAction } from "./delete-item"; import { DeleteAction } from "./delete-item";
import { MoveAction } from "./move-item";
import { RenameAction } from "./rename-item"; import { RenameAction } from "./rename-item";
export class Actions { 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[] { public static getActionsPerType(type: string): Action[] {
/*switch (type) { /*switch (type) {
case 'SharedFolder': case 'SharedFolder':

View File

@ -1,4 +1,4 @@
import { AlertOptions, ModalOptions } from "@ionic/angular"; import { ModalOptions } from "@ionic/angular";
import { Observable } from "rxjs"; import { Observable } from "rxjs";
import { StoragehubService } from "src/app/storagehub.service"; import { StoragehubService } from "src/app/storagehub.service";
import { WsViewerComponent } from "src/app/ws-viewer/ws-viewer.component"; import { WsViewerComponent } from "src/app/ws-viewer/ws-viewer.component";
@ -8,19 +8,26 @@ import { Action } from "./action";
export class CopyAction extends 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 { return {
component: WsViewerComponent, component: WsViewerComponent,
componentProps: { componentProps: {
finishLabel: "Copy here", 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> { actionHandler(data: {item: WSItem, destinationItem : WSItem}, storagehub: StoragehubService): Observable<any> {
return storagehub.renameItem(data.item.item.id, data.newName); return storagehub.copyItem(data.destinationItem.item.id, data.item.item.id, data.item.item.name);
} }
getName(): string { getName(): string {

View File

@ -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;
}
}

View File

@ -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) { error(error: HttpErrorResponse) {
let errorMessage = ''; let errorMessage = '';
if (error.error instanceof ErrorEvent) { if (error.error instanceof ErrorEvent) {

View File

@ -1,29 +1,39 @@
<ion-header> <ion-header>
<ion-toolbar> <ion-toolbar>
<ion-buttons slot="start"> <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-buttons>
<ion-title class="ion-text-center">{{ title }}</ion-title> <ion-title class="ion-text-center">{{ title }}</ion-title>
</ion-toolbar> </ion-toolbar>
</ion-header> </ion-header>
<ion-content class="ion-padding"> <ion-content class="ion-padding">
<ion-text color="medium" *ngIf="items.length == 0" class="ion-padding ion-text-center"> <ion-progress-bar *ngIf="!items; else showItems" type="indeterminate"></ion-progress-bar>
<p>Empty folder</p> <ng-template #showItems>
</ion-text> <p *ngIf="!anchestors"></p>
<ion-list> <p *ngIf="anchestors">
<ion-item *ngFor="let i of items" (click)="itemClicked(i)" [disabled]="!i.isFolder()"> <ion-buttons slot="start">
<mat-icon slot="start">{{ i.getIconInfo() }}</mat-icon> <ion-button (click)="backClicked()"><mat-icon>arrow_back_ios</mat-icon></ion-button>
<ion-label text-wrap> <ion-title class="ion-text-center">{{ currentItem?.getTitle() }}</ion-title>
{{ i.getTitle() }} </ion-buttons>
</ion-label> </p>
<mat-icon *ngIf="i.isFolder()" slot="end">keyboard_arrow_right</mat-icon> <ion-text color="medium" *ngIf="items?.length == 0" class="ion-padding ion-text-center">
</ion-item> <p>Empty folder</p>
</ion-list> </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-content>
<ion-footer> <ion-footer>
<ion-toolbar> <ion-toolbar>
<ion-buttons slot="end"> <ion-buttons slot="end">
<ion-button (click)="confirm()">{{ finishLabel }}</ion-button> <ion-button [disabled]="!items || !isCurrentItemSelectable()" (click)="confirm()">{{ finishLabel }}</ion-button>
</ion-buttons> </ion-buttons>
</ion-toolbar> </ion-toolbar>
</ion-footer> </ion-footer>

View File

@ -1,7 +1,7 @@
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { Component, Input, OnInit } from '@angular/core'; import { Component, Input, OnInit } from '@angular/core';
import { MatIconModule } from '@angular/material/icon'; 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 { WSItem } from '../model/ws-item';
import { StoragehubService } from '../storagehub.service'; import { StoragehubService } from '../storagehub.service';
@ -17,20 +17,27 @@ import { StoragehubService } from '../storagehub.service';
}) })
export class WsViewerComponent implements OnInit { 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() finishLabel: string = "Confirm";
@Input() title: string = "Operation"; @Input() title: string = "Operation";
@Input() onSelected :Function = () => {};
currentItem: WSItem | undefined; currentItem: WSItem | undefined;
items: WSItem[] = [] anchestors: WSItem[] | undefined ;
items: WSItem[] | undefined = undefined;
ngOnInit() { ngOnInit() {
this.loadDocuments(); this.loadDocuments();
} }
loadDocuments() { loadDocuments() {
if (this.currentItem) { if (this.currentItem) {
this.storagehub.getChildren(this.currentItem.item.id).subscribe( this.storagehub.getChildren(this.currentItem.item.id).subscribe(
@ -43,7 +50,6 @@ export class WsViewerComponent implements OnInit {
this.storagehub.getWsRoot().subscribe( this.storagehub.getWsRoot().subscribe(
(res) => this.addVresToWs(new WSItem(res)) (res) => this.addVresToWs(new WSItem(res))
); );
} }
addVresToWs(wsRoot: WSItem) { 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) { itemClicked(item: WSItem) {
this.items = undefined;
if (this.currentItem)
this.anchestors?.push(this.currentItem);
else this.anchestors =[]
this.currentItem = item; this.currentItem = item;
this.ngOnInit(); 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() { cancel() {
return this.modalCtrl.dismiss(null, 'cancel'); return this.modalCtrl.dismiss(null, 'cancel');
} }
confirm() { confirm() {
this.onSelected(this.currentItem);
return this.modalCtrl.dismiss(null, 'confirm'); return this.modalCtrl.dismiss(null, 'confirm');
} }
sort(item1: WSItem, item2: WSItem) { sort(item1: WSItem, item2: WSItem) {
if (item1.isFolder() && !item2.isFolder()) return -1; if (item1.isFolder() && !item2.isFolder()) return -1;
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; return 0;
} }
} }