From 3d90d19358f8e1eeb857deae5ac2d462d2de057c Mon Sep 17 00:00:00 2001 From: Lucio Lelii Date: Fri, 24 Feb 2023 18:41:00 +0100 Subject: [PATCH] reload on operation added --- src/app/model/actions.ts | 15 +++++++++------ src/app/show-folder/show-folder.component.ts | 4 ++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/app/model/actions.ts b/src/app/model/actions.ts index 44cd712..b3c8c4c 100644 --- a/src/app/model/actions.ts +++ b/src/app/model/actions.ts @@ -1,14 +1,15 @@ import { AlertOptions } from "@ionic/angular"; import { title } from "process"; +import { Observable } from "rxjs"; import { StoragehubService } from "../storagehub.service"; import { Item } from "./item.model"; import { WSItem } from "./ws-item"; export interface Action { - getAlertOptions(item: WSItem, storagehub: StoragehubService): AlertOptions; + getAlertOptions(item: WSItem, storagehub: StoragehubService, postOp?: Function): AlertOptions; - actionHandler(data: any, storagehub: StoragehubService): any; + actionHandler(data: any, storagehub: StoragehubService): Observable; getName(): string; @@ -19,7 +20,7 @@ export interface Action { export class DeleteAction implements Action { - getAlertOptions(item: WSItem, storagehub: StoragehubService): AlertOptions { + getAlertOptions(item: WSItem, storagehub: StoragehubService, reload: Function): AlertOptions { var title = item.getTitle(); var options: AlertOptions = { header: `Are you sure to delete item ${title} ?`, @@ -30,15 +31,17 @@ export class DeleteAction implements Action { { text: 'Yes', handler: () => { - this.actionHandler(item, storagehub); + this.actionHandler(item, storagehub).subscribe( + reload() + ); } }] }; return options; } - actionHandler(data: WSItem, storagehub: StoragehubService) { - storagehub.deleteItem(data.item.id).subscribe((res) =>console.log(`item ${data.getTitle()} deleted`) ); + actionHandler(data: WSItem, storagehub: StoragehubService): Observable { + return storagehub.deleteItem(data.item.id); } getName(): string { diff --git a/src/app/show-folder/show-folder.component.ts b/src/app/show-folder/show-folder.component.ts index af6d059..ddeccb7 100644 --- a/src/app/show-folder/show-folder.component.ts +++ b/src/app/show-folder/show-folder.component.ts @@ -149,11 +149,11 @@ export class ShowFolderComponent implements OnInit { } async actionHandler(action: Action, item: WSItem){ - var options: AlertOptions = action.getAlertOptions(item, this.storagehub); + var options: AlertOptions = action.getAlertOptions(item, this.storagehub, () => {this.loadDocuments()}); if (options){ await this.presentAlertControl(options); }else - await action.actionHandler(item, this.storagehub); + action.actionHandler(item, this.storagehub); }