Add dashboard and widget reference to widget settings form. Add default value method.

This commit is contained in:
Igor Kulikov 2022-03-22 17:13:21 +02:00
parent cb32151ffe
commit ec6a7ae5a4
14 changed files with 96 additions and 37 deletions

View File

@ -163,8 +163,9 @@
"templateHtml": "<tb-qrcode-widget \n [ctx]=\"ctx\">\n</tb-qrcode-widget>", "templateHtml": "<tb-qrcode-widget \n [ctx]=\"ctx\">\n</tb-qrcode-widget>",
"templateCss": "#container {\n overflow: auto;\n}\n\n.tbDatasource-container {\n margin: 5px;\n padding: 8px;\n}\n\n.tbDatasource-title {\n font-size: 1.200rem;\n font-weight: 500;\n padding-bottom: 10px;\n}\n\n.tbDatasource-table {\n width: 100%;\n box-shadow: 0 0 10px #ccc;\n border-collapse: collapse;\n white-space: nowrap;\n font-size: 1.000rem;\n color: #757575;\n}\n\n.tbDatasource-table td {\n position: relative;\n border-top: 1px solid rgba(0, 0, 0, 0.12);\n border-bottom: 1px solid rgba(0, 0, 0, 0.12);\n padding: 0px 18px;\n box-sizing: border-box;\n}", "templateCss": "#container {\n overflow: auto;\n}\n\n.tbDatasource-container {\n margin: 5px;\n padding: 8px;\n}\n\n.tbDatasource-title {\n font-size: 1.200rem;\n font-weight: 500;\n padding-bottom: 10px;\n}\n\n.tbDatasource-table {\n width: 100%;\n box-shadow: 0 0 10px #ccc;\n border-collapse: collapse;\n white-space: nowrap;\n font-size: 1.000rem;\n color: #757575;\n}\n\n.tbDatasource-table td {\n position: relative;\n border-top: 1px solid rgba(0, 0, 0, 0.12);\n border-bottom: 1px solid rgba(0, 0, 0, 0.12);\n padding: 0px 18px;\n box-sizing: border-box;\n}",
"controllerScript": "self.onInit = function() {\n}\n\nself.onDataUpdated = function() {\n self.ctx.$scope.qrCodeWidget.onDataUpdated();\n}\n\nself.typeParameters = function() {\n return {\n dataKeysOptional: true,\n datasourcesOptional: true\n };\n}\n\nself.onDestroy = function() {\n}\n\n", "controllerScript": "self.onInit = function() {\n}\n\nself.onDataUpdated = function() {\n self.ctx.$scope.qrCodeWidget.onDataUpdated();\n}\n\nself.typeParameters = function() {\n return {\n dataKeysOptional: true,\n datasourcesOptional: true\n };\n}\n\nself.onDestroy = function() {\n}\n\n",
"settingsSchema": "{\n \"schema\": {\n \"type\": \"object\",\n \"title\": \"QR Code\",\n \"properties\": {\n \"qrCodeTextPattern\": {\n \"title\": \"QR code text pattern (for ex. '${entityName} | ${keyName} - some text.')\",\n \"type\": \"string\",\n \"default\": \"${entityName}\"\n },\n \"useQrCodeTextFunction\": {\n \"title\": \"Use QR code text function\",\n \"type\": \"boolean\",\n \"default\": false\n },\n \"qrCodeTextFunction\": {\n \"title\": \"QR code text function: f(data)\",\n \"type\": \"string\",\n \"default\": \"return data[0]['entityName'];\"\n }\n },\n \"required\": []\n },\n \"form\": [\n \"useQrCodeTextFunction\",\n {\n \"key\": \"qrCodeTextPattern\",\n \"condition\": \"model.useQrCodeTextFunction !== true\"\n },\n {\n \"key\": \"qrCodeTextFunction\",\n \"type\": \"javascript\",\n \"helpId\": \"widget/lib/qrcode/qrcode_text_fn\",\n \"condition\": \"model.useQrCodeTextFunction === true\"\n }\n ]\n}\n", "settingsSchema": "{}\n",
"dataKeySettingsSchema": "{}\n", "dataKeySettingsSchema": "{}\n",
"settingsDirective": "tb-qrcode-widget-settings",
"defaultConfig": "{\"datasources\":[{\"type\":\"function\",\"name\":\"function\",\"entityAliasId\":null,\"filterId\":null,\"dataKeys\":[{\"name\":\"f(x)\",\"type\":\"function\",\"label\":\"Random\",\"color\":\"#2196f3\",\"settings\":{},\"_hash\":0.7036904308224163,\"funcBody\":\"var value = prevValue + Math.random() * 100 - 50;\\nvar multiplier = Math.pow(10, 2 || 0);\\nvar value = Math.round(value * multiplier) / multiplier;\\nif (value < -1000) {\\n\\tvalue = -1000;\\n} else if (value > 1000) {\\n\\tvalue = 1000;\\n}\\nreturn value;\"}]}],\"timewindow\":{\"realtime\":{\"timewindowMs\":60000}},\"showTitle\":true,\"backgroundColor\":\"#fff\",\"color\":\"rgba(0, 0, 0, 0.87)\",\"padding\":\"8px\",\"settings\":{\"qrCodeTextPattern\":\"${entityName}\",\"useQrCodeTextFunction\":false,\"qrCodeTextFunction\":\"return data[0] ? data[0]['entityName'] : '';\"},\"title\":\"QR Code\"}" "defaultConfig": "{\"datasources\":[{\"type\":\"function\",\"name\":\"function\",\"entityAliasId\":null,\"filterId\":null,\"dataKeys\":[{\"name\":\"f(x)\",\"type\":\"function\",\"label\":\"Random\",\"color\":\"#2196f3\",\"settings\":{},\"_hash\":0.7036904308224163,\"funcBody\":\"var value = prevValue + Math.random() * 100 - 50;\\nvar multiplier = Math.pow(10, 2 || 0);\\nvar value = Math.round(value * multiplier) / multiplier;\\nif (value < -1000) {\\n\\tvalue = -1000;\\n} else if (value > 1000) {\\n\\tvalue = 1000;\\n}\\nreturn value;\"}]}],\"timewindow\":{\"realtime\":{\"timewindowMs\":60000}},\"showTitle\":true,\"backgroundColor\":\"#fff\",\"color\":\"rgba(0, 0, 0, 0.87)\",\"padding\":\"8px\",\"settings\":{\"qrCodeTextPattern\":\"${entityName}\",\"useQrCodeTextFunction\":false,\"qrCodeTextFunction\":\"return data[0] ? data[0]['entityName'] : '';\"},\"title\":\"QR Code\"}"
} }
}, },

View File

@ -33,9 +33,8 @@
<tb-widget-config <tb-widget-config
[aliasController]="aliasController" [aliasController]="aliasController"
[functionsOnly]="false" [functionsOnly]="false"
[entityAliases]="dashboard.configuration.entityAliases" [dashboard]="dashboard"
[filters]="dashboard.configuration.filters" [widget]="widget"
[dashboardStates]="dashboard.configuration.states"
formControlName="widgetConfig"> formControlName="widgetConfig">
</tb-widget-config> </tb-widget-config>
</fieldset> </fieldset>

View File

@ -20,9 +20,8 @@
<tb-widget-config <tb-widget-config
[aliasController]="aliasController" [aliasController]="aliasController"
[functionsOnly]="widgetEditMode" [functionsOnly]="widgetEditMode"
[entityAliases]="dashboard.configuration.entityAliases" [dashboard]="dashboard"
[filters]="dashboard.configuration.filters" [widget]="widget"
[dashboardStates]="dashboard.configuration.states"
formControlName="widgetConfig"> formControlName="widgetConfig">
</tb-widget-config> </tb-widget-config>
</fieldset> </fieldset>

View File

@ -33,6 +33,8 @@
[dataKeySettingsSchema]="data.dataKeySettingsSchema" [dataKeySettingsSchema]="data.dataKeySettingsSchema"
[dataKeySettingsDirective]="data.dataKeySettingsDirective" [dataKeySettingsDirective]="data.dataKeySettingsDirective"
[entityAliasId]="data.entityAliasId" [entityAliasId]="data.entityAliasId"
[dashboard]="data.dashboard"
[widget]="data.widget"
[showPostProcessing]="data.showPostProcessing" [showPostProcessing]="data.showPostProcessing"
[callbacks]="data.callbacks" [callbacks]="data.callbacks"
formControlName="dataKey"> formControlName="dataKey">

View File

@ -22,14 +22,17 @@ import { AppState } from '@core/core.state';
import { FormBuilder, FormControl, FormGroup, FormGroupDirective, NgForm, Validators } from '@angular/forms'; import { FormBuilder, FormControl, FormGroup, FormGroupDirective, NgForm, Validators } from '@angular/forms';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { DialogComponent } from '@shared/components/dialog.component'; import { DialogComponent } from '@shared/components/dialog.component';
import { DataKey } from '@shared/models/widget.models'; import { DataKey, Widget } from '@shared/models/widget.models';
import { DataKeysCallbacks } from './data-keys.component.models'; import { DataKeysCallbacks } from './data-keys.component.models';
import { DataKeyConfigComponent } from '@home/components/widget/data-key-config.component'; import { DataKeyConfigComponent } from '@home/components/widget/data-key-config.component';
import { Dashboard } from '@shared/models/dashboard.models';
export interface DataKeyConfigDialogData { export interface DataKeyConfigDialogData {
dataKey: DataKey; dataKey: DataKey;
dataKeySettingsSchema: any; dataKeySettingsSchema: any;
dataKeySettingsDirective: string; dataKeySettingsDirective: string;
dashboard: Dashboard;
widget: Widget;
entityAliasId?: string; entityAliasId?: string;
showPostProcessing?: boolean; showPostProcessing?: boolean;
callbacks?: DataKeysCallbacks; callbacks?: DataKeysCallbacks;

View File

@ -100,6 +100,8 @@
<div class="mat-padding" fxLayout="column"> <div class="mat-padding" fxLayout="column">
<tb-widget-settings <tb-widget-settings
[settingsDirective]="dataKeySettingsDirective" [settingsDirective]="dataKeySettingsDirective"
[dashboard]="dashboard"
[widget]="widget"
formControlName="settings"> formControlName="settings">
</tb-widget-settings> </tb-widget-settings>
</div> </div>

View File

@ -18,7 +18,7 @@ import { Component, ElementRef, forwardRef, Input, OnInit, ViewChild } from '@an
import { PageComponent } from '@shared/components/page.component'; import { PageComponent } from '@shared/components/page.component';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
import { AppState } from '@core/core.state'; import { AppState } from '@core/core.state';
import { DataKey } from '@shared/models/widget.models'; import { DataKey, Widget } from '@shared/models/widget.models';
import { import {
ControlValueAccessor, ControlValueAccessor,
FormBuilder, FormBuilder,
@ -41,6 +41,7 @@ import { alarmFields } from '@shared/models/alarm.models';
import { JsFuncComponent } from '@shared/components/js-func.component'; import { JsFuncComponent } from '@shared/components/js-func.component';
import { JsonFormComponentData } from '@shared/components/json-form/json-form-component.models'; import { JsonFormComponentData } from '@shared/components/json-form/json-form-component.models';
import { WidgetService } from '@core/http/widget.service'; import { WidgetService } from '@core/http/widget.service';
import { Dashboard } from '@shared/models/dashboard.models';
@Component({ @Component({
selector: 'tb-data-key-config', selector: 'tb-data-key-config',
@ -69,6 +70,12 @@ export class DataKeyConfigComponent extends PageComponent implements OnInit, Con
@Input() @Input()
callbacks: DataKeysCallbacks; callbacks: DataKeysCallbacks;
@Input()
dashboard: Dashboard;
@Input()
widget: Widget;
@Input() @Input()
dataKeySettingsSchema: any; dataKeySettingsSchema: any;

View File

@ -46,7 +46,7 @@ import { MatAutocomplete } from '@angular/material/autocomplete';
import { MatChipInputEvent, MatChipList } from '@angular/material/chips'; import { MatChipInputEvent, MatChipList } from '@angular/material/chips';
import { coerceBooleanProperty } from '@angular/cdk/coercion'; import { coerceBooleanProperty } from '@angular/cdk/coercion';
import { DataKeyType } from '@shared/models/telemetry/telemetry.models'; import { DataKeyType } from '@shared/models/telemetry/telemetry.models';
import { DataKey, DatasourceType, widgetType } from '@shared/models/widget.models'; import { DataKey, DatasourceType, Widget, widgetType } from '@shared/models/widget.models';
import { IAliasController } from '@core/api/widget-api.models'; import { IAliasController } from '@core/api/widget-api.models';
import { DataKeysCallbacks } from './data-keys.component.models'; import { DataKeysCallbacks } from './data-keys.component.models';
import { alarmFields } from '@shared/models/alarm.models'; import { alarmFields } from '@shared/models/alarm.models';
@ -61,6 +61,7 @@ import {
} from '@home/components/widget/data-key-config-dialog.component'; } from '@home/components/widget/data-key-config-dialog.component';
import { deepClone } from '@core/utils'; import { deepClone } from '@core/utils';
import { MatChipDropEvent } from '@app/shared/components/mat-chip-draggable.directive'; import { MatChipDropEvent } from '@app/shared/components/mat-chip-draggable.directive';
import { Dashboard } from '@shared/models/dashboard.models';
@Component({ @Component({
selector: 'tb-data-keys', selector: 'tb-data-keys',
@ -116,6 +117,12 @@ export class DataKeysComponent implements ControlValueAccessor, OnInit, AfterVie
@Input() @Input()
dataKeySettingsDirective: string; dataKeySettingsDirective: string;
@Input()
dashboard: Dashboard;
@Input()
widget: Widget;
@Input() @Input()
callbacks: DataKeysCallbacks; callbacks: DataKeysCallbacks;
@ -399,6 +406,8 @@ export class DataKeysComponent implements ControlValueAccessor, OnInit, AfterVie
dataKey: deepClone(key), dataKey: deepClone(key),
dataKeySettingsSchema: this.datakeySettingsSchema, dataKeySettingsSchema: this.datakeySettingsSchema,
dataKeySettingsDirective: this.dataKeySettingsDirective, dataKeySettingsDirective: this.dataKeySettingsDirective,
dashboard: this.dashboard,
widget: this.widget,
entityAliasId: this.entityAliasId, entityAliasId: this.entityAliasId,
showPostProcessing: this.widgetType !== widgetType.alarm, showPostProcessing: this.widgetType !== widgetType.alarm,
callbacks: this.callbacks callbacks: this.callbacks

View File

@ -28,7 +28,8 @@
</mat-form-field> </mat-form-field>
<section fxLayout="column" [fxShow]="qrCodeWidgetSettingsForm.get('useQrCodeTextFunction').value === true"> <section fxLayout="column" [fxShow]="qrCodeWidgetSettingsForm.get('useQrCodeTextFunction').value === true">
<label translate class="tb-title no-padding">widgets.qr-code.qr-code-text-function</label> <label translate class="tb-title no-padding">widgets.qr-code.qr-code-text-function</label>
<tb-js-func formControlName="qrCodeTextFunction" <tb-js-func #qrCodeTextFunctionComponent
formControlName="qrCodeTextFunction"
[functionArgs]="['data']" [functionArgs]="['data']"
helpId="widget/lib/qrcode/qrcode_text_fn"> helpId="widget/lib/qrcode/qrcode_text_fn">
</tb-js-func> </tb-js-func>

View File

@ -14,12 +14,12 @@
/// limitations under the License. /// limitations under the License.
/// ///
import { Component } from '@angular/core'; import { Component, ViewChild } from '@angular/core';
import { WidgetSettings, WidgetSettingsComponent } from '@shared/models/widget.models'; import { WidgetSettings, WidgetSettingsComponent } from '@shared/models/widget.models';
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { AbstractControl, FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
import { AppState } from '@core/core.state'; import { AppState } from '@core/core.state';
import { JsFuncComponent } from '@shared/components/js-func.component';
@Component({ @Component({
selector: 'tb-qrcode-widget-settings', selector: 'tb-qrcode-widget-settings',
@ -28,6 +28,8 @@ import { AppState } from '@core/core.state';
}) })
export class QrCodeWidgetSettingsComponent extends WidgetSettingsComponent { export class QrCodeWidgetSettingsComponent extends WidgetSettingsComponent {
@ViewChild('qrCodeTextFunctionComponent', {static: true}) qrCodeTextFunctionComponent: JsFuncComponent;
qrCodeWidgetSettingsForm: FormGroup; qrCodeWidgetSettingsForm: FormGroup;
constructor(protected store: Store<AppState>, constructor(protected store: Store<AppState>,
@ -39,11 +41,19 @@ export class QrCodeWidgetSettingsComponent extends WidgetSettingsComponent {
return this.qrCodeWidgetSettingsForm; return this.qrCodeWidgetSettingsForm;
} }
protected defaultSettings(): WidgetSettings {
return {
qrCodeTextPattern: '${entityName}',
useQrCodeTextFunction: false,
qrCodeTextFunction: 'return data[0][\'entityName\'];'
};
}
protected onSettingsSet(settings: WidgetSettings) { protected onSettingsSet(settings: WidgetSettings) {
this.qrCodeWidgetSettingsForm = this.fb.group({ this.qrCodeWidgetSettingsForm = this.fb.group({
qrCodeTextPattern: [settings ? settings.qrCodeTextPattern : '${entityName}', []], qrCodeTextPattern: [settings.qrCodeTextPattern, []],
useQrCodeTextFunction: [settings ? settings.useQrCodeTextFunction : false, []], useQrCodeTextFunction: [settings.useQrCodeTextFunction, []],
qrCodeTextFunction: [settings ? settings.qrCodeTextFunction : 'return data[0][\'entityName\'];', []] qrCodeTextFunction: [settings.qrCodeTextFunction, []]
}); });
} }
@ -55,7 +65,9 @@ export class QrCodeWidgetSettingsComponent extends WidgetSettingsComponent {
const useQrCodeTextFunction: boolean = this.qrCodeWidgetSettingsForm.get('useQrCodeTextFunction').value; const useQrCodeTextFunction: boolean = this.qrCodeWidgetSettingsForm.get('useQrCodeTextFunction').value;
if (useQrCodeTextFunction) { if (useQrCodeTextFunction) {
this.qrCodeWidgetSettingsForm.get('qrCodeTextPattern').setValidators([]); this.qrCodeWidgetSettingsForm.get('qrCodeTextPattern').setValidators([]);
this.qrCodeWidgetSettingsForm.get('qrCodeTextFunction').setValidators([Validators.required]); this.qrCodeWidgetSettingsForm.get('qrCodeTextFunction').setValidators([Validators.required,
(control: AbstractControl) => this.qrCodeTextFunctionComponent.validate(control as FormControl)
]);
} else { } else {
this.qrCodeWidgetSettingsForm.get('qrCodeTextPattern').setValidators([Validators.required]); this.qrCodeWidgetSettingsForm.get('qrCodeTextPattern').setValidators([Validators.required]);
this.qrCodeWidgetSettingsForm.get('qrCodeTextFunction').setValidators([]); this.qrCodeWidgetSettingsForm.get('qrCodeTextFunction').setValidators([]);

View File

@ -191,6 +191,8 @@
[aliasController]="aliasController" [aliasController]="aliasController"
[datakeySettingsSchema]="modelValue?.dataKeySettingsSchema" [datakeySettingsSchema]="modelValue?.dataKeySettingsSchema"
[dataKeySettingsDirective]="modelValue?.dataKeySettingsDirective" [dataKeySettingsDirective]="modelValue?.dataKeySettingsDirective"
[dashboard]="dashboard"
[widget]="widget"
[callbacks]="widgetConfigCallbacks" [callbacks]="widgetConfigCallbacks"
[entityAliasId]="datasourceControl.get('entityAliasId').value" [entityAliasId]="datasourceControl.get('entityAliasId').value"
[formControl]="datasourceControl.get('dataKeys')"> [formControl]="datasourceControl.get('dataKeys')">
@ -285,6 +287,8 @@
[aliasController]="aliasController" [aliasController]="aliasController"
[datakeySettingsSchema]="modelValue?.dataKeySettingsSchema" [datakeySettingsSchema]="modelValue?.dataKeySettingsSchema"
[dataKeySettingsDirective]="modelValue?.dataKeySettingsDirective" [dataKeySettingsDirective]="modelValue?.dataKeySettingsDirective"
[dashboard]="dashboard"
[widget]="widget"
[callbacks]="widgetConfigCallbacks" [callbacks]="widgetConfigCallbacks"
[entityAliasId]="alarmSourceSettings.get('entityAliasId').value" [entityAliasId]="alarmSourceSettings.get('entityAliasId').value"
formControlName="dataKeys"> formControlName="dataKeys">
@ -480,6 +484,8 @@
fxLayout="column"> fxLayout="column">
<tb-widget-settings <tb-widget-settings
[settingsDirective]="modelValue.settingsDirective" [settingsDirective]="modelValue.settingsDirective"
[dashboard]="dashboard"
[widget]="widget"
formControlName="settings"> formControlName="settings">
</tb-widget-settings> </tb-widget-settings>
</div> </div>

View File

@ -25,7 +25,7 @@ import {
datasourceTypeTranslationMap, datasourceTypeTranslationMap,
defaultLegendConfig, defaultLegendConfig,
GroupInfo, GroupInfo,
JsonSchema, JsonSchema, Widget,
widgetType widgetType
} from '@shared/models/widget.models'; } from '@shared/models/widget.models';
import { import {
@ -65,7 +65,7 @@ import { MatDialog } from '@angular/material/dialog';
import { EntityService } from '@core/http/entity.service'; import { EntityService } from '@core/http/entity.service';
import { JsonFormComponentData } from '@shared/components/json-form/json-form-component.models'; import { JsonFormComponentData } from '@shared/components/json-form/json-form-component.models';
import { WidgetActionsData } from './action/manage-widget-actions.component.models'; import { WidgetActionsData } from './action/manage-widget-actions.component.models';
import { DashboardState } from '@shared/models/dashboard.models'; import { Dashboard, DashboardState } from '@shared/models/dashboard.models';
import { entityFields } from '@shared/models/entity.models'; import { entityFields } from '@shared/models/entity.models';
import { Filter, Filters } from '@shared/models/query/query.models'; import { Filter, Filters } from '@shared/models/query/query.models';
import { FilterDialogComponent, FilterDialogData } from '@home/components/filter/filter-dialog.component'; import { FilterDialogComponent, FilterDialogData } from '@home/components/filter/filter-dialog.component';
@ -126,17 +126,14 @@ export class WidgetConfigComponent extends PageComponent implements OnInit, Cont
aliasController: IAliasController; aliasController: IAliasController;
@Input() @Input()
entityAliases: EntityAliases; dashboard: Dashboard;
@Input() @Input()
filters: Filters; widget: Widget;
@Input() @Input()
functionsOnly: boolean; functionsOnly: boolean;
@Input()
dashboardStates: {[id: string]: DashboardState };
@Input() disabled: boolean; @Input() disabled: boolean;
widgetType: widgetType; widgetType: widgetType;
@ -831,14 +828,14 @@ export class WidgetConfigComponent extends PageComponent implements OnInit, Cont
data: { data: {
isAdd: true, isAdd: true,
allowedEntityTypes, allowedEntityTypes,
entityAliases: this.entityAliases, entityAliases: this.dashboard.configuration.entityAliases,
alias: singleEntityAlias alias: singleEntityAlias
} }
}).afterClosed().pipe( }).afterClosed().pipe(
tap((entityAlias) => { tap((entityAlias) => {
if (entityAlias) { if (entityAlias) {
this.entityAliases[entityAlias.id] = entityAlias; this.dashboard.configuration.entityAliases[entityAlias.id] = entityAlias;
this.aliasController.updateEntityAliases(this.entityAliases); this.aliasController.updateEntityAliases(this.dashboard.configuration.entityAliases);
} }
}) })
); );
@ -852,14 +849,14 @@ export class WidgetConfigComponent extends PageComponent implements OnInit, Cont
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'], panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
data: { data: {
isAdd: true, isAdd: true,
filters: this.filters, filters: this.dashboard.configuration.filters,
filter: singleFilter filter: singleFilter
} }
}).afterClosed().pipe( }).afterClosed().pipe(
tap((result) => { tap((result) => {
if (result) { if (result) {
this.filters[result.id] = result; this.dashboard.configuration.filters[result.id] = result;
this.aliasController.updateFilters(this.filters); this.aliasController.updateFilters(this.dashboard.configuration.filters);
} }
}) })
); );
@ -881,7 +878,7 @@ export class WidgetConfigComponent extends PageComponent implements OnInit, Cont
} }
private fetchDashboardStates(query: string): Array<string> { private fetchDashboardStates(query: string): Array<string> {
const stateIds = Object.keys(this.dashboardStates); const stateIds = Object.keys(this.dashboard.configuration.states);
const result = query ? stateIds.filter(this.createFilterForDashboardState(query)) : stateIds; const result = query ? stateIds.filter(this.createFilterForDashboardState(query)) : stateIds;
if (result && result.length) { if (result && result.length) {
return result; return result;

View File

@ -40,8 +40,9 @@ import { deepClone } from '@core/utils';
import { RuleChainType } from '@shared/models/rule-chain.models'; import { RuleChainType } from '@shared/models/rule-chain.models';
import { JsonFormComponent } from '@shared/components/json-form/json-form.component'; import { JsonFormComponent } from '@shared/components/json-form/json-form.component';
import { JsonFormComponentData } from '@shared/components/json-form/json-form-component.models'; import { JsonFormComponentData } from '@shared/components/json-form/json-form-component.models';
import { IWidgetSettingsComponent, WidgetSettings } from '@shared/models/widget.models'; import { IWidgetSettingsComponent, Widget, WidgetSettings } from '@shared/models/widget.models';
import { widgetSettingsComponentsMap } from '@home/components/widget/lib/settings/widget-settings.module'; import { widgetSettingsComponentsMap } from '@home/components/widget/lib/settings/widget-settings.module';
import { Dashboard } from '@shared/models/dashboard.models';
@Component({ @Component({
selector: 'tb-widget-settings', selector: 'tb-widget-settings',
@ -62,6 +63,12 @@ export class WidgetSettingsComponent implements ControlValueAccessor, OnInit, On
@Input() @Input()
disabled: boolean; disabled: boolean;
@Input()
dashboard: Dashboard;
@Input()
widget: Widget;
settingsDirectiveValue: string; settingsDirectiveValue: string;
@Input() @Input()
@ -134,6 +141,8 @@ export class WidgetSettingsComponent implements ControlValueAccessor, OnInit, On
this.changeSubscription = null; this.changeSubscription = null;
} }
if (this.definedSettingsComponent) { if (this.definedSettingsComponent) {
this.definedSettingsComponent.dashboard = this.dashboard;
this.definedSettingsComponent.widget = this.widget;
this.definedSettingsComponent.settings = this.widgetSettingsFormData.model; this.definedSettingsComponent.settings = this.widgetSettingsFormData.model;
this.changeSubscription = this.definedSettingsComponent.settingsChanged.subscribe((settings) => { this.changeSubscription = this.definedSettingsComponent.settingsChanged.subscribe((settings) => {
this.updateModel(settings); this.updateModel(settings);
@ -185,7 +194,8 @@ export class WidgetSettingsComponent implements ControlValueAccessor, OnInit, On
const factory = this.cfr.resolveComponentFactory(componentType); const factory = this.cfr.resolveComponentFactory(componentType);
this.definedSettingsComponentRef = this.definedSettingsContainer.createComponent(factory); this.definedSettingsComponentRef = this.definedSettingsContainer.createComponent(factory);
this.definedSettingsComponent = this.definedSettingsComponentRef.instance; this.definedSettingsComponent = this.definedSettingsComponentRef.instance;
this.definedSettingsComponent.settings = this.widgetSettingsFormData?.model; this.definedSettingsComponent.dashboard = this.dashboard;
this.definedSettingsComponent.widget = this.widget;
this.changeSubscription = this.definedSettingsComponent.settingsChanged.subscribe((settings) => { this.changeSubscription = this.definedSettingsComponent.settingsChanged.subscribe((settings) => {
this.updateModel(settings); this.updateModel(settings);
}); });

View File

@ -33,6 +33,7 @@ import { AbstractControl, FormGroup } from '@angular/forms';
import {RuleChainType} from "@shared/models/rule-chain.models"; import {RuleChainType} from "@shared/models/rule-chain.models";
import {Observable} from "rxjs"; import {Observable} from "rxjs";
import {RuleNodeConfiguration} from "@shared/models/rule-node.models"; import {RuleNodeConfiguration} from "@shared/models/rule-node.models";
import { Dashboard } from '@shared/models/dashboard.models';
export enum widgetType { export enum widgetType {
timeseries = 'timeseries', timeseries = 'timeseries',
@ -587,6 +588,8 @@ export interface WidgetSize {
} }
export interface IWidgetSettingsComponent { export interface IWidgetSettingsComponent {
dashboard: Dashboard;
widget: Widget;
settings: WidgetSettings; settings: WidgetSettings;
settingsChanged: Observable<WidgetSettings>; settingsChanged: Observable<WidgetSettings>;
validate(); validate();
@ -598,17 +601,21 @@ export interface IWidgetSettingsComponent {
export abstract class WidgetSettingsComponent extends PageComponent implements export abstract class WidgetSettingsComponent extends PageComponent implements
IWidgetSettingsComponent, OnInit, AfterViewInit { IWidgetSettingsComponent, OnInit, AfterViewInit {
dashboard: Dashboard;
widget: Widget;
settingsValue: WidgetSettings; settingsValue: WidgetSettings;
private settingsSet = false; private settingsSet = false;
set settings(value: WidgetSettings) { set settings(value: WidgetSettings) {
this.settingsValue = value; this.settingsValue = value || this.defaultSettings();
if (!this.settingsSet) { if (!this.settingsSet) {
this.settingsSet = true; this.settingsSet = true;
this.setupSettings(value); this.setupSettings(this.settingsValue);
} else { } else {
this.updateSettings(value); this.updateSettings(this.settingsValue);
} }
} }
@ -694,4 +701,8 @@ export abstract class WidgetSettingsComponent extends PageComponent implements
protected abstract onSettingsSet(settings: WidgetSettings); protected abstract onSettingsSet(settings: WidgetSettings);
protected defaultSettings(): WidgetSettings {
return {};
}
} }