rename action added
This commit is contained in:
parent
3d90d19358
commit
3d40c43cc5
|
@ -14,8 +14,6 @@ export interface Action {
|
||||||
getName(): string;
|
getName(): string;
|
||||||
|
|
||||||
getActionType(): string | undefined;
|
getActionType(): string | undefined;
|
||||||
|
|
||||||
mustReload(): boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class DeleteAction implements Action {
|
export class DeleteAction implements Action {
|
||||||
|
@ -32,7 +30,7 @@ export class DeleteAction implements Action {
|
||||||
text: 'Yes',
|
text: 'Yes',
|
||||||
handler: () => {
|
handler: () => {
|
||||||
this.actionHandler(item, storagehub).subscribe(
|
this.actionHandler(item, storagehub).subscribe(
|
||||||
reload()
|
() => reload()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
|
@ -51,14 +49,55 @@ export class DeleteAction implements Action {
|
||||||
return "destructive";
|
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 {
|
export class Actions {
|
||||||
|
|
||||||
private static actions: Action[] = [new DeleteAction()];
|
private static actions: Action[] = [new DeleteAction(), new RenameAction()];
|
||||||
public static getActionsPerType(type: string): Action[] {
|
public static getActionsPerType(type: string): Action[] {
|
||||||
/*switch (type) {
|
/*switch (type) {
|
||||||
case 'SharedFolder':
|
case 'SharedFolder':
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
<ion-content class="padding">
|
<ion-content class="padding">
|
||||||
<ion-toolbar>
|
<ion-toolbar>
|
||||||
<ion-buttons slot="start" *ngIf="parentItem">
|
<ion-buttons slot="start" *ngIf="!root">
|
||||||
<ion-back-button text="" defaultHref="/tabs/ws">
|
<ion-back-button text="" defaultHref="/">
|
||||||
<mat-icon>arrow_back_ios_new</mat-icon>
|
<mat-icon>arrow_back_ios_new</mat-icon>
|
||||||
</ion-back-button>
|
</ion-back-button>
|
||||||
</ion-buttons>
|
</ion-buttons>
|
||||||
<ion-title> {{ parentItem ? parentItem.getTitle() : tabName }} </ion-title>
|
<ion-title> {{ !root && parentItem ? parentItem.getTitle() : tabName }} </ion-title>
|
||||||
</ion-toolbar>
|
</ion-toolbar>
|
||||||
|
|
||||||
<input hidden type="file" #filepicker (change)="fileSelected($event)" />
|
<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';
|
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>();
|
@Output() folderClickedEvent = new EventEmitter<WSItem>();
|
||||||
|
|
||||||
@Input() items: WSItem[] = [];
|
@Input() items: WSItem[] = [];
|
||||||
|
|
||||||
@Input() parentItem: WSItem | undefined;
|
@Input() parentItem: WSItem | undefined;
|
||||||
|
|
||||||
@Input() tabName: string = "";
|
@Input() tabName: string = "";
|
||||||
|
|
||||||
|
@Input() root: boolean = false;
|
||||||
|
|
||||||
@ViewChild('filepicker') uploader!: ElementRef;
|
@ViewChild('filepicker') uploader!: ElementRef;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private actionSheetCtrl: ActionSheetController,
|
private actionSheetCtrl: ActionSheetController,
|
||||||
private storagehub: StoragehubService,
|
private storagehub: StoragehubService,
|
||||||
private alertCtrl: AlertController
|
private alertCtrl: AlertController,
|
||||||
|
private ref: ChangeDetectorRef
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
loadDocuments() {
|
loadDocuments() {
|
||||||
console.log("loadDoc called");
|
if (this.parentItem) {
|
||||||
if (this.parentItem)
|
console.log("loadDoc called");
|
||||||
this.storagehub.getChildren(this.parentItem.item.id, false).subscribe(
|
this.storagehub.getChildren(this.parentItem.item.id).subscribe(
|
||||||
(res) => {
|
(res) => {
|
||||||
const tmpItems$ : WSItem[] = []
|
const tmpItems$ : WSItem[] = []
|
||||||
res.forEach(i => tmpItems$.push(new WSItem(i)));
|
res.forEach(i => tmpItems$.push(new WSItem(i)));
|
||||||
this.items = tmpItems$;
|
this.items = tmpItems$;
|
||||||
}
|
})
|
||||||
)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
itemClicked(item: WSItem) {
|
itemClicked(item: WSItem) {
|
||||||
if (item.isFolder()) {
|
if (item.isFolder()) {
|
||||||
this.folderClickedEvent.emit(item);
|
this.folderClickedEvent.emit(item);
|
||||||
|
@ -112,8 +115,8 @@ export class ShowFolderComponent implements OnInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
async presentActionSheet(item: WSItem) {
|
async presentActionSheet(item: WSItem) {
|
||||||
var buttons :ActionSheetButton<any>[] = [];
|
var buttons: ActionSheetButton<any>[] = [];
|
||||||
Actions.getActionsPerType(item.type).forEach( action => buttons.push({
|
Actions.getActionsPerType(item.type).forEach(action => buttons.push({
|
||||||
text: action.getName(),
|
text: action.getName(),
|
||||||
data: {
|
data: {
|
||||||
action: action.getName(),
|
action: action.getName(),
|
||||||
|
@ -121,7 +124,7 @@ export class ShowFolderComponent implements OnInit {
|
||||||
role: action.getActionType(),
|
role: action.getActionType(),
|
||||||
handler: () => this.actionHandler(action, item)
|
handler: () => this.actionHandler(action, item)
|
||||||
}));
|
}));
|
||||||
|
|
||||||
buttons.push({
|
buttons.push({
|
||||||
text: 'Cancel',
|
text: 'Cancel',
|
||||||
role: 'cancel',
|
role: 'cancel',
|
||||||
|
@ -131,7 +134,7 @@ export class ShowFolderComponent implements OnInit {
|
||||||
});
|
});
|
||||||
|
|
||||||
const actionSheet = await this.actionSheetCtrl.create({
|
const actionSheet = await this.actionSheetCtrl.create({
|
||||||
|
|
||||||
header: `${item.item.title}`,
|
header: `${item.item.title}`,
|
||||||
mode: 'ios',
|
mode: 'ios',
|
||||||
translucent: true,
|
translucent: true,
|
||||||
|
@ -143,18 +146,18 @@ export class ShowFolderComponent implements OnInit {
|
||||||
const result = await actionSheet.onDidDismiss();
|
const result = await actionSheet.onDidDismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
async presentAlertControl(options: AlertOptions){
|
async presentAlertControl(options: AlertOptions) {
|
||||||
let alert = await this.alertCtrl.create(options);
|
let alert = await this.alertCtrl.create(options);
|
||||||
await alert.present();
|
await alert.present();
|
||||||
}
|
}
|
||||||
|
|
||||||
async actionHandler(action: Action, item: WSItem){
|
async actionHandler(action: Action, item: WSItem) {
|
||||||
var options: AlertOptions = action.getAlertOptions(item, this.storagehub, () => {this.loadDocuments()});
|
var options: AlertOptions = action.getAlertOptions(item, this.storagehub, () => { this.loadDocuments() });
|
||||||
if (options){
|
if (options) {
|
||||||
await this.presentAlertControl(options);
|
await this.presentAlertControl(options);
|
||||||
}else
|
} else
|
||||||
action.actionHandler(item, this.storagehub);
|
action.actionHandler(item, this.storagehub);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,12 +92,19 @@ export class StoragehubService {
|
||||||
|
|
||||||
deleteItem(itemId: string) : Observable<any> {
|
deleteItem(itemId: string) : Observable<any> {
|
||||||
let deleteItemUrl = `${shURL}/items/${itemId}?gcube-token=${token}`;
|
let deleteItemUrl = `${shURL}/items/${itemId}?gcube-token=${token}`;
|
||||||
console.log("delete item done with url "+deleteItemUrl);
|
|
||||||
return this.http.delete( deleteItemUrl).pipe(
|
return this.http.delete( deleteItemUrl).pipe(
|
||||||
catchError(this.error)
|
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) {
|
error(error: HttpErrorResponse) {
|
||||||
let errorMessage = '';
|
let errorMessage = '';
|
||||||
if (error.error instanceof ErrorEvent) {
|
if (error.error instanceof ErrorEvent) {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<ion-content [fullscreen]="true">
|
<ion-content [fullscreen]="true">
|
||||||
<show-folder tabName="Trash" [items]="getValues()"></show-folder>
|
<show-folder tabName="Trash" [items]="getValues()" [root]="true"></show-folder>
|
||||||
</ion-content>
|
</ion-content>
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
<ion-content [fullscreen]="true">
|
<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>
|
</ion-content>
|
||||||
|
|
|
@ -18,6 +18,8 @@ export class VresPage implements OnInit {
|
||||||
|
|
||||||
folderid: string | undefined;
|
folderid: string | undefined;
|
||||||
|
|
||||||
|
root: boolean = false;
|
||||||
|
|
||||||
constructor(private storagehub: StoragehubService,
|
constructor(private storagehub: StoragehubService,
|
||||||
private router: Router,
|
private router: Router,
|
||||||
private route: ActivatedRoute) { }
|
private route: ActivatedRoute) { }
|
||||||
|
@ -25,6 +27,7 @@ export class VresPage implements OnInit {
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.folderid = this.route.snapshot.paramMap.get('folderid') || undefined;
|
this.folderid = this.route.snapshot.paramMap.get('folderid') || undefined;
|
||||||
|
this.root = !this.folderid;
|
||||||
if (!this.folderid)
|
if (!this.folderid)
|
||||||
this.storagehub.getVres().subscribe(
|
this.storagehub.getVres().subscribe(
|
||||||
(res) => {
|
(res) => {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
|
|
||||||
<ion-content [fullscreen]="true">
|
<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>
|
</ion-content>
|
||||||
|
|
|
@ -20,15 +20,21 @@ export class WsPage implements OnInit {
|
||||||
|
|
||||||
item : WSItem | undefined ;
|
item : WSItem | undefined ;
|
||||||
|
|
||||||
|
root: boolean = false;
|
||||||
|
|
||||||
constructor(private storagehub: StoragehubService,
|
constructor(private storagehub: StoragehubService,
|
||||||
private router: Router,
|
private router: Router,
|
||||||
private route: ActivatedRoute) { }
|
private route: ActivatedRoute) { }
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.folderid = this.route.snapshot.paramMap.get('folderid') || undefined;
|
this.folderid = this.route.snapshot.paramMap.get('folderid') || undefined;
|
||||||
|
this.root = !this.folderid;
|
||||||
if (!this.folderid)
|
if (!this.folderid)
|
||||||
this.storagehub.getWsRoot().subscribe(
|
this.storagehub.getWsRoot().subscribe(
|
||||||
(res) => this.onSuccess(res)
|
(res) => {
|
||||||
|
this.item = new WSItem(res);
|
||||||
|
this.onSuccess(res)
|
||||||
|
}
|
||||||
);
|
);
|
||||||
else
|
else
|
||||||
this.storagehub.getItem(this.folderid).subscribe(
|
this.storagehub.getItem(this.folderid).subscribe(
|
||||||
|
|
Loading…
Reference in New Issue