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 { 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<any>;
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<any> {
return storagehub.deleteItem(data.item.id);
}
getName(): string {

View File

@ -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);
}