This commit is contained in:
Gaurav Kumar
2025-11-03 19:25:02 +05:30
parent fc36794b22
commit ff2f5a1c34
7 changed files with 50 additions and 44 deletions

View File

@@ -8,7 +8,7 @@ import { ChartTemplate } from './chart-config-manager.component';
} }
) )
export class ChartTemplateService { export class ChartTemplateService {
private chartTemplatesUrl = 'chart-templates'; private chartTemplatesUrl = 'api/chart-templates';
constructor(private apiRequest: ApiRequestService) { } constructor(private apiRequest: ApiRequestService) { }

View File

@@ -7,7 +7,7 @@ import { ComponentProperty } from './chart-config-manager.component';
providedIn: 'root' providedIn: 'root'
}) })
export class ComponentPropertyService { export class ComponentPropertyService {
private componentPropertiesUrl = 'component-properties'; private componentPropertiesUrl = 'api/component-properties';
constructor(private apiRequest: ApiRequestService) { } constructor(private apiRequest: ApiRequestService) { }

View File

@@ -7,7 +7,7 @@ import { DynamicField } from './chart-config-manager.component';
providedIn: 'root' providedIn: 'root'
}) })
export class DynamicFieldService { export class DynamicFieldService {
private dynamicFieldsUrl = 'dynamic-fields'; private dynamicFieldsUrl = 'api/dynamic-fields';
constructor(private apiRequest: ApiRequestService) { } constructor(private apiRequest: ApiRequestService) { }

View File

@@ -7,7 +7,7 @@ import { UiComponent } from './chart-config-manager.component';
providedIn: 'root' providedIn: 'root'
}) })
export class UiComponentService { export class UiComponentService {
private uiComponentsUrl = 'ui-components'; private uiComponentsUrl = 'api/ui-components';
constructor(private apiRequest: ApiRequestService) { } constructor(private apiRequest: ApiRequestService) { }

View File

@@ -93,42 +93,6 @@ export class ChartTypeManagerComponent implements OnInit {
return ''; return '';
} }
deleteChartType(id: number): void {
if (!confirm('Are you sure you want to delete this chart type?')) {
return;
}
this.chartTypeLoadingState = ClrLoadingState.LOADING;
this.chartTypeService.deleteChartType(id).subscribe({
next: () => {
this.chartTypes = this.chartTypes.filter(ct => ct.id !== id);
this.showSuccess('Chart type deleted successfully');
this.chartTypeLoadingState = ClrLoadingState.SUCCESS;
},
error: (error) => {
console.error('Error deleting chart type:', error);
this.showError('Error deleting chart type: ' + (error.error?.message || error.message || 'Unknown error'));
this.chartTypeLoadingState = ClrLoadingState.ERROR;
}
});
}
}
// Handle ISO string within object
if (date.date) {
return date.date;
}
// Handle other object formats
try {
return new Date(date).toISOString();
} catch {
return '';
}
}
return '';
}
deleteChartType(id: number): void { deleteChartType(id: number): void {
if (!confirm('Are you sure you want to delete this chart type?')) { if (!confirm('Are you sure you want to delete this chart type?')) {
return; return;

View File

@@ -137,11 +137,11 @@
</div> </div>
<div class="detail-item"> <div class="detail-item">
<label>Created At:</label> <label>Created At:</label>
<span>{{ chartType.createdAt | date:'medium' }}</span> <span>{{ chartType.createdAt ? (chartType.createdAt | date:'medium') : 'N/A' }}</span>
</div> </div>
<div class="detail-item"> <div class="detail-item">
<label>Updated At:</label> <label>Updated At:</label>
<span>{{ chartType.updatedAt | date:'medium' }}</span> <span>{{ chartType.updatedAt ? (chartType.updatedAt | date:'medium') : 'N/A' }}</span>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -52,7 +52,12 @@ export class EditChartTypeComponent implements OnInit {
this.loadingState = ClrLoadingState.LOADING; this.loadingState = ClrLoadingState.LOADING;
this.chartTypeService.getChartTypeById(id).subscribe({ this.chartTypeService.getChartTypeById(id).subscribe({
next: (data) => { next: (data) => {
this.chartType = data; // Process the data to ensure dates are properly formatted
this.chartType = {
...data,
createdAt: this.formatDate(data.createdAt),
updatedAt: this.formatDate(data.updatedAt)
};
this.loadingState = ClrLoadingState.SUCCESS; this.loadingState = ClrLoadingState.SUCCESS;
}, },
error: (error) => { error: (error) => {
@@ -63,6 +68,38 @@ export class EditChartTypeComponent implements OnInit {
}); });
} }
// Format date to handle both string and object formats
private formatDate(date: any): string {
if (!date) return '';
// If it's already a string, return as is
if (typeof date === 'string') {
return date;
}
// If it's an object, try to convert to string
if (typeof date === 'object') {
// Handle various date object formats
if (date instanceof Date) {
return date.toISOString();
}
// Handle ISO string within object
if (date.date) {
return date.date;
}
// Handle other object formats
try {
return new Date(date).toISOString();
} catch {
return '';
}
}
return '';
}
updateChartType(): void { updateChartType(): void {
if (!this.chartType || !this.chartType.name) { if (!this.chartType || !this.chartType.name) {
this.showError('Chart type name is required'); this.showError('Chart type name is required');
@@ -72,7 +109,12 @@ export class EditChartTypeComponent implements OnInit {
this.loadingState = ClrLoadingState.LOADING; this.loadingState = ClrLoadingState.LOADING;
this.chartTypeService.updateChartType(this.chartType.id, this.chartType).subscribe({ this.chartTypeService.updateChartType(this.chartType.id, this.chartType).subscribe({
next: (data) => { next: (data) => {
this.chartType = data; // Process the data to ensure dates are properly formatted
this.chartType = {
...data,
createdAt: this.formatDate(data.createdAt),
updatedAt: this.formatDate(data.updatedAt)
};
this.showSuccess('Chart type updated successfully'); this.showSuccess('Chart type updated successfully');
this.loadingState = ClrLoadingState.SUCCESS; this.loadingState = ClrLoadingState.SUCCESS;
// Redirect to chart types list after a short delay // Redirect to chart types list after a short delay