reload on operation added

This commit is contained in:
Lucio Lelii 2023-02-24 18:41:00 +01:00
parent 86b7c21ebb
commit 3d90d19358
2 changed files with 11 additions and 8 deletions

View File

@ -1,14 +1,15 @@
import { AlertOptions } from "@ionic/angular"; import { AlertOptions } from "@ionic/angular";
import { title } from "process"; import { title } from "process";
import { Observable } from "rxjs";
import { StoragehubService } from "../storagehub.service"; import { StoragehubService } from "../storagehub.service";
import { Item } from "./item.model"; import { Item } from "./item.model";
import { WSItem } from "./ws-item"; import { WSItem } from "./ws-item";
export interface Action { 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<any>;
getName(): string; getName(): string;
@ -19,7 +20,7 @@ export interface Action {
export class DeleteAction implements 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 title = item.getTitle();
var options: AlertOptions = { var options: AlertOptions = {
header: `Are you sure to delete item ${title} ?`, header: `Are you sure to delete item ${title} ?`,
@ -30,15 +31,17 @@ export class DeleteAction implements Action {
{ {
text: 'Yes', text: 'Yes',
handler: () => { handler: () => {
this.actionHandler(item, storagehub); this.actionHandler(item, storagehub).subscribe(
reload()
);
} }
}] }]
}; };
return options; return options;
} }
actionHandler(data: WSItem, storagehub: StoragehubService) { actionHandler(data: WSItem, storagehub: StoragehubService): Observable<any> {
storagehub.deleteItem(data.item.id).subscribe((res) =>console.log(`item ${data.getTitle()} deleted`) ); return storagehub.deleteItem(data.item.id);
} }
getName(): string { getName(): string {

View File

@ -149,11 +149,11 @@ export class ShowFolderComponent implements OnInit {
} }
async actionHandler(action: Action, item: WSItem){ 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){ if (options){
await this.presentAlertControl(options); await this.presentAlertControl(options);
}else }else
await action.actionHandler(item, this.storagehub); action.actionHandler(item, this.storagehub);
} }