From 3fcb913645762f0925fe02b0732fd68dcd656ee1 Mon Sep 17 00:00:00 2001 From: Igor Kulikov Date: Fri, 26 Jan 2024 17:54:24 +0200 Subject: [PATCH] UI: Update Widget action form style. --- ui-ngx/src/app/modules/common/modules-map.ts | 12 +- .../home/components/home-components.module.ts | 9 - .../manage-widget-actions.component.models.ts | 30 +- .../widget-action-dialog.component.html | 280 +++-------- .../action/widget-action-dialog.component.ts | 350 +------------ ...custom-action-pretty-editor.component.html | 3 +- ...custom-action-pretty-editor.component.scss | 2 +- .../custom-action-pretty-editor.component.ts | 4 +- ...ction-pretty-resources-tabs.component.html | 1 + ...ction-pretty-resources-tabs.component.scss | 0 ...-action-pretty-resources-tabs.component.ts | 2 +- .../action/custom-action.models.ts | 24 + .../{ => config}/action/custom-sample-css.raw | 0 .../action/custom-sample-html.raw | 0 .../{ => config}/action/custom-sample-js.raw | 0 .../mobile-action-editor.component.html | 56 ++- .../action/mobile-action-editor.component.ts | 35 +- .../action/mobile-action-editor.models.ts | 40 +- .../action/widget-action.component.html | 234 +++++++++ .../config/action/widget-action.component.ts | 463 ++++++++++++++++++ .../config/widget-config-components.module.ts | 17 +- .../common/css-size-input.component.html | 33 ++ .../common/css-size-input.component.ts | 124 +++++ .../common/css-unit-select.component.html | 2 +- .../common/css-unit-select.component.ts | 3 + .../common/widget-settings-common.module.ts | 3 + .../components/widget/widget.component.ts | 2 +- .../dashboard-autocomplete.component.html | 24 +- .../dashboard-autocomplete.component.ts | 40 +- .../shared/components/js-func.component.html | 12 +- .../shared/components/js-func.component.scss | 6 +- .../shared/components/js-func.component.ts | 20 +- .../shared/models/widget-settings.models.ts | 4 +- ui-ngx/src/app/shared/models/widget.models.ts | 24 +- .../assets/locale/locale.constant-ca_ES.json | 6 +- .../assets/locale/locale.constant-cs_CZ.json | 2 +- .../assets/locale/locale.constant-da_DK.json | 2 +- .../assets/locale/locale.constant-de_DE.json | 2 +- .../assets/locale/locale.constant-el_GR.json | 2 +- .../assets/locale/locale.constant-en_US.json | 19 +- .../assets/locale/locale.constant-es_ES.json | 6 +- .../assets/locale/locale.constant-fa_IR.json | 2 +- .../assets/locale/locale.constant-fr_FR.json | 2 +- .../assets/locale/locale.constant-it_IT.json | 2 +- .../assets/locale/locale.constant-ja_JP.json | 2 +- .../assets/locale/locale.constant-ka_GE.json | 2 +- .../assets/locale/locale.constant-ko_KR.json | 2 +- .../assets/locale/locale.constant-lv_LV.json | 2 +- .../assets/locale/locale.constant-nl_BE.json | 6 +- .../assets/locale/locale.constant-pt_BR.json | 2 +- .../assets/locale/locale.constant-ro_RO.json | 2 +- .../assets/locale/locale.constant-sl_SI.json | 2 +- .../assets/locale/locale.constant-tr_TR.json | 2 +- .../assets/locale/locale.constant-uk_UA.json | 2 +- .../assets/locale/locale.constant-zh_CN.json | 6 +- .../assets/locale/locale.constant-zh_TW.json | 6 +- ui-ngx/src/form.scss | 6 +- 57 files changed, 1217 insertions(+), 729 deletions(-) rename ui-ngx/src/app/modules/home/components/widget/{ => config}/action/custom-action-pretty-editor.component.html (94%) rename ui-ngx/src/app/modules/home/components/widget/{ => config}/action/custom-action-pretty-editor.component.scss (96%) rename ui-ngx/src/app/modules/home/components/widget/{ => config}/action/custom-action-pretty-editor.component.ts (96%) rename ui-ngx/src/app/modules/home/components/widget/{ => config}/action/custom-action-pretty-resources-tabs.component.html (98%) rename ui-ngx/src/app/modules/home/components/widget/{ => config}/action/custom-action-pretty-resources-tabs.component.scss (100%) rename ui-ngx/src/app/modules/home/components/widget/{ => config}/action/custom-action-pretty-resources-tabs.component.ts (99%) rename ui-ngx/src/app/modules/home/components/widget/{ => config}/action/custom-action.models.ts (71%) rename ui-ngx/src/app/modules/home/components/widget/{ => config}/action/custom-sample-css.raw (100%) rename ui-ngx/src/app/modules/home/components/widget/{ => config}/action/custom-sample-html.raw (100%) rename ui-ngx/src/app/modules/home/components/widget/{ => config}/action/custom-sample-js.raw (100%) rename ui-ngx/src/app/modules/home/components/widget/{ => config}/action/mobile-action-editor.component.html (74%) rename ui-ngx/src/app/modules/home/components/widget/{ => config}/action/mobile-action-editor.component.ts (91%) rename ui-ngx/src/app/modules/home/components/widget/{ => config}/action/mobile-action-editor.models.ts (92%) create mode 100644 ui-ngx/src/app/modules/home/components/widget/config/action/widget-action.component.html create mode 100644 ui-ngx/src/app/modules/home/components/widget/config/action/widget-action.component.ts create mode 100644 ui-ngx/src/app/modules/home/components/widget/lib/settings/common/css-size-input.component.html create mode 100644 ui-ngx/src/app/modules/home/components/widget/lib/settings/common/css-size-input.component.ts diff --git a/ui-ngx/src/app/modules/common/modules-map.ts b/ui-ngx/src/app/modules/common/modules-map.ts index c19b96e2a7..f8dab27af9 100644 --- a/ui-ngx/src/app/modules/common/modules-map.ts +++ b/ui-ngx/src/app/modules/common/modules-map.ts @@ -226,9 +226,9 @@ import * as DataKeyConfigComponent from '@home/components/widget/config/data-key import * as LegendConfigComponent from '@home/components/widget/lib/settings/common/legend-config.component'; import * as ManageWidgetActionsComponent from '@home/components/widget/action/manage-widget-actions.component'; import * as WidgetActionDialogComponent from '@home/components/widget/action/widget-action-dialog.component'; -import * as CustomActionPrettyResourcesTabsComponent from '@home/components/widget/action/custom-action-pretty-resources-tabs.component'; -import * as CustomActionPrettyEditorComponent from '@home/components/widget/action/custom-action-pretty-editor.component'; -import * as MobileActionEditorComponent from '@home/components/widget/action/mobile-action-editor.component'; +import * as CustomActionPrettyResourcesTabsComponent from '@home/components/widget/config/action/custom-action-pretty-resources-tabs.component'; +import * as CustomActionPrettyEditorComponent from '@home/components/widget/config/action/custom-action-pretty-editor.component'; +import * as MobileActionEditorComponent from '@home/components/widget/config/action/mobile-action-editor.component'; import * as CustomDialogService from '@home/components/widget/dialog/custom-dialog.service'; import * as CustomDialogContainerComponent from '@home/components/widget/dialog/custom-dialog-container.component'; import * as ImportDialogComponent from '@shared/import-export/import-dialog.component'; @@ -541,9 +541,9 @@ class ModulesMap implements IModulesMap { '@home/components/widget/lib/settings/common/legend-config.component': LegendConfigComponent, '@home/components/widget/action/manage-widget-actions.component': ManageWidgetActionsComponent, '@home/components/widget/action/widget-action-dialog.component': WidgetActionDialogComponent, - '@home/components/widget/action/custom-action-pretty-resources-tabs.component': CustomActionPrettyResourcesTabsComponent, - '@home/components/widget/action/custom-action-pretty-editor.component': CustomActionPrettyEditorComponent, - '@home/components/widget/action/mobile-action-editor.component': MobileActionEditorComponent, + '@home/components/widget/config/action/custom-action-pretty-resources-tabs.component': CustomActionPrettyResourcesTabsComponent, + '@home/components/widget/config/action/custom-action-pretty-editor.component': CustomActionPrettyEditorComponent, + '@home/components/widget/config/action/mobile-action-editor.component': MobileActionEditorComponent, '@home/components/widget/dialog/custom-dialog.service': CustomDialogService, '@home/components/widget/dialog/custom-dialog-container.component': CustomDialogContainerComponent, '@home/components/attribute/add-widget-to-dashboard-dialog.component': AddWidgetToDashboardDialogComponent, diff --git a/ui-ngx/src/app/modules/home/components/home-components.module.ts b/ui-ngx/src/app/modules/home/components/home-components.module.ts index 4694b5ead8..5390a915d3 100644 --- a/ui-ngx/src/app/modules/home/components/home-components.module.ts +++ b/ui-ngx/src/app/modules/home/components/home-components.module.ts @@ -46,9 +46,6 @@ import { EntityFilterComponent } from '@home/components/entity/entity-filter.com import { RelationFiltersComponent } from '@home/components/relation/relation-filters.component'; import { ManageWidgetActionsComponent } from '@home/components/widget/action/manage-widget-actions.component'; import { WidgetActionDialogComponent } from '@home/components/widget/action/widget-action-dialog.component'; -import { CustomActionPrettyResourcesTabsComponent } from '@home/components/widget/action/custom-action-pretty-resources-tabs.component'; -import { CustomActionPrettyEditorComponent } from '@home/components/widget/action/custom-action-pretty-editor.component'; -import { MobileActionEditorComponent } from '@home/components/widget/action/mobile-action-editor.component'; import { CustomDialogService } from '@home/components/widget/dialog/custom-dialog.service'; import { CustomDialogContainerComponent } from '@home/components/widget/dialog/custom-dialog-container.component'; import { AddWidgetToDashboardDialogComponent } from '@home/components/attribute/add-widget-to-dashboard-dialog.component'; @@ -218,9 +215,6 @@ import { DeleteTimeseriesPanelComponent } from '@home/components/attribute/delet ManageWidgetActionsComponent, WidgetActionDialogComponent, ManageWidgetActionsDialogComponent, - CustomActionPrettyResourcesTabsComponent, - CustomActionPrettyEditorComponent, - MobileActionEditorComponent, CustomDialogContainerComponent, SelectTargetLayoutDialogComponent, SelectTargetStateDialogComponent, @@ -359,9 +353,6 @@ import { DeleteTimeseriesPanelComponent } from '@home/components/attribute/delet ManageWidgetActionsComponent, WidgetActionDialogComponent, ManageWidgetActionsDialogComponent, - CustomActionPrettyResourcesTabsComponent, - CustomActionPrettyEditorComponent, - MobileActionEditorComponent, CustomDialogContainerComponent, SelectTargetLayoutDialogComponent, SelectTargetStateDialogComponent, diff --git a/ui-ngx/src/app/modules/home/components/widget/action/manage-widget-actions.component.models.ts b/ui-ngx/src/app/modules/home/components/widget/action/manage-widget-actions.component.models.ts index 941affd220..428fb6fa1b 100644 --- a/ui-ngx/src/app/modules/home/components/widget/action/manage-widget-actions.component.models.ts +++ b/ui-ngx/src/app/modules/home/components/widget/action/manage-widget-actions.component.models.ts @@ -15,7 +15,6 @@ /// import { - CustomActionDescriptor, WidgetActionDescriptor, WidgetActionSource, widgetActionTypeTranslationMap @@ -27,11 +26,7 @@ import { TranslateService } from '@ngx-translate/core'; import { PageLink } from '@shared/models/page/page-link'; import { catchError, map, publishReplay, refCount } from 'rxjs/operators'; import { UtilsService } from '@core/services/utils.service'; -import { deepClone, isDefined, isUndefined } from '@core/utils'; - -import customSampleJs from '!raw-loader!./custom-sample-js.raw'; -import customSampleCss from '!raw-loader!./custom-sample-css.raw'; -import customSampleHtml from '!raw-loader!./custom-sample-html.raw'; +import { deepClone } from '@core/utils'; export interface WidgetActionCallbacks { fetchDashboardStates: (query: string) => Array; @@ -48,32 +43,13 @@ export interface WidgetActionDescriptorInfo extends WidgetActionDescriptor { typeName?: string; } -export function toWidgetActionDescriptor(action: WidgetActionDescriptorInfo): WidgetActionDescriptor { +export const toWidgetActionDescriptor = (action: WidgetActionDescriptorInfo): WidgetActionDescriptor => { const copy = deepClone(action); delete copy.actionSourceId; delete copy.actionSourceName; delete copy.typeName; return copy; -} - -export function toCustomAction(action: WidgetActionDescriptorInfo): CustomActionDescriptor { - let result: CustomActionDescriptor; - if (!action || (isUndefined(action.customFunction) && isUndefined(action.customHtml) && isUndefined(action.customCss))) { - result = { - customHtml: customSampleHtml, - customCss: customSampleCss, - customFunction: customSampleJs - }; - } else { - result = { - customHtml: action.customHtml, - customCss: action.customCss, - customFunction: action.customFunction - }; - } - result.customResources = action && isDefined(action.customResources) ? deepClone(action.customResources) : []; - return result; -} +}; export class WidgetActionsDatasource implements DataSource { 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 94e88350e1..f75b2e44e7 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 @@ -27,219 +27,82 @@ -
+
- - widget-config.action-source - - - {{ actionSourceName(actionSourceItem.value) }} - - - - {{ 'widget-config.action-source-required' | translate }} - - - - widget-config.action-name - - - - {{ 'widget-config.action-name-required' | translate }} - - - - - - - - {{ 'widget-config.show-hide-action-using-function' | translate }} - - - - widget-config.action-type - - - {{ widgetActionTypeTranslations.get(widgetActionType[actionType]) | translate }} - - - - {{ 'widget-config.action-type-required' | translate }} - - -
- -
widget-action.target-dashboard
- -
- - - - - - - - - - - {{ 'widget-action.target-dashboard-state-required' | translate }} - - - - - - {{ 'widget-action.open-right-layout' | translate }} - - - - - {{ 'widget-action.open-new-browser-tab' | translate }} - - - - - {{ 'widget-action.set-entity-from-widget' | translate }} - - - alias.state-entity-parameter-name - - - - - - widget-action.state-display-type - - - {{ stateDisplayTypeName(displayType) }} +
+
+
{{'widget-config.action-source' | translate}}*
+ + + + {{ actionSourceName(actionSourceItem.value) }} + + warning + -
- - - widget-action.dialog-title - - - - {{ 'widget-action.dialog-hide-dashboard-toolbar' | translate }} - - - widget-action.dialog-width - - - {{ 'widget-action.dialog-size-range-error' | translate }} - - - {{ 'widget-action.dialog-size-range-error' | translate }} - - - - widget-action.dialog-height - - - {{ 'widget-action.dialog-size-range-error' | translate }} - - - {{ 'widget-action.dialog-size-range-error' | translate }} - - - - - - widget-action.popover-preferred-placement - - - {{ popoverPlacementName(placement) }} - - - - - {{ 'widget-action.popover-hide-on-click-outside' | translate }} - - - {{ 'widget-action.popover-hide-dashboard-toolbar' | translate }} - - - widget-action.popover-width - - - - widget-action.popover-height - - - - - +
+
+
{{'widget-config.action-name' | translate}}*
+ + + + warning + + +
+
+
{{'widget-config.icon' | translate}}
+ + +
+
+ + + + + {{ 'widget-config.show-hide-action-using-function' | translate }} + + + + + -
- - - - - - - - - - - - - + +
+ + +
@@ -251,8 +114,7 @@
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 15ece4f772..1eec44b714 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 @@ -14,46 +14,38 @@ /// limitations under the License. /// -import { Component, ElementRef, Inject, OnInit, SkipSelf, ViewChild } from '@angular/core'; +import { Component, Inject, OnDestroy, OnInit, SkipSelf } from '@angular/core'; import { ErrorStateMatcher } from '@angular/material/core'; import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; import { Store } from '@ngrx/store'; import { AppState } from '@core/core.state'; import { + FormGroupDirective, + NgForm, UntypedFormBuilder, UntypedFormControl, UntypedFormGroup, - FormGroupDirective, - NgForm, ValidatorFn, Validators } from '@angular/forms'; -import { Observable, of, Subject, Subscription } from 'rxjs'; +import { Subject } from 'rxjs'; import { Router } from '@angular/router'; import { DialogComponent } from '@app/shared/components/dialog.component'; import { - toCustomAction, WidgetActionCallbacks, WidgetActionDescriptorInfo, WidgetActionsData } from '@home/components/widget/action/manage-widget-actions.component.models'; import { UtilsService } from '@core/services/utils.service'; import { + actionDescriptorToAction, WidgetActionSource, WidgetActionType, - widgetActionTypeTranslationMap + widgetType } from '@shared/models/widget.models'; -import { map, mergeMap, startWith, takeUntil, tap } from 'rxjs/operators'; -import { DashboardService } from '@core/http/dashboard.service'; -import { Dashboard } from '@shared/models/dashboard.models'; -import { DashboardUtilsService } from '@core/services/dashboard-utils.service'; -import { CustomActionEditorCompleter } from '@home/components/widget/action/custom-action.models'; -import { isDefinedAndNotNull } from '@core/utils'; -import { MobileActionEditorComponent } from '@home/components/widget/action/mobile-action-editor.component'; -import { widgetType } from '@shared/models/widget.models'; +import { takeUntil } from 'rxjs/operators'; +import { CustomActionEditorCompleter } from '@home/components/widget/config/action/custom-action.models'; import { WidgetService } from '@core/http/widget.service'; -import { TranslateService } from '@ngx-translate/core'; -import { PopoverPlacement, PopoverPlacements } from '@shared/components/popover.models'; export interface WidgetActionDialogData { isAdd: boolean; @@ -63,18 +55,6 @@ export interface WidgetActionDialogData { widgetType: widgetType; } -const stateDisplayTypes = ['normal', 'separateDialog', 'popover'] as const; -type stateDisplayTypeTuple = typeof stateDisplayTypes; -export type stateDisplayType = stateDisplayTypeTuple[number]; - -const stateDisplayTypesTranslations = new Map( - [ - ['normal', 'widget-action.open-normal'], - ['separateDialog', 'widget-action.open-in-separate-dialog'], - ['popover', 'widget-action.open-in-popover'], - ] -); - @Component({ selector: 'tb-widget-action-dialog', templateUrl: './widget-action-dialog.component.html', @@ -82,49 +62,25 @@ const stateDisplayTypesTranslations = new Map( styleUrls: [] }) export class WidgetActionDialogComponent extends DialogComponent implements OnInit, ErrorStateMatcher { - - @ViewChild('dashboardStateInput') dashboardStateInput: ElementRef; - - @ViewChild('mobileActionEditor', {static: false}) mobileActionEditor: MobileActionEditorComponent; + WidgetActionDescriptorInfo> implements OnInit, OnDestroy, ErrorStateMatcher { private destroy$ = new Subject(); - private dashboard: Dashboard; - widgetActionFormGroup: UntypedFormGroup; - actionTypeFormGroup: UntypedFormGroup; - actionTypeFormGroupSubscriptions: Subscription[] = []; - stateDisplayTypeFormGroup: UntypedFormGroup; isAdd: boolean; action: WidgetActionDescriptorInfo; - widgetActionTypes = Object.keys(WidgetActionType); - widgetActionTypeTranslations = widgetActionTypeTranslationMap; - widgetActionType = WidgetActionType; - - filteredDashboardStates: Observable>; - targetDashboardStateSearchText = ''; - selectedDashboardStateIds: Observable>; - customActionEditorCompleter = CustomActionEditorCompleter; submitted = false; - widgetType = widgetType; functionScopeVariables: string[]; - allStateDisplayTypes = stateDisplayTypes; - allPopoverPlacements = PopoverPlacements; - constructor(protected store: Store, protected router: Router, private utils: UtilsService, - private dashboardService: DashboardService, - private dashboardUtils: DashboardUtilsService, private widgetService: WidgetService, - private translate: TranslateService, @Inject(MAT_DIALOG_DATA) public data: WidgetActionDialogData, @SkipSelf() private errorStateMatcher: ErrorStateMatcher, public dialogRef: MatDialogRef, @@ -136,7 +92,11 @@ export class WidgetActionDialogComponent extends DialogComponent { - this.updateActionTypeFormGroup(type); - }); this.widgetActionFormGroup.get('actionSourceId').valueChanges.pipe( takeUntil(this.destroy$) ).subscribe(() => { @@ -209,233 +163,6 @@ export class WidgetActionDialogComponent extends DialogComponent s.unsubscribe()); - this.actionTypeFormGroupSubscriptions.length = 0; - this.actionTypeFormGroup = this.fb.group({}); - if (type) { - switch (type) { - case WidgetActionType.openDashboard: - case WidgetActionType.openDashboardState: - case WidgetActionType.updateDashboardState: - this.actionTypeFormGroup.addControl( - 'targetDashboardStateId', - this.fb.control(action ? action.targetDashboardStateId : null, - type === WidgetActionType.openDashboardState ? [Validators.required] : []) - ); - this.actionTypeFormGroup.addControl( - 'setEntityId', - this.fb.control(this.data.widgetType === widgetType.static ? false : action ? action.setEntityId : true, []) - ); - this.actionTypeFormGroup.addControl( - 'stateEntityParamName', - this.fb.control(action ? action.stateEntityParamName : null, []) - ); - if (type === WidgetActionType.openDashboard) { - this.actionTypeFormGroup.addControl( - 'openNewBrowserTab', - this.fb.control(action ? action.openNewBrowserTab : false, []) - ); - this.actionTypeFormGroup.addControl( - 'targetDashboardId', - this.fb.control(action ? action.targetDashboardId : null, - [Validators.required]) - ); - this.setupSelectedDashboardStateIds(); - } else { - if (type === WidgetActionType.openDashboardState) { - const displayType = this.getStateDisplayType(action); - this.actionTypeFormGroup.addControl( - 'stateDisplayType', - this.fb.control(this.getStateDisplayType(action), [Validators.required]) - ); - this.updateStateDisplayTypeFormGroup(displayType, action); - this.actionTypeFormGroupSubscriptions.push( - this.actionTypeFormGroup.get('stateDisplayType').valueChanges.pipe( - takeUntil(this.destroy$) - ).subscribe((displayTypeValue: stateDisplayType) => { - this.updateStateDisplayTypeFormGroup(displayTypeValue); - }) - ); - } - this.actionTypeFormGroup.addControl( - 'openRightLayout', - this.fb.control(action ? action.openRightLayout : false, []) - ); - } - this.setupFilteredDashboardStates(); - break; - case WidgetActionType.custom: - this.actionTypeFormGroup.addControl( - 'customFunction', - this.fb.control(action ? action.customFunction : null, []) - ); - break; - case WidgetActionType.customPretty: - this.actionTypeFormGroup.addControl( - 'customAction', - this.fb.control(toCustomAction(action), [Validators.required]) - ); - break; - case WidgetActionType.mobileAction: - this.actionTypeFormGroup.addControl( - 'mobileAction', - this.fb.control(action ? action.mobileAction : null, [Validators.required]) - ); - break; - } - } - } - - private updateStateDisplayTypeFormGroup(displayType?: stateDisplayType, action?: WidgetActionDescriptorInfo) { - this.stateDisplayTypeFormGroup = this.fb.group({}); - if (displayType) { - switch (displayType) { - case 'normal': - break; - case 'separateDialog': - this.stateDisplayTypeFormGroup.addControl( - 'dialogTitle', - this.fb.control(action ? action.dialogTitle : '', []) - ); - this.stateDisplayTypeFormGroup.addControl( - 'dialogHideDashboardToolbar', - this.fb.control(action && isDefinedAndNotNull(action.dialogHideDashboardToolbar) - ? action.dialogHideDashboardToolbar : true, []) - ); - this.stateDisplayTypeFormGroup.addControl( - 'dialogWidth', - this.fb.control(action ? action.dialogWidth : null, [Validators.min(1), Validators.max(100)]) - ); - this.stateDisplayTypeFormGroup.addControl( - 'dialogHeight', - this.fb.control(action ? action.dialogHeight : null, [Validators.min(1), Validators.max(100)]) - ); - break; - case 'popover': - this.stateDisplayTypeFormGroup.addControl( - 'popoverPreferredPlacement', - this.fb.control(action && isDefinedAndNotNull(action.popoverPreferredPlacement) - ? action.popoverPreferredPlacement : 'top', []) - ); - this.stateDisplayTypeFormGroup.addControl( - 'popoverHideOnClickOutside', - this.fb.control(action && isDefinedAndNotNull(action.popoverHideOnClickOutside) - ? action.popoverHideOnClickOutside : true, []) - ); - this.stateDisplayTypeFormGroup.addControl( - 'popoverHideDashboardToolbar', - this.fb.control(action && isDefinedAndNotNull(action.popoverHideDashboardToolbar) - ? action.popoverHideDashboardToolbar : true, []) - ); - this.stateDisplayTypeFormGroup.addControl( - 'popoverWidth', - this.fb.control(action && isDefinedAndNotNull(action.popoverWidth) ? action.popoverWidth : '25vw', []) - ); - this.stateDisplayTypeFormGroup.addControl( - 'popoverHeight', - this.fb.control(action && isDefinedAndNotNull(action.popoverHeight) ? action.popoverHeight : '25vh', []) - ); - this.stateDisplayTypeFormGroup.addControl( - 'popoverStyle', - this.fb.control(action && isDefinedAndNotNull(action.popoverStyle) ? action.popoverStyle : {}, []) - ); - break; - } - } - } - - private getStateDisplayType(action?: WidgetActionDescriptorInfo): stateDisplayType { - let res: stateDisplayType = 'normal'; - if (action) { - if (action.openInSeparateDialog) { - res = 'separateDialog'; - } else if (action.openInPopover) { - res = 'popover'; - } - } - return res; - } - - private setupSelectedDashboardStateIds() { - this.selectedDashboardStateIds = - this.actionTypeFormGroup.get('targetDashboardId').valueChanges.pipe( - tap((dashboardId) => { - if (!dashboardId) { - this.actionTypeFormGroup.get('targetDashboardStateId') - .patchValue('', {emitEvent: true}); - } - - this.targetDashboardStateSearchText = ''; - }), - mergeMap((dashboardId) => { - if (dashboardId) { - if (this.dashboard?.id.id === dashboardId) { - return of(this.dashboard); - } else { - return this.dashboardService.getDashboard(dashboardId); - } - } else { - return of(null); - } - }), - map((dashboard: Dashboard) => { - if (dashboard) { - if (this.dashboard?.id.id !== dashboard.id.id) { - this.dashboard = this.dashboardUtils.validateAndUpdateDashboard(dashboard); - } - - return Object.keys(this.dashboard.configuration.states); - } else { - return []; - } - }) - ); - } - - private setupFilteredDashboardStates() { - this.targetDashboardStateSearchText = ''; - this.filteredDashboardStates = this.actionTypeFormGroup.get('targetDashboardStateId').valueChanges - .pipe( - startWith(''), - map(value => value ? value : ''), - mergeMap(name => this.fetchDashboardStates(name)), - takeUntil(this.destroy$) - ); - } - - private fetchDashboardStates(searchText?: string): Observable> { - this.targetDashboardStateSearchText = searchText; - if (this.widgetActionFormGroup.get('type').value === WidgetActionType.openDashboard) { - return this.selectedDashboardStateIds.pipe( - map(stateIds => { - const result = searchText ? stateIds.filter(this.createFilterForDashboardState(searchText)) : stateIds; - if (result && result.length) { - return result; - } else { - return [searchText]; - } - }) - ); - } else { - return of(this.data.callbacks.fetchDashboardStates(searchText)); - } - } - - private createFilterForDashboardState(query: string): (stateId: string) => boolean { - const lowercaseQuery = query.toLowerCase(); - return stateId => stateId.toLowerCase().indexOf(lowercaseQuery) === 0; - } - - public clearTargetDashboardState(value: string = '') { - this.dashboardStateInput.nativeElement.value = value; - this.actionTypeFormGroup.get('targetDashboardStateId').patchValue(value, {emitEvent: true}); - setTimeout(() => { - this.dashboardStateInput.nativeElement.blur(); - this.dashboardStateInput.nativeElement.focus(); - }, 0); - } - private validateActionName(): ValidatorFn { return (c: UntypedFormControl) => { const newName = c.value; @@ -474,53 +201,16 @@ export class WidgetActionDialogComponent extends DialogComponent -
+
diff --git a/ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-editor.component.scss b/ui-ngx/src/app/modules/home/components/widget/config/action/custom-action-pretty-editor.component.scss similarity index 96% rename from ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-editor.component.scss rename to ui-ngx/src/app/modules/home/components/widget/config/action/custom-action-pretty-editor.component.scss index 6af29b3cff..4087b33aa3 100644 --- a/ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-editor.component.scss +++ b/ui-ngx/src/app/modules/home/components/widget/config/action/custom-action-pretty-editor.component.scss @@ -64,7 +64,7 @@ .gutter.gutter-horizontal { cursor: col-resize; - background-image: url("../../../../../../assets/split.js/grips/vertical.png"); + background-image: url("../../../../../../../assets/split.js/grips/vertical.png"); } .tb-split.tb-split-horizontal, diff --git a/ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-editor.component.ts b/ui-ngx/src/app/modules/home/components/widget/config/action/custom-action-pretty-editor.component.ts similarity index 96% rename from ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-editor.component.ts rename to ui-ngx/src/app/modules/home/components/widget/config/action/custom-action-pretty-editor.component.ts index 47178013ae..d18ec34183 100644 --- a/ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-editor.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/config/action/custom-action-pretty-editor.component.ts @@ -15,7 +15,7 @@ /// // eslint-disable-next-line @typescript-eslint/triple-slash-reference -/// +/// import { AfterViewInit, @@ -35,7 +35,7 @@ import { Store } from '@ngrx/store'; import { AppState } from '@core/core.state'; import { combineLatest } from 'rxjs'; import { CustomActionDescriptor } from '@shared/models/widget.models'; -import { CustomPrettyActionEditorCompleter } from '@home/components/widget/action/custom-action.models'; +import { CustomPrettyActionEditorCompleter } from '@home/components/widget/config/action/custom-action.models'; @Component({ selector: 'tb-custom-action-pretty-editor', diff --git a/ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-resources-tabs.component.html b/ui-ngx/src/app/modules/home/components/widget/config/action/custom-action-pretty-resources-tabs.component.html similarity index 98% rename from ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-resources-tabs.component.html rename to ui-ngx/src/app/modules/home/components/widget/config/action/custom-action-pretty-resources-tabs.component.html index 5145fc13ce..f9610ecbee 100644 --- a/ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-resources-tabs.component.html +++ b/ui-ngx/src/app/modules/home/components/widget/config/action/custom-action-pretty-resources-tabs.component.html @@ -100,6 +100,7 @@ [disableUndefinedCheck]="true" [validationArgs]="[]" [editorCompleter]="customPrettyActionEditorCompleter" + functionTitle="{{ 'widget-action.custom-pretty-function' | translate }}" helpId="widget/action/custom_pretty_action_fn"> diff --git a/ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-resources-tabs.component.scss b/ui-ngx/src/app/modules/home/components/widget/config/action/custom-action-pretty-resources-tabs.component.scss similarity index 100% rename from ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-resources-tabs.component.scss rename to ui-ngx/src/app/modules/home/components/widget/config/action/custom-action-pretty-resources-tabs.component.scss diff --git a/ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-resources-tabs.component.ts b/ui-ngx/src/app/modules/home/components/widget/config/action/custom-action-pretty-resources-tabs.component.ts similarity index 99% rename from ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-resources-tabs.component.ts rename to ui-ngx/src/app/modules/home/components/widget/config/action/custom-action-pretty-resources-tabs.component.ts index 71bb0a4a2e..a5beaa7f7a 100644 --- a/ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-resources-tabs.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/config/action/custom-action-pretty-resources-tabs.component.ts @@ -35,7 +35,7 @@ import { CustomActionDescriptor } from '@shared/models/widget.models'; import { Ace } from 'ace-builds'; import { CancelAnimationFrame, RafService } from '@core/services/raf.service'; import { ResizeObserver } from '@juggle/resize-observer'; -import { CustomPrettyActionEditorCompleter } from '@home/components/widget/action/custom-action.models'; +import { CustomPrettyActionEditorCompleter } from '@home/components/widget/config/action/custom-action.models'; import { Observable } from 'rxjs/internal/Observable'; import { forkJoin, from } from 'rxjs'; import { map, tap } from 'rxjs/operators'; diff --git a/ui-ngx/src/app/modules/home/components/widget/action/custom-action.models.ts b/ui-ngx/src/app/modules/home/components/widget/config/action/custom-action.models.ts similarity index 71% rename from ui-ngx/src/app/modules/home/components/widget/action/custom-action.models.ts rename to ui-ngx/src/app/modules/home/components/widget/config/action/custom-action.models.ts index d9083bfe12..f1c3b98c74 100644 --- a/ui-ngx/src/app/modules/home/components/widget/action/custom-action.models.ts +++ b/ui-ngx/src/app/modules/home/components/widget/config/action/custom-action.models.ts @@ -17,6 +17,11 @@ import { TbEditorCompleter, TbEditorCompletions } from '@shared/models/ace/completion.models'; import { widgetContextCompletions } from '@shared/models/ace/widget-completion.models'; import { entityIdHref, entityTypeHref, serviceCompletions } from '@shared/models/ace/service-completion.models'; +import { CustomActionDescriptor, WidgetAction } from '@shared/models/widget.models'; +import { deepClone, isDefined, isUndefined } from '@core/utils'; +import customSampleJs from '!raw-loader!./custom-sample-js.raw'; +import customSampleCss from '!raw-loader!./custom-sample-css.raw'; +import customSampleHtml from '!raw-loader!./custom-sample-html.raw'; const customActionCompletions: TbEditorCompletions = { ...{ @@ -73,5 +78,24 @@ const customPrettyActionCompletions: TbEditorCompletions = { ...customActionCompletions }; +export const toCustomAction = (action: WidgetAction): CustomActionDescriptor => { + let result: CustomActionDescriptor; + if (!action || (isUndefined(action.customFunction) && isUndefined(action.customHtml) && isUndefined(action.customCss))) { + result = { + customHtml: customSampleHtml, + customCss: customSampleCss, + customFunction: customSampleJs + }; + } else { + result = { + customHtml: action.customHtml, + customCss: action.customCss, + customFunction: action.customFunction + }; + } + result.customResources = action && isDefined(action.customResources) ? deepClone(action.customResources) : []; + return result; +}; + export const CustomActionEditorCompleter = new TbEditorCompleter(customActionCompletions); export const CustomPrettyActionEditorCompleter = new TbEditorCompleter(customPrettyActionCompletions); diff --git a/ui-ngx/src/app/modules/home/components/widget/action/custom-sample-css.raw b/ui-ngx/src/app/modules/home/components/widget/config/action/custom-sample-css.raw similarity index 100% rename from ui-ngx/src/app/modules/home/components/widget/action/custom-sample-css.raw rename to ui-ngx/src/app/modules/home/components/widget/config/action/custom-sample-css.raw diff --git a/ui-ngx/src/app/modules/home/components/widget/action/custom-sample-html.raw b/ui-ngx/src/app/modules/home/components/widget/config/action/custom-sample-html.raw similarity index 100% rename from ui-ngx/src/app/modules/home/components/widget/action/custom-sample-html.raw rename to ui-ngx/src/app/modules/home/components/widget/config/action/custom-sample-html.raw diff --git a/ui-ngx/src/app/modules/home/components/widget/action/custom-sample-js.raw b/ui-ngx/src/app/modules/home/components/widget/config/action/custom-sample-js.raw similarity index 100% rename from ui-ngx/src/app/modules/home/components/widget/action/custom-sample-js.raw rename to ui-ngx/src/app/modules/home/components/widget/config/action/custom-sample-js.raw diff --git a/ui-ngx/src/app/modules/home/components/widget/action/mobile-action-editor.component.html b/ui-ngx/src/app/modules/home/components/widget/config/action/mobile-action-editor.component.html similarity index 74% rename from ui-ngx/src/app/modules/home/components/widget/action/mobile-action-editor.component.html rename to ui-ngx/src/app/modules/home/components/widget/config/action/mobile-action-editor.component.html index 4338061a2a..458e619185 100644 --- a/ui-ngx/src/app/modules/home/components/widget/action/mobile-action-editor.component.html +++ b/ui-ngx/src/app/modules/home/components/widget/config/action/mobile-action-editor.component.html @@ -15,19 +15,27 @@ limitations under the License. --> -
- - widget-action.mobile.action-type - - - {{ mobileActionTypeTranslations.get(mobileActionType[actionType]) | translate }} - - - - {{ 'widget-action.mobile.action-type-required' | translate }} - - -
+
+
+
{{ 'widget-action.mobile.action-type' | translate }}*
+ + + + {{ mobileActionTypeTranslations.get(mobileActionType[actionType]) | translate }} + + + + warning + + +
+ @@ -37,6 +45,7 @@ [functionArgs]="['$event', 'widgetContext', 'entityId', 'entityName', 'additionalParams', 'entityLabel']" [globalVariables]="functionScopeVariables" [editorCompleter]="customActionEditorCompleter" + hideBrackets helpId="widget/action/mobile_get_location_fn" > @@ -47,6 +56,7 @@ [functionArgs]="['$event', 'widgetContext', 'entityId', 'entityName', 'additionalParams', 'entityLabel']" [globalVariables]="functionScopeVariables" [editorCompleter]="customActionEditorCompleter" + hideBrackets helpId="widget/action/mobile_get_phone_number_fn" > @@ -60,6 +70,7 @@ [functionArgs]="['imageUrl', '$event', 'widgetContext', 'entityId', 'entityName', 'additionalParams', 'entityLabel']" [globalVariables]="functionScopeVariables" [editorCompleter]="customActionEditorCompleter" + hideBrackets helpId="widget/action/mobile_process_image_fn" > @@ -70,6 +81,7 @@ [functionArgs]="['code', 'format', '$event', 'widgetContext', 'entityId', 'entityName', 'additionalParams', 'entityLabel']" [globalVariables]="functionScopeVariables" [editorCompleter]="customActionEditorCompleter" + hideBrackets helpId="widget/action/mobile_process_qr_code_fn" > @@ -80,6 +92,7 @@ [functionArgs]="['latitude', 'longitude', '$event', 'widgetContext', 'entityId', 'entityName', 'additionalParams', 'entityLabel']" [globalVariables]="functionScopeVariables" [editorCompleter]="customActionEditorCompleter" + hideBrackets helpId="widget/action/mobile_process_location_fn" > @@ -93,24 +106,27 @@ [functionArgs]="['launched', '$event', 'widgetContext', 'entityId', 'entityName', 'additionalParams', 'entityLabel']" [globalVariables]="functionScopeVariables" [editorCompleter]="customActionEditorCompleter" + hideBrackets helpId="widget/action/mobile_process_launch_result_fn" > -
+
diff --git a/ui-ngx/src/app/modules/home/components/widget/action/mobile-action-editor.component.ts b/ui-ngx/src/app/modules/home/components/widget/config/action/mobile-action-editor.component.ts similarity index 91% rename from ui-ngx/src/app/modules/home/components/widget/action/mobile-action-editor.component.ts rename to ui-ngx/src/app/modules/home/components/widget/config/action/mobile-action-editor.component.ts index af028ac0ae..a95e34bec9 100644 --- a/ui-ngx/src/app/modules/home/components/widget/action/mobile-action-editor.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/config/action/mobile-action-editor.component.ts @@ -14,18 +14,22 @@ /// limitations under the License. /// -import { Component, forwardRef, Input, OnInit, QueryList, ViewChildren } from '@angular/core'; -import { ControlValueAccessor, UntypedFormBuilder, UntypedFormGroup, NG_VALUE_ACCESSOR, Validators } from '@angular/forms'; -import { Store } from '@ngrx/store'; -import { AppState } from '@app/core/core.state'; +import { Component, forwardRef, Input, OnInit } from '@angular/core'; +import { + ControlValueAccessor, + NG_VALUE_ACCESSOR, + UntypedFormBuilder, + UntypedFormGroup, + Validators +} from '@angular/forms'; import { coerceBooleanProperty } from '@angular/cdk/coercion'; import { + WidgetActionType, WidgetMobileActionDescriptor, WidgetMobileActionType, widgetMobileActionTypeTranslationMap } from '@shared/models/widget.models'; -import { CustomActionEditorCompleter } from '@home/components/widget/action/custom-action.models'; -import { JsFuncComponent } from '@shared/components/js-func.component'; +import { CustomActionEditorCompleter } from '@home/components/widget/config/action/custom-action.models'; import { getDefaultGetLocationFunction, getDefaultGetPhoneNumberFunction, @@ -35,7 +39,7 @@ import { getDefaultProcessLaunchResultFunction, getDefaultProcessLocationFunction, getDefaultProcessQrCodeFunction -} from '@home/components/widget/action/mobile-action-editor.models'; +} from '@home/components/widget/config/action/mobile-action-editor.models'; import { WidgetService } from '@core/http/widget.service'; @Component({ @@ -50,8 +54,6 @@ import { WidgetService } from '@core/http/widget.service'; }) export class MobileActionEditorComponent implements ControlValueAccessor, OnInit { - @ViewChildren(JsFuncComponent) jsFuncComponents: QueryList; - mobileActionTypes = Object.keys(WidgetMobileActionType); mobileActionTypeTranslations = widgetMobileActionTypeTranslationMap; mobileActionType = WidgetMobileActionType; @@ -75,10 +77,9 @@ export class MobileActionEditorComponent implements ControlValueAccessor, OnInit @Input() disabled: boolean; - private propagateChange = (v: any) => { }; + private propagateChange = (_v: any) => { }; - constructor(private store: Store, - private fb: UntypedFormBuilder, + constructor(private fb: UntypedFormBuilder, private widgetService: WidgetService) { this.functionScopeVariables = this.widgetService.getWidgetScopeVariables(); } @@ -87,7 +88,7 @@ export class MobileActionEditorComponent implements ControlValueAccessor, OnInit this.propagateChange = fn; } - registerOnTouched(fn: any): void { + registerOnTouched(_fn: any): void { } ngOnInit() { @@ -158,7 +159,7 @@ export class MobileActionEditorComponent implements ControlValueAccessor, OnInit } this.mobileActionTypeFormGroup = this.fb.group({}); if (type) { - let processLaunchResultFunction; + let processLaunchResultFunction: string; switch (type) { case WidgetMobileActionType.takePictureFromGallery: case WidgetMobileActionType.takePhoto: @@ -253,9 +254,5 @@ export class MobileActionEditorComponent implements ControlValueAccessor, OnInit }); } - public validateOnSubmit() { - for (const jsFuncComponent of this.jsFuncComponents.toArray()) { - jsFuncComponent.validateOnSubmit(); - } - } + protected readonly WidgetActionType = WidgetActionType; } diff --git a/ui-ngx/src/app/modules/home/components/widget/action/mobile-action-editor.models.ts b/ui-ngx/src/app/modules/home/components/widget/config/action/mobile-action-editor.models.ts similarity index 92% rename from ui-ngx/src/app/modules/home/components/widget/action/mobile-action-editor.models.ts rename to ui-ngx/src/app/modules/home/components/widget/config/action/mobile-action-editor.models.ts index 2a7270a14d..5abf69c523 100644 --- a/ui-ngx/src/app/modules/home/components/widget/action/mobile-action-editor.models.ts +++ b/ui-ngx/src/app/modules/home/components/widget/config/action/mobile-action-editor.models.ts @@ -24,6 +24,7 @@ const processImageFunctionTemplate = '\n' + 'function showImageDialog(title, imageUrl) {\n' + ' setTimeout(function() {\n' + + // eslint-disable-next-line max-len ' widgetContext.customDialog.customDialog(imageDialogTemplate, ImageDialogController, {imageUrl: imageUrl, title: title}).subscribe();\n' + ' }, 100);\n' + '}\n' + @@ -82,6 +83,7 @@ const processImageFunctionTemplate = '}\n'; const processLaunchResultFunctionTemplate = + // eslint-disable-next-line max-len '// Optional function body to process result of attempt to launch external mobile application (for ex. map application or phone call application). \n' + '// - launched - boolean value indicating if the external application was successfully launched.\n\n' + 'showLaunchStatusDialog(\'--TITLE--\', launched);\n' + @@ -166,6 +168,7 @@ const getLocationFunctionTemplate = '\n' + 'function getLocationFromEntityAttributes() {\n' + ' if (entityId) {\n' + + // eslint-disable-next-line max-len ' return widgetContext.attributeService.getEntityAttributes(entityId, \'SERVER_SCOPE\', [\'latitude\', \'longitude\']).pipe(widgetContext.rxjs.map(function(attributeData) {\n' + ' var res = [0,0];\n' + ' if (attributeData && attributeData.length === 2) {\n' + @@ -188,6 +191,7 @@ const getPhoneNumberFunctionTemplate = '\n' + 'function getPhoneNumberFromEntityAttributes() {\n' + ' if (entityId) {\n' + + // eslint-disable-next-line max-len ' return widgetContext.attributeService.getEntityAttributes(entityId, \'SERVER_SCOPE\', [\'phone\']).pipe(widgetContext.rxjs.map(function(attributeData) {\n' + ' var res = 0;\n' + ' if (attributeData && attributeData.length === 1) {\n' + @@ -200,8 +204,8 @@ const getPhoneNumberFunctionTemplate = ' }\n' + '}\n'; -export function getDefaultProcessImageFunction(type: WidgetMobileActionType): string { - let title; +export const getDefaultProcessImageFunction = (type: WidgetMobileActionType): string => { + let title: string; switch (type) { case WidgetMobileActionType.takePictureFromGallery: title = 'Gallery picture'; @@ -214,10 +218,10 @@ export function getDefaultProcessImageFunction(type: WidgetMobileActionType): st break; } return processImageFunctionTemplate.replace('--TITLE--', title); -} +}; -export function getDefaultProcessLaunchResultFunction(type: WidgetMobileActionType): string { - let title; +export const getDefaultProcessLaunchResultFunction = (type: WidgetMobileActionType): string => { + let title: string; switch (type) { case WidgetMobileActionType.mapLocation: title = 'Map location'; @@ -230,25 +234,17 @@ export function getDefaultProcessLaunchResultFunction(type: WidgetMobileActionTy break; } return processLaunchResultFunctionTemplate.replace('--TITLE--', title); -} +}; -export function getDefaultProcessQrCodeFunction() { - return processQrCodeFunction; -} +export const getDefaultProcessQrCodeFunction = () => processQrCodeFunction; -export function getDefaultProcessLocationFunction() { - return processLocationFunction; -} +export const getDefaultProcessLocationFunction = () => processLocationFunction; -export function getDefaultGetLocationFunction() { - return getLocationFunctionTemplate; -} +export const getDefaultGetLocationFunction = () => getLocationFunctionTemplate; -export function getDefaultGetPhoneNumberFunction() { - return getPhoneNumberFunctionTemplate; -} +export const getDefaultGetPhoneNumberFunction = () => getPhoneNumberFunctionTemplate; -export function getDefaultHandleEmptyResultFunction(type: WidgetMobileActionType): string { +export const getDefaultHandleEmptyResultFunction = (type: WidgetMobileActionType): string => { let message = 'Mobile action was cancelled!'; switch (type) { case WidgetMobileActionType.takePictureFromGallery: @@ -277,9 +273,9 @@ export function getDefaultHandleEmptyResultFunction(type: WidgetMobileActionType break; } return handleEmptyResultFunctionTemplate.replace('--MESSAGE--', message); -} +}; -export function getDefaultHandleErrorFunction(type: WidgetMobileActionType): string { +export const getDefaultHandleErrorFunction = (type: WidgetMobileActionType): string => { let title = 'Mobile action failed'; switch (type) { case WidgetMobileActionType.takePictureFromGallery: @@ -308,4 +304,4 @@ export function getDefaultHandleErrorFunction(type: WidgetMobileActionType): str break; } return handleErrorFunctionTemplate.replace('--TITLE--', title); -} +}; diff --git a/ui-ngx/src/app/modules/home/components/widget/config/action/widget-action.component.html b/ui-ngx/src/app/modules/home/components/widget/config/action/widget-action.component.html new file mode 100644 index 0000000000..35ca3f3144 --- /dev/null +++ b/ui-ngx/src/app/modules/home/components/widget/config/action/widget-action.component.html @@ -0,0 +1,234 @@ + +
+
+
widget-config.action
+ + + + {{ widgetActionTypeTranslations.get(widgetActionType[actionType]) | translate }} + + + +
+ + +
+
{{ 'widget-action.target-dashboard' | translate }}*
+ +
+
+ +
+
{{ 'widget-action.target-dashboard-state' | translate }} + {{widgetActionFormGroup.get('type').value === widgetActionType.openDashboardState ? '*' : ''}}
+ + + + + warning + + + + + + + +
+
+ +
+ + {{ 'widget-action.open-right-layout' | translate }} + +
+
+ +
+ + {{ 'widget-action.open-new-browser-tab' | translate }} + +
+
+ +
+ + {{ 'widget-action.set-entity-from-widget' | translate }} + +
+
+
{{ 'alias.state-entity-parameter-name' | translate }}
+ + + +
+
+ +
+
{{ 'widget-action.state-display-type' | translate }}
+ + + + {{ stateDisplayTypeName(displayType) }} + + + +
+ + +
+
{{ 'widget-action.dialog-title' | translate }}
+ + + +
+
+ + {{ 'widget-action.dialog-hide-dashboard-toolbar' | translate }} + +
+
+
{{ 'widget-action.dialog-width' | translate }}
+ + + + warning + + +
+
+
{{ 'widget-action.dialog-height' | translate }}
+ + + + warning + + +
+
+ +
+
{{ 'widget-action.popover-preferred-placement' | translate }}
+ + + + {{ popoverPlacementName(placement) }} + + + +
+
+ + {{ 'widget-action.popover-hide-on-click-outside' | translate }} + +
+
+ + {{ 'widget-action.popover-hide-dashboard-toolbar' | translate }} + +
+
+
{{ 'widget-action.popover-width' | translate }}
+ + +
+
+
{{ 'widget-action.popover-height' | translate }}
+ + +
+ +
+ + +
+
+ + + + + + + + + + + +
+
diff --git a/ui-ngx/src/app/modules/home/components/widget/config/action/widget-action.component.ts b/ui-ngx/src/app/modules/home/components/widget/config/action/widget-action.component.ts new file mode 100644 index 0000000000..ed7690fe28 --- /dev/null +++ b/ui-ngx/src/app/modules/home/components/widget/config/action/widget-action.component.ts @@ -0,0 +1,463 @@ +/// +/// Copyright © 2016-2024 The Thingsboard Authors +/// +/// Licensed under the Apache License, Version 2.0 (the "License"); +/// you may not use this file except in compliance with the License. +/// You may obtain a copy of the License at +/// +/// http://www.apache.org/licenses/LICENSE-2.0 +/// +/// Unless required by applicable law or agreed to in writing, software +/// distributed under the License is distributed on an "AS IS" BASIS, +/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +/// See the License for the specific language governing permissions and +/// limitations under the License. +/// + +import { + ControlValueAccessor, + NG_VALIDATORS, + NG_VALUE_ACCESSOR, + UntypedFormBuilder, + UntypedFormControl, + UntypedFormGroup, + Validator, + Validators +} from '@angular/forms'; +import { Component, ElementRef, forwardRef, Input, OnInit, ViewChild } from '@angular/core'; +import { + WidgetAction, + WidgetActionType, + widgetActionTypeTranslationMap, + widgetType +} from '@shared/models/widget.models'; +import { WidgetService } from '@core/http/widget.service'; +import { WidgetActionCallbacks } from '@home/components/widget/action/manage-widget-actions.component.models'; +import { map, mergeMap, share, startWith, takeUntil, tap } from 'rxjs/operators'; +import { Observable, of, Subject, Subscription } from 'rxjs'; +import { Dashboard } from '@shared/models/dashboard.models'; +import { DashboardService } from '@core/http/dashboard.service'; +import { DashboardUtilsService } from '@core/services/dashboard-utils.service'; +import { isDefinedAndNotNull } from '@core/utils'; +import { TranslateService } from '@ngx-translate/core'; +import { PopoverPlacement, PopoverPlacements } from '@shared/components/popover.models'; +import { + CustomActionEditorCompleter, + toCustomAction +} from '@home/components/widget/config/action/custom-action.models'; + +const stateDisplayTypes = ['normal', 'separateDialog', 'popover'] as const; +type stateDisplayTypeTuple = typeof stateDisplayTypes; +export type stateDisplayType = stateDisplayTypeTuple[number]; + +const stateDisplayTypesTranslations = new Map( + [ + ['normal', 'widget-action.open-normal'], + ['separateDialog', 'widget-action.open-in-separate-dialog'], + ['popover', 'widget-action.open-in-popover'], + ] +); + +@Component({ + selector: 'tb-widget-action', + templateUrl: './widget-action.component.html', + styleUrls: [], + providers: [ + { + provide: NG_VALUE_ACCESSOR, + useExisting: forwardRef(() => WidgetActionComponent), + multi: true + }, + { + provide: NG_VALIDATORS, + useExisting: forwardRef(() => WidgetActionComponent), + multi: true, + } + ] +}) +export class WidgetActionComponent implements ControlValueAccessor, OnInit, Validator { + + @ViewChild('dashboardStateInput', {static: false}) dashboardStateInput: ElementRef; + + @Input() + disabled: boolean; + + @Input() + widgetType: widgetType; + + @Input() + callbacks: WidgetActionCallbacks; + + widgetActionTypes = Object.keys(WidgetActionType); + widgetActionTypeTranslations = widgetActionTypeTranslationMap; + widgetActionType = WidgetActionType; + + allStateDisplayTypes = stateDisplayTypes; + allPopoverPlacements = PopoverPlacements; + + WidgetType = widgetType; + + filteredDashboardStates: Observable>; + targetDashboardStateSearchText = ''; + selectedDashboardStateIds: Observable>; + + customActionEditorCompleter = CustomActionEditorCompleter; + + functionScopeVariables = this.widgetService.getWidgetScopeVariables(); + + widgetActionFormGroup: UntypedFormGroup; + actionTypeFormGroup: UntypedFormGroup; + stateDisplayTypeFormGroup: UntypedFormGroup; + + private propagateChange = (_val: any) => {}; + private actionTypeFormGroupSubscriptions: Subscription[] = []; + private stateDisplayTypeFormGroupSubscriptions: Subscription[] = []; + private destroy$ = new Subject(); + private dashboard: Dashboard; + + constructor(private fb: UntypedFormBuilder, + private widgetService: WidgetService, + private dashboardService: DashboardService, + private dashboardUtils: DashboardUtilsService, + private translate: TranslateService) { + } + + registerOnChange(fn: any): void { + this.propagateChange = fn; + } + + registerOnTouched(_fn: any): void { + } + + setDisabledState(isDisabled: boolean): void { + this.disabled = isDisabled; + if (this.disabled) { + this.widgetActionFormGroup.disable({emitEvent: false}); + if (this.actionTypeFormGroup) { + this.actionTypeFormGroup.disable({emitEvent: false}); + } + if (this.stateDisplayTypeFormGroup) { + this.stateDisplayTypeFormGroup.disable({emitEvent: false}); + } + } else { + this.widgetActionFormGroup.enable({emitEvent: false}); + } + } + + ngOnInit() { + this.widgetActionFormGroup = this.fb.group({}); + this.widgetActionFormGroup.addControl('type', + this.fb.control(null, [Validators.required])); + this.widgetActionFormGroup.get('type').valueChanges.pipe( + takeUntil(this.destroy$) + ).subscribe((type: WidgetActionType) => { + this.updateActionTypeFormGroup(type); + }); + this.widgetActionFormGroup.valueChanges.pipe( + takeUntil(this.destroy$) + ).subscribe(() => { + this.widgetActionUpdated(); + }); + } + + writeValue(widgetAction?: WidgetAction): void { + this.widgetActionFormGroup.patchValue({ + type: widgetAction?.type + }, {emitEvent: false}); + this.updateActionTypeFormGroup(widgetAction?.type, widgetAction); + } + + validate(_c: UntypedFormControl) { + return (this.widgetActionFormGroup.valid && + this.actionTypeFormGroup.valid && (!this.stateDisplayTypeFormGroup || this.stateDisplayTypeFormGroup.valid)) ? null : { + widgetAction: { + valid: false, + } + }; + } + + clearTargetDashboardState(value: string = '') { + this.dashboardStateInput.nativeElement.value = value; + this.actionTypeFormGroup.get('targetDashboardStateId').patchValue(value, {emitEvent: true}); + setTimeout(() => { + this.dashboardStateInput.nativeElement.blur(); + this.dashboardStateInput.nativeElement.focus(); + }, 0); + } + + onDashboardStateInputFocus(): void { + this.actionTypeFormGroup.get('targetDashboardStateId').updateValueAndValidity({onlySelf: true, emitEvent: true}); + } + + stateDisplayTypeName(displayType: stateDisplayType): string { + if (displayType) { + return this.translate.instant(stateDisplayTypesTranslations.get(displayType)) + ''; + } else { + return ''; + } + } + + popoverPlacementName(placement: PopoverPlacement): string { + if (placement) { + return this.translate.instant(`widget-action.popover-placement-${placement}`) + ''; + } else { + return ''; + } + } + + private updateActionTypeFormGroup(type?: WidgetActionType, action?: WidgetAction) { + this.actionTypeFormGroupSubscriptions.forEach(s => s.unsubscribe()); + this.actionTypeFormGroupSubscriptions.length = 0; + this.actionTypeFormGroup = this.fb.group({}); + if (type) { + switch (type) { + case WidgetActionType.openDashboard: + case WidgetActionType.openDashboardState: + case WidgetActionType.updateDashboardState: + this.actionTypeFormGroup.addControl( + 'targetDashboardStateId', + this.fb.control(action ? action.targetDashboardStateId : null, + type === WidgetActionType.openDashboardState ? [Validators.required] : []) + ); + this.actionTypeFormGroup.addControl( + 'setEntityId', + this.fb.control(this.widgetType === widgetType.static ? false : action ? action.setEntityId : true, []) + ); + this.actionTypeFormGroup.addControl( + 'stateEntityParamName', + this.fb.control(action ? action.stateEntityParamName : null, []) + ); + if (type === WidgetActionType.openDashboard) { + this.actionTypeFormGroup.addControl( + 'openNewBrowserTab', + this.fb.control(action ? action.openNewBrowserTab : false, []) + ); + this.actionTypeFormGroup.addControl( + 'targetDashboardId', + this.fb.control(action ? action.targetDashboardId : null, + [Validators.required]) + ); + this.setupSelectedDashboardStateIds(); + } else { + if (type === WidgetActionType.openDashboardState) { + const displayType = this.getStateDisplayType(action); + this.actionTypeFormGroup.addControl( + 'stateDisplayType', + this.fb.control(this.getStateDisplayType(action), [Validators.required]) + ); + this.updateStateDisplayTypeFormGroup(displayType, action); + this.actionTypeFormGroupSubscriptions.push( + this.actionTypeFormGroup.get('stateDisplayType').valueChanges.pipe( + takeUntil(this.destroy$) + ).subscribe((displayTypeValue: stateDisplayType) => { + this.updateStateDisplayTypeFormGroup(displayTypeValue); + }) + ); + } + this.actionTypeFormGroup.addControl( + 'openRightLayout', + this.fb.control(action ? action.openRightLayout : false, []) + ); + } + this.setupFilteredDashboardStates(); + break; + case WidgetActionType.custom: + this.actionTypeFormGroup.addControl( + 'customFunction', + this.fb.control(action ? action.customFunction : null, []) + ); + break; + case WidgetActionType.customPretty: + this.actionTypeFormGroup.addControl( + 'customAction', + this.fb.control(toCustomAction(action), [Validators.required]) + ); + break; + case WidgetActionType.mobileAction: + this.actionTypeFormGroup.addControl( + 'mobileAction', + this.fb.control(action ? action.mobileAction : null, [Validators.required]) + ); + break; + } + } + this.actionTypeFormGroupSubscriptions.push( + this.actionTypeFormGroup.valueChanges.pipe( + takeUntil(this.destroy$) + ).subscribe(() => { + this.widgetActionUpdated(); + }) + ); + } + + private updateStateDisplayTypeFormGroup(displayType?: stateDisplayType, action?: WidgetAction) { + this.stateDisplayTypeFormGroupSubscriptions.forEach(s => s.unsubscribe()); + this.stateDisplayTypeFormGroupSubscriptions.length = 0; + this.stateDisplayTypeFormGroup = this.fb.group({}); + if (displayType) { + switch (displayType) { + case 'normal': + break; + case 'separateDialog': + this.stateDisplayTypeFormGroup.addControl( + 'dialogTitle', + this.fb.control(action ? action.dialogTitle : '', []) + ); + this.stateDisplayTypeFormGroup.addControl( + 'dialogHideDashboardToolbar', + this.fb.control(action && isDefinedAndNotNull(action.dialogHideDashboardToolbar) + ? action.dialogHideDashboardToolbar : true, []) + ); + this.stateDisplayTypeFormGroup.addControl( + 'dialogWidth', + this.fb.control(action ? action.dialogWidth : null, [Validators.min(1), Validators.max(100)]) + ); + this.stateDisplayTypeFormGroup.addControl( + 'dialogHeight', + this.fb.control(action ? action.dialogHeight : null, [Validators.min(1), Validators.max(100)]) + ); + break; + case 'popover': + this.stateDisplayTypeFormGroup.addControl( + 'popoverPreferredPlacement', + this.fb.control(action && isDefinedAndNotNull(action.popoverPreferredPlacement) + ? action.popoverPreferredPlacement : 'top', []) + ); + this.stateDisplayTypeFormGroup.addControl( + 'popoverHideOnClickOutside', + this.fb.control(action && isDefinedAndNotNull(action.popoverHideOnClickOutside) + ? action.popoverHideOnClickOutside : true, []) + ); + this.stateDisplayTypeFormGroup.addControl( + 'popoverHideDashboardToolbar', + this.fb.control(action && isDefinedAndNotNull(action.popoverHideDashboardToolbar) + ? action.popoverHideDashboardToolbar : true, []) + ); + this.stateDisplayTypeFormGroup.addControl( + 'popoverWidth', + this.fb.control(action && isDefinedAndNotNull(action.popoverWidth) ? action.popoverWidth : '25vw', []) + ); + this.stateDisplayTypeFormGroup.addControl( + 'popoverHeight', + this.fb.control(action && isDefinedAndNotNull(action.popoverHeight) ? action.popoverHeight : '25vh', []) + ); + this.stateDisplayTypeFormGroup.addControl( + 'popoverStyle', + this.fb.control(action && isDefinedAndNotNull(action.popoverStyle) ? action.popoverStyle : {}, []) + ); + break; + } + } + this.stateDisplayTypeFormGroupSubscriptions.push( + this.stateDisplayTypeFormGroup.valueChanges.pipe( + takeUntil(this.destroy$) + ).subscribe(() => { + this.widgetActionUpdated(); + }) + ); + } + + private setupSelectedDashboardStateIds() { + this.selectedDashboardStateIds = + this.actionTypeFormGroup.get('targetDashboardId').valueChanges.pipe( + tap((dashboardId) => { + if (!dashboardId) { + this.actionTypeFormGroup.get('targetDashboardStateId') + .patchValue('', {emitEvent: true}); + } + + this.targetDashboardStateSearchText = ''; + }), + mergeMap((dashboardId) => { + if (dashboardId) { + if (this.dashboard?.id.id === dashboardId) { + return of(this.dashboard); + } else { + return this.dashboardService.getDashboard(dashboardId); + } + } else { + return of(null); + } + }), + map((dashboard: Dashboard) => { + if (dashboard) { + if (this.dashboard?.id.id !== dashboard.id.id) { + this.dashboard = this.dashboardUtils.validateAndUpdateDashboard(dashboard); + } + + return Object.keys(this.dashboard.configuration.states); + } else { + return []; + } + }), + share() + ); + } + + private setupFilteredDashboardStates() { + this.targetDashboardStateSearchText = ''; + this.filteredDashboardStates = this.actionTypeFormGroup.get('targetDashboardStateId').valueChanges + .pipe( + startWith(''), + map(value => value ? value : ''), + mergeMap(name => this.fetchDashboardStates(name)), + takeUntil(this.destroy$) + ); + } + + private fetchDashboardStates(searchText?: string): Observable> { + this.targetDashboardStateSearchText = searchText; + if (this.widgetActionFormGroup.get('type').value === WidgetActionType.openDashboard) { + return this.selectedDashboardStateIds.pipe( + map(stateIds => { + const result = searchText ? stateIds.filter(this.createFilterForDashboardState(searchText)) : stateIds; + if (result && result.length) { + return result; + } else { + return [searchText]; + } + }) + ); + } else { + return of(this.callbacks.fetchDashboardStates(searchText)); + } + } + + private createFilterForDashboardState(query: string): (stateId: string) => boolean { + const lowercaseQuery = query.toLowerCase(); + return stateId => stateId.toLowerCase().indexOf(lowercaseQuery) === 0; + } + + private getStateDisplayType(action?: WidgetAction): stateDisplayType { + let res: stateDisplayType = 'normal'; + if (action) { + if (action.openInSeparateDialog) { + res = 'separateDialog'; + } else if (action.openInPopover) { + res = 'popover'; + } + } + return res; + } + + private widgetActionUpdated() { + const type: WidgetActionType = this.widgetActionFormGroup.get('type').value; + let result: WidgetAction; + if (type === WidgetActionType.customPretty) { + result = {...this.widgetActionFormGroup.value, ...this.actionTypeFormGroup.get('customAction').value}; + } else { + result = {...this.widgetActionFormGroup.value, ...this.actionTypeFormGroup.value}; + } + if (this.actionTypeFormGroup.get('stateDisplayType') && + this.actionTypeFormGroup.get('stateDisplayType').value !== 'normal') { + result = {...result, ...this.stateDisplayTypeFormGroup.value}; + result.openInSeparateDialog = this.actionTypeFormGroup.get('stateDisplayType').value === 'separateDialog'; + result.openInPopover = this.actionTypeFormGroup.get('stateDisplayType').value === 'popover'; + } else { + result.openInSeparateDialog = false; + result.openInPopover = false; + } + delete (result as any).stateDisplayType; + this.propagateChange(result); + } +} diff --git a/ui-ngx/src/app/modules/home/components/widget/config/widget-config-components.module.ts b/ui-ngx/src/app/modules/home/components/widget/config/widget-config-components.module.ts index 4470fc1327..7b80b4b088 100644 --- a/ui-ngx/src/app/modules/home/components/widget/config/widget-config-components.module.ts +++ b/ui-ngx/src/app/modules/home/components/widget/config/widget-config-components.module.ts @@ -33,6 +33,11 @@ import { WidgetSettingsCommonModule } from '@home/components/widget/lib/settings import { TimewindowStyleComponent } from '@home/components/widget/config/timewindow-style.component'; import { TimewindowStylePanelComponent } from '@home/components/widget/config/timewindow-style-panel.component'; import { TargetDeviceComponent } from '@home/components/widget/config/target-device.component'; +import { WidgetActionComponent } from '@home/components/widget/config/action/widget-action.component'; +import { CustomActionPrettyResourcesTabsComponent } + from '@home/components/widget/config/action/custom-action-pretty-resources-tabs.component'; +import { CustomActionPrettyEditorComponent } from '@home/components/widget/config/action/custom-action-pretty-editor.component'; +import { MobileActionEditorComponent } from '@home/components/widget/config/action/mobile-action-editor.component'; @NgModule({ declarations: @@ -50,7 +55,11 @@ import { TargetDeviceComponent } from '@home/components/widget/config/target-dev TimewindowStyleComponent, TimewindowStylePanelComponent, TimewindowConfigPanelComponent, - WidgetSettingsComponent + WidgetSettingsComponent, + WidgetActionComponent, + CustomActionPrettyResourcesTabsComponent, + CustomActionPrettyEditorComponent, + MobileActionEditorComponent ], imports: [ CommonModule, @@ -73,7 +82,11 @@ import { TargetDeviceComponent } from '@home/components/widget/config/target-dev TimewindowStylePanelComponent, TimewindowConfigPanelComponent, WidgetSettingsComponent, - WidgetSettingsCommonModule + WidgetSettingsCommonModule, + WidgetActionComponent, + CustomActionPrettyResourcesTabsComponent, + CustomActionPrettyEditorComponent, + MobileActionEditorComponent ] }) export class WidgetConfigComponentsModule { } diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/css-size-input.component.html b/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/css-size-input.component.html new file mode 100644 index 0000000000..31836d433d --- /dev/null +++ b/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/css-size-input.component.html @@ -0,0 +1,33 @@ + +
+ + + + warning + + + +
diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/css-size-input.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/css-size-input.component.ts new file mode 100644 index 0000000000..dcd579e071 --- /dev/null +++ b/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/css-size-input.component.ts @@ -0,0 +1,124 @@ +/// +/// Copyright © 2016-2024 The Thingsboard Authors +/// +/// Licensed under the Apache License, Version 2.0 (the "License"); +/// you may not use this file except in compliance with the License. +/// You may obtain a copy of the License at +/// +/// http://www.apache.org/licenses/LICENSE-2.0 +/// +/// Unless required by applicable law or agreed to in writing, software +/// distributed under the License is distributed on an "AS IS" BASIS, +/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +/// See the License for the specific language governing permissions and +/// limitations under the License. +/// + +import { Component, forwardRef, Input, OnInit } from '@angular/core'; +import { + ControlValueAccessor, + NG_VALIDATORS, + NG_VALUE_ACCESSOR, + UntypedFormBuilder, + UntypedFormControl, + UntypedFormGroup, + Validator, + Validators +} from '@angular/forms'; +import { cssUnit, resolveCssSize } from '@shared/models/widget-settings.models'; +import { coerceBoolean } from '@shared/decorators/coercion'; +import { isDefinedAndNotNull } from '@core/utils'; + +@Component({ + selector: 'tb-css-size-input', + templateUrl: './css-size-input.component.html', + styleUrls: [], + providers: [ + { + provide: NG_VALUE_ACCESSOR, + useExisting: forwardRef(() => CssSizeInputComponent), + multi: true + }, + { + provide: NG_VALIDATORS, + useExisting: forwardRef(() => CssSizeInputComponent), + multi: true, + } + ] +}) +export class CssSizeInputComponent implements OnInit, ControlValueAccessor, Validator { + + @Input() + disabled: boolean; + + @Input() + @coerceBoolean() + required = false; + + @Input() + requiredText: string; + + @Input() + @coerceBoolean() + allowEmptyUnit = false; + + cssSizeFormGroup: UntypedFormGroup; + + modelValue: string; + + private propagateChange = null; + + constructor(private fb: UntypedFormBuilder) {} + + ngOnInit(): void { + this.cssSizeFormGroup = this.fb.group({ + size: [null, this.required ? [Validators.required, Validators.min(0)] : [Validators.min(0)]], + unit: [null, []] + }); + this.cssSizeFormGroup.valueChanges.subscribe((value: {size: number; unit: cssUnit}) => { + this.updateModel(value); + }); + } + + registerOnChange(fn: any): void { + this.propagateChange = fn; + } + + registerOnTouched(fn: any): void { + } + + setDisabledState(isDisabled: boolean): void { + this.disabled = isDisabled; + if (this.disabled) { + this.cssSizeFormGroup.disable({emitEvent: false}); + } else { + this.cssSizeFormGroup.enable({emitEvent: false}); + } + } + + writeValue(value: string): void { + this.modelValue = value; + const size = resolveCssSize(value); + this.cssSizeFormGroup.patchValue({ + size: size[0], + unit: size[1] + }, {emitEvent: false}); + } + + validate(_c: UntypedFormControl) { + return this.cssSizeFormGroup.valid ? null : { + cssSize: { + valid: false, + } + }; + } + + private updateModel(value: {size: number; unit: cssUnit}): void { + const result: string = isDefinedAndNotNull(value?.size) && isDefinedAndNotNull(value?.unit) + ? value.size + value.unit : ''; + if (this.modelValue !== result) { + this.modelValue = result; + this.propagateChange(this.modelValue); + } + } +} diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/css-unit-select.component.html b/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/css-unit-select.component.html index 8455c9b2cf..095310606f 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/css-unit-select.component.html +++ b/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/css-unit-select.component.html @@ -15,7 +15,7 @@ limitations under the License. --> - + diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/css-unit-select.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/css-unit-select.component.ts index 8c78d26a39..588871b7b9 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/css-unit-select.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/css-unit-select.component.ts @@ -40,6 +40,9 @@ export class CssUnitSelectComponent implements OnInit, ControlValueAccessor { @coerceBoolean() allowEmpty = false; + @Input() + width = '100%'; + cssUnitsList = cssUnits; cssUnitFormControl: UntypedFormControl; diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/widget-settings-common.module.ts b/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/widget-settings-common.module.ts index ba08a39bb7..8275f53e54 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/widget-settings-common.module.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/widget-settings-common.module.ts @@ -66,6 +66,7 @@ import { import { RpcUpdateStateSettingsPanelComponent } from '@home/components/widget/lib/settings/common/rpc/rpc-update-state-settings-panel.component'; +import { CssSizeInputComponent } from '@home/components/widget/lib/settings/common/css-size-input.component'; @NgModule({ declarations: [ @@ -76,6 +77,7 @@ import { ColorSettingsComponent, ColorSettingsPanelComponent, CssUnitSelectComponent, + CssSizeInputComponent, DateFormatSelectComponent, DateFormatSettingsPanelComponent, BackgroundSettingsComponent, @@ -106,6 +108,7 @@ import { ColorSettingsComponent, ColorSettingsPanelComponent, CssUnitSelectComponent, + CssSizeInputComponent, DateFormatSelectComponent, DateFormatSettingsPanelComponent, BackgroundSettingsComponent, 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 a7fbc64db7..1c029b6524 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 @@ -1345,7 +1345,7 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI this.widgetContext.parentDashboard : this.widgetContext.dashboard, popoverComponent: componentRef.instance }, - {width: popoverWidth, height: popoverHeight}, + {width: popoverWidth || '25vw', height: popoverHeight || '25vh'}, popoverStyle, {} ); diff --git a/ui-ngx/src/app/shared/components/dashboard-autocomplete.component.html b/ui-ngx/src/app/shared/components/dashboard-autocomplete.component.html index e9f177e851..5d41da6b4a 100644 --- a/ui-ngx/src/app/shared/components/dashboard-autocomplete.component.html +++ b/ui-ngx/src/app/shared/components/dashboard-autocomplete.component.html @@ -15,9 +15,14 @@ limitations under the License. --> - - {{ label }} + + {{ label }} close + + warning + - + - + > diff --git a/ui-ngx/src/app/shared/components/dashboard-autocomplete.component.ts b/ui-ngx/src/app/shared/components/dashboard-autocomplete.component.ts index 308087bd31..2cdaf2d13c 100644 --- a/ui-ngx/src/app/shared/components/dashboard-autocomplete.component.ts +++ b/ui-ngx/src/app/shared/components/dashboard-autocomplete.component.ts @@ -15,7 +15,13 @@ /// import { AfterViewInit, Component, ElementRef, forwardRef, Input, OnInit, ViewChild } from '@angular/core'; -import { ControlValueAccessor, NG_VALUE_ACCESSOR, UntypedFormBuilder, UntypedFormGroup } from '@angular/forms'; +import { + ControlValueAccessor, + NG_VALUE_ACCESSOR, + UntypedFormBuilder, + UntypedFormGroup, + Validators +} from '@angular/forms'; import { Observable, of } from 'rxjs'; import { PageLink } from '@shared/models/page/page-link'; import { Direction } from '@shared/models/page/sort-order'; @@ -28,11 +34,11 @@ import { AppState } from '@app/core/core.state'; import { getCurrentAuthUser } from '@app/core/auth/auth.selectors'; import { Authority } from '@shared/models/authority.enum'; import { TranslateService } from '@ngx-translate/core'; -import { coerceBooleanProperty } from '@angular/cdk/coercion'; import { FloatLabelType, MatFormFieldAppearance, SubscriptSizing } from '@angular/material/form-field'; import { getEntityDetailsPageURL } from '@core/utils'; import { EntityType } from '@shared/models/entity-type.models'; import { AuthUser } from '@shared/models/user.model'; +import { coerceBoolean } from '@shared/decorators/coercion'; @Component({ selector: 'tb-dashboard-autocomplete', @@ -82,14 +88,16 @@ export class DashboardAutocompleteComponent implements ControlValueAccessor, OnI @Input() subscriptSizing: SubscriptSizing = 'fixed'; - private requiredValue: boolean; - get required(): boolean { - return this.requiredValue; - } @Input() - set required(value: boolean) { - this.requiredValue = coerceBooleanProperty(value); - } + @coerceBoolean() + inlineField: boolean; + + @Input() + requiredText: string; + + @Input() + @coerceBoolean() + required: boolean; @Input() disabled: boolean; @@ -106,7 +114,7 @@ export class DashboardAutocompleteComponent implements ControlValueAccessor, OnI private authUser: AuthUser; - private propagateChange = (v: any) => { }; + private propagateChange = (_v: any) => { }; constructor(private store: Store, public translate: TranslateService, @@ -118,7 +126,7 @@ export class DashboardAutocompleteComponent implements ControlValueAccessor, OnI } this.selectDashboardFormGroup = this.fb.group({ - dashboard: [null] + dashboard: [null, this.required ? [Validators.required] : []] }); } @@ -126,7 +134,7 @@ export class DashboardAutocompleteComponent implements ControlValueAccessor, OnI this.propagateChange = fn; } - registerOnTouched(fn: any): void { + registerOnTouched(_fn: any): void { } ngOnInit() { @@ -134,7 +142,7 @@ export class DashboardAutocompleteComponent implements ControlValueAccessor, OnI .pipe( debounceTime(150), tap(value => { - let modelValue; + let modelValue: string | DashboardInfo; if (typeof value === 'string' || !value) { modelValue = null; } else { @@ -218,15 +226,13 @@ export class DashboardAutocompleteComponent implements ControlValueAccessor, OnI fetchDashboards(searchText?: string): Observable> { this.searchText = searchText; - const pageLink = new PageLink(10, 0, searchText, { + const pageLink = new PageLink(25, 0, searchText, { property: 'title', direction: Direction.ASC }); return this.getDashboards(pageLink).pipe( catchError(() => of(emptyPageData())), - map(pageData => { - return pageData.data; - }) + map(pageData => pageData.data) ); } diff --git a/ui-ngx/src/app/shared/components/js-func.component.html b/ui-ngx/src/app/shared/components/js-func.component.html index e072759213..66bced8adf 100644 --- a/ui-ngx/src/app/shared/components/js-func.component.html +++ b/ui-ngx/src/app/shared/components/js-func.component.html @@ -15,14 +15,14 @@ limitations under the License. --> -
- - +