|
|
|
@ -88,6 +88,8 @@ import { |
|
|
|
ExportResourceDialogDialogResult |
|
|
|
} from '@shared/import-export/export-resource-dialog.component'; |
|
|
|
import { FormProperty, propertyValid } from '@shared/models/dynamic-form.models'; |
|
|
|
import { CalculatedFieldsService } from '@core/http/calculated-fields.service'; |
|
|
|
import { CalculatedField } from '@shared/models/calculated-field.models'; |
|
|
|
|
|
|
|
export type editMissingAliasesFunction = (widgets: Array<Widget>, isSingleWidget: boolean, |
|
|
|
customTitle: string, missingEntityAliases: EntityAliases) => Observable<EntityAliases>; |
|
|
|
@ -116,6 +118,7 @@ export class ImportExportService { |
|
|
|
private imageService: ImageService, |
|
|
|
private utils: UtilsService, |
|
|
|
private itembuffer: ItemBufferService, |
|
|
|
private calculatedFieldsService: CalculatedFieldsService, |
|
|
|
private dialog: MatDialog) { |
|
|
|
|
|
|
|
} |
|
|
|
@ -171,6 +174,35 @@ export class ImportExportService { |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
public exportCalculatedField(calculatedFieldId: string): void { |
|
|
|
this.calculatedFieldsService.getCalculatedFieldById(calculatedFieldId).subscribe({ |
|
|
|
next: (calculatedField) => { |
|
|
|
let name = calculatedField.name; |
|
|
|
name = name.toLowerCase().replace(/\W/g, '_'); |
|
|
|
this.exportToPc(this.prepareCalculatedFieldExport(calculatedField), name); |
|
|
|
}, |
|
|
|
error: (e) => { |
|
|
|
this.handleExportError(e, 'calculated-fields.export-failed-error'); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
public importCalculatedField(entityId: EntityId): Observable<CalculatedField> { |
|
|
|
return this.openImportDialog('calculated-fields.import', 'calculated-fields.file').pipe( |
|
|
|
mergeMap((calculatedField: CalculatedField) => { |
|
|
|
if (!this.validateImportedCalculatedField({ entityId, ...calculatedField })) { |
|
|
|
this.store.dispatch(new ActionNotificationShow( |
|
|
|
{message: this.translate.instant('calculated-fields.invalid-file-error'), |
|
|
|
type: 'error'})); |
|
|
|
throw new Error('Invalid calculated field file'); |
|
|
|
} else { |
|
|
|
return this.calculatedFieldsService.saveCalculatedField(this.prepareImport({ entityId, ...calculatedField })); |
|
|
|
} |
|
|
|
}), |
|
|
|
catchError(() => of(null)), |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
public exportDashboard(dashboardId: string) { |
|
|
|
this.getIncludeResourcesPreference('includeResourcesInExportDashboard').subscribe(includeResources => { |
|
|
|
this.openExportDialog('dashboard.export', 'dashboard.export-prompt', includeResources).subscribe(result => { |
|
|
|
@ -957,6 +989,17 @@ export class ImportExportService { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private validateImportedCalculatedField(calculatedField: CalculatedField): boolean { |
|
|
|
const { name, configuration, entityId } = calculatedField; |
|
|
|
return isNotEmptyStr(name) |
|
|
|
&& isDefined(configuration) |
|
|
|
&& isDefined(entityId?.id) |
|
|
|
&& !!Object.keys(configuration.arguments).length |
|
|
|
&& isDefined(configuration.expression) |
|
|
|
&& isDefined(configuration.output) |
|
|
|
&& isNotEmptyStr(configuration.output.name); |
|
|
|
} |
|
|
|
|
|
|
|
private validateImportedImage(image: ImageExportData): boolean { |
|
|
|
return !(!isNotEmptyStr(image.data) |
|
|
|
|| !isNotEmptyStr(image.title) |
|
|
|
@ -1209,6 +1252,11 @@ export class ImportExportService { |
|
|
|
return profile; |
|
|
|
} |
|
|
|
|
|
|
|
private prepareCalculatedFieldExport(calculatedField: CalculatedField): CalculatedField { |
|
|
|
delete calculatedField.entityId; |
|
|
|
return this.prepareExport(calculatedField); |
|
|
|
} |
|
|
|
|
|
|
|
private prepareExport(data: any): any { |
|
|
|
const exportedData = deepClone(data); |
|
|
|
if (isDefined(exportedData.id)) { |
|
|
|
|