|
|
@ -38,7 +38,7 @@ import { AbstractControl, UntypedFormGroup } from '@angular/forms'; |
|
|
import { Observable } from 'rxjs'; |
|
|
import { Observable } from 'rxjs'; |
|
|
import { Dashboard } from '@shared/models/dashboard.models'; |
|
|
import { Dashboard } from '@shared/models/dashboard.models'; |
|
|
import { IAliasController } from '@core/api/widget-api.models'; |
|
|
import { IAliasController } from '@core/api/widget-api.models'; |
|
|
import { isEmptyStr, isNotEmptyStr } from '@core/utils'; |
|
|
import { isNotEmptyStr } from '@core/utils'; |
|
|
import { WidgetConfigComponentData } from '@home/models/widget-component.models'; |
|
|
import { WidgetConfigComponentData } from '@home/models/widget-component.models'; |
|
|
import { ComponentStyle, Font, TimewindowStyle } from '@shared/models/widget-settings.models'; |
|
|
import { ComponentStyle, Font, TimewindowStyle } from '@shared/models/widget-settings.models'; |
|
|
import { NULL_UUID } from '@shared/models/id/has-uuid'; |
|
|
import { NULL_UUID } from '@shared/models/id/has-uuid'; |
|
|
@ -750,23 +750,10 @@ export interface IWidgetSettingsComponent { |
|
|
functionScopeVariables: string[]; |
|
|
functionScopeVariables: string[]; |
|
|
settings: WidgetSettings; |
|
|
settings: WidgetSettings; |
|
|
settingsChanged: Observable<WidgetSettings>; |
|
|
settingsChanged: Observable<WidgetSettings>; |
|
|
validate(); |
|
|
validateSettings(): boolean; |
|
|
[key: string]: any; |
|
|
[key: string]: any; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const removeEmptyWidgetSettings = (settings: WidgetSettings): WidgetSettings => { |
|
|
|
|
|
if (settings) { |
|
|
|
|
|
const keys = Object.keys(settings); |
|
|
|
|
|
for (const key of keys) { |
|
|
|
|
|
const val = settings[key]; |
|
|
|
|
|
if (val === null || isEmptyStr(val)) { |
|
|
|
|
|
delete settings[key]; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return settings; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
@Directive() |
|
|
@Directive() |
|
|
// eslint-disable-next-line @angular-eslint/directive-class-suffix
|
|
|
// eslint-disable-next-line @angular-eslint/directive-class-suffix
|
|
|
export abstract class WidgetSettingsComponent extends PageComponent implements |
|
|
export abstract class WidgetSettingsComponent extends PageComponent implements |
|
|
@ -823,15 +810,15 @@ export abstract class WidgetSettingsComponent extends PageComponent implements |
|
|
ngOnInit() {} |
|
|
ngOnInit() {} |
|
|
|
|
|
|
|
|
ngAfterViewInit(): void { |
|
|
ngAfterViewInit(): void { |
|
|
setTimeout(() => { |
|
|
if (!this.validateSettings()) { |
|
|
if (!this.validateSettings()) { |
|
|
setTimeout(() => { |
|
|
this.settingsChangedEmitter.emit(null); |
|
|
this.onSettingsChanged(this.prepareOutputSettings(this.settingsForm().getRawValue())); |
|
|
} |
|
|
}, 0); |
|
|
}, 0); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
validate() { |
|
|
public validateSettings(): boolean { |
|
|
this.onValidate(); |
|
|
return this.settingsForm().valid; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
protected setupSettings(settings: WidgetSettings) { |
|
|
protected setupSettings(settings: WidgetSettings) { |
|
|
@ -847,8 +834,8 @@ export abstract class WidgetSettingsComponent extends PageComponent implements |
|
|
this.updateValidators(true, trigger); |
|
|
this.updateValidators(true, trigger); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
this.settingsForm().valueChanges.subscribe((updated: any) => { |
|
|
this.settingsForm().valueChanges.subscribe(() => { |
|
|
this.onSettingsChanged(this.prepareOutputSettings(updated)); |
|
|
this.onSettingsChanged(this.prepareOutputSettings(this.settingsForm().getRawValue())); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -867,12 +854,8 @@ export abstract class WidgetSettingsComponent extends PageComponent implements |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
protected onSettingsChanged(updated: WidgetSettings) { |
|
|
protected onSettingsChanged(updated: WidgetSettings) { |
|
|
this.settingsValue = removeEmptyWidgetSettings(updated); |
|
|
this.settingsValue = updated; |
|
|
if (this.validateSettings()) { |
|
|
this.settingsChangedEmitter.emit(this.settingsValue); |
|
|
this.settingsChangedEmitter.emit(this.settingsValue); |
|
|
|
|
|
} else { |
|
|
|
|
|
this.settingsChangedEmitter.emit(null); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
protected doUpdateSettings(settingsForm: UntypedFormGroup, settings: WidgetSettings) { |
|
|
protected doUpdateSettings(settingsForm: UntypedFormGroup, settings: WidgetSettings) { |
|
|
@ -886,12 +869,6 @@ export abstract class WidgetSettingsComponent extends PageComponent implements |
|
|
return settings; |
|
|
return settings; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
protected validateSettings(): boolean { |
|
|
|
|
|
return this.settingsForm().valid; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected onValidate() {} |
|
|
|
|
|
|
|
|
|
|
|
protected abstract settingsForm(): UntypedFormGroup; |
|
|
protected abstract settingsForm(): UntypedFormGroup; |
|
|
|
|
|
|
|
|
protected abstract onSettingsSet(settings: WidgetSettings); |
|
|
protected abstract onSettingsSet(settings: WidgetSettings); |
|
|
|