|
|
|
@ -26,10 +26,10 @@ import { DataKey, Datasource, DatasourceData, DatasourceType, WidgetConfig } fro |
|
|
|
import { IWidgetSubscription } from '@core/api/widget-api.models'; |
|
|
|
import { |
|
|
|
createLabelFromDatasource, |
|
|
|
isBoolean, isDefined, |
|
|
|
isBoolean, |
|
|
|
isDefined, |
|
|
|
isDefinedAndNotNull, |
|
|
|
isEqual, |
|
|
|
isNotEmptyStr, |
|
|
|
isUndefined |
|
|
|
} from '@core/utils'; |
|
|
|
import { EntityType } from '@shared/models/entity-type.models'; |
|
|
|
@ -42,14 +42,19 @@ import { forkJoin, Observable, Subject } from 'rxjs'; |
|
|
|
import { EntityId } from '@shared/models/id/entity-id'; |
|
|
|
import { ResizeObserver } from '@juggle/resize-observer'; |
|
|
|
import { takeUntil } from 'rxjs/operators'; |
|
|
|
import { |
|
|
|
JsonObjectEditDialogComponent, |
|
|
|
JsonObjectEditDialogData |
|
|
|
} from '@shared/components/dialog/json-object-edit-dialog.component'; |
|
|
|
import { MatDialog } from '@angular/material/dialog'; |
|
|
|
import { DomSanitizer, SafeUrl } from '@angular/platform-browser'; |
|
|
|
|
|
|
|
type FieldAlignment = 'row' | 'column'; |
|
|
|
|
|
|
|
type MultipleInputWidgetDataKeyType = 'server' | 'shared' | 'timeseries'; |
|
|
|
type MultipleInputWidgetDataKeyValueType = 'string' | 'double' | 'integer' | |
|
|
|
'booleanCheckbox' | 'booleanSwitch' | |
|
|
|
'dateTime' | 'date' | 'time' | 'select'; |
|
|
|
export type MultipleInputWidgetDataKeyValueType = 'string' | 'double' | 'integer' | |
|
|
|
'JSON' | 'booleanCheckbox' | 'booleanSwitch' | |
|
|
|
'dateTime' | 'date' | 'time' | 'select'; |
|
|
|
type MultipleInputWidgetDataKeyEditableType = 'editable' | 'disabled' | 'readonly'; |
|
|
|
|
|
|
|
type ConvertGetValueFunction = (value: any, ctx: WidgetContext) => any; |
|
|
|
@ -90,6 +95,7 @@ interface MultipleInputWidgetDataKeySettings { |
|
|
|
invalidDateErrorMessage?: string; |
|
|
|
minValueErrorMessage?: string; |
|
|
|
maxValueErrorMessage?: string; |
|
|
|
invalidJsonErrorMessage?: string; |
|
|
|
useCustomIcon: boolean; |
|
|
|
icon: string; |
|
|
|
customIcon: string ; |
|
|
|
@ -103,6 +109,9 @@ interface MultipleInputWidgetDataKeySettings { |
|
|
|
useSetValueFunction?: boolean; |
|
|
|
setValueFunctionBody?: string; |
|
|
|
setValueFunction?: ConvertSetValueFunction; |
|
|
|
dialogTitle?: string; |
|
|
|
saveButtonLabel?: string; |
|
|
|
cancelButtonLabel?: string; |
|
|
|
} |
|
|
|
|
|
|
|
interface MultipleInputWidgetDataKey extends DataKey { |
|
|
|
@ -161,7 +170,8 @@ export class MultipleInputWidgetComponent extends PageComponent implements OnIni |
|
|
|
private fb: UntypedFormBuilder, |
|
|
|
private attributeService: AttributeService, |
|
|
|
private translate: TranslateService, |
|
|
|
private sanitizer: DomSanitizer) { |
|
|
|
private sanitizer: DomSanitizer, |
|
|
|
private dialog: MatDialog) { |
|
|
|
super(store); |
|
|
|
} |
|
|
|
|
|
|
|
@ -425,6 +435,13 @@ export class MultipleInputWidgetComponent extends PageComponent implements OnIni |
|
|
|
case 'select': |
|
|
|
value = keyValue !== null ? keyValue.toString() : null; |
|
|
|
break; |
|
|
|
case 'JSON': |
|
|
|
try { |
|
|
|
value = JSON.parse(keyValue); |
|
|
|
} catch (e) { |
|
|
|
value = keyValue ? keyValue : null; |
|
|
|
} |
|
|
|
break; |
|
|
|
default: |
|
|
|
value = keyValue; |
|
|
|
} |
|
|
|
@ -520,6 +537,10 @@ export class MultipleInputWidgetComponent extends PageComponent implements OnIni |
|
|
|
errorMessage = keySettings.invalidDateErrorMessage; |
|
|
|
defaultMessage = 'widgets.input-widgets.invalid-date'; |
|
|
|
break; |
|
|
|
case 'invalidJSON': |
|
|
|
errorMessage = keySettings.invalidJsonErrorMessage; |
|
|
|
defaultMessage = 'widgets.input-widgets.json-invalid'; |
|
|
|
break; |
|
|
|
default: |
|
|
|
return ''; |
|
|
|
} |
|
|
|
@ -670,8 +691,8 @@ export class MultipleInputWidgetComponent extends PageComponent implements OnIni |
|
|
|
} |
|
|
|
}); |
|
|
|
if (tasks.length) { |
|
|
|
forkJoin(tasks).subscribe( |
|
|
|
() => { |
|
|
|
forkJoin(tasks).subscribe({ |
|
|
|
next: () => { |
|
|
|
this.multipleInputFormGroup.markAsPristine(); |
|
|
|
this.ctx.detectChanges(); |
|
|
|
this.isSavingInProgress = false; |
|
|
|
@ -680,13 +701,13 @@ export class MultipleInputWidgetComponent extends PageComponent implements OnIni |
|
|
|
1000, 'bottom', 'left', this.toastTargetId); |
|
|
|
} |
|
|
|
}, |
|
|
|
() => { |
|
|
|
error: () => { |
|
|
|
this.isSavingInProgress = false; |
|
|
|
if (this.settings.showResultMessage) { |
|
|
|
this.ctx.showErrorToast(this.translate.instant('widgets.input-widgets.update-failed'), |
|
|
|
'bottom', 'left', this.toastTargetId); |
|
|
|
} |
|
|
|
}); |
|
|
|
}}); |
|
|
|
} else { |
|
|
|
this.multipleInputFormGroup.markAsPristine(); |
|
|
|
this.ctx.detectChanges(); |
|
|
|
@ -718,4 +739,31 @@ export class MultipleInputWidgetComponent extends PageComponent implements OnIni |
|
|
|
}); |
|
|
|
this.multipleInputFormGroup.markAsPristine(); |
|
|
|
} |
|
|
|
|
|
|
|
openEditJSONDialog($event: Event, key: MultipleInputWidgetDataKey, source: MultipleInputWidgetSource) { |
|
|
|
if ($event) { |
|
|
|
$event.stopPropagation(); |
|
|
|
} |
|
|
|
const formControl = this.multipleInputFormGroup.controls[key.formId]; |
|
|
|
this.dialog.open<JsonObjectEditDialogComponent, JsonObjectEditDialogData, object>(JsonObjectEditDialogComponent, { |
|
|
|
disableClose: true, |
|
|
|
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'], |
|
|
|
data: { |
|
|
|
jsonValue: formControl.value, |
|
|
|
title: key.settings.dialogTitle, |
|
|
|
saveLabel: key.settings.saveButtonLabel, |
|
|
|
cancelLabel: key.settings.cancelButtonLabel |
|
|
|
} |
|
|
|
}).afterClosed().subscribe( |
|
|
|
(res) => { |
|
|
|
if (!isEqual(res, formControl.value)) { |
|
|
|
formControl.patchValue(res); |
|
|
|
formControl.markAsDirty(); |
|
|
|
if(!this.settings.showActionButtons) { |
|
|
|
this.inputChanged(source, key); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|