This commit is contained in:
2023-03-12 08:32:42 +01:00
parent b5028e03be
commit 96ed788793
5 changed files with 23 additions and 77 deletions

View File

@@ -1,6 +1,7 @@
import { HttpErrorResponse } from '@angular/common/http';
import { Component, OnInit } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { MatSnackBar } from '@angular/material/snack-bar';
import { ConfirmationDialogComponent } from '../confirmation-dialog/confirmation-dialog.component';
import { Dashboard, DashboardCreationData, DashboardList, DashboardService } from '../dashboard.service';
import { NewDashboardComponent } from './new-dashboard/new-dashboard.component';
@@ -16,9 +17,10 @@ export class DashboardPageComponent implements OnInit {
loading = true;
error = "";
constructor(public dialog: MatDialog, private dashboardService: DashboardService){
}
constructor(
public dialog: MatDialog,
private dashboardService: DashboardService,
private snackBar: MatSnackBar){}
ngOnInit(): void {
this.refreshTable();
@@ -44,39 +46,32 @@ export class DashboardPageComponent implements OnInit {
createNewDashboard() {
const dialogRef = this.dialog.open(NewDashboardComponent, {
data: {name: "", description: ""},
hasBackdrop: true
data: {name: "", description: ""}
});
dialogRef.afterClosed().subscribe((result: DashboardCreationData) => {
console.log('The dialog was closed with result ', JSON.stringify(result));
this.dashboardService.createDashboard(result).subscribe(result => {
console.log(result);
this.refreshTable();
});
this.dashboardService.createDashboard(result).subscribe(result => this.refreshTable());
});
}
delete(dashboard: Dashboard){
const dialogRef = this.dialog.open(ConfirmationDialogComponent, {
data: {title: "", text: "Delete dashboard '"+dashboard.name+"'?", btnOkLabel: "Delete", btnCancelLabel: "Cancel"},
hasBackdrop: true
data: {title: "", text: "Delete dashboard '"+dashboard.name+"'?", btnOkLabel: "Delete", btnCancelLabel: "Cancel"}
});
dialogRef.afterClosed().subscribe((result: boolean) => {
if (result === true) {
this.dashboardService.deleteDashboard(dashboard.id).subscribe({
'error': (error) => {
this.snackBar.open("failed to delete dashboard","", {
duration: 5000,
verticalPosition: 'top'
});
},
'complete': () => this.refreshTable()
});
}
});
});
}
}