rename action added

This commit is contained in:
Lucio Lelii 2023-02-25 12:53:05 +01:00
parent 3d90d19358
commit 3d40c43cc5
9 changed files with 95 additions and 37 deletions

View File

@ -14,8 +14,6 @@ export interface Action {
getName(): string;
getActionType(): string | undefined;
mustReload(): boolean;
}
export class DeleteAction implements Action {
@ -32,7 +30,7 @@ export class DeleteAction implements Action {
text: 'Yes',
handler: () => {
this.actionHandler(item, storagehub).subscribe(
reload()
() => reload()
);
}
}]
@ -51,14 +49,55 @@ export class DeleteAction implements Action {
return "destructive";
}
mustReload(): boolean {
return true;
}
export class RenameAction implements Action {
getAlertOptions(item: WSItem, storagehub: StoragehubService, reload: Function): AlertOptions {
var title = item.getTitle();
var options: AlertOptions = {
header: 'Rename Item',
message: 'Please specify the new name',
inputs: [
{
name: 'name',
type: 'text',
placeholder: item.getTitle()
}
],
buttons: [
{
text: 'Cancel',
role: 'cancel'
},
{
text: 'Rename',
handler: (data) => {
this.actionHandler({item: item, newName: data.name}, storagehub).subscribe(
() => reload()
);
}
}
]
};
return options;
}
actionHandler(data: {item: WSItem, newName : string}, storagehub: StoragehubService): Observable<any> {
return storagehub.renameItem(data.item.item.id, data.newName);
}
getName(): string {
return "Rename";
}
getActionType(): string | undefined {
return undefined;
}
}
export class Actions {
private static actions: Action[] = [new DeleteAction()];
private static actions: Action[] = [new DeleteAction(), new RenameAction()];
public static getActionsPerType(type: string): Action[] {
/*switch (type) {
case 'SharedFolder':

View File

@ -1,11 +1,11 @@
<ion-content class="padding">
<ion-toolbar>
<ion-buttons slot="start" *ngIf="parentItem">
<ion-back-button text="" defaultHref="/tabs/ws">
<ion-buttons slot="start" *ngIf="!root">
<ion-back-button text="" defaultHref="/">
<mat-icon>arrow_back_ios_new</mat-icon>
</ion-back-button>
</ion-buttons>
<ion-title> {{ parentItem ? parentItem.getTitle() : tabName }} </ion-title>
<ion-title> {{ !root && parentItem ? parentItem.getTitle() : tabName }} </ion-title>
</ion-toolbar>
<input hidden type="file" #filepicker (change)="fileSelected($event)" />

View File

@ -1,4 +1,4 @@
import { Component, OnInit, Input, CUSTOM_ELEMENTS_SCHEMA, Output, EventEmitter, ElementRef, ViewChild } from '@angular/core';
import { Component, OnInit, Input, CUSTOM_ELEMENTS_SCHEMA, Output, EventEmitter, ElementRef, ViewChild, ChangeDetectorRef } from '@angular/core';
import { Platform, AlertController, ToastController, IonicModule, ActionSheetController, ActionSheetButton, AlertOptions } from '@ionic/angular';
@ -33,12 +33,15 @@ export class ShowFolderComponent implements OnInit {
@Input() tabName: string = "";
@Input() root: boolean = false;
@ViewChild('filepicker') uploader!: ElementRef;
constructor(
private actionSheetCtrl: ActionSheetController,
private storagehub: StoragehubService,
private alertCtrl: AlertController
private alertCtrl: AlertController,
private ref: ChangeDetectorRef
) { }
ngOnInit(): void {
@ -46,15 +49,15 @@ export class ShowFolderComponent implements OnInit {
loadDocuments() {
if (this.parentItem) {
console.log("loadDoc called");
if (this.parentItem)
this.storagehub.getChildren(this.parentItem.item.id, false).subscribe(
this.storagehub.getChildren(this.parentItem.item.id).subscribe(
(res) => {
const tmpItems$ : WSItem[] = []
res.forEach(i => tmpItems$.push(new WSItem(i)));
this.items = tmpItems$;
})
}
)
}
itemClicked(item: WSItem) {

View File

@ -92,12 +92,19 @@ export class StoragehubService {
deleteItem(itemId: string) : Observable<any> {
let deleteItemUrl = `${shURL}/items/${itemId}?gcube-token=${token}`;
console.log("delete item done with url "+deleteItemUrl);
return this.http.delete( deleteItemUrl).pipe(
catchError(this.error)
);
}
renameItem(itemId: string, newName: string) : Observable<any> {
let renameItemUrl = `${shURL}/items/${itemId}/rename?gcube-token=${token}`;
let body = `newName=${newName}`;
return this.http.put(renameItemUrl,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) {

View File

@ -1,4 +1,4 @@
<ion-content [fullscreen]="true">
<show-folder tabName="Trash" [items]="getValues()"></show-folder>
<show-folder tabName="Trash" [items]="getValues()" [root]="true"></show-folder>
</ion-content>

View File

@ -1,3 +1,3 @@
<ion-content [fullscreen]="true">
<show-folder [items]="getValues()" tabName="My VREs" [parentItem]="getCurrentItem()" (folderClickedEvent)="openFolder($event)"></show-folder>
<show-folder [items]="getValues()" tabName="My VREs" [parentItem]="getCurrentItem()" (folderClickedEvent)="openFolder($event)" [root]="root"></show-folder>
</ion-content>

View File

@ -18,6 +18,8 @@ export class VresPage implements OnInit {
folderid: string | undefined;
root: boolean = false;
constructor(private storagehub: StoragehubService,
private router: Router,
private route: ActivatedRoute) { }
@ -25,6 +27,7 @@ export class VresPage implements OnInit {
ngOnInit() {
this.folderid = this.route.snapshot.paramMap.get('folderid') || undefined;
this.root = !this.folderid;
if (!this.folderid)
this.storagehub.getVres().subscribe(
(res) => {

View File

@ -1,5 +1,5 @@
<ion-content [fullscreen]="true">
<show-folder tabName="My Workspace" [items]="getValues()" [parentItem]="getCurrentItem()" (folderClickedEvent)="openFolder($event)"></show-folder>
<show-folder tabName="My Workspace" [items]="getValues()" [parentItem]="getCurrentItem()" (folderClickedEvent)="openFolder($event)" [root]="root"></show-folder>
</ion-content>

View File

@ -20,15 +20,21 @@ export class WsPage implements OnInit {
item : WSItem | undefined ;
root: boolean = false;
constructor(private storagehub: StoragehubService,
private router: Router,
private route: ActivatedRoute) { }
ngOnInit() {
this.folderid = this.route.snapshot.paramMap.get('folderid') || undefined;
this.root = !this.folderid;
if (!this.folderid)
this.storagehub.getWsRoot().subscribe(
(res) => this.onSuccess(res)
(res) => {
this.item = new WSItem(res);
this.onSuccess(res)
}
);
else
this.storagehub.getItem(this.folderid).subscribe(