Browse Source

UI: Add new 'Get Dashboard State with Parameters' action type

pull/12551/head
Vladyslav_Prykhodko 2 years ago
parent
commit
8b7bf4a633
  1. 23
      ui-ngx/src/app/modules/home/components/widget/lib/action/action-widget.models.ts
  2. 4
      ui-ngx/src/app/modules/home/components/widget/lib/settings/common/action/get-value-action-settings-panel.component.html
  3. 10
      ui-ngx/src/app/modules/home/components/widget/lib/settings/common/action/get-value-action-settings-panel.component.ts
  4. 8
      ui-ngx/src/app/modules/home/components/widget/lib/settings/common/action/get-value-action-settings.component.ts
  5. 6
      ui-ngx/src/app/shared/models/action-widget-settings.models.ts
  6. 3
      ui-ngx/src/assets/locale/locale.constant-en_US.json

23
ui-ngx/src/app/modules/home/components/widget/lib/action/action-widget.models.ts

@ -57,6 +57,7 @@ import { isDefinedAndNotNull } from '@core/utils';
import { parseError } from '@shared/models/error.models';
import { CompiledTbFunction, compileTbFunction } from '@shared/models/js-function.models';
import { HttpClient } from '@angular/common/http';
import { StateObject } from '@core/api/widget-api.models';
@Directive()
// eslint-disable-next-line @angular-eslint/directive-class-suffix
@ -269,6 +270,8 @@ export abstract class ValueGetter<V> extends ValueAction {
return new AlarmStatusValueGetter<V>(ctx, settings, valueType, valueObserver, simulated);
case GetValueAction.GET_DASHBOARD_STATE:
return new DashboardStateGetter<V>(ctx, settings, valueType, valueObserver, simulated);
case GetValueAction.GET_DASHBOARD_STATE_WITH_PARAMS:
return new DashboardStateWithParamsGetter<V>(ctx, settings, valueType, valueObserver, simulated);
}
}
@ -641,6 +644,26 @@ export class DashboardStateGetter<V> extends ValueGetter<V> {
}
}
export class DashboardStateWithParamsGetter<V> extends ValueGetter<V> {
constructor(protected ctx: WidgetContext,
protected settings: GetValueSettings<V>,
protected valueType: ValueType,
protected valueObserver: Partial<Observer<V>>,
protected simulated: boolean) {
super(ctx, settings, valueType, valueObserver, simulated);
}
protected doGetValue(): Observable<StateObject> {
if (this.simulated) {
return of({id: 'default', params: {}});
} else {
return this.ctx.stateController.dashboardCtrl.dashboardCtx.stateId.pipe(
map(id => ({id, params: this.ctx.stateController.getStateParams()}))
);
}
}
}
export class ExecuteRpcValueSetter<V> extends ValueSetter<V> {
private readonly executeRpcSettings: RpcSettings;

4
ui-ngx/src/app/modules/home/components/widget/lib/settings/common/action/get-value-action-settings-panel.component.html

@ -131,7 +131,9 @@
class="tb-form-panel stroked" formGroupName="dataToValue">
<div class="tb-form-row no-padding no-border column-xs">
<div class="fixed-title-width" translate>widgets.value-action.action-result-converter</div>
<tb-toggle-select class="flex-1" formControlName="type">
<tb-toggle-select formControlName="type"
class="flex-1"
[class.invisible]="getValueSettingsFormGroup.get('action').value === getValueAction.GET_DASHBOARD_STATE_WITH_PARAMS">
<tb-toggle-option [value]="dataToValueType.NONE">{{ 'widgets.value-action.converter-none' | translate }}</tb-toggle-option>
<tb-toggle-option [value]="dataToValueType.FUNCTION">{{ 'widgets.value-action.converter-function' | translate }}</tb-toggle-option>
</tb-toggle-select>

10
ui-ngx/src/app/modules/home/components/widget/lib/settings/common/action/get-value-action-settings-panel.component.ts

@ -99,6 +99,8 @@ export class GetValueActionSettingsPanelComponent extends PageComponent implemen
getValueSettingsFormGroup: UntypedFormGroup;
entityType = EntityType;
alarmSeverities = Object.keys(AlarmSeverity) as AlarmSeverity[];
alarmSeverityTranslationMap = alarmSeverityTranslations;
@ -167,7 +169,7 @@ export class GetValueActionSettingsPanelComponent extends PageComponent implemen
private updateValidators() {
const action: GetValueAction = this.getValueSettingsFormGroup.get('action').value;
const dataToValueType: DataToValueType = this.getValueSettingsFormGroup.get('dataToValue').get('type').value;
let dataToValueType: DataToValueType = this.getValueSettingsFormGroup.get('dataToValue').get('type').value;
this.getValueSettingsFormGroup.get('defaultValue').disable({emitEvent: false});
this.getValueSettingsFormGroup.get('executeRpc').disable({emitEvent: false});
@ -196,6 +198,10 @@ export class GetValueActionSettingsPanelComponent extends PageComponent implemen
case GetValueAction.GET_ALARM_STATUS:
this.getValueSettingsFormGroup.get('getAlarmStatus').enable({emitEvent: false});
break;
case GetValueAction.GET_DASHBOARD_STATE_WITH_PARAMS:
this.getValueSettingsFormGroup.get('dataToValue.type').setValue(DataToValueType.FUNCTION, {emitEvent: false});
dataToValueType = DataToValueType.FUNCTION;
break
}
if (action === GetValueAction.DO_NOTHING || action === GetValueAction.GET_ALARM_STATUS) {
this.getValueSettingsFormGroup.get('dataToValue').disable({emitEvent: false});
@ -208,6 +214,4 @@ export class GetValueActionSettingsPanelComponent extends PageComponent implemen
}
}
}
protected readonly entityType = EntityType;
}

8
ui-ngx/src/app/modules/home/components/widget/lib/settings/common/action/get-value-action-settings.component.ts

@ -191,6 +191,14 @@ export class GetValueActionSettingsComponent implements OnInit, ControlValueAcce
this.displayValue = this.translate.instant('widgets.value-action.get-dashboard-state-text');
}
break;
case GetValueAction.GET_DASHBOARD_STATE_WITH_PARAMS:
if (this.valueType === ValueType.BOOLEAN) {
const state = this.modelValue.dataToValue?.compareToValue;
this.displayValue = this.translate.instant('widgets.value-action.when-dashboard-state-with-params-function-is-text', {state});
} else {
this.displayValue = this.translate.instant('widgets.value-action.get-dashboard-state-with-params-text');
}
break;
}
this.cd.markForCheck();
}

6
ui-ngx/src/app/shared/models/action-widget-settings.models.ts

@ -25,7 +25,8 @@ export enum GetValueAction {
GET_ATTRIBUTE = 'GET_ATTRIBUTE',
GET_TIME_SERIES = 'GET_TIME_SERIES',
GET_ALARM_STATUS = 'GET_ALARM_STATUS',
GET_DASHBOARD_STATE = 'GET_DASHBOARD_STATE'
GET_DASHBOARD_STATE = 'GET_DASHBOARD_STATE',
GET_DASHBOARD_STATE_WITH_PARAMS = 'GET_DASHBOARD_STATE_WITH_PARAMS',
}
export const getValueActions = Object.keys(GetValueAction) as GetValueAction[];
@ -45,7 +46,8 @@ export const getValueActionTranslations = new Map<GetValueAction, string>(
[GetValueAction.GET_ATTRIBUTE, 'widgets.value-action.get-attribute'],
[GetValueAction.GET_TIME_SERIES, 'widgets.value-action.get-time-series'],
[GetValueAction.GET_ALARM_STATUS, 'widgets.value-action.get-alarm-status'],
[GetValueAction.GET_DASHBOARD_STATE, 'widgets.value-action.get-dashboard-state']
[GetValueAction.GET_DASHBOARD_STATE, 'widgets.value-action.get-dashboard-state'],
[GetValueAction.GET_DASHBOARD_STATE_WITH_PARAMS, 'widgets.value-action.get-dashboard-state-with-params'],
]
);

3
ui-ngx/src/assets/locale/locale.constant-en_US.json

@ -8265,14 +8265,17 @@
"get-time-series": "Get time series",
"get-alarm-status": "Get alarm status",
"get-dashboard-state": "Get dashboard state",
"get-dashboard-state-with-params": "Get dashboard state with params",
"add-time-series": "Add time series",
"execute-rpc-text": "Execute RPC method '{{methodName}}'",
"get-time-series-text": "Use time series '{{key}}'",
"get-attribute-text": "Use attribute '{{key}}'",
"get-alarm-status-text": "Use alarm status",
"get-dashboard-state-text": "Use dashboard state",
"get-dashboard-state-with-params-text": "Use dashboard state with params",
"when-dashboard-state-is-text": "When dashboard state is '{{state}}'",
"when-dashboard-state-function-is-text": "When f(dashboard state) is '{{state}}'",
"when-dashboard-state-with-params-function-is-text": "When f(dashboard state with params) is '{{state}}'",
"set-attribute-to-value-text": "Set '{{key}}' attribute to: {{value}}",
"add-time-series-value-text": "Add '{{key}}' time series value: {{value}}",
"set-attribute-text": "Set '{{key}}' attribute",

Loading…
Cancel
Save