From 347037be418611933002eff50ec518e3593df2d7 Mon Sep 17 00:00:00 2001 From: Dmitriymush Date: Thu, 8 Feb 2024 18:09:12 +0200 Subject: [PATCH] UI: added new open URL action type --- .../action/widget-action.component.html | 19 ++++++++++++++++++- .../common/action/widget-action.component.ts | 10 ++++++++++ .../components/widget/widget.component.ts | 3 +++ ui-ngx/src/app/shared/models/widget.models.ts | 7 +++++-- .../assets/locale/locale.constant-en_US.json | 3 +++ 5 files changed, 39 insertions(+), 3 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/action/widget-action.component.html b/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/action/widget-action.component.html index 35ca3f3144..3752fb3b3c 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/action/widget-action.component.html +++ b/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/action/widget-action.component.html @@ -80,6 +80,22 @@ + +
+
{{ 'widget-action.URL' | translate }}
+ + + + warning + + +
+
@@ -89,7 +105,8 @@ -
diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/action/widget-action.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/action/widget-action.component.ts index c93a05fafd..6c2cd3fb8f 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/action/widget-action.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/action/widget-action.component.ts @@ -279,6 +279,16 @@ export class WidgetActionComponent implements ControlValueAccessor, OnInit, Vali this.fb.control(action ? action.mobileAction : null, [Validators.required]) ); break; + case WidgetActionType.openURL: + this.actionTypeFormGroup.addControl( + 'openNewBrowserTab', + this.fb.control(action ? action.openNewBrowserTab : false, []) + ); + this.actionTypeFormGroup.addControl( + 'url', + this.fb.control(action ? action.url : null, [Validators.required]) + ); + break; } } this.actionTypeFormGroupSubscriptions.push( 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 15e982c060..a79fa89242 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 @@ -1089,6 +1089,9 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI this.router.navigateByUrl(url); } break; + case WidgetActionType.openURL: + window.open(descriptor.url, descriptor.openNewBrowserTab ? '_blank' : '_self'); + break; case WidgetActionType.custom: const customFunction = descriptor.customFunction; if (customFunction && customFunction.length > 0) { diff --git a/ui-ngx/src/app/shared/models/widget.models.ts b/ui-ngx/src/app/shared/models/widget.models.ts index 625d957cff..5f4ca8f7be 100644 --- a/ui-ngx/src/app/shared/models/widget.models.ts +++ b/ui-ngx/src/app/shared/models/widget.models.ts @@ -538,7 +538,8 @@ export enum WidgetActionType { openDashboard = 'openDashboard', custom = 'custom', customPretty = 'customPretty', - mobileAction = 'mobileAction' + mobileAction = 'mobileAction', + openURL = 'openURL' } export enum WidgetMobileActionType { @@ -559,7 +560,8 @@ export const widgetActionTypeTranslationMap = new Map( [ WidgetActionType.openDashboard, 'widget-action.open-dashboard' ], [ WidgetActionType.custom, 'widget-action.custom' ], [ WidgetActionType.customPretty, 'widget-action.custom-pretty' ], - [ WidgetActionType.mobileAction, 'widget-action.mobile-action' ] + [ WidgetActionType.mobileAction, 'widget-action.mobile-action' ], + [ WidgetActionType.openURL, 'widget-action.open-URL' ] ] ); @@ -671,6 +673,7 @@ export interface WidgetAction extends CustomActionDescriptor { setEntityId?: boolean; stateEntityParamName?: string; mobileAction?: WidgetMobileActionDescriptor; + url?: string; } export interface WidgetActionDescriptor extends WidgetAction { diff --git a/ui-ngx/src/assets/locale/locale.constant-en_US.json b/ui-ngx/src/assets/locale/locale.constant-en_US.json index b3d2821e30..ee3d1d29d7 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -5036,6 +5036,9 @@ "popover-height": "Popover height", "popover-style": "Popover style", "open-new-browser-tab": "Open in a new browser tab", + "open-URL": "Open URL", + "URL": "URL", + "url-required": "URL is required.", "mobile": { "action-type": "Mobile action type", "select-action-type": "Select mobile action type",