diff --git a/ui-ngx/src/app/core/services/dashboard-utils.service.ts b/ui-ngx/src/app/core/services/dashboard-utils.service.ts index 8afacfcc9a..de1eb3a6ac 100644 --- a/ui-ngx/src/app/core/services/dashboard-utils.service.ts +++ b/ui-ngx/src/app/core/services/dashboard-utils.service.ts @@ -19,6 +19,8 @@ import { DashboardState, DashboardStateLayouts, GridSettings, + htmlPageDefaultConfig, + htmlPageWidgetId, LayoutType, WidgetLayout } from '@shared/models/dashboard.models'; @@ -29,8 +31,10 @@ import { isDefinedAndNotNull, isNotEmptyStr, isString, - isUndefined + isUndefined, + mergeDeep } from '@core/utils'; +import { htmlContainerDefaultSettings, HtmlContainerWidgetSettings } from '@shared/models/html-container.models'; import { Datasource, datasourcesHasAggregation, @@ -458,7 +462,7 @@ export class DashboardUtilsService { }; } - private createDefaultGridSettings(): GridSettings { + public createDefaultGridSettings(): GridSettings { return { layoutType: LayoutType.default, backgroundColor: '#eeeeee', @@ -614,7 +618,7 @@ export class DashboardUtilsService { for (const state of Object.values(states)) { for (const layout of Object.values(state.layouts)) { - if (layout.widgets[widgetId]) { + if (layout.widgets && layout.widgets[widgetId]) { foundWidgetRefs++; } if (layout.breakpoints) { @@ -650,11 +654,11 @@ export class DashboardUtilsService { const layout: DashboardLayout = state.layouts[l]; if (layout) { result[l]= { - default: this.getBreakpointLayoutData(layout) + default: this.getBreakpointLayoutData(layout, targetState) }; if (layout.breakpoints) { for (const breakpoint of Object.keys(layout.breakpoints)) { - result[l][breakpoint] = this.getBreakpointLayoutData(layout.breakpoints[breakpoint]); + result[l][breakpoint] = this.getBreakpointLayoutData(layout.breakpoints[breakpoint], targetState); } } } @@ -665,17 +669,56 @@ export class DashboardUtilsService { } } - private getBreakpointLayoutData(layout: DashboardLayout): BreakpointLayoutInfo { + private getBreakpointLayoutData(layout: DashboardLayout, stateId: string): BreakpointLayoutInfo { const result: BreakpointLayoutInfo = { widgetIds: [], widgetLayouts: {}, gridSettings: {} }; - for (const id of Object.keys(layout.widgets)) { - result.widgetIds.push(id); + if (layout.gridSettings?.layoutType === LayoutType.html) { + result.gridSettings = { + layoutType: LayoutType.html, + autoFillHeight: true, + mobileAutoFillHeight: true, + columns: 1, + minColumns: 1, + margin: 0, + outerMargin: false + }; + // Stable per state: an unchanged page keeps its rendered instance, a changed one is re-rendered. + const widgetId = htmlPageWidgetId(stateId); + const config = mergeDeep({}, + htmlPageDefaultConfig, + { + settings: layout.gridSettings?.htmlPageConfig?.settings || mergeDeep({} as HtmlContainerWidgetSettings, htmlContainerDefaultSettings), + actions: layout.gridSettings?.htmlPageConfig?.actions + } + ); + result.widget = { + id: widgetId, + col: 0, + row: 0, + sizeX: 1, + sizeY: 1, + typeFullFqn: 'system.html_container', + type: widgetType.static, + config + }; + result.widgetLayouts[widgetId] = { + col: 0, + row: 0, + sizeX: 1, + sizeY: 1, + resizable: false, + mobileOrder: 0 + }; + } else { + for (const id of Object.keys(layout.widgets)) { + result.widgetIds.push(id); + } + result.widgetLayouts = layout.widgets; + result.gridSettings = layout.gridSettings; } - result.widgetLayouts = layout.widgets; - result.gridSettings = layout.gridSettings; return result; } @@ -691,11 +734,12 @@ export class DashboardUtilsService { } public isEmptyDashboard(dashboard: Dashboard): boolean { - if (dashboard?.configuration?.widgets) { - return Object.keys(dashboard?.configuration?.widgets).length === 0; - } else { - return true; + if (dashboard?.configuration?.widgets && Object.keys(dashboard.configuration.widgets).length) { + return false; } + // An HTML page has content but no stored widgets: its widget is virtual. + return !Object.values(dashboard?.configuration?.states || {}).some(state => + Object.values(state.layouts || {}).some(layout => layout?.gridSettings?.layoutType === LayoutType.html)); } public addWidgetToLayout(dashboard: Dashboard, @@ -865,6 +909,10 @@ export class DashboardUtilsService { const columns = gridSettings.columns || 24; const ratio = columns / prevColumns; layout.gridSettings = gridSettings; + if (!layout.widgets) { + // HTML page layout: no widget grid to rescale + return; + } for (const w of Object.keys(layout.widgets)) { const widget = layout.widgets[w]; if (!widget.sizeX) { @@ -963,7 +1011,7 @@ export class DashboardUtilsService { const state = states[s]; for (const l of Object.keys(state.layouts)) { const layout: DashboardLayout = state.layouts[l]; - if (layout.widgets[widgetId]) { + if (layout.widgets && layout.widgets[widgetId]) { found = true; break; } @@ -1273,7 +1321,11 @@ export class DashboardUtilsService { if (layoutInfo.gridSettings) { layout.layoutCtx.gridSettings = layoutInfo.gridSettings; } - layout.layoutCtx.widgets.setWidgetIds(layoutInfo.widgetIds); + if (layoutInfo.widget) { + layout.layoutCtx.widgets.setWidget(layoutInfo.widget); + } else { + layout.layoutCtx.widgets.setWidgetIds(layoutInfo.widgetIds); + } layout.layoutCtx.widgetLayouts = layoutInfo.widgetLayouts; if (layout.show && layout.layoutCtx.ctrl) { layout.layoutCtx.ctrl.reload(); diff --git a/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.html b/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.html index 445fb2792f..614fb2ab21 100644 --- a/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.html +++ b/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.html @@ -298,19 +298,35 @@ } } @if (isEdit) { - - + @if (isHtml) { + + + } @else { + + + } }

{{ translatedDashboardTitle }}

- + dashboard.title
- @if (tbEditWidget.widgetConfig?.hasBasicMode) { + @if (tbEditWidget.widgetConfig?.hasBasicMode && !isHtml) { {{ 'widget.basic-mode' | translate }} {{ 'widget.advanced-mode' | translate }} diff --git a/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.ts b/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.ts index 2b27e54fbd..411e612f2f 100644 --- a/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.ts +++ b/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.ts @@ -67,6 +67,7 @@ import { EntityService } from '@core/http/entity.service'; import { AliasController } from '@core/api/alias-controller'; import { BehaviorSubject, Observable, of, Subject, Subscription, throwError } from 'rxjs'; import { DashboardUtilsService } from '@core/services/dashboard-utils.service'; +import { HtmlContainerWidgetSettings } from '@shared/models/html-container.models'; import { DashboardService } from '@core/http/dashboard.service'; import { DashboardContextMenuItem, @@ -196,6 +197,10 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC return ((this.hideToolbarValue || this.hideToolbarSetting()) && !this.isEdit) || (this.isEditingWidget || this.isAddingWidget); } + get isHtml(): boolean { + return this.layouts.main?.layoutCtx?.gridSettings?.layoutType === LayoutType.html; + } + @Input() hideMainToolbar = true; @@ -1086,7 +1091,8 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC } let gridSettings: GridSettings = null; const layoutKeys = this.dashboardUtils.isSingleLayoutDashboard(this.dashboard); - if (layoutKeys) { + // An HTML page has no widget grid, so the dialog shows only the dashboard settings. + if (layoutKeys && !this.isHtml) { const layouts = this.dashboardUtils.getDashboardLayoutConfig( this.dashboard.configuration.states[layoutKeys.state].layouts[layoutKeys.layout], this.layouts[layoutKeys.layout].layoutCtx.breakpoint); @@ -1114,6 +1120,7 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC this.dashboardUtils.updateLayoutSettings(layoutConfig, newGridSettings); this.updateDashboardLayouts(layouts); } + this.cd.markForCheck(); } }); } @@ -1584,13 +1591,22 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC const widget = this.dashboardUtils.prepareWidgetForSaving(deepClone(this.editingWidget)); const widgetLayout = deepClone(this.editingWidgetLayout); const id = this.editingWidgetOriginal.id; - this.dashboardConfiguration.widgets[id] = widget; this.editingWidgetOriginal = widget; this.editingWidgetLayoutOriginal = widgetLayout; - this.editingLayoutCtx.widgetLayouts[widget.id] = widgetLayout; - setTimeout(() => { - this.editingLayoutCtx.ctrl.highlightWidget(widget.id, 0); - }, 0); + if (this.isHtml) { + const state = this.dashboardConfiguration.states[this.dashboardCtx.state]; + state.layouts.main.gridSettings.htmlPageConfig = { + settings: widget.config.settings as HtmlContainerWidgetSettings, + actions: widget.config.actions + }; + this.updateLayouts(); + } else { + this.dashboardConfiguration.widgets[id] = widget; + this.editingLayoutCtx.widgetLayouts[widget.id] = widgetLayout; + setTimeout(() => { + this.editingLayoutCtx.ctrl.highlightWidget(widget.id, 0); + }, 0); + } } onEditWidgetClosed() { @@ -1618,31 +1634,22 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC if (this.editingWidgetOriginal === widget) { this.onEditWidgetClosed(); } else { - const transition = !this.forceDashboardMobileMode; - this.editingWidgetOriginal = widget; - this.editingWidgetLayoutOriginal = layoutCtx.widgetLayouts[widget.id]; - this.editingWidget = deepClone(this.editingWidgetOriginal); - this.editingWidgetLayout = deepClone(this.editingWidgetLayoutOriginal); - this.editingLayoutCtx = layoutCtx; - this.editingWidgetSubtitle = this.widgetComponentService.getInstantWidgetInfo(this.editingWidget).widgetName; - this.forceDashboardMobileMode = true; - this.isEditingWidget = true; - this.updateLayoutSizes(); - if (layoutCtx) { - const delayOffset = transition ? 350 : 0; - const delay = transition ? 400 : 300; - setTimeout(() => { - layoutCtx.ctrl.highlightWidget(widget.id, delay); - }, delayOffset); - } + this.prepareWidgetEdit(widget, layoutCtx); } } + editHtmlPage($event: Event) { + $event.stopPropagation(); + const layoutCtx = this.layouts.main?.layoutCtx; + const widget = layoutCtx.widgets.widgetByIndex(0); + this.prepareWidgetEdit(widget, layoutCtx, ''); + } + showLayoutConfigInEdit(layoutCtx: DashboardPageLayoutContext): boolean { - return layoutCtx?.gridSettings?.layoutType === LayoutType.divider || + return layoutCtx?.gridSettings?.layoutType !== LayoutType.html && (layoutCtx?.gridSettings?.layoutType === LayoutType.divider || layoutCtx?.gridSettings?.layoutType === LayoutType.default && (layoutCtx?.breakpoint === 'default' || - layoutCtx?.breakpoint !== 'default' && layoutCtx?.gridSettings?.viewFormat === ViewFormatType.list); + layoutCtx?.breakpoint !== 'default' && layoutCtx?.gridSettings?.viewFormat === ViewFormatType.list)); } replaceReferenceWithWidgetCopy($event: Event, layoutCtx: DashboardPageLayoutContext, widget: Widget) { @@ -1733,7 +1740,7 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC prepareDashboardContextMenu(layoutCtx: DashboardPageLayoutContext): Array { const dashboardContextActions: Array = []; - if (this.isEdit && !this.isEditingWidget && !this.widgetEditMode) { + if (this.isEdit && !this.isEditingWidget && !this.widgetEditMode && !this.isHtml) { dashboardContextActions.push( { action: this.openDashboardSettings.bind(this), @@ -1788,7 +1795,7 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC prepareWidgetContextMenu(layoutCtx: DashboardPageLayoutContext, widget: Widget, isReference: boolean): Array { const widgetContextActions: Array = []; - if (this.isEdit && !this.isEditingWidget) { + if (this.isEdit && !this.isEditingWidget && !this.isHtml) { widgetContextActions.push( { action: (event, currentWidget) => { @@ -1952,4 +1959,28 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC private getDashboardLogoLink(): UrlTree { return this.forceFullscreen ? null : this.router.createUrlTree([], {relativeTo: this.route}); } + + private prepareWidgetEdit(widget: Widget, layoutCtx: DashboardPageLayoutContext, subtitle?: string) { + const transition = !this.forceDashboardMobileMode; + this.editingWidgetOriginal = widget; + this.editingWidgetLayoutOriginal = layoutCtx.widgetLayouts[widget.id]; + this.editingWidget = deepClone(this.editingWidgetOriginal); + this.editingWidgetLayout = deepClone(this.editingWidgetLayoutOriginal); + this.editingLayoutCtx = layoutCtx; + if (isDefinedAndNotNull(subtitle)) { + this.editingWidgetSubtitle = subtitle; + } else { + this.editingWidgetSubtitle = this.widgetComponentService.getInstantWidgetInfo(this.editingWidget).widgetName; + } + this.forceDashboardMobileMode = true; + this.isEditingWidget = true; + this.updateLayoutSizes(); + if (layoutCtx) { + const delayOffset = transition ? 350 : 0; + const delay = transition ? 400 : 300; + setTimeout(() => { + layoutCtx.ctrl.highlightWidget(widget.id, delay); + }, delayOffset); + } + } } diff --git a/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.models.ts b/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.models.ts index 5cbb4b709b..39207b18b5 100644 --- a/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.models.ts +++ b/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.models.ts @@ -93,6 +93,8 @@ export class LayoutWidgetsArray implements Iterable { private widgetIds: string[] = []; + private widget: Widget; + private loaded = false; constructor(private dashboardCtx: DashboardContext) { @@ -112,6 +114,13 @@ export class LayoutWidgetsArray implements Iterable { setWidgetIds(widgetIds: string[]) { this.widgetIds = widgetIds; + this.widget = null; + this.loaded = true; + } + + setWidget(widget: Widget) { + this.widget = widget; + this.widgetIds = [this.widget.id]; this.loaded = true; } @@ -130,13 +139,19 @@ export class LayoutWidgetsArray implements Iterable { [Symbol.iterator](): Iterator { let pointer = 0; + const oneWidget = this.widget; const widgetIds = this.widgetIds; const dashboard = this.dashboardCtx.getDashboard(); return { next(value?: any): IteratorResult { if (pointer < widgetIds.length) { const widgetId = widgetIds[pointer++]; - const widget = dashboard.configuration.widgets[widgetId]; + let widget: Widget; + if (oneWidget && oneWidget.id === widgetId) { + widget = oneWidget; + } else { + widget = dashboard.configuration.widgets[widgetId]; + } return { done: false, value: widget @@ -161,7 +176,11 @@ export class LayoutWidgetsArray implements Iterable { } private widgetById(widgetId: string): Widget { - return this.dashboardCtx.getDashboard().configuration.widgets[widgetId]; + if (this.widget && this.widget.id === widgetId) { + return this.widget; + } else { + return this.dashboardCtx.getDashboard().configuration.widgets[widgetId]; + } } } diff --git a/ui-ngx/src/app/modules/home/components/dashboard-page/layout/dashboard-layout.component.html b/ui-ngx/src/app/modules/home/components/dashboard-page/layout/dashboard-layout.component.html index 5284c797f1..c3537a8ce9 100644 --- a/ui-ngx/src/app/modules/home/components/dashboard-page/layout/dashboard-layout.component.html +++ b/ui-ngx/src/app/modules/home/components/dashboard-page/layout/dashboard-layout.component.html @@ -60,7 +60,7 @@ [aliasController]="dashboardCtx.aliasController" [stateController]="dashboardCtx.stateController" [dashboardTimewindow]="dashboardCtx.dashboardTimewindow" - [isEdit]="isEdit" + [isEdit]="isEdit && !isHtml" [isEditingWidget]="isEditingWidget" [autofillHeight]="autoFillHeight" [mobileAutofillHeight]="mobileAutoFillHeight" @@ -68,9 +68,9 @@ [isMobile]="isMobileValue" [isMobileDisabled]="isMobileDisabled" [disableWidgetInteraction]="isEdit" - [isEditActionEnabled]="isEdit && !isEditingWidget" - [isExportActionEnabled]="isEdit && !widgetEditMode && !isEditingWidget" - [isRemoveActionEnabled]="isEdit && !widgetEditMode && !isEditingWidget" + [isEditActionEnabled]="isEdit && !isEditingWidget && !isHtml" + [isExportActionEnabled]="isEdit && !widgetEditMode && !isEditingWidget && !isHtml" + [isRemoveActionEnabled]="isEdit && !widgetEditMode && !isEditingWidget && !isHtml" [callbacks]="this" [ignoreLoading]="layoutCtx.ignoreLoading" [parentDashboard]="parentDashboard" diff --git a/ui-ngx/src/app/modules/home/components/dashboard-page/layout/dashboard-layout.component.ts b/ui-ngx/src/app/modules/home/components/dashboard-page/layout/dashboard-layout.component.ts index 7fcb115bdf..48a7069f40 100644 --- a/ui-ngx/src/app/modules/home/components/dashboard-page/layout/dashboard-layout.component.ts +++ b/ui-ngx/src/app/modules/home/components/dashboard-page/layout/dashboard-layout.component.ts @@ -61,20 +61,40 @@ export class DashboardLayoutComponent extends PageComponent implements ILayoutCo return this.layoutCtx.gridSettings.layoutType === LayoutType.scada; } + get isHtml(): boolean { + return this.layoutCtx.gridSettings.layoutType === LayoutType.html; + } + + // The HTML page layout has no widget grid: its only widget is virtual and is not stored in the layout, + // so widgets cannot be pasted into it, cut from it or referenced. + get widgetLayoutEditable(): boolean { + return this.isEdit && !this.isEditingWidget && !this.widgetEditMode && !this.isHtml; + } + + get disableMargins(): boolean { + return this.isScada || this.isHtml; + } + get outerMargin(): boolean { - return this.isScada ? false : this.layoutCtx.gridSettings.outerMargin; + return this.disableMargins ? false : this.layoutCtx.gridSettings.outerMargin; } get margin(): number { - return this.isScada ? 0 : this.layoutCtx.gridSettings.margin; + return this.disableMargins ? 0 : this.layoutCtx.gridSettings.margin; } get autoFillHeight(): boolean { - return (this.isEdit || this.isScada) ? false : this.layoutCtx.gridSettings.autoFillHeight; + if (this.isHtml) { + return true; + } else { + return (this.isEdit || this.isScada) ? false : this.layoutCtx.gridSettings.autoFillHeight; + } } get mobileAutoFillHeight(): boolean { - if (this.isEdit || this.isScada) { + if (this.isHtml) { + return true; + } else if (this.isEdit || this.isScada) { return false; } else if (this.layoutCtx.breakpoint !== 'default' && this.layoutCtx.gridSettings.viewFormat === ViewFormatType.list) { return this.layoutCtx.gridSettings.autoFillHeight; @@ -87,7 +107,7 @@ export class DashboardLayoutComponent extends PageComponent implements ILayoutCo } get isMobileDisabled(): boolean { - return this.widgetEditMode || this.isScada || (this.layoutCtx.breakpoint !== 'default' && !this.isMobileValue); + return this.widgetEditMode || this.isScada || this.isHtml || (this.layoutCtx.breakpoint !== 'default' && !this.isMobileValue); } get mobielRowHeigth(): number { @@ -176,7 +196,7 @@ export class DashboardLayoutComponent extends PageComponent implements ILayoutCo ); this.hotKeys.push( new Hotkey(['ctrl+r', 'meta+r'], (event: KeyboardEvent) => { - if (this.isEdit && !this.isEditingWidget && !this.widgetEditMode) { + if (this.widgetLayoutEditable) { const widget = this.dashboard.getSelectedWidget(); if (widget) { event.preventDefault(); @@ -190,7 +210,7 @@ export class DashboardLayoutComponent extends PageComponent implements ILayoutCo ); this.hotKeys.push( new Hotkey(['ctrl+v', 'meta+v'], (event: KeyboardEvent) => { - if (this.isEdit && !this.isEditingWidget && !this.widgetEditMode) { + if (this.widgetLayoutEditable) { if (this.itembuffer.hasWidget()) { event.preventDefault(); this.pasteWidget(event); @@ -203,7 +223,7 @@ export class DashboardLayoutComponent extends PageComponent implements ILayoutCo ); this.hotKeys.push( new Hotkey(['ctrl+i', 'meta+i'], (event: KeyboardEvent) => { - if (this.isEdit && !this.isEditingWidget && !this.widgetEditMode) { + if (this.widgetLayoutEditable) { if (this.itembuffer.canPasteWidgetReference(this.dashboardCtx.getDashboard(), this.dashboardCtx.state, this.layoutCtx.id, this.layoutCtx.breakpoint)) { event.preventDefault(); @@ -217,7 +237,7 @@ export class DashboardLayoutComponent extends PageComponent implements ILayoutCo ); this.hotKeys.push( new Hotkey(['ctrl+x', 'meta+x'], (event: KeyboardEvent) => { - if (this.isEdit && !this.isEditingWidget && !this.widgetEditMode) { + if (this.widgetLayoutEditable) { const widget = this.dashboard.getSelectedWidget(); if (widget) { event.preventDefault(); diff --git a/ui-ngx/src/app/modules/home/components/dashboard-page/layout/manage-dashboard-layouts-dialog.component.html b/ui-ngx/src/app/modules/home/components/dashboard-page/layout/manage-dashboard-layouts-dialog.component.html index c89865433e..79deeb7399 100644 --- a/ui-ngx/src/app/modules/home/components/dashboard-page/layout/manage-dashboard-layouts-dialog.component.html +++ b/ui-ngx/src/app/modules/home/components/dashboard-page/layout/manage-dashboard-layouts-dialog.component.html @@ -29,7 +29,7 @@
- @if (!isDividerLayout) { + @if (isBreakpointsLayout) {
@@ -85,11 +85,10 @@ add
- } @else { + } @else if (isDividerLayout) {
+ formControlName="type"> {{ 'layout.percentage-width' | translate }} @@ -125,7 +124,7 @@ - {{ (isDividerLayout ? 'layout.left' : 'layout.main') | translate }} + {{ 'layout.left' | translate }} @if (showPreviewInputs('main')) { @@ -140,7 +139,55 @@ required> } @if (layoutsFormGroup.get('type').value === layoutWidthType.FIXED && - layoutsFormGroup.get('fixedLayout').value === 'main') { + layoutsFormGroup.get('fixedLayout').value === 'main') { + + } +
+ } +
+
+ + + @if (showPreviewInputs('right')) { +
+ @if (layoutsFormGroup.get('type').value !== layoutWidthType.FIXED) { + + } + @if (layoutsFormGroup.get('type').value === layoutWidthType.FIXED) { }
- @if (isDividerLayout) { -
- - - @if (showPreviewInputs('right')) { -
- @if (layoutsFormGroup.get('type').value !== layoutWidthType.FIXED) { - - } - @if (layoutsFormGroup.get('type').value === layoutWidthType.FIXED) { - - } -
- } -
- }
- @if (isDividerLayout) { -
- @if (layoutsFormGroup.get('type').value === layoutWidthType.PERCENTAGE) { - - - } - @if (layoutsFormGroup.get('type').value !== layoutWidthType.PERCENTAGE) { - - - } -
- - -
+
+ @if (layoutsFormGroup.get('type').value === layoutWidthType.PERCENTAGE) { + + + } + @if (layoutsFormGroup.get('type').value !== layoutWidthType.PERCENTAGE) { + + + } +
+ +
- } +
+
+ } @else if (isHtmlLayout) { +
+
{{ 'dashboard.html-page' | translate }}
} diff --git a/ui-ngx/src/app/modules/home/components/dashboard-page/layout/manage-dashboard-layouts-dialog.component.ts b/ui-ngx/src/app/modules/home/components/dashboard-page/layout/manage-dashboard-layouts-dialog.component.ts index fe67491ca9..ea5ed441c6 100644 --- a/ui-ngx/src/app/modules/home/components/dashboard-page/layout/manage-dashboard-layouts-dialog.component.ts +++ b/ui-ngx/src/app/modules/home/components/dashboard-page/layout/manage-dashboard-layouts-dialog.component.ts @@ -1,5 +1,6 @@ // SPDX-FileCopyrightText: Copyright The ThingsBoard Authors -// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: Modifications Copyright ThingsBoard, Inc. +// SPDX-License-Identifier: Apache-2.0 AND BUSL-1.1 import { Component, Inject, OnDestroy, SkipSelf, ViewChild } from '@angular/core'; import { ErrorStateMatcher } from '@angular/material/core'; import { MAT_DIALOG_DATA, MatDialog, MatDialogRef } from '@angular/material/dialog'; @@ -74,6 +75,8 @@ export class ManageDashboardLayoutsDialogComponent extends DialogComponent { + if (res) { + this.applyLayouts(); + } + }); + } else { + this.applyLayouts(); + } + } + + private applyLayouts(): void { const layoutType = this.layoutsFormGroup.value.layoutType; + if (this.initialLayoutType === LayoutType.html && !this.isHtmlLayout) { + // The HTML page kept no grid settings: start the widget grid from the defaults. + this.layouts.main.gridSettings = this.dashboardUtils.createDefaultGridSettings(); + } this.layouts.main.gridSettings.layoutType = layoutType; - if (!this.isDividerLayout) { - delete this.layouts.right; + delete this.layouts.main.gridSettings.layoutDimension; + if (this.isBreakpointsLayout) { if (this.layouts.main.breakpoints) { for (const breakpoint of Object.values(this.layouts.main.breakpoints)) { breakpoint.gridSettings.layoutType = layoutType; @@ -287,13 +313,10 @@ export class ManageDashboardLayoutsDialogComponent extends DialogComponent(); + const layouts = [this.layouts.main, ...Object.values(this.layouts.main?.breakpoints || {})]; + if (this.initialLayoutType === LayoutType.divider) { + layouts.push(this.layouts.right); + } + for (const layout of layouts) { + Object.keys(layout?.widgets || {}).forEach(id => widgetIds.add(id)); + } + return widgetIds.size; + } + + get isHtmlLayout(): boolean { + return this.layoutsFormGroup.get('layoutType').value === LayoutType.html; + } + + get isBreakpointsLayout(): boolean { + return [LayoutType.default, LayoutType.scada].includes(this.layoutsFormGroup.get('layoutType').value); + } + addBreakpoint() { this.dialog.open(AddNewBreakpointDialogComponent, { diff --git a/ui-ngx/src/app/modules/home/components/widget/config/basic/html/html-container-basic-config.component.ts b/ui-ngx/src/app/modules/home/components/widget/config/basic/html/html-container-basic-config.component.ts index 7d94cb146d..1d9b03cd36 100644 --- a/ui-ngx/src/app/modules/home/components/widget/config/basic/html/html-container-basic-config.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/config/basic/html/html-container-basic-config.component.ts @@ -1,5 +1,6 @@ // SPDX-FileCopyrightText: Copyright The ThingsBoard Authors -// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: Modifications Copyright ThingsBoard, Inc. +// SPDX-License-Identifier: Apache-2.0 AND BUSL-1.1 import { Component, HostBinding } from '@angular/core'; import { UntypedFormBuilder, UntypedFormGroup } from '@angular/forms'; import { Store } from '@ngrx/store'; @@ -7,10 +8,7 @@ import { AppState } from '@core/core.state'; import { BasicWidgetConfigComponent } from '@home/components/widget/config/widget-config.component.models'; import { WidgetConfigComponentData } from '@home/models/widget-component.models'; import { WidgetConfigComponent } from '@home/components/widget/widget-config.component'; -import { - htmlContainerDefaultSettings, - HtmlContainerWidgetSettings -} from '@home/components/widget/lib/html/html-container-widget.models'; +import { htmlContainerDefaultSettings, HtmlContainerWidgetSettings } from '@shared/models/html-container.models'; @Component({ selector: 'tb-html-container-basic-config', diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/html/html-container-widget.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/html/html-container-widget.component.ts index 5e3e5bd125..29e56a8c38 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/html/html-container-widget.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/html/html-container-widget.component.ts @@ -1,5 +1,6 @@ // SPDX-FileCopyrightText: Copyright The ThingsBoard Authors -// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: Modifications Copyright ThingsBoard, Inc. +// SPDX-License-Identifier: Apache-2.0 AND BUSL-1.1 import { ChangeDetectorRef, Component, ComponentRef, @@ -16,9 +17,6 @@ import { } from '@angular/core'; import { WidgetContext } from '@home/models/widget-component.models'; import { - htmlContainerDefaultSettings, - HtmlContainerWidgetSettings, - HtmlContainerWidgetType, WidgetContainerAngularFunction, WidgetContainerPlainFunction } from '@home/components/widget/lib/html/html-container-widget.models'; @@ -40,6 +38,11 @@ import { import { MODULES_MAP } from '@shared/models/constants'; import { IModulesMap } from '@modules/common/modules-map.models'; import { TbAnchorComponent } from '@shared/components/tb-anchor.component'; +import { + htmlContainerDefaultSettings, + HtmlContainerWidgetSettings, + HtmlContainerWidgetType +} from '@shared/models/html-container.models'; @Component({ selector: 'tb-html-container-widget', diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/html/html-container-widget.models.ts b/ui-ngx/src/app/modules/home/components/widget/lib/html/html-container-widget.models.ts index d8cb440887..fbcc4309ca 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/html/html-container-widget.models.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/html/html-container-widget.models.ts @@ -1,31 +1,13 @@ // SPDX-FileCopyrightText: Copyright The ThingsBoard Authors -// SPDX-License-Identifier: Apache-2.0 -import { TbFunction } from '@shared/models/js-function.models'; +// SPDX-FileCopyrightText: Modifications Copyright ThingsBoard, Inc. +// SPDX-License-Identifier: Apache-2.0 AND BUSL-1.1 import { WidgetContext } from '@home/models/widget-component.models'; import { TbEditorCompleter, TbEditorCompletions } from '@shared/models/ace/completion.models'; import { widgetContextCompletions } from '@shared/models/ace/widget-completion.models'; -import { WidgetResource } from '@shared/models/widget.models'; -export enum HtmlContainerWidgetType { - PLAIN = 'PLAIN', - ANGULAR = 'ANGULAR' -} - -export interface HtmlContainerWidgetSettings { - type: HtmlContainerWidgetType; - html: string; - css: string; - js: TbFunction; - resources: WidgetResource[]; -} - -export const htmlContainerDefaultSettings: HtmlContainerWidgetSettings = { - type: HtmlContainerWidgetType.PLAIN, - html: '', - css: '', - js: '', - resources: [], -}; +// Moved to @shared/models/html-container.models (the HTML page layout uses them too); re-exported for existing imports. +export { HtmlContainerWidgetType, htmlContainerDefaultSettings } from '@shared/models/html-container.models'; +export type { HtmlContainerWidgetSettings } from '@shared/models/html-container.models'; export type WidgetContainerPlainFunction = (ctx: WidgetContext, container: HTMLElement) => void; export type WidgetContainerAngularFunction = (ctx: WidgetContext) => void; diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/html/html-container-settings.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/html/html-container-settings.component.ts index 17012b3a8c..b0c2a94a69 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/html/html-container-settings.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/html/html-container-settings.component.ts @@ -1,5 +1,6 @@ // SPDX-FileCopyrightText: Copyright The ThingsBoard Authors -// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: Modifications Copyright ThingsBoard, Inc. +// SPDX-License-Identifier: Apache-2.0 AND BUSL-1.1 import { AfterViewInit, Component, @@ -27,12 +28,11 @@ import { import { AngularContainerFunctionEditorCompleter, HTMLContainerFunctionEditorCompleter, - HtmlContainerWidgetSettings, - HtmlContainerWidgetType } from '@home/components/widget/lib/html/html-container-widget.models'; import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; import { isJSResource } from '@shared/models/resource.models'; import { WidgetService } from '@core/http/widget.service'; +import { HtmlContainerWidgetSettings, HtmlContainerWidgetType } from '@shared/models/html-container.models'; @Component({ selector: 'tb-html-container-settings', diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/settings/html/html-container-widget-settings.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/settings/html/html-container-widget-settings.component.ts index 2f9987a6ce..a7bb0e0b99 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/settings/html/html-container-widget-settings.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/settings/html/html-container-widget-settings.component.ts @@ -1,11 +1,12 @@ // SPDX-FileCopyrightText: Copyright The ThingsBoard Authors -// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: Modifications Copyright ThingsBoard, Inc. +// SPDX-License-Identifier: Apache-2.0 AND BUSL-1.1 import { Component, HostBinding } from '@angular/core'; import { WidgetSettings, WidgetSettingsComponent } from '@shared/models/widget.models'; import { UntypedFormBuilder, UntypedFormGroup } from '@angular/forms'; import { Store } from '@ngrx/store'; import { AppState } from '@core/core.state'; -import { htmlContainerDefaultSettings } from '@home/components/widget/lib/html/html-container-widget.models'; +import { htmlContainerDefaultSettings } from '@shared/models/html-container.models'; @Component({ selector: 'tb-html-container-widget-settings', diff --git a/ui-ngx/src/app/modules/home/components/widget/widget-container.component.ts b/ui-ngx/src/app/modules/home/components/widget/widget-container.component.ts index 6aa76187de..557ce4b142 100644 --- a/ui-ngx/src/app/modules/home/components/widget/widget-container.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/widget-container.component.ts @@ -321,6 +321,9 @@ export class WidgetContainerComponent extends PageComponent implements OnInit, O const container = parent.getBoundingClientRect(); position.coord.left = Math.max(0,clientRect.right - position.size.width - container.left); position.coord.top = position.coord.top - container.top; + if (position.coord.top < 2) { + position.coord.top = 2; + } position.target = clientRect.right; return position; }, diff --git a/ui-ngx/src/app/shared/models/dashboard.models.ts b/ui-ngx/src/app/shared/models/dashboard.models.ts index a6466ab974..fdad34e2b4 100644 --- a/ui-ngx/src/app/shared/models/dashboard.models.ts +++ b/ui-ngx/src/app/shared/models/dashboard.models.ts @@ -5,13 +5,14 @@ import { BaseData, ExportableEntity, GroupEntityInfo } from '@shared/models/base import { DashboardId } from '@shared/models/id/dashboard-id'; import { TenantId } from '@shared/models/id/tenant-id'; import { ShortCustomerInfo } from '@shared/models/customer.model'; -import { Widget } from './widget.models'; +import { Widget, WidgetActionsMap, WidgetConfig, WidgetConfigMode } from './widget.models'; import { Timewindow } from '@shared/models/time/time.models'; import { EntityAliases } from './alias.models'; import { CustomerId } from '@shared/models/id/customer-id'; import { Filters } from '@shared/models/query/query.models'; import { MatDialogRef } from '@angular/material/dialog'; import { HasTenantId, HasVersion } from '@shared/models/entity.models'; +import { HtmlContainerWidgetSettings } from '@shared/models/html-container.models'; export interface WidgetLayout { sizeX?: number; @@ -34,6 +35,7 @@ export enum LayoutType { default = 'default', scada = 'scada', divider = 'divider', + html = 'html' } export const layoutTypes = Object.keys(LayoutType) as LayoutType[]; @@ -43,6 +45,7 @@ export const layoutTypeTranslationMap = new Map( [ LayoutType.default, 'dashboard.layout-type-default' ], [ LayoutType.scada, 'dashboard.layout-type-scada' ], [ LayoutType.divider, 'dashboard.layout-type-divider' ], + [ LayoutType.html, 'dashboard.layout-type-html' ] ] ); @@ -60,6 +63,27 @@ export const viewFormatTypeTranslationMap = new Map( ] ); +export const htmlPageDefaultConfig: WidgetConfig = { + showTitle: false, + backgroundColor: 'rgba(255, 255, 255, 0)', + color: 'rgba(0, 0, 0, 0.87)', + padding: '0', + dropShadow: false, + enableFullscreen: false, + widgetStyle: {}, + title: 'HTML page', + configMode: WidgetConfigMode.basic +}; + +export interface HtmlPageConfig { + settings: HtmlContainerWidgetSettings; + actions?: WidgetActionsMap; +} + +// Id of the virtual HTML Container widget that renders a state's HTML page. It is never stored in +// dashboard.configuration.widgets, so it cannot collide with a widget id there. +export const htmlPageWidgetId = (stateId: string): string => `html-page-${stateId}`; + export interface GridSettings { layoutType?: LayoutType; backgroundColor?: string; @@ -76,6 +100,8 @@ export interface GridSettings { mobileRowHeight?: number; mobileDisplayLayoutFirst?: boolean; layoutDimension?: LayoutDimension; + // For LayoutType.html + htmlPageConfig?: HtmlPageConfig; } export interface DashboardLayout { @@ -90,6 +116,7 @@ export interface BreakpointLayoutInfo { widgetIds?: string[]; widgetLayouts?: WidgetLayouts; gridSettings?: GridSettings; + widget?: Widget; } export declare type BreakpointSystemId = 'default' | 'xs' | 'sm' | 'md' | 'lg' | 'xl'; diff --git a/ui-ngx/src/app/shared/models/html-container.models.ts b/ui-ngx/src/app/shared/models/html-container.models.ts new file mode 100644 index 0000000000..49d3251c1a --- /dev/null +++ b/ui-ngx/src/app/shared/models/html-container.models.ts @@ -0,0 +1,25 @@ +// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. +// SPDX-License-Identifier: BUSL-1.1 +import { TbFunction } from '@shared/models/js-function.models'; +import { WidgetResource } from '@shared/models/widget.models'; + +export enum HtmlContainerWidgetType { + PLAIN = 'PLAIN', + ANGULAR = 'ANGULAR' +} + +export interface HtmlContainerWidgetSettings { + type: HtmlContainerWidgetType; + html: string; + css: string; + js: TbFunction; + resources: WidgetResource[]; +} + +export const htmlContainerDefaultSettings: HtmlContainerWidgetSettings = { + type: HtmlContainerWidgetType.PLAIN, + html: '', + css: '', + js: '', + resources: [], +}; 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 fda314e14d..c89b168042 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -2375,6 +2375,8 @@ "no-widgets": "No widgets configured", "add-widget": "Add new widget", "add-widget-button-text": "Add widget", + "edit-html-page": "Edit HTML page", + "html-page": "HTML page", "title": "Title", "image": "Dashboard image", "mobile-app-settings": "Mobile application settings", @@ -2448,6 +2450,7 @@ "layout-type-default": "Default", "layout-type-scada": "SCADA", "layout-type-divider": "Divider", + "layout-type-html": "HTML Page", "layout-settings-type": "Layout settings: {{ type }} breakpoint", "columns-count": "Columns count", "columns-count-required": "Columns count is required.", @@ -6573,6 +6576,8 @@ "no-data": "No entries" }, "layout": { + "switch-to-html-page-title": "Switch to HTML page?", + "switch-to-html-page-text": "The HTML page replaces the widget grid of this state. { count, plural, =1 {1 widget} other {# widgets} } placed in its layouts will be removed from this state.", "layout": "Layout", "layouts": "Layouts", "manage": "Manage layouts",