diff --git a/frontend/angular-clarity-master/src/app/modules/main/builder/dashboardnew/chart-config/chart-config-manager.component.ts b/frontend/angular-clarity-master/src/app/modules/main/builder/dashboardnew/chart-config/chart-config-manager.component.ts index 6ef6390..c943fa5 100644 --- a/frontend/angular-clarity-master/src/app/modules/main/builder/dashboardnew/chart-config/chart-config-manager.component.ts +++ b/frontend/angular-clarity-master/src/app/modules/main/builder/dashboardnew/chart-config/chart-config-manager.component.ts @@ -505,23 +505,12 @@ export class ChartConfigManagerComponent implements OnInit { this.chartTemplateLoadingState = ClrLoadingState.LOADING; - // Create a complete chartType object with only the ID - const chartTypeWithId = { - id: this.selectedChartType.id, - name: '', - displayName: '', - description: '', - isActive: true, - createdAt: '', - updatedAt: '' - }; + // Remove the chartType from the template data since we're passing it as a parameter + const chartTemplateData = { ...this.newChartTemplate }; + // Remove chartType property if it exists + delete (chartTemplateData as any).chartType; - const chartTemplateData = { - ...this.newChartTemplate, - chartType: chartTypeWithId - }; - - this.chartTemplateService.createChartTemplate(chartTemplateData).subscribe({ + this.chartTemplateService.createChartTemplate(chartTemplateData, this.selectedChartType.id).subscribe({ next: (data) => { this.chartTemplates.push(data); this.newChartTemplate = {}; diff --git a/frontend/angular-clarity-master/src/app/modules/main/builder/dashboardnew/chart-config/chart-template.service.ts b/frontend/angular-clarity-master/src/app/modules/main/builder/dashboardnew/chart-config/chart-template.service.ts index f6d261e..9b9d787 100644 --- a/frontend/angular-clarity-master/src/app/modules/main/builder/dashboardnew/chart-config/chart-template.service.ts +++ b/frontend/angular-clarity-master/src/app/modules/main/builder/dashboardnew/chart-config/chart-template.service.ts @@ -5,8 +5,7 @@ import { ChartTemplate } from './chart-config-manager.component'; @Injectable({ providedIn: 'root' -} -) +}) export class ChartTemplateService { private chartTemplatesUrl = 'api/chart-templates'; @@ -24,9 +23,13 @@ export class ChartTemplateService { return this.apiRequest.get(url); } - // Create new chart template - createChartTemplate(chartTemplate: Partial): Observable { - return this.apiRequest.post(this.chartTemplatesUrl, chartTemplate); + // Create new chart template with optional chart type ID as parameter + createChartTemplate(chartTemplate: Partial, chartTypeId?: number): Observable { + let url = this.chartTemplatesUrl; + if (chartTypeId) { + url = `${this.chartTemplatesUrl}?chartTypeId=${chartTypeId}`; + } + return this.apiRequest.post(url, chartTemplate); } // Update chart template diff --git a/frontend/angular-clarity-master/src/app/modules/main/builder/dashboardnew/chart-type-manager/chart-type-templates.component.ts b/frontend/angular-clarity-master/src/app/modules/main/builder/dashboardnew/chart-type-manager/chart-type-templates.component.ts index de8ad0c..85de681 100644 --- a/frontend/angular-clarity-master/src/app/modules/main/builder/dashboardnew/chart-type-manager/chart-type-templates.component.ts +++ b/frontend/angular-clarity-master/src/app/modules/main/builder/dashboardnew/chart-type-manager/chart-type-templates.component.ts @@ -101,7 +101,7 @@ export class ChartTypeTemplatesComponent implements OnInit { }; this.loadingState = ClrLoadingState.LOADING; - this.chartTemplateService.createChartTemplate(templateData).subscribe({ + this.chartTemplateService.createChartTemplate(templateData, this.chartType.id).subscribe({ next: (data) => { this.chartTemplates.push(data); this.newChartTemplate = { isDefault: false };