Merge pull request #10153 from Dmitriymush/enhacements/open-url-action

Added new widget action type: Open URL
This commit is contained in:
Igor Kulikov 2024-02-12 14:04:23 +02:00 committed by GitHub
commit e5c135fc10
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 39 additions and 3 deletions

View File

@ -80,6 +80,22 @@
</mat-form-field>
</div>
</ng-template>
<ng-template [ngSwitchCase]="widgetActionType.openURL">
<div class="tb-form-row">
<div class="tb-required">{{ 'widget-action.URL' | translate }}</div>
<mat-form-field fxFlex style="margin-left: 9px" appearance="outline" subscriptSizing="dynamic">
<input matInput placeholder="{{ 'widget-config.set' | translate }}" formControlName="url">
<mat-icon matSuffix
matTooltipPosition="above"
matTooltipClass="tb-error-tooltip"
[matTooltip]="'widget-action.url-required' | translate"
*ngIf="actionTypeFormGroup.get('url').invalid && actionTypeFormGroup.get('url').touched"
class="tb-error">
warning
</mat-icon>
</mat-form-field>
</div>
</ng-template>
<ng-template [ngSwitchCase]="widgetActionFormGroup.get('type').value === widgetActionType.openDashboardState ||
widgetActionFormGroup.get('type').value === widgetActionType.updateDashboardState ?
widgetActionFormGroup.get('type').value : ''">
@ -89,7 +105,8 @@
</mat-slide-toggle>
</div>
</ng-template>
<ng-template [ngSwitchCase]="widgetActionFormGroup.get('type').value === widgetActionType.openDashboard ?
<ng-template [ngSwitchCase]="widgetActionFormGroup.get('type').value === widgetActionType.openDashboard ||
widgetActionFormGroup.get('type').value === widgetActionType.openURL ?
widgetActionFormGroup.get('type').value : ''">
<div class="tb-form-row">
<mat-slide-toggle class="mat-slide" formControlName="openNewBrowserTab">

View File

@ -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(

View File

@ -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) {

View File

@ -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, string>(
[ 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 {

View File

@ -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",