rename action added
This commit is contained in:
parent
3d90d19358
commit
3d40c43cc5
|
@ -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':
|
||||
|
|
|
@ -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)" />
|
||||
|
|
|
@ -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';
|
||||
|
||||
|
@ -28,35 +28,38 @@ export class ShowFolderComponent implements OnInit {
|
|||
@Output() folderClickedEvent = new EventEmitter<WSItem>();
|
||||
|
||||
@Input() items: WSItem[] = [];
|
||||
|
||||
|
||||
@Input() parentItem: WSItem | undefined;
|
||||
|
||||
@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 {
|
||||
}
|
||||
|
||||
|
||||
|
||||
loadDocuments() {
|
||||
console.log("loadDoc called");
|
||||
if (this.parentItem)
|
||||
this.storagehub.getChildren(this.parentItem.item.id, false).subscribe(
|
||||
if (this.parentItem) {
|
||||
console.log("loadDoc called");
|
||||
this.storagehub.getChildren(this.parentItem.item.id).subscribe(
|
||||
(res) => {
|
||||
const tmpItems$ : WSItem[] = []
|
||||
const tmpItems$ : WSItem[] = []
|
||||
res.forEach(i => tmpItems$.push(new WSItem(i)));
|
||||
this.items = tmpItems$;
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
itemClicked(item: WSItem) {
|
||||
if (item.isFolder()) {
|
||||
this.folderClickedEvent.emit(item);
|
||||
|
@ -112,8 +115,8 @@ export class ShowFolderComponent implements OnInit {
|
|||
}
|
||||
|
||||
async presentActionSheet(item: WSItem) {
|
||||
var buttons :ActionSheetButton<any>[] = [];
|
||||
Actions.getActionsPerType(item.type).forEach( action => buttons.push({
|
||||
var buttons: ActionSheetButton<any>[] = [];
|
||||
Actions.getActionsPerType(item.type).forEach(action => buttons.push({
|
||||
text: action.getName(),
|
||||
data: {
|
||||
action: action.getName(),
|
||||
|
@ -121,7 +124,7 @@ export class ShowFolderComponent implements OnInit {
|
|||
role: action.getActionType(),
|
||||
handler: () => this.actionHandler(action, item)
|
||||
}));
|
||||
|
||||
|
||||
buttons.push({
|
||||
text: 'Cancel',
|
||||
role: 'cancel',
|
||||
|
@ -131,7 +134,7 @@ export class ShowFolderComponent implements OnInit {
|
|||
});
|
||||
|
||||
const actionSheet = await this.actionSheetCtrl.create({
|
||||
|
||||
|
||||
header: `${item.item.title}`,
|
||||
mode: 'ios',
|
||||
translucent: true,
|
||||
|
@ -143,18 +146,18 @@ export class ShowFolderComponent implements OnInit {
|
|||
const result = await actionSheet.onDidDismiss();
|
||||
}
|
||||
|
||||
async presentAlertControl(options: AlertOptions){
|
||||
async presentAlertControl(options: AlertOptions) {
|
||||
let alert = await this.alertCtrl.create(options);
|
||||
await alert.present();
|
||||
}
|
||||
|
||||
async actionHandler(action: Action, item: WSItem){
|
||||
var options: AlertOptions = action.getAlertOptions(item, this.storagehub, () => {this.loadDocuments()});
|
||||
if (options){
|
||||
await this.presentAlertControl(options);
|
||||
}else
|
||||
action.actionHandler(item, this.storagehub);
|
||||
|
||||
async actionHandler(action: Action, item: WSItem) {
|
||||
var options: AlertOptions = action.getAlertOptions(item, this.storagehub, () => { this.loadDocuments() });
|
||||
if (options) {
|
||||
await this.presentAlertControl(options);
|
||||
} else
|
||||
action.actionHandler(item, this.storagehub);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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>
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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) => {
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue