Commit 03e89323 by Ooh-Ao

dataset

parent d7952bf7
...@@ -15,6 +15,7 @@ import { WidgetModel } from '../../models/widgets.model'; ...@@ -15,6 +15,7 @@ import { WidgetModel } from '../../models/widgets.model';
export interface WidgetConfigDialogData { export interface WidgetConfigDialogData {
widget: WidgetModel; widget: WidgetModel;
availableColumns: string[]; availableColumns: string[];
currentConfig?: any; // Add optional currentConfig for editing
} }
@Component({ @Component({
...@@ -50,10 +51,13 @@ export class WidgetConfigComponent implements OnInit { ...@@ -50,10 +51,13 @@ export class WidgetConfigComponent implements OnInit {
this.availableColumns = this.data.availableColumns; this.availableColumns = this.data.availableColumns;
this.widgetType = this.data.widget.component; this.widgetType = this.data.widget.component;
// Handle config whether it is a string or an object // Prioritize the passed-in currentConfig for editing, otherwise use the widget's default config.
if (this.data.currentConfig && Object.keys(this.data.currentConfig).length > 0) {
this.currentConfig = JSON.parse(JSON.stringify(this.data.currentConfig)); // Deep copy to prevent modifying the original object
} else {
try { try {
if (typeof this.data.widget.config === 'string') { if (typeof this.data.widget.config === 'string') {
this.currentConfig = JSON.parse(this.data.widget.config); this.currentConfig = JSON.parse(this.data.widget.config || '{}');
} else { } else {
this.currentConfig = JSON.parse(JSON.stringify(this.data.widget.config || {})); this.currentConfig = JSON.parse(JSON.stringify(this.data.widget.config || {}));
} }
...@@ -61,6 +65,7 @@ export class WidgetConfigComponent implements OnInit { ...@@ -61,6 +65,7 @@ export class WidgetConfigComponent implements OnInit {
console.error('Error parsing widget config:', e); console.error('Error parsing widget config:', e);
this.currentConfig = {}; this.currentConfig = {};
} }
}
const gridLikeWidgets = ['SyncfusionDatagridWidgetComponent', 'NewDataTableWidget', 'MatrixWidgetComponent']; const gridLikeWidgets = ['SyncfusionDatagridWidgetComponent', 'NewDataTableWidget', 'MatrixWidgetComponent'];
if (gridLikeWidgets.includes(this.widgetType) && !this.currentConfig.columns) { if (gridLikeWidgets.includes(this.widgetType) && !this.currentConfig.columns) {
......
...@@ -35,13 +35,13 @@ ...@@ -35,13 +35,13 @@
<ul *ngIf="linkedWidgets.length > 0" class="space-y-2"> <ul *ngIf="linkedWidgets.length > 0" class="space-y-2">
<li *ngFor="let widget of linkedWidgets" <li *ngFor="let widget of linkedWidgets"
class="flex items-center justify-between p-2 rounded-md transition-colors cursor-pointer" class="flex items-center justify-between p-2 rounded-md transition-colors cursor-pointer"
[class.bg-sky-100]="widget.itemId === widgetToPreview?.itemId" [class.bg-sky-100]="widget.widget.widgetId === widgetToPreview?.widget?.widgetId"
[class.hover:bg-gray-100]="widget.itemId !== widgetToPreview?.itemId" [class.hover:bg-gray-100]="widget.widget.widgetId !== widgetToPreview?.widget?.widgetId"
(click)="viewWidget(widget)"> (click)="viewWidget(widget)">
<span class="font-medium">{{ widget.widget.thName }}</span> <span class="font-medium">{{ widget.widget.thName }}</span>
<div class="flex items-center space-x-2"> <div class="flex items-center space-x-2">
<button (click)="removeWidget(widget, $event)" class="text-red-600 hover:text-red-800" title="Remove"> <button (click)="removeWidget(widget, $event)" class="text-red hover:text-red-800" title="Remove">
<i class="bi bi-trash-fill"></i> <i class="bi bi-trash-fill text-red"></i>
</button> </button>
</div> </div>
</li> </li>
......
...@@ -209,6 +209,10 @@ export class DatasetWidgetLinkerComponent implements OnInit { ...@@ -209,6 +209,10 @@ export class DatasetWidgetLinkerComponent implements OnInit {
// Persist the changes to the backend // Persist the changes to the backend
this.mMenuitemsWidgetService.saveLinkedWidget(this.widgetToPreview!).subscribe(() => { this.mMenuitemsWidgetService.saveLinkedWidget(this.widgetToPreview!).subscribe(() => {
this.notificationService.success('Success', 'Configuration saved successfully!'); this.notificationService.success('Success', 'Configuration saved successfully!');
// Re-trigger the data fetch in the state service to get fresh data
this.dashboardStateService.selectDataset(this.selectedDatasetId!);
// Refresh the entire preview to reflect the changes // Refresh the entire preview to reflect the changes
this.viewWidget(this.widgetToPreview!); this.viewWidget(this.widgetToPreview!);
}); });
......
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