WIP
This commit is contained in:
+16
-6
@@ -18,6 +18,7 @@ export class MyReimbursementsPageComponent implements OnInit {
|
||||
rows: ExpenseListItemDto[] = [];
|
||||
loading = false;
|
||||
dialogOpen = false;
|
||||
editRow: ExpenseListItemDto | null = null;
|
||||
|
||||
constructor(private api: ExpenseApiService) {}
|
||||
|
||||
@@ -31,14 +32,23 @@ export class MyReimbursementsPageComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
openNew(): void { this.dialogOpen = true; }
|
||||
openNew(): void { this.editRow = null; this.dialogOpen = true; }
|
||||
openEdit(row: ExpenseListItemDto): void { this.editRow = row; this.dialogOpen = true; }
|
||||
closeDialog(): void { this.dialogOpen = false; this.editRow = null; }
|
||||
|
||||
onSave(result: ExpenseFormResult): void {
|
||||
this.api.create(result.request).pipe(
|
||||
switchMap(created => result.receipt
|
||||
? this.api.uploadReceipt(created.id, result.receipt).pipe(switchMap(() => of(created)))
|
||||
: of(created)),
|
||||
).subscribe(() => { this.dialogOpen = false; this.load(); });
|
||||
if (this.editRow) {
|
||||
const id = this.editRow.id;
|
||||
this.api.update(id, result.request).pipe(
|
||||
switchMap(() => result.receipt ? this.api.uploadReceipt(id, result.receipt) : of(void 0)),
|
||||
).subscribe(() => { this.closeDialog(); this.load(); });
|
||||
} else {
|
||||
this.api.create(result.request).pipe(
|
||||
switchMap(created => result.receipt
|
||||
? this.api.uploadReceipt(created.id, result.receipt).pipe(switchMap(() => of(created)))
|
||||
: of(created)),
|
||||
).subscribe(() => { this.closeDialog(); this.load(); });
|
||||
}
|
||||
}
|
||||
|
||||
submit(row: ExpenseListItemDto): void { this.api.submit(row.id).subscribe(() => this.load()); }
|
||||
|
||||
Reference in New Issue
Block a user