edit dashboard and text widgets

This commit is contained in:
2023-03-11 10:39:28 +01:00
parent cb5b160d3c
commit e3945a4d33
10 changed files with 99 additions and 23 deletions

View File

@@ -4,8 +4,9 @@ import { Component, ElementRef, OnInit } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { MatSnackBar } from '@angular/material/snack-bar';
import { ActivatedRoute } from '@angular/router';
import { BaseWidget, Dashboard, DashboardService, PlotSize, PlotWidget, PlotWidgetRenderData, TextWidget } from 'src/app/dashboard.service';
import { BaseWidget, Dashboard, DashboardCreationData, DashboardService, PlotSize, PlotWidget, PlotWidgetRenderData, TextWidget } from 'src/app/dashboard.service';
import { PlotConfig, PlotRequest, PlotResponse, PlotService, RenderOptions } from 'src/app/plot.service';
import { NewDashboardComponent } from '../new-dashboard/new-dashboard.component';
import { AddPlotDialogComponent } from './add-plot-dialog/add-plot-dialog.component';
import { AddTextDialogComponent } from './add-text-dialog/add-text-dialog.component';
@@ -141,6 +142,7 @@ export class DashboardComponent implements OnInit {
addText() {
this.dialog.open(AddTextDialogComponent,{
data: {text:""},
width: '600px'
}).afterClosed().subscribe((text: string) => {
const widget = new TextWidget(crypto.randomUUID(),'MEDIUM', text);
@@ -184,7 +186,18 @@ export class DashboardComponent implements OnInit {
this.service.saveDashboard(this.dashboard!).subscribe({
'complete': () => {
this.snackBar.open("saved dashboard","", {
const successMessages = [
"dashboard saved",
"saving the dashboard was a complete success",
"dashboard state securely stored",
"the save was successful",
"done",
"success",
"saved"
];
const randomMessage = successMessages[Math.floor(Math.random()*successMessages.length)];
this.snackBar.open(randomMessage,"", {
duration: 5000,
verticalPosition: 'top'
});
@@ -192,6 +205,22 @@ export class DashboardComponent implements OnInit {
});
}
editNameAndDescription() {
const dialogRef = this.dialog.open(NewDashboardComponent, {
data: {name: this.dashboard!.name, description: this.dashboard!.description},
hasBackdrop: true
});
dialogRef.afterClosed().subscribe((result?: DashboardCreationData) => {
if (result) {
this.dashboard!.name = result.name;
this.dashboard!.description = result.description;
}
});
}
isTextWidget(id: string): boolean {
return this.getTextWidget(id) !== undefined;
}
@@ -220,8 +249,4 @@ export class DashboardComponent implements OnInit {
);
}
}
s(a: any){
return JSON.stringify(a);
}
}