From 0e6e4899e5b9b0b84df1ab724ee48db1f185a842 Mon Sep 17 00:00:00 2001 From: Gaurav Kumar Date: Tue, 4 Nov 2025 17:41:18 +0530 Subject: [PATCH] unifield --- .../editnewdash/editnewdash.component.ts | 129 ++++++++++++------ .../unified-chart.component.html | 7 +- .../unified-chart/unified-chart.component.ts | 126 ++++++++++++++++- 3 files changed, 216 insertions(+), 46 deletions(-) diff --git a/frontend/angular-clarity-master/src/app/modules/main/builder/dashboardnew/editnewdash/editnewdash.component.ts b/frontend/angular-clarity-master/src/app/modules/main/builder/dashboardnew/editnewdash/editnewdash.component.ts index 67eaed6..5e444c9 100644 --- a/frontend/angular-clarity-master/src/app/modules/main/builder/dashboardnew/editnewdash/editnewdash.component.ts +++ b/frontend/angular-clarity-master/src/app/modules/main/builder/dashboardnew/editnewdash/editnewdash.component.ts @@ -60,6 +60,7 @@ export class EditnewdashComponent implements OnInit { // Add availableKeys property for compact filter availableKeys: string[] = []; + // Initialize with default widgets and update dynamically WidgetsMock: WidgetModel[] = [ { name: 'Common Filter', @@ -77,26 +78,26 @@ export class EditnewdashComponent implements OnInit { name: 'Line Chart', identifier: 'line_chart' }, - { - name: 'Bar Chart', - identifier: 'bar_chart' - }, - { - name: 'Pie Chart', - identifier: 'pie_chart' - }, - { - name: 'Polar Area Chart', - identifier: 'polar_area_chart' - }, - { - name: 'Bubble Chart', - identifier: 'bubble_chart' - }, - { - name: 'Scatter Chart', - identifier: 'scatter_chart' - }, + // { + // name: 'Bar Chart', + // identifier: 'bar_chart' + // }, + // { + // name: 'Pie Chart', + // identifier: 'pie_chart' + // }, + // { + // name: 'Polar Area Chart', + // identifier: 'polar_area_chart' + // }, + // { + // name: 'Bubble Chart', + // identifier: 'bubble_chart' + // }, + // { + // name: 'Scatter Chart', + // identifier: 'scatter_chart' + // }, { name: 'Dynamic Chart', identifier: 'dynamic_chart' @@ -208,6 +209,9 @@ export class EditnewdashComponent implements OnInit { // Add drilldown column data property drilldownColumnData = []; // Add drilldown column data property + // Add chart types property for dynamic chart selection + chartTypes: any[] = []; + constructor(private route: ActivatedRoute, private router: Router, private dashboardService: Dashboard3Service, @@ -302,12 +306,46 @@ export class EditnewdashComponent implements OnInit { apiUrl: [''] }); + // Load chart types for dynamic chart selection + this.loadChartTypesForSelection(); + // Load sureconnect data first, then load dashboard data this.loadSureconnectData(); // Load common filter data if it exists this.loadCommonFilterData(); } + + // Add method to load all chart types for dynamic selection + loadChartTypesForSelection() { + console.log('Loading chart types for selection'); + this.dynamicChartLoader.loadActiveChartTypes().subscribe({ + next: (chartTypes) => { + console.log('Loaded chart types for selection:', chartTypes); + this.chartTypes = chartTypes; + + // Convert each chart type to a WidgetModel + const newWidgets = chartTypes.map(ct => ({ + name: ct.displayName || ct.name, + // identifier: ct.name.toLowerCase().replace(/\s+/g, '_') + identifier: `${ct.name.toLowerCase().replace(/\s+/g, '_')}_chart` + })); + + // Filter out duplicates by identifier + const existingIds = new Set(this.WidgetsMock.map(w => w.identifier)); + const uniqueNewWidgets = newWidgets.filter(w => !existingIds.has(w.identifier)); + + // Append unique new widgets to WidgetsMock + this.WidgetsMock = [...this.WidgetsMock, ...uniqueNewWidgets]; + + console.log('Updated WidgetsMock:', this.WidgetsMock); + }, + error: (error) => { + console.error('Error loading chart types for selection:', error); + } + }); +} + // Add method to load sureconnect data loadSureconnectData() { @@ -2151,20 +2189,7 @@ export class EditnewdashComponent implements OnInit { }); } - // Add method to load all chart types for dynamic selection - loadChartTypesForSelection() { - console.log('Loading chart types for selection'); - this.dynamicChartLoader.loadActiveChartTypes().subscribe({ - next: (chartTypes) => { - console.log('Loaded chart types for selection:', chartTypes); - // Here you would update the UI to show available chart types - // For example, populate a dropdown or list - }, - error: (error) => { - console.error('Error loading chart types for selection:', error); - } - }); - } + // Add method to create a dynamic chart with configuration from database createDynamicChart(chartTypeName: string, maxChartId: number) { @@ -2212,24 +2237,24 @@ export class EditnewdashComponent implements OnInit { error: (error) => { console.error(`Error loading configuration for ${chartTypeName}:`, error); // Fallback to default configuration - this.createDefaultChart(chartTypeName, maxChartId); + // this.createDefaultChart(chartTypeName, maxChartId); } }); } else { console.warn(`Chart type ${chartTypeName} not found, using default configuration`); - this.createDefaultChart(chartTypeName, maxChartId); + // this.createDefaultChart(chartTypeName, maxChartId); } }, error: (error) => { - console.error(`Error finding chart type ${chartTypeName}:`, error); + console.error('Error loading configuration for chart type:', error); // Fallback to default configuration - this.createDefaultChart(chartTypeName, maxChartId); + // this.createDefaultChart(chartType.name, chartType.displayName || chartType.name); } }); } // Fallback method to create default chart configuration - createDefaultChart(chartTypeName: string, maxChartId: number) { + createDefaultChart(chartTypeName: string, chartDisplayName: string) { console.log(`Creating default chart for ${chartTypeName}`); // Map chart type names to chart types @@ -2247,6 +2272,18 @@ export class EditnewdashComponent implements OnInit { // Get the chart type from the name const chartType = chartTypeMap[chartTypeName.toLowerCase()] || 'bar'; + // Safely calculate maxChartId, handling cases where chartid might be NaN or missing + let maxChartId = 0; + if (this.dashboardArray && this.dashboardArray.length > 0) { + const validChartIds = this.dashboardArray + .map(item => item.chartid) + .filter(chartid => typeof chartid === 'number' && !isNaN(chartid)); + + if (validChartIds.length > 0) { + maxChartId = Math.max(...validChartIds); + } + } + const chartItem = { cols: 5, rows: 6, @@ -2254,7 +2291,7 @@ export class EditnewdashComponent implements OnInit { y: 0, chartid: maxChartId + 1, component: UnifiedChartComponent, - name: this.getChartDisplayName(chartTypeName), + name: chartDisplayName, chartType: chartType, xAxis: '', yAxis: '', @@ -2263,9 +2300,17 @@ export class EditnewdashComponent implements OnInit { }; this.dashboardArray.push(chartItem); - console.log(`Created default chart:`, chartItem); + console.log('Created default chart:', chartItem); + + // Update the dashboard collection + this.dashboardCollection.dashboard = this.dashboardArray.slice(); + + // Force gridster to refresh + if (this.options && this.options.api) { + this.options.api.optionsChanged(); + } } - + // Helper method to get display name for chart type getChartDisplayName(chartTypeName: string): string { const displayNameMap = { diff --git a/frontend/angular-clarity-master/src/app/modules/main/builder/dashboardnew/gadgets/unified-chart/unified-chart.component.html b/frontend/angular-clarity-master/src/app/modules/main/builder/dashboardnew/gadgets/unified-chart/unified-chart.component.html index c416a9f..20296fe 100644 --- a/frontend/angular-clarity-master/src/app/modules/main/builder/dashboardnew/gadgets/unified-chart/unified-chart.component.html +++ b/frontend/angular-clarity-master/src/app/modules/main/builder/dashboardnew/gadgets/unified-chart/unified-chart.component.html @@ -1,4 +1,7 @@
+ +
+