From 1f5a8ef70f8912a00912b318abcf3396e7d72f61 Mon Sep 17 00:00:00 2001 From: Kalutka Zhenya Date: Tue, 18 May 2021 10:52:38 +0300 Subject: [PATCH 1/4] Updated logic for 'Set entity from widget' in static widget --- .../widget/action/manage-widget-actions.component.ts | 6 +++++- .../action/widget-action-dialog.component.html | 2 +- .../widget/action/widget-action-dialog.component.ts | 12 +++++++++++- .../components/widget/widget-config.component.html | 1 + 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/widget/action/manage-widget-actions.component.ts b/ui-ngx/src/app/modules/home/components/widget/action/manage-widget-actions.component.ts index 0367cf3ce5..2a68251c3d 100644 --- a/ui-ngx/src/app/modules/home/components/widget/action/manage-widget-actions.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/action/manage-widget-actions.component.ts @@ -42,6 +42,7 @@ import { WidgetActionDialogData } from '@home/components/widget/action/widget-action-dialog.component'; import { deepClone } from '@core/utils'; +import { WidgetConfigComponentData } from '@home/models/widget-component.models'; @Component({ selector: 'tb-manage-widget-actions', @@ -59,6 +60,8 @@ export class ManageWidgetActionsComponent extends PageComponent implements OnIni @Input() disabled: boolean; + @Input() modelValue: WidgetConfigComponentData; + @Input() callbacks: WidgetActionCallbacks; innerValue: WidgetActionsData; @@ -180,7 +183,8 @@ export class ManageWidgetActionsComponent extends PageComponent implements OnIni isAdd, callbacks: this.callbacks, actionsData, - action: deepClone(action) + action: deepClone(action), + modelValue: this.modelValue } }).afterClosed().subscribe( (res) => { diff --git a/ui-ngx/src/app/modules/home/components/widget/action/widget-action-dialog.component.html b/ui-ngx/src/app/modules/home/components/widget/action/widget-action-dialog.component.html index 44bfe44e1e..36234da531 100644 --- a/ui-ngx/src/app/modules/home/components/widget/action/widget-action-dialog.component.html +++ b/ui-ngx/src/app/modules/home/components/widget/action/widget-action-dialog.component.html @@ -120,7 +120,7 @@ widgetActionFormGroup.get('type').value === widgetActionType.updateDashboardState || widgetActionFormGroup.get('type').value === widgetActionType.openDashboard ? widgetActionFormGroup.get('type').value : ''"> - + {{ 'widget-action.set-entity-from-widget' | translate }} , protected router: Router, @@ -139,9 +148,10 @@ export class WidgetActionDialogComponent extends DialogComponent From bcfa6e7f544f36dae7403a6a0ee225dc66e9f78f Mon Sep 17 00:00:00 2001 From: Kalutka Zhenya Date: Tue, 18 May 2021 11:01:01 +0300 Subject: [PATCH 2/4] Refactoring --- .../widget/action/widget-action-dialog.component.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/widget/action/widget-action-dialog.component.ts b/ui-ngx/src/app/modules/home/components/widget/action/widget-action-dialog.component.ts index 72798bfd1a..76956152fa 100644 --- a/ui-ngx/src/app/modules/home/components/widget/action/widget-action-dialog.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/action/widget-action-dialog.component.ts @@ -29,8 +29,7 @@ import { Validators } from '@angular/forms'; import { - WidgetConfigComponentData, - WidgetInfo + WidgetConfigComponentData } from '@home/models/widget-component.models'; import { Observable, of } from 'rxjs'; import { Router } from '@angular/router'; @@ -73,10 +72,8 @@ export class WidgetActionDialogComponent extends DialogComponent Date: Thu, 20 May 2021 13:25:34 +0300 Subject: [PATCH 3/4] Refactoring and updated fix --- .../widget/action/manage-widget-actions.component.ts | 6 +++--- .../widget/action/widget-action-dialog.component.html | 2 +- .../widget/action/widget-action-dialog.component.ts | 7 ++----- .../home/components/widget/widget-config.component.html | 2 +- .../app/modules/home/components/widget/widget.component.ts | 2 +- 5 files changed, 8 insertions(+), 11 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/widget/action/manage-widget-actions.component.ts b/ui-ngx/src/app/modules/home/components/widget/action/manage-widget-actions.component.ts index 2a68251c3d..d3fdd47bba 100644 --- a/ui-ngx/src/app/modules/home/components/widget/action/manage-widget-actions.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/action/manage-widget-actions.component.ts @@ -42,7 +42,7 @@ import { WidgetActionDialogData } from '@home/components/widget/action/widget-action-dialog.component'; import { deepClone } from '@core/utils'; -import { WidgetConfigComponentData } from '@home/models/widget-component.models'; +import { widgetType } from '@shared/models/widget.models'; @Component({ selector: 'tb-manage-widget-actions', @@ -60,7 +60,7 @@ export class ManageWidgetActionsComponent extends PageComponent implements OnIni @Input() disabled: boolean; - @Input() modelValue: WidgetConfigComponentData; + @Input() widgetType: widgetType; @Input() callbacks: WidgetActionCallbacks; @@ -184,7 +184,7 @@ export class ManageWidgetActionsComponent extends PageComponent implements OnIni callbacks: this.callbacks, actionsData, action: deepClone(action), - modelValue: this.modelValue + widgetType: this.widgetType } }).afterClosed().subscribe( (res) => { diff --git a/ui-ngx/src/app/modules/home/components/widget/action/widget-action-dialog.component.html b/ui-ngx/src/app/modules/home/components/widget/action/widget-action-dialog.component.html index 36234da531..2c7b826200 100644 --- a/ui-ngx/src/app/modules/home/components/widget/action/widget-action-dialog.component.html +++ b/ui-ngx/src/app/modules/home/components/widget/action/widget-action-dialog.component.html @@ -120,7 +120,7 @@ widgetActionFormGroup.get('type').value === widgetActionType.updateDashboardState || widgetActionFormGroup.get('type').value === widgetActionType.openDashboard ? widgetActionFormGroup.get('type').value : ''"> - + {{ 'widget-action.set-entity-from-widget' | translate }} diff --git a/ui-ngx/src/app/modules/home/components/widget/widget.component.ts b/ui-ngx/src/app/modules/home/components/widget/widget.component.ts index 4caf5f3edd..d010ea24a0 100644 --- a/ui-ngx/src/app/modules/home/components/widget/widget.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/widget.component.ts @@ -1015,7 +1015,7 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI const type = descriptor.type; const targetEntityParamName = descriptor.stateEntityParamName; let targetEntityId: EntityId; - if (descriptor.setEntityId && validateEntityId(entityId)) { + if (this.widgetInfo.type !== 'static' && descriptor.setEntityId && validateEntityId(entityId)) { targetEntityId = entityId; } switch (type) { From ae7897366d7d88629069cf40eefef314478b766f Mon Sep 17 00:00:00 2001 From: Kalutka Zhenya Date: Fri, 21 May 2021 18:14:19 +0300 Subject: [PATCH 4/4] Updated 'validateEntityId' logic --- ui-ngx/src/app/core/utils.ts | 4 ++-- .../app/modules/home/components/widget/widget.component.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ui-ngx/src/app/core/utils.ts b/ui-ngx/src/app/core/utils.ts index 7be030bf54..6291438a58 100644 --- a/ui-ngx/src/app/core/utils.ts +++ b/ui-ngx/src/app/core/utils.ts @@ -438,6 +438,6 @@ export function generateSecret(length?: number): string { return str.concat(generateSecret(length - str.length)); } -export function validateEntityId(entityId: EntityId): boolean { - return isDefinedAndNotNull(entityId.id) && entityId.id !== NULL_UUID && isDefinedAndNotNull(entityId.entityType); +export function validateEntityId(entityId: EntityId | null): boolean { + return isDefinedAndNotNull(entityId?.id) && entityId.id !== NULL_UUID && isDefinedAndNotNull(entityId?.entityType); } diff --git a/ui-ngx/src/app/modules/home/components/widget/widget.component.ts b/ui-ngx/src/app/modules/home/components/widget/widget.component.ts index d010ea24a0..4caf5f3edd 100644 --- a/ui-ngx/src/app/modules/home/components/widget/widget.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/widget.component.ts @@ -1015,7 +1015,7 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI const type = descriptor.type; const targetEntityParamName = descriptor.stateEntityParamName; let targetEntityId: EntityId; - if (this.widgetInfo.type !== 'static' && descriptor.setEntityId && validateEntityId(entityId)) { + if (descriptor.setEntityId && validateEntityId(entityId)) { targetEntityId = entityId; } switch (type) {