Commit affd9160 by Ooh-Ao

config

parent cd412f68
...@@ -624,11 +624,17 @@ export class DashboardManagementComponent implements OnInit { ...@@ -624,11 +624,17 @@ export class DashboardManagementComponent implements OnInit {
mapWidgetsToPanels(widgets: WidgetModel[]): DashboardPanel[] { mapWidgetsToPanels(widgets: WidgetModel[]): DashboardPanel[] {
return widgets.map(widget => { return widgets.map(widget => {
// Always pass the entire widget.config as the input to the component let widgetConfig: any = {};
// Ensure widget.config exists, initialize if not. if (typeof widget.config === 'string') {
const widgetConfig = widget.config || {}; try {
widgetConfig = JSON.parse(widget.config);
} catch (e) {
console.error('Error parsing widget config string:', widget.config, e);
widgetConfig = {}; // Default to empty object on error
}
} else {
widgetConfig = widget.config || {};
}
return { return {
id: widget.widgetId, id: widget.widgetId,
...@@ -852,6 +858,7 @@ export class DashboardManagementComponent implements OnInit { ...@@ -852,6 +858,7 @@ export class DashboardManagementComponent implements OnInit {
openWidgetConfigDialog(panel: PanelModel & { componentType: Type<any>, componentInputs?: { [key: string]: any }, originalWidget: WidgetModel }): void { openWidgetConfigDialog(panel: PanelModel & { componentType: Type<any>, componentInputs?: { [key: string]: any }, originalWidget: WidgetModel }): void {
const widget = panel.originalWidget; const widget = panel.originalWidget;
console.log('Opening config dialog for widget:', widget);
this.dashboardStateService.selectedDataset$.subscribe((selectedDataset: SelectedDataset | null) => { this.dashboardStateService.selectedDataset$.subscribe((selectedDataset: SelectedDataset | null) => {
const availableColumns = selectedDataset ? selectedDataset.columns : []; const availableColumns = selectedDataset ? selectedDataset.columns : [];
......
...@@ -129,7 +129,18 @@ export class DashboardViewerComponent implements OnInit { ...@@ -129,7 +129,18 @@ export class DashboardViewerComponent implements OnInit {
mapWidgetsToPanels(widgets: WidgetModel[]): DashboardPanel[] { mapWidgetsToPanels(widgets: WidgetModel[]): DashboardPanel[] {
return widgets.map(widget => { return widgets.map(widget => {
const widgetConfig = widget.config || {}; let widgetConfig: any = {};
if (typeof widget.config === 'string') {
try {
widgetConfig = JSON.parse(widget.config);
} catch (e) {
console.error('Error parsing widget config string:', widget.config, e);
widgetConfig = {}; // Default to empty object on error
}
} else {
widgetConfig = widget.config || {};
}
return { return {
id: widget.widgetId, id: widget.widgetId,
header: widget.thName, header: widget.thName,
......
...@@ -26,22 +26,38 @@ export class SimpleKpiWidgetComponent extends BaseWidgetComponent { ...@@ -26,22 +26,38 @@ export class SimpleKpiWidgetComponent extends BaseWidgetComponent {
this.unit = this.config.unit || ''; this.unit = this.config.unit || '';
this.trend = this.config.trend || 'neutral'; this.trend = this.config.trend || 'neutral';
this.trendValue = this.config.trendValue || ''; this.trendValue = this.config.trendValue || '';
this.value = '...'; // Loading indicator this.value = '-'; // Initial state before data loads
} }
onDataUpdate(data: any[]): void { onDataUpdate(data: any[]): void {
if (data.length > 0) { console.log('SimpleKpiWidget onDataUpdate config:', this.config);
let kpiValue = 0; // Handle count aggregation separately as it doesn't need a valueField
if (this.config.aggregation === 'count') { if (this.config.aggregation === 'count') {
kpiValue = data.length; this.value = (data?.length || 0).toLocaleString();
} else if (this.config.aggregation === 'sum') { return;
kpiValue = data.reduce((sum, item) => sum + (item[this.config.valueField] || 0), 0);
} else {
// Default to first value if no aggregation
kpiValue = data[0][this.config.valueField];
}
this.value = kpiValue.toLocaleString();
} }
// For other aggregations, valueField is required
if (!this.config.valueField) {
this.value = 'N/A'; // Indicate a configuration error
console.error('SimpleKpiWidget Error: valueField is not configured for this widget.', this.config);
return;
}
// If data is empty, result is 0
if (!data || data.length === 0) {
this.value = '0';
return;
}
let kpiValue = 0;
if (this.config.aggregation === 'sum') {
kpiValue = data.reduce((sum, item) => sum + (item[this.config.valueField] || 0), 0);
} else {
// Default to first value if no aggregation is specified
kpiValue = data[0][this.config.valueField] || 0;
}
this.value = kpiValue.toLocaleString();
} }
onReset(): void { onReset(): void {
......
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