Commit 46c4bceb by Ooh-Ao

remove widget

parent bb2c4a7c
...@@ -111,7 +111,7 @@ ...@@ -111,7 +111,7 @@
<e-panels> <e-panels>
<e-panel <e-panel
*ngFor="let panel of panels" *ngFor="let panel of panels"
[id]="panel.id + '-' + panel.row + '-' + panel.col" [id]="panel.id"
[sizeX]="panel.sizeX" [sizeX]="panel.sizeX"
[sizeY]="panel.sizeY" [sizeY]="panel.sizeY"
[row]="panel.row" [row]="panel.row"
...@@ -131,11 +131,7 @@ ...@@ -131,11 +131,7 @@
<i class="bi bi-gear"></i> <i class="bi bi-gear"></i>
</button> </button>
<button <button
(click)=" (click)="removeWidgetFromDashboard(panel.id!)"
removeWidgetFromDashboard(
panel.id + '-' + panel.row + '-' + panel.col
)
"
class="text-red-500 hover:text-red-700 p-1 rounded hover:bg-red-50 transition-colors" class="text-red-500 hover:text-red-700 p-1 rounded hover:bg-red-50 transition-colors"
title="Remove widget" title="Remove widget"
aria-label="Remove widget" aria-label="Remove widget"
......
...@@ -321,10 +321,33 @@ export class DashboardManagementComponent implements OnInit { ...@@ -321,10 +321,33 @@ export class DashboardManagementComponent implements OnInit {
} }
removeWidgetFromDashboard(panelId: string): void { removeWidgetFromDashboard(panelId: string): void {
if (!this.dashboardData) return; if (!this.dashboardData || !panelId) return;
if (confirm('Are you sure you want to remove this widget?' + panelId)) { if (confirm('Are you sure you want to remove this widget?')) {
this.dashboardData.widgets = this.dashboardData.widgets.filter((w: any) => w.instanceId !== panelId); // Find the widget by matching the panel ID
this.panels = this.mapWidgetsToPanels(this.dashboardData.widgets); // Panel ID format: instanceId-y-x
const widgetToRemove = this.dashboardData.widgets.find((w: any) => {
const expectedPanelId = `${w.instanceId}-${w.y}-${w.x}`;
return expectedPanelId === panelId;
});
if (widgetToRemove) {
this.dashboardData.widgets = this.dashboardData.widgets.filter((w: any) => w !== widgetToRemove);
this.panels = this.mapWidgetsToPanels(this.dashboardData.widgets);
// Save the dashboard after removing the widget
const dashboardToSave = this.convertWidgetsToStrings(this.dashboardData);
this.dashboardDataService.saveDashboard(dashboardToSave).pipe(
catchError(error => {
this.notificationService.error('Error', 'Failed to save dashboard after widget removal.');
return throwError(() => error);
})
).subscribe(() => {
this.notificationService.success('Success', 'Widget removed and dashboard saved successfully!');
});
} else {
this.notificationService.error('Error', 'Widget not found for removal.');
console.error('Panel ID not found:', panelId, 'Available widgets:', this.dashboardData.widgets.map(w => `${(w as any).instanceId}-${w.y}-${w.x}`));
}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment