You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by ri...@apache.org on 2026/04/25 19:16:23 UTC
(streampipes) 01/01: feat: Add layout elements to dashboard
This is an automated email from the ASF dual-hosted git repository.
dominikriemer pushed a commit to branch add-layout-elements
in repository https://gitbox.apache.org/repos/asf/streampipes.git
commit e250b69c3e1117cff75b3f6ad1e0d2e9d21c9409
Author: Dominik Riemer <do...@gmail.com>
AuthorDate: Sat Apr 25 21:15:51 2026 +0200
feat: Add layout elements to dashboard
---
.../management/DataExplorerResourceManager.java | 13 +-
.../src/lib/model/dashboard/dashboard.model.ts | 8 +-
.../chart-view/abstract-chart-view.directive.ts | 37 ++-
.../grid-view/dashboard-grid-view.component.html | 12 +
.../grid-view/dashboard-grid-view.component.ts | 11 +-
.../slide-view/dashboard-slide-view.component.html | 71 +++---
.../slide-view/dashboard-slide-view.component.ts | 51 ++++-
.../dashboard-layout-item.component.html | 124 ++++++++++
.../dashboard-layout-item.component.scss | 148 ++++++++++++
.../layout-item/dashboard-layout-item.component.ts | 113 ++++++++++
.../dashboard-shared/utils/dashboard-item.utils.ts | 251 +++++++++++++++++++++
.../chart-selection-panel.component.html | 26 ++-
.../chart-selection-panel.component.ts | 51 ++++-
.../layout-properties-panel.component.html | 109 +++++++++
.../layout-properties-panel.component.scss | 29 +++
.../layout-properties-panel.component.ts | 129 +++++++++++
.../layout-selection.component.html | 49 ++++
.../layout-selection.component.scss | 50 ++++
.../layout-selection.component.ts} | 34 +--
.../panel/dashboard-panel.component.html | 22 +-
.../components/panel/dashboard-panel.component.ts | 85 ++++++-
21 files changed, 1353 insertions(+), 70 deletions(-)
diff --git a/streampipes-resource-management/src/main/java/org/apache/streampipes/resource/management/DataExplorerResourceManager.java b/streampipes-resource-management/src/main/java/org/apache/streampipes/resource/management/DataExplorerResourceManager.java
index cb5aa69656..ea7bb58046 100644
--- a/streampipes-resource-management/src/main/java/org/apache/streampipes/resource/management/DataExplorerResourceManager.java
+++ b/streampipes-resource-management/src/main/java/org/apache/streampipes/resource/management/DataExplorerResourceManager.java
@@ -18,6 +18,7 @@
package org.apache.streampipes.resource.management;
import org.apache.streampipes.model.dashboard.CompositeDashboardModel;
+import org.apache.streampipes.model.dashboard.DashboardItem;
import org.apache.streampipes.model.dashboard.DashboardModel;
import org.apache.streampipes.model.datalake.DataExplorerWidgetModel;
import org.apache.streampipes.storage.api.explorer.IDataExplorerWidgetStorage;
@@ -26,6 +27,7 @@ import org.apache.streampipes.storage.management.StorageDispatcher;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
public class DataExplorerResourceManager extends CrudResourceManager<DashboardModel> {
@@ -41,7 +43,12 @@ public class DataExplorerResourceManager extends CrudResourceManager<DashboardMo
public CompositeDashboardModel getCompositeDashboard(String dashboardId) {
var dashboard = db.getElementById(dashboardId);
var widgets = dashboard.getWidgets().stream()
- .map(w -> widgetStorage.getElementById(w.getDataViewElementId())).toList();
+ .map(DashboardItem::getDataViewElementId)
+ .filter(Objects::nonNull)
+ .filter(dataViewElementId -> !dataViewElementId.isBlank())
+ .map(widgetStorage::getElementById)
+ .filter(Objects::nonNull)
+ .toList();
var dataLakeMeasures = getMeasureNames(widgets).stream().map(dataLakeMeasureStorage::getByMeasureName).toList();
return new CompositeDashboardModel(dashboard, widgets, dataLakeMeasures);
@@ -50,6 +57,10 @@ public class DataExplorerResourceManager extends CrudResourceManager<DashboardMo
private List<String> getMeasureNames(List<DataExplorerWidgetModel> widgets) {
return widgets.stream().map(DataExplorerWidgetModel::getDataConfig)
.map(dataConfig -> (List<?>) ((Map<?, ?>) dataConfig).get("sourceConfigs"))
+ .filter(List.class::isInstance)
+ .map(List.class::cast)
+ .filter(sourceConfigs -> !sourceConfigs.isEmpty())
+ .map(sourceConfigs -> sourceConfigs.get(0))
.filter(Map.class::isInstance)
.map(Map.class::cast)
.map(cfg -> cfg.get("measureName"))
diff --git a/ui/projects/streampipes/platform-services/src/lib/model/dashboard/dashboard.model.ts b/ui/projects/streampipes/platform-services/src/lib/model/dashboard/dashboard.model.ts
index ad7b00aae7..6de0a1a41b 100644
--- a/ui/projects/streampipes/platform-services/src/lib/model/dashboard/dashboard.model.ts
+++ b/ui/projects/streampipes/platform-services/src/lib/model/dashboard/dashboard.model.ts
@@ -24,8 +24,10 @@ import {
} from '../gen/streampipes-model';
export interface ClientDashboardItem {
- dataViewElementId: string;
- widgetType: string;
+ dataViewElementId?: string;
+ widgetType?: string;
+ component?: string;
+ settings?: string[];
timeSettings?: TimeSettings;
id: string;
name?: string;
@@ -35,6 +37,8 @@ export interface ClientDashboardItem {
y: number;
w?: number;
h?: number;
+ minH?: number;
+ maxH?: number;
}
export interface DashboardLiveSettings {
diff --git a/ui/src/app/dashboard-shared/components/chart-view/abstract-chart-view.directive.ts b/ui/src/app/dashboard-shared/components/chart-view/abstract-chart-view.directive.ts
index 25a9f59780..2f2267cfb8 100644
--- a/ui/src/app/dashboard-shared/components/chart-view/abstract-chart-view.directive.ts
+++ b/ui/src/app/dashboard-shared/components/chart-view/abstract-chart-view.directive.ts
@@ -27,6 +27,11 @@ import {
} from '@streampipes/platform-services';
import { ChartRegistry } from '../../../chart-shared/registry/chart-registry.service';
import { ObservableGenerator } from '../../../chart-shared/models/dataview-dashboard.model';
+import {
+ applyDashboardItemGridConstraints,
+ getDashboardItemLabel,
+ isChartDashboardItem,
+} from '../../utils/dashboard-item.utils';
@Directive()
export abstract class AbstractChartViewDirective {
@@ -63,9 +68,14 @@ export abstract class AbstractChartViewDirective {
@Input()
timeSettings: TimeSettings;
+ @Input()
+ selectedDashboardItemId?: string;
+
@Output() deleteCallback: EventEmitter<number> = new EventEmitter<number>();
@Output() startEditModeEmitter: EventEmitter<DataExplorerWidgetModel> =
new EventEmitter<DataExplorerWidgetModel>();
+ @Output() selectDashboardItemEmitter: EventEmitter<string | undefined> =
+ new EventEmitter<string | undefined>();
startEditMode(value: DataExplorerWidgetModel) {
this.startEditModeEmitter.emit(value);
@@ -73,8 +83,12 @@ export abstract class AbstractChartViewDirective {
loadWidgetConfigs() {
this.dashboard.widgets.forEach(widgetConfig => {
+ applyDashboardItemGridConstraints(widgetConfig);
widgetConfig.w ??= widgetConfig.cols;
widgetConfig.h ??= widgetConfig.rows;
+ if (!isChartDashboardItem(widgetConfig)) {
+ return;
+ }
const availableWidget = this.widgets.find(
w => w.elementId === widgetConfig.dataViewElementId,
);
@@ -88,8 +102,17 @@ export abstract class AbstractChartViewDirective {
if (!this.isGridView()) {
this.widgetsAvailable = false;
}
+ if (!isChartDashboardItem(dashboardItem)) {
+ if (!this.isGridView()) {
+ this.selectNewWidget(dashboardItem.id);
+ this.widgetsVisible = true;
+ }
+ this.widgetsAvailable = true;
+ return;
+ }
+
this.dataViewDataExplorerService
- .getChart(dashboardItem.dataViewElementId)
+ .getChart(dashboardItem.dataViewElementId!)
.subscribe(response => {
this.processWidget(response);
if (!this.isGridView()) {
@@ -113,6 +136,18 @@ export abstract class AbstractChartViewDirective {
}
}
+ isChartItem(item: ClientDashboardItem | undefined): boolean {
+ return isChartDashboardItem(item);
+ }
+
+ getDashboardItemLabel(item: ClientDashboardItem | undefined): string {
+ return getDashboardItemLabel(item);
+ }
+
+ selectDashboardItem(itemId: string | undefined): void {
+ this.selectDashboardItemEmitter.emit(itemId);
+ }
+
abstract onWidgetsAvailable(): void;
abstract isGridView(): boolean;
diff --git a/ui/src/app/dashboard-shared/components/chart-view/grid-view/dashboard-grid-view.component.html b/ui/src/app/dashboard-shared/components/chart-view/grid-view/dashboard-grid-view.component.html
index c1dbe2d9c0..57a43bc842 100644
--- a/ui/src/app/dashboard-shared/components/chart-view/grid-view/dashboard-grid-view.component.html
+++ b/ui/src/app/dashboard-shared/components/chart-view/grid-view/dashboard-grid-view.component.html
@@ -32,6 +32,7 @@
@for (item of dashboard.widgets; let i = $index; track item.id) {
<gridstack-item [options]="item">
@if (
+ isChartItem(item) &&
widgetsAvailable &&
configuredWidgets.has(item.dataViewElementId)
) {
@@ -58,6 +59,17 @@
dashboard.dashboardGeneralSettings?.chartOverrides || {}
"
></sp-chart-container>
+ } @else if (!isChartItem(item)) {
+ <sp-dashboard-layout-item
+ [dashboardItem]="item"
+ [editMode]="editMode"
+ [kioskMode]="kioskMode"
+ [widgetIndex]="i"
+ [selected]="selectedDashboardItemId === item.id"
+ (deleteCallback)="deleteCallback.emit($event)"
+ (selectItemEmitter)="selectDashboardItem($event)"
+ >
+ </sp-dashboard-layout-item>
}
</gridstack-item>
}
diff --git a/ui/src/app/dashboard-shared/components/chart-view/grid-view/dashboard-grid-view.component.ts b/ui/src/app/dashboard-shared/components/chart-view/grid-view/dashboard-grid-view.component.ts
index 7e735f7747..db2da920d3 100644
--- a/ui/src/app/dashboard-shared/components/chart-view/grid-view/dashboard-grid-view.component.ts
+++ b/ui/src/app/dashboard-shared/components/chart-view/grid-view/dashboard-grid-view.component.ts
@@ -33,6 +33,11 @@ import {
nodesCB,
} from 'gridstack/dist/angular';
import { ChartContainerComponent } from '../../../../chart-shared/components/chart-container/chart-container.component';
+import { DashboardLayoutItemComponent } from '../../layout-item/dashboard-layout-item.component';
+import {
+ applyDashboardItemGridConstraints,
+ hasFixedHeightDashboardItem,
+} from '../../../utils/dashboard-item.utils';
@Component({
selector: 'sp-dashboard-grid-view',
@@ -42,6 +47,7 @@ import { ChartContainerComponent } from '../../../../chart-shared/components/cha
GridstackComponent,
GridstackItemComponent,
ChartContainerComponent,
+ DashboardLayoutItemComponent,
],
})
export class DashboardGridViewComponent
@@ -100,10 +106,13 @@ export class DashboardGridViewComponent
w => w.id === (changed as any).id,
);
if (widget) {
+ applyDashboardItemGridConstraints(widget);
widget.x = changed.x;
widget.y = changed.y;
widget.w = changed.w;
- widget.h = changed.h;
+ if (!hasFixedHeightDashboardItem(widget)) {
+ widget.h = changed.h;
+ }
}
});
}
diff --git a/ui/src/app/dashboard-shared/components/chart-view/slide-view/dashboard-slide-view.component.html b/ui/src/app/dashboard-shared/components/chart-view/slide-view/dashboard-slide-view.component.html
index efdb497400..1caa582b5d 100644
--- a/ui/src/app/dashboard-shared/components/chart-view/slide-view/dashboard-slide-view.component.html
+++ b/ui/src/app/dashboard-shared/components/chart-view/slide-view/dashboard-slide-view.component.html
@@ -18,17 +18,17 @@
<div fxFlex="100" fxLayout="column" style="overflow-y: hidden">
<div class="h-100" fxLayout="row" fxFlex="100">
- @if (widgetsAvailable && currentWidget) {
+ @if (widgetsAvailable && dashboard.widgets.length > 0) {
<div fxFlex="200px" fxLayout="column" class="selection-box">
@for (item of dashboard.widgets; track item; let i = $index) {
<div
[ngClass]="
- item.dataViewElementId === currentWidget.elementId
+ i === selectedWidgetIndex
? 'viz-preview viz-preview-selected'
: 'viz-preview'
"
fxLayoutAlign="center center"
- (click)="selectWidget(i, item.dataViewElementId)"
+ (click)="selectWidget(i)"
>
<div
fxFlex="100"
@@ -37,9 +37,7 @@
>
@if (widgetsVisible) {
<span class="slide-view-title text-sm">{{
- configuredWidgets.get(
- item.dataViewElementId
- ).baseAppearanceConfig.widgetTitle
+ getSlideItemLabel(item)
}}</span>
}
</div>
@@ -49,31 +47,42 @@
}
<div fxFlex="100">
<div class="h-100 w-100 mw-100" id="slideViewOuter" fxFlex="100">
- @if (
- widgetsAvailable &&
- displayWidget &&
- currentWidget &&
- widgetsVisible
- ) {
- <sp-chart-container
- [timeSettings]="timeSettings"
- [globalTimeEnabled]="
- dashboard.dashboardGeneralSettings.globalTimeEnabled
- "
- (deleteCallback)="deleteCallback.emit($event)"
- (startEditModeEmitter)="startEditMode($event)"
- [dashboardItem]="currentDashboardItem"
- [configuredWidget]="currentWidget"
- [dataLakeMeasure]="currentMeasure"
- [observableGenerator]="observableGenerator"
- [editMode]="editMode"
- [gridMode]="false"
- [widgetIndex]="i"
- [dashboardChartOverrides]="
- dashboard.dashboardGeneralSettings
- ?.chartOverrides || {}
- "
- ></sp-chart-container>
+ @if (widgetsAvailable && displayWidget && widgetsVisible) {
+ @if (isChartItem(currentDashboardItem) && currentWidget) {
+ <sp-chart-container
+ [timeSettings]="timeSettings"
+ [globalTimeEnabled]="
+ dashboard.dashboardGeneralSettings
+ .globalTimeEnabled
+ "
+ (deleteCallback)="deleteCallback.emit($event)"
+ (startEditModeEmitter)="startEditMode($event)"
+ [dashboardItem]="currentDashboardItem"
+ [configuredWidget]="currentWidget"
+ [dataLakeMeasure]="currentMeasure"
+ [observableGenerator]="observableGenerator"
+ [editMode]="editMode"
+ [gridMode]="false"
+ [widgetIndex]="selectedWidgetIndex"
+ [dashboardChartOverrides]="
+ dashboard.dashboardGeneralSettings
+ ?.chartOverrides || {}
+ "
+ ></sp-chart-container>
+ } @else if (!isChartItem(currentDashboardItem)) {
+ <sp-dashboard-layout-item
+ [dashboardItem]="currentDashboardItem"
+ [editMode]="editMode"
+ [selected]="
+ selectedDashboardItemId ===
+ currentDashboardItem.id
+ "
+ [widgetIndex]="selectedWidgetIndex"
+ (deleteCallback)="deleteCallback.emit($event)"
+ (selectItemEmitter)="selectDashboardItem($event)"
+ >
+ </sp-dashboard-layout-item>
+ }
}
</div>
</div>
diff --git a/ui/src/app/dashboard-shared/components/chart-view/slide-view/dashboard-slide-view.component.ts b/ui/src/app/dashboard-shared/components/chart-view/slide-view/dashboard-slide-view.component.ts
index 7931745daa..7c8494ec63 100644
--- a/ui/src/app/dashboard-shared/components/chart-view/slide-view/dashboard-slide-view.component.ts
+++ b/ui/src/app/dashboard-shared/components/chart-view/slide-view/dashboard-slide-view.component.ts
@@ -31,6 +31,7 @@ import {
import { NgClass } from '@angular/common';
import { ClassDirective } from '@ngbracket/ngx-layout/extended';
import { ChartContainerComponent } from '../../../../chart-shared/components/chart-container/chart-container.component';
+import { DashboardLayoutItemComponent } from '../../layout-item/dashboard-layout-item.component';
@Component({
selector: 'sp-dashboard-slide-view',
@@ -43,6 +44,7 @@ import { ChartContainerComponent } from '../../../../chart-shared/components/cha
NgClass,
ClassDirective,
ChartContainerComponent,
+ DashboardLayoutItemComponent,
],
})
export class DashboardSlideViewComponent
@@ -50,9 +52,9 @@ export class DashboardSlideViewComponent
implements OnInit
{
selectedWidgetIndex = 0;
- currentWidget: DataExplorerWidgetModel;
- currentMeasure: DataLakeMeasure;
- currentDashboardItem: ClientDashboardItem;
+ currentWidget?: DataExplorerWidgetModel;
+ currentMeasure?: DataLakeMeasure;
+ currentDashboardItem?: ClientDashboardItem;
displayWidget = false;
@@ -62,19 +64,47 @@ export class DashboardSlideViewComponent
this.loadWidgetConfigs();
}
- selectWidget(index: number, dataViewElementId: string): void {
+ selectWidget(index: number): void {
this.displayWidget = false;
setTimeout(() => {
this.selectedWidgetIndex = index;
- this.currentWidget = this.configuredWidgets.get(dataViewElementId);
- this.currentMeasure = this.dataLakeMeasures.get(dataViewElementId);
this.currentDashboardItem = this.dashboard.widgets[index];
+ if (!this.isChartItem(this.currentDashboardItem)) {
+ this.selectDashboardItem(this.currentDashboardItem.id);
+ } else {
+ this.selectDashboardItem(undefined);
+ }
+ if (this.isChartItem(this.currentDashboardItem)) {
+ const dataViewElementId =
+ this.currentDashboardItem.dataViewElementId!;
+ this.currentWidget =
+ this.configuredWidgets.get(dataViewElementId)!;
+ this.currentMeasure =
+ this.dataLakeMeasures.get(dataViewElementId)!;
+ } else {
+ this.currentWidget = undefined;
+ this.currentMeasure = undefined;
+ }
this.displayWidget = true;
});
}
onWidgetsAvailable(): void {
- this.selectWidget(0, this.dashboard.widgets[0].dataViewElementId);
+ if (this.dashboard.widgets.length > 0) {
+ this.selectWidget(0);
+ }
+ }
+
+ getSlideItemLabel(item: ClientDashboardItem): string {
+ if (this.isChartItem(item)) {
+ return (
+ this.configuredWidgets.get(item.dataViewElementId!)
+ ?.baseAppearanceConfig.widgetTitle ||
+ this.getDashboardItemLabel(item)
+ );
+ }
+
+ return this.getDashboardItemLabel(item);
}
isGridView(): boolean {
@@ -82,6 +112,11 @@ export class DashboardSlideViewComponent
}
selectNewWidget(widgetId: string): void {
- this.selectWidget(this.dashboard.widgets.length - 1, widgetId);
+ const itemIndex = this.dashboard.widgets.findIndex(
+ item => item.id === widgetId,
+ );
+ if (itemIndex >= 0) {
+ this.selectWidget(itemIndex);
+ }
}
}
diff --git a/ui/src/app/dashboard-shared/components/layout-item/dashboard-layout-item.component.html b/ui/src/app/dashboard-shared/components/layout-item/dashboard-layout-item.component.html
new file mode 100644
index 0000000000..c2fb7a55c2
--- /dev/null
+++ b/ui/src/app/dashboard-shared/components/layout-item/dashboard-layout-item.component.html
@@ -0,0 +1,124 @@
+<!--
+~ Licensed to the Apache Software Foundation (ASF) under one or more
+~ contributor license agreements. See the NOTICE file distributed with
+~ this work for additional information regarding copyright ownership.
+~ The ASF licenses this file to You 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.
+~
+-->
+
+<div
+ class="layout-item"
+ [class.layout-item-edit-mode]="editMode"
+ [class.layout-item-selected]="selected"
+ [class.layout-item-rich-text]="itemType === 'rich-text'"
+ [class.layout-item-header]="itemType === 'header'"
+ [class.layout-item-divider]="itemType === 'divider'"
+ [class.layout-item-spacer]="itemType === 'spacer'"
+ [attr.data-cy]="'dashboard-layout-' + itemType"
+ (click)="selectItem()"
+>
+ @if (showActionOverlay) {
+ <div
+ class="layout-item-overlay"
+ fxLayout="row"
+ fxLayoutAlign="end center"
+ >
+ <button
+ mat-icon-button
+ type="button"
+ (click)="removeItem(); $event.stopPropagation()"
+ [matTooltip]="'Delete element' | translate"
+ >
+ <mat-icon>clear</mat-icon>
+ </button>
+ </div>
+ }
+
+ <div class="layout-item-body">
+ @switch (itemType) {
+ @case ('rich-text') {
+ <div fxLayout="column" class="rich-text-layout">
+ @if (richTextPreview) {
+ <div class="markdown-preview">
+ <markdown [data]="richTextPreview"></markdown>
+ </div>
+ } @else if (editMode) {
+ <div class="layout-placeholder text-sm">
+ {{
+ 'Select the element to edit its content.'
+ | translate
+ }}
+ </div>
+ }
+ </div>
+ }
+ @case ('header') {
+ <div
+ class="header-layout"
+ fxLayout="column"
+ [class.header-layout-sm]="size === 'sm'"
+ [class.header-layout-md]="size === 'md'"
+ [class.header-layout-lg]="size === 'lg'"
+ [class.header-layout-center]="alignment === 'center'"
+ [class.header-layout-right]="alignment === 'right'"
+ >
+ <div class="header-title">{{ headerText }}</div>
+ </div>
+ }
+ @case ('divider') {
+ <div
+ class="divider-layout"
+ fxLayout="column"
+ fxLayoutAlign="center center"
+ >
+ @if (label) {
+ <div
+ class="divider-with-label"
+ [class.divider-with-label-dashed]="
+ dividerStyle === 'dashed'
+ "
+ fxLayout="row"
+ fxLayoutAlign="center center"
+ >
+ <span class="divider-line"></span>
+ <span class="divider-label text-sm">{{
+ label
+ }}</span>
+ <span class="divider-line"></span>
+ </div>
+ } @else {
+ <div
+ class="divider-line"
+ [class.divider-line-dashed]="
+ dividerStyle === 'dashed'
+ "
+ ></div>
+ }
+ </div>
+ }
+ @case ('spacer') {
+ <div
+ class="spacer-layout"
+ fxLayout="column"
+ fxLayoutAlign="center center"
+ >
+ @if (editMode) {
+ <span class="text-sm">
+ {{ 'Spacer' | translate }}
+ </span>
+ }
+ </div>
+ }
+ }
+ </div>
+</div>
diff --git a/ui/src/app/dashboard-shared/components/layout-item/dashboard-layout-item.component.scss b/ui/src/app/dashboard-shared/components/layout-item/dashboard-layout-item.component.scss
new file mode 100644
index 0000000000..cd09e457be
--- /dev/null
+++ b/ui/src/app/dashboard-shared/components/layout-item/dashboard-layout-item.component.scss
@@ -0,0 +1,148 @@
+/*!
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ *
+ */
+
+.layout-item {
+ position: relative;
+ height: 100%;
+ background: transparent;
+ border: 1px solid transparent;
+ border-radius: var(--button-border-radius);
+ overflow: hidden;
+}
+
+.layout-item-edit-mode {
+ cursor: pointer;
+}
+
+.layout-item-selected {
+ border-color: var(--color-border-subtle);
+ background: var(--color-surface-selected-subtle);
+}
+
+.layout-item-rich-text {
+ background: var(--color-bg-0);
+ border-color: var(--color-border-subtle);
+}
+
+.layout-item-body {
+ height: 100%;
+ padding: var(--space-sm) var(--space-md);
+}
+
+.markdown-preview {
+ overflow: auto;
+ height: 100%;
+}
+
+.layout-item-overlay {
+ position: absolute;
+ top: var(--space-2xs);
+ right: var(--space-2xs);
+ z-index: 2;
+}
+
+.rich-text-layout,
+.header-layout,
+.divider-layout,
+.spacer-layout {
+ height: 100%;
+}
+
+.layout-placeholder {
+ color: var(--fg-muted);
+}
+
+.header-layout {
+ height: var(--size-panel-header-compact);
+ min-height: var(--size-panel-header-compact);
+ justify-content: center;
+ width: 100%;
+}
+
+.header-layout-center {
+ align-items: center;
+ text-align: center;
+}
+
+.header-layout-right {
+ align-items: flex-end;
+ text-align: right;
+}
+
+.header-title {
+ margin: 0;
+ font-weight: var(--font-weight-semibold);
+ line-height: var(--line-height-tight);
+ width: 100%;
+}
+
+.header-layout-sm .header-title {
+ font-size: var(--font-size-lg);
+}
+
+.header-layout-md .header-title {
+ font-size: var(--font-size-2xl);
+}
+
+.header-layout-lg .header-title {
+ font-size: var(--font-size-3xl);
+}
+
+.divider-line {
+ width: 100%;
+ border-top: 1px solid var(--color-border-subtle);
+}
+
+.divider-line-dashed {
+ border-top-style: dashed;
+}
+
+.divider-with-label {
+ width: 100%;
+ gap: var(--space-sm);
+}
+
+.divider-with-label-dashed .divider-line {
+ border-top-style: dashed;
+}
+
+.divider-label {
+ color: var(--fg-muted);
+ white-space: nowrap;
+}
+
+.layout-item-header .layout-item-body {
+ padding: 0;
+}
+
+.layout-item-divider .layout-item-body {
+ padding-top: 0;
+ padding-bottom: 0;
+}
+
+.spacer-layout {
+ border: 1px dashed var(--color-border-subtle);
+ border-radius: var(--button-border-radius);
+ color: var(--fg-muted);
+}
+
+.layout-item-spacer:not(.layout-item-edit-mode):not(.layout-item-selected)
+ .spacer-layout {
+ border-color: transparent;
+ color: transparent;
+}
diff --git a/ui/src/app/dashboard-shared/components/layout-item/dashboard-layout-item.component.ts b/ui/src/app/dashboard-shared/components/layout-item/dashboard-layout-item.component.ts
new file mode 100644
index 0000000000..8e58fdfece
--- /dev/null
+++ b/ui/src/app/dashboard-shared/components/layout-item/dashboard-layout-item.component.ts
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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, DoCheck, EventEmitter, Input, Output } from '@angular/core';
+import { ClientDashboardItem } from '@streampipes/platform-services';
+import { MatIcon } from '@angular/material/icon';
+import { MatIconButton } from '@angular/material/button';
+import { MatTooltip } from '@angular/material/tooltip';
+import {
+ FlexDirective,
+ LayoutAlignDirective,
+ LayoutDirective,
+} from '@ngbracket/ngx-layout/flex';
+import { MarkdownComponent } from 'ngx-markdown';
+import { TranslatePipe } from '@ngx-translate/core';
+import {
+ DashboardItemType,
+ getDashboardItemType,
+ getMergedDashboardLayoutSettings,
+} from '../../utils/dashboard-item.utils';
+
+@Component({
+ selector: 'sp-dashboard-layout-item',
+ templateUrl: './dashboard-layout-item.component.html',
+ styleUrls: ['./dashboard-layout-item.component.scss'],
+ imports: [
+ MatIcon,
+ MatIconButton,
+ MatTooltip,
+ LayoutDirective,
+ LayoutAlignDirective,
+ FlexDirective,
+ MarkdownComponent,
+ TranslatePipe,
+ ],
+})
+export class DashboardLayoutItemComponent implements DoCheck {
+ @Input()
+ dashboardItem: ClientDashboardItem;
+
+ @Input()
+ editMode = false;
+
+ @Input()
+ kioskMode = false;
+
+ @Input()
+ widgetIndex: number;
+
+ @Input()
+ selected = false;
+
+ @Output()
+ deleteCallback = new EventEmitter<number>();
+
+ @Output()
+ selectItemEmitter = new EventEmitter<string>();
+
+ itemType: Exclude<DashboardItemType, 'chart'> = 'rich-text';
+ content = '';
+ label = '';
+ size: 'sm' | 'md' | 'lg' = 'md';
+ alignment: 'left' | 'center' | 'right' = 'left';
+ dividerStyle: 'solid' | 'dashed' = 'solid';
+
+ ngDoCheck(): void {
+ this.itemType = getDashboardItemType(this.dashboardItem) as Exclude<
+ DashboardItemType,
+ 'chart'
+ >;
+ const settings = getMergedDashboardLayoutSettings(this.dashboardItem);
+ this.content = settings.content ?? '';
+ this.label = settings.label ?? '';
+ this.size = settings.size ?? 'md';
+ this.alignment = settings.alignment ?? 'left';
+ this.dividerStyle = settings.dividerStyle ?? 'solid';
+ }
+
+ get richTextPreview(): string {
+ return this.content?.trim();
+ }
+
+ get headerText(): string {
+ return this.content?.trim();
+ }
+
+ get showActionOverlay(): boolean {
+ return this.editMode && this.selected && !this.kioskMode;
+ }
+
+ selectItem(): void {
+ this.selectItemEmitter.emit(this.dashboardItem.id);
+ }
+
+ removeItem(): void {
+ this.deleteCallback.emit(this.widgetIndex);
+ }
+}
diff --git a/ui/src/app/dashboard-shared/utils/dashboard-item.utils.ts b/ui/src/app/dashboard-shared/utils/dashboard-item.utils.ts
new file mode 100644
index 0000000000..5630cf2b09
--- /dev/null
+++ b/ui/src/app/dashboard-shared/utils/dashboard-item.utils.ts
@@ -0,0 +1,251 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 { ClientDashboardItem } from '@streampipes/platform-services';
+
+export type DashboardItemType =
+ | 'chart'
+ | 'rich-text'
+ | 'header'
+ | 'divider'
+ | 'spacer';
+
+export interface DashboardLayoutSettings {
+ content?: string;
+ size?: 'sm' | 'md' | 'lg';
+ alignment?: 'left' | 'center' | 'right';
+ label?: string;
+ dividerStyle?: 'solid' | 'dashed';
+}
+
+export interface DashboardLayoutDefinition {
+ type: Exclude<DashboardItemType, 'chart'>;
+ icon: string;
+ title: string;
+ description: string;
+ defaultName: string;
+ defaultWidth: number;
+ defaultHeight: number;
+ defaultContent?: string;
+}
+
+const LAYOUT_COMPONENTS: DashboardItemType[] = [
+ 'rich-text',
+ 'header',
+ 'divider',
+ 'spacer',
+];
+
+export const DASHBOARD_LAYOUT_DEFINITIONS: DashboardLayoutDefinition[] = [
+ {
+ type: 'rich-text',
+ icon: 'notes',
+ title: 'Rich text',
+ description: 'Add markdown notes, explanations, or instructions.',
+ defaultName: 'Rich text',
+ defaultWidth: 4,
+ defaultHeight: 3,
+ defaultContent:
+ '## Notes\nUse this area to document the dashboard context.',
+ },
+ {
+ type: 'header',
+ icon: 'title',
+ title: 'Header',
+ description: 'Add a section headline to structure the dashboard.',
+ defaultName: 'Header',
+ defaultWidth: 12,
+ defaultHeight: 1,
+ defaultContent: 'Section heading',
+ },
+ {
+ type: 'divider',
+ icon: 'horizontal_rule',
+ title: 'Divider',
+ description: 'Separate dashboard sections with a visual line.',
+ defaultName: 'Divider',
+ defaultWidth: 12,
+ defaultHeight: 1,
+ },
+ {
+ type: 'spacer',
+ icon: 'space_bar',
+ title: 'Spacer',
+ description: 'Reserve empty space in the layout.',
+ defaultName: 'Spacer',
+ defaultWidth: 2,
+ defaultHeight: 1,
+ },
+];
+
+export function getDashboardItemType(
+ item: ClientDashboardItem | undefined,
+): DashboardItemType {
+ if (!item) {
+ return 'chart';
+ }
+
+ const component = item.component as DashboardItemType | undefined;
+ if (component && LAYOUT_COMPONENTS.includes(component)) {
+ return component;
+ }
+
+ return 'chart';
+}
+
+export function isChartDashboardItem(
+ item: ClientDashboardItem | undefined,
+): boolean {
+ return getDashboardItemType(item) === 'chart';
+}
+
+export function hasFixedHeightDashboardItem(
+ item: ClientDashboardItem | undefined,
+): boolean {
+ return getDashboardItemType(item) === 'header';
+}
+
+export function getLayoutDefinition(
+ type: Exclude<DashboardItemType, 'chart'>,
+): DashboardLayoutDefinition {
+ return (
+ DASHBOARD_LAYOUT_DEFINITIONS.find(
+ definition => definition.type === type,
+ ) || DASHBOARD_LAYOUT_DEFINITIONS[0]
+ );
+}
+
+export function getDashboardItemTypeLabel(type: DashboardItemType): string {
+ if (type === 'chart') {
+ return 'Chart';
+ }
+
+ return getLayoutDefinition(type).defaultName;
+}
+
+export function getDashboardItemTitle(
+ item: ClientDashboardItem | undefined,
+): string {
+ if (!item) {
+ return 'Chart';
+ }
+
+ const type = getDashboardItemType(item);
+ if (type === 'chart') {
+ return item.name || 'Chart';
+ }
+
+ const definition = getLayoutDefinition(type);
+ const settings = parseDashboardLayoutSettings(item);
+ const content = settings.content?.trim();
+
+ if (type === 'rich-text' || type === 'header') {
+ return content || item.name || definition.defaultName;
+ }
+
+ return item.name || definition.defaultName;
+}
+
+export function getDashboardItemLabel(item: ClientDashboardItem): string {
+ return getDashboardItemTitle(item);
+}
+
+export function parseDashboardLayoutSettings(
+ item: ClientDashboardItem | undefined,
+): DashboardLayoutSettings {
+ const rawSettings = item?.settings?.[0];
+ if (!rawSettings) {
+ return {};
+ }
+
+ try {
+ const parsed = JSON.parse(rawSettings) as DashboardLayoutSettings;
+ return parsed ?? {};
+ } catch {
+ return {};
+ }
+}
+
+export function getDefaultDashboardLayoutSettings(
+ type: Exclude<DashboardItemType, 'chart'>,
+): DashboardLayoutSettings {
+ switch (type) {
+ case 'header':
+ return {
+ content: getLayoutDefinition(type).defaultContent,
+ size: 'md',
+ alignment: 'left',
+ };
+ case 'divider':
+ return {
+ label: '',
+ dividerStyle: 'solid',
+ };
+ case 'spacer':
+ return {};
+ case 'rich-text':
+ default:
+ return {
+ content: getLayoutDefinition(type).defaultContent,
+ };
+ }
+}
+
+export function getMergedDashboardLayoutSettings(
+ item: ClientDashboardItem | undefined,
+): DashboardLayoutSettings {
+ const itemType = getDashboardItemType(item);
+ if (itemType === 'chart') {
+ return {};
+ }
+
+ return {
+ ...getDefaultDashboardLayoutSettings(itemType),
+ ...parseDashboardLayoutSettings(item),
+ };
+}
+
+export function writeDashboardLayoutSettings(
+ item: ClientDashboardItem,
+ settings: DashboardLayoutSettings,
+): void {
+ const itemType = getDashboardItemType(item);
+ if (itemType === 'chart') {
+ return;
+ }
+
+ item.settings = [
+ JSON.stringify({
+ ...getDefaultDashboardLayoutSettings(itemType),
+ ...settings,
+ }),
+ ];
+}
+
+export function applyDashboardItemGridConstraints(
+ item: ClientDashboardItem,
+): ClientDashboardItem {
+ if (getDashboardItemType(item) === 'header') {
+ item.rows = 1;
+ item.h = 1;
+ item.minH = 1;
+ item.maxH = 1;
+ }
+
+ return item;
+}
diff --git a/ui/src/app/dashboard/components/panel/chart-selection-panel/chart-selection-panel.component.html b/ui/src/app/dashboard/components/panel/chart-selection-panel/chart-selection-panel.component.html
index 37166e0a2e..c0541115fa 100644
--- a/ui/src/app/dashboard/components/panel/chart-selection-panel/chart-selection-panel.component.html
+++ b/ui/src/app/dashboard/components/panel/chart-selection-panel/chart-selection-panel.component.html
@@ -19,12 +19,13 @@
<div fxFlex="100" class="designer-panel-content" fxLayout="column">
<div fxFlex="100" fxLayout="column" class="no-overflow">
<mat-tab-group
+ [(selectedIndex)]="selectedTabIndex"
color="accent"
fxFlexFill
class="small-tab-headers mat-tab-fill-height"
>
<mat-tab
- data-cy="designer-panel-data-config"
+ data-cy="designer-panel-charts"
[label]="'Charts' | translate"
>
<div class="scroll-tab-content">
@@ -35,6 +36,29 @@
</sp-chart-selection>
</div>
</mat-tab>
+ <mat-tab
+ data-cy="designer-panel-layout"
+ [label]="'Layout elements' | translate"
+ >
+ <div class="scroll-tab-content">
+ <sp-dashboard-layout-selection
+ (addLayoutEmitter)="addLayoutEmitter.emit($event)"
+ >
+ </sp-dashboard-layout-selection>
+ </div>
+ </mat-tab>
+ <mat-tab
+ data-cy="designer-panel-properties"
+ [label]="'Properties' | translate"
+ [disabled]="!selectedLayoutItem"
+ >
+ <div class="scroll-tab-content">
+ <sp-dashboard-layout-properties-panel
+ [dashboardItem]="selectedLayoutItem"
+ >
+ </sp-dashboard-layout-properties-panel>
+ </div>
+ </mat-tab>
</mat-tab-group>
</div>
</div>
diff --git a/ui/src/app/dashboard/components/panel/chart-selection-panel/chart-selection-panel.component.ts b/ui/src/app/dashboard/components/panel/chart-selection-panel/chart-selection-panel.component.ts
index a6eef3e077..bb1313c625 100644
--- a/ui/src/app/dashboard/components/panel/chart-selection-panel/chart-selection-panel.component.ts
+++ b/ui/src/app/dashboard/components/panel/chart-selection-panel/chart-selection-panel.component.ts
@@ -16,7 +16,14 @@
*
*/
-import { Component, EventEmitter, Output } from '@angular/core';
+import {
+ Component,
+ EventEmitter,
+ Input,
+ OnChanges,
+ Output,
+ SimpleChanges,
+} from '@angular/core';
import { MatTab, MatTabGroup } from '@angular/material/tabs';
import {
FlexDirective,
@@ -25,6 +32,13 @@ import {
} from '@ngbracket/ngx-layout/flex';
import { ChartSelectionComponent } from './chart-selection/chart-selection.component';
import { TranslatePipe } from '@ngx-translate/core';
+import { LayoutSelectionComponent } from './layout-selection/layout-selection.component';
+import { LayoutPropertiesPanelComponent } from './layout-properties-panel/layout-properties-panel.component';
+import {
+ DashboardItemType,
+ isChartDashboardItem,
+} from '../../../../dashboard-shared/utils/dashboard-item.utils';
+import { ClientDashboardItem } from '@streampipes/platform-services';
@Component({
selector: 'sp-dashboard-chart-selection-panel',
@@ -40,10 +54,43 @@ import { TranslatePipe } from '@ngx-translate/core';
FlexFillDirective,
MatTab,
ChartSelectionComponent,
+ LayoutSelectionComponent,
+ LayoutPropertiesPanelComponent,
TranslatePipe,
],
})
-export class ChartSelectionPanelComponent {
+export class ChartSelectionPanelComponent implements OnChanges {
+ @Input()
+ selectedDashboardItem?: ClientDashboardItem;
+
@Output()
addChartEmitter: EventEmitter<string> = new EventEmitter<string>();
+
+ @Output()
+ addLayoutEmitter = new EventEmitter<Exclude<DashboardItemType, 'chart'>>();
+
+ selectedTabIndex = 0;
+
+ get selectedLayoutItem(): ClientDashboardItem | undefined {
+ if (
+ !this.selectedDashboardItem ||
+ isChartDashboardItem(this.selectedDashboardItem)
+ ) {
+ return undefined;
+ }
+
+ return this.selectedDashboardItem;
+ }
+
+ ngOnChanges(changes: SimpleChanges): void {
+ if (!changes['selectedDashboardItem']) {
+ return;
+ }
+
+ if (this.selectedLayoutItem) {
+ this.selectedTabIndex = 2;
+ } else if (this.selectedTabIndex === 2) {
+ this.selectedTabIndex = 0;
+ }
+ }
}
diff --git a/ui/src/app/dashboard/components/panel/chart-selection-panel/layout-properties-panel/layout-properties-panel.component.html b/ui/src/app/dashboard/components/panel/chart-selection-panel/layout-properties-panel/layout-properties-panel.component.html
new file mode 100644
index 0000000000..cbe14de3ff
--- /dev/null
+++ b/ui/src/app/dashboard/components/panel/chart-selection-panel/layout-properties-panel/layout-properties-panel.component.html
@@ -0,0 +1,109 @@
+<!--
+~ Licensed to the Apache Software Foundation (ASF) under one or more
+~ contributor license agreements. See the NOTICE file distributed with
+~ this work for additional information regarding copyright ownership.
+~ The ASF licenses this file to You 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.
+~
+-->
+
+<div class="properties-panel" fxLayout="column" fxLayoutGap="var(--space-md)">
+ @if (dashboardItem) {
+ @switch (itemType) {
+ @case ('rich-text') {
+ <mat-form-field class="w-100">
+ <textarea
+ matInput
+ rows="10"
+ [placeholder]="'Rich text' | translate"
+ [ngModel]="content"
+ (ngModelChange)="updateContent($event)"
+ ></textarea>
+ </mat-form-field>
+ }
+ @case ('header') {
+ <mat-form-field class="w-100">
+ <input
+ matInput
+ [placeholder]="'Header' | translate"
+ [ngModel]="content"
+ (ngModelChange)="updateContent($event)"
+ />
+ </mat-form-field>
+
+ <mat-form-field class="w-100">
+ <mat-select
+ [placeholder]="'Size' | translate"
+ [ngModel]="size"
+ (ngModelChange)="updateSize($event)"
+ >
+ @for (option of sizeOptions; track option) {
+ <mat-option [value]="option">
+ {{ option | translate }}
+ </mat-option>
+ }
+ </mat-select>
+ </mat-form-field>
+
+ <mat-form-field class="w-100">
+ <mat-select
+ [placeholder]="'Alignment' | translate"
+ [ngModel]="alignment"
+ (ngModelChange)="updateAlignment($event)"
+ >
+ @for (option of alignmentOptions; track option) {
+ <mat-option [value]="option">
+ {{ option | translate }}
+ </mat-option>
+ }
+ </mat-select>
+ </mat-form-field>
+ }
+ @case ('divider') {
+ <mat-form-field class="w-100">
+ <input
+ matInput
+ [placeholder]="'Label (optional)' | translate"
+ [ngModel]="label"
+ (ngModelChange)="updateLabel($event)"
+ />
+ </mat-form-field>
+
+ <mat-form-field class="w-100">
+ <mat-select
+ [placeholder]="'Style' | translate"
+ [ngModel]="dividerStyle"
+ (ngModelChange)="updateDividerStyle($event)"
+ >
+ @for (option of dividerStyleOptions; track option) {
+ <mat-option [value]="option">
+ {{ option | translate }}
+ </mat-option>
+ }
+ </mat-select>
+ </mat-form-field>
+ }
+ @case ('spacer') {
+ <div class="properties-hint text-sm">
+ {{
+ 'Resize the spacer directly on the dashboard canvas.'
+ | translate
+ }}
+ </div>
+ }
+ }
+ } @else {
+ <div class="properties-hint text-sm">
+ {{ 'Select a layout element to edit its properties.' | translate }}
+ </div>
+ }
+</div>
diff --git a/ui/src/app/dashboard/components/panel/chart-selection-panel/layout-properties-panel/layout-properties-panel.component.scss b/ui/src/app/dashboard/components/panel/chart-selection-panel/layout-properties-panel/layout-properties-panel.component.scss
new file mode 100644
index 0000000000..c1072ca68d
--- /dev/null
+++ b/ui/src/app/dashboard/components/panel/chart-selection-panel/layout-properties-panel/layout-properties-panel.component.scss
@@ -0,0 +1,29 @@
+/*!
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ *
+ */
+
+.properties-panel {
+ padding: var(--space-md);
+}
+
+.properties-hint {
+ color: var(--fg-muted);
+}
+
+.w-100 {
+ width: 100%;
+}
diff --git a/ui/src/app/dashboard/components/panel/chart-selection-panel/layout-properties-panel/layout-properties-panel.component.ts b/ui/src/app/dashboard/components/panel/chart-selection-panel/layout-properties-panel/layout-properties-panel.component.ts
new file mode 100644
index 0000000000..4fe62c345e
--- /dev/null
+++ b/ui/src/app/dashboard/components/panel/chart-selection-panel/layout-properties-panel/layout-properties-panel.component.ts
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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, Input, OnChanges } from '@angular/core';
+import { FormsModule } from '@angular/forms';
+import { ClientDashboardItem } from '@streampipes/platform-services';
+import { MatFormField } from '@angular/material/form-field';
+import { MatInput } from '@angular/material/input';
+import { MatOption, MatSelect } from '@angular/material/select';
+import { TranslatePipe } from '@ngx-translate/core';
+import {
+ FlexDirective,
+ LayoutDirective,
+ LayoutGapDirective,
+} from '@ngbracket/ngx-layout/flex';
+import {
+ DashboardItemType,
+ getDashboardItemType,
+ getMergedDashboardLayoutSettings,
+ writeDashboardLayoutSettings,
+} from '../../../../../dashboard-shared/utils/dashboard-item.utils';
+
+type LayoutAlignment = 'left' | 'center' | 'right';
+type LayoutSize = 'sm' | 'md' | 'lg';
+type DividerStyle = 'solid' | 'dashed';
+
+@Component({
+ selector: 'sp-dashboard-layout-properties-panel',
+ templateUrl: './layout-properties-panel.component.html',
+ styleUrls: ['./layout-properties-panel.component.scss'],
+ imports: [
+ FormsModule,
+ MatFormField,
+ MatInput,
+ MatSelect,
+ MatOption,
+ TranslatePipe,
+ FlexDirective,
+ LayoutDirective,
+ LayoutGapDirective,
+ ],
+})
+export class LayoutPropertiesPanelComponent implements OnChanges {
+ @Input()
+ dashboardItem?: ClientDashboardItem;
+
+ itemType: Exclude<DashboardItemType, 'chart'> = 'rich-text';
+ content = '';
+ label = '';
+ size: LayoutSize = 'md';
+ alignment: LayoutAlignment = 'left';
+ dividerStyle: DividerStyle = 'solid';
+
+ readonly alignmentOptions: LayoutAlignment[] = ['left', 'center', 'right'];
+ readonly sizeOptions: LayoutSize[] = ['sm', 'md', 'lg'];
+ readonly dividerStyleOptions: DividerStyle[] = ['solid', 'dashed'];
+
+ ngOnChanges(): void {
+ if (!this.dashboardItem) {
+ return;
+ }
+
+ this.itemType = getDashboardItemType(this.dashboardItem) as Exclude<
+ DashboardItemType,
+ 'chart'
+ >;
+
+ const settings = getMergedDashboardLayoutSettings(this.dashboardItem);
+ this.content = settings.content ?? '';
+ this.label = settings.label ?? '';
+ this.size = settings.size ?? 'md';
+ this.alignment = settings.alignment ?? 'left';
+ this.dividerStyle = settings.dividerStyle ?? 'solid';
+ }
+
+ updateContent(value: string): void {
+ this.content = value;
+ this.persistSettings();
+ }
+
+ updateLabel(value: string): void {
+ this.label = value;
+ this.persistSettings();
+ }
+
+ updateSize(value: LayoutSize): void {
+ this.size = value;
+ this.persistSettings();
+ }
+
+ updateAlignment(value: LayoutAlignment): void {
+ this.alignment = value;
+ this.persistSettings();
+ }
+
+ updateDividerStyle(value: DividerStyle): void {
+ this.dividerStyle = value;
+ this.persistSettings();
+ }
+
+ private persistSettings(): void {
+ if (!this.dashboardItem) {
+ return;
+ }
+
+ writeDashboardLayoutSettings(this.dashboardItem, {
+ content: this.content,
+ label: this.label,
+ size: this.size,
+ alignment: this.alignment,
+ dividerStyle: this.dividerStyle,
+ });
+ }
+}
diff --git a/ui/src/app/dashboard/components/panel/chart-selection-panel/layout-selection/layout-selection.component.html b/ui/src/app/dashboard/components/panel/chart-selection-panel/layout-selection/layout-selection.component.html
new file mode 100644
index 0000000000..ab5dcaf525
--- /dev/null
+++ b/ui/src/app/dashboard/components/panel/chart-selection-panel/layout-selection/layout-selection.component.html
@@ -0,0 +1,49 @@
+<!--
+~ Licensed to the Apache Software Foundation (ASF) under one or more
+~ contributor license agreements. See the NOTICE file distributed with
+~ this work for additional information regarding copyright ownership.
+~ The ASF licenses this file to You 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.
+~
+-->
+
+<div fxLayout="column" fxLayoutGap="0.75rem" class="layout-selection">
+ @for (definition of layoutDefinitions; track definition.type) {
+ <div
+ fxLayout="row"
+ class="layout-option-card"
+ [attr.data-cy]="'add-layout-' + definition.type"
+ role="button"
+ tabindex="0"
+ (click)="addLayoutEmitter.emit(definition.type)"
+ (keydown.enter)="addLayoutEmitter.emit(definition.type)"
+ (keydown.space)="addLayoutEmitter.emit(definition.type)"
+ >
+ <div fxFlex fxLayout="column">
+ <h5>{{ definition.title | translate }}</h5>
+ <div fxLayout="row" fxLayoutGap="15px" class="text-sm">
+ <span fxLayoutAlign="start center">
+ <mat-icon color="primary">{{
+ definition.icon
+ }}</mat-icon>
+ </span>
+ <span fxFlex class="layout-description">{{
+ definition.description | translate
+ }}</span>
+ </div>
+ </div>
+ <div fxLayoutAlign="end center" class="layout-option-add">
+ <i class="material-icons">add</i>
+ </div>
+ </div>
+ }
+</div>
diff --git a/ui/src/app/dashboard/components/panel/chart-selection-panel/layout-selection/layout-selection.component.scss b/ui/src/app/dashboard/components/panel/chart-selection-panel/layout-selection/layout-selection.component.scss
new file mode 100644
index 0000000000..5e644ce678
--- /dev/null
+++ b/ui/src/app/dashboard/components/panel/chart-selection-panel/layout-selection/layout-selection.component.scss
@@ -0,0 +1,50 @@
+/*!
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ *
+ */
+
+.layout-selection {
+ padding: 0.625rem;
+}
+
+.layout-option-card {
+ border: 1px solid var(--color-bg-2);
+ padding: 10px;
+}
+
+.layout-option-card:hover,
+.layout-option-card:focus {
+ border-color: var(--color-bg-3);
+ background: var(--color-bg-1);
+ cursor: pointer;
+ outline: none;
+}
+
+h5 {
+ margin: 0 0 10px 0;
+}
+
+.layout-description {
+ overflow-wrap: anywhere;
+}
+
+mat-icon {
+ --mat-icon-color: var(--mat-sys-secondary);
+}
+
+.layout-option-add {
+ padding-left: 10px;
+}
diff --git a/ui/src/app/dashboard/components/panel/chart-selection-panel/chart-selection-panel.component.ts b/ui/src/app/dashboard/components/panel/chart-selection-panel/layout-selection/layout-selection.component.ts
similarity index 62%
copy from ui/src/app/dashboard/components/panel/chart-selection-panel/chart-selection-panel.component.ts
copy to ui/src/app/dashboard/components/panel/chart-selection-panel/layout-selection/layout-selection.component.ts
index a6eef3e077..dca0e945ed 100644
--- a/ui/src/app/dashboard/components/panel/chart-selection-panel/chart-selection-panel.component.ts
+++ b/ui/src/app/dashboard/components/panel/chart-selection-panel/layout-selection/layout-selection.component.ts
@@ -17,33 +17,33 @@
*/
import { Component, EventEmitter, Output } from '@angular/core';
-import { MatTab, MatTabGroup } from '@angular/material/tabs';
+import { MatIcon } from '@angular/material/icon';
+import { TranslatePipe } from '@ngx-translate/core';
import {
FlexDirective,
- FlexFillDirective,
LayoutDirective,
+ LayoutGapDirective,
} from '@ngbracket/ngx-layout/flex';
-import { ChartSelectionComponent } from './chart-selection/chart-selection.component';
-import { TranslatePipe } from '@ngx-translate/core';
+import {
+ DASHBOARD_LAYOUT_DEFINITIONS,
+ DashboardItemType,
+} from '../../../../../dashboard-shared/utils/dashboard-item.utils';
@Component({
- selector: 'sp-dashboard-chart-selection-panel',
- templateUrl: './chart-selection-panel.component.html',
- styleUrls: [
- './chart-selection-panel.component.scss',
- '../../../../chart/components/chart-view/designer-panel/chart-designer-panel.component.scss',
- ],
+ selector: 'sp-dashboard-layout-selection',
+ templateUrl: './layout-selection.component.html',
+ styleUrls: ['./layout-selection.component.scss'],
imports: [
+ MatIcon,
+ TranslatePipe,
FlexDirective,
LayoutDirective,
- MatTabGroup,
- FlexFillDirective,
- MatTab,
- ChartSelectionComponent,
- TranslatePipe,
+ LayoutGapDirective,
],
})
-export class ChartSelectionPanelComponent {
+export class LayoutSelectionComponent {
+ readonly layoutDefinitions = DASHBOARD_LAYOUT_DEFINITIONS;
+
@Output()
- addChartEmitter: EventEmitter<string> = new EventEmitter<string>();
+ addLayoutEmitter = new EventEmitter<Exclude<DashboardItemType, 'chart'>>();
}
diff --git a/ui/src/app/dashboard/components/panel/dashboard-panel.component.html b/ui/src/app/dashboard/components/panel/dashboard-panel.component.html
index d524dee1cd..66111796fd 100644
--- a/ui/src/app/dashboard/components/panel/dashboard-panel.component.html
+++ b/ui/src/app/dashboard/components/panel/dashboard-panel.component.html
@@ -76,9 +76,15 @@
<div fxLayout="column" fxFlex="100">
@if (editMode) {
<sp-dashboard-chart-selection-panel
+ [selectedDashboardItem]="
+ selectedDashboardItem
+ "
(addChartEmitter)="
addChartToDashboard($event)
"
+ (addLayoutEmitter)="
+ addLayoutElementToDashboard($event)
+ "
fxFlex="100"
>
</sp-dashboard-chart-selection-panel>
@@ -144,8 +150,12 @@
[widgets]="widgets"
[observableGenerator]="observableGenerator"
[timeSettings]="timeSettings"
- (deleteCallback)="
- removeChartFromDashboard($event)
+ [selectedDashboardItemId]="
+ selectedDashboardItemId
+ "
+ (deleteCallback)="removeDashboardItem($event)"
+ (selectDashboardItemEmitter)="
+ selectDashboardItem($event)
"
(startEditModeEmitter)="startEditMode($event)"
class="h-100 dashboard-grid"
@@ -163,8 +173,12 @@
[widgets]="widgets"
[observableGenerator]="observableGenerator"
[timeSettings]="timeSettings"
- (deleteCallback)="
- removeChartFromDashboard($event)
+ [selectedDashboardItemId]="
+ selectedDashboardItemId
+ "
+ (deleteCallback)="removeDashboardItem($event)"
+ (selectDashboardItemEmitter)="
+ selectDashboardItem($event)
"
(startEditModeEmitter)="startEditMode($event)"
>
diff --git a/ui/src/app/dashboard/components/panel/dashboard-panel.component.ts b/ui/src/app/dashboard/components/panel/dashboard-panel.component.ts
index b508838153..12e1b02b7c 100644
--- a/ui/src/app/dashboard/components/panel/dashboard-panel.component.ts
+++ b/ui/src/app/dashboard/components/panel/dashboard-panel.component.ts
@@ -71,6 +71,13 @@ import {
LayoutAlignDirective,
LayoutDirective,
} from '@ngbracket/ngx-layout/flex';
+import {
+ applyDashboardItemGridConstraints,
+ DashboardItemType,
+ getLayoutDefinition,
+ isChartDashboardItem,
+ writeDashboardLayoutSettings,
+} from '../../../dashboard-shared/utils/dashboard-item.utils';
@Component({
selector: 'sp-dashboard-panel',
@@ -111,6 +118,7 @@ export class DashboardPanelComponent
editMode = false;
chartSelectionPanelExpanded = false;
+ selectedDashboardItemId?: string;
timeRangeVisible = true;
_dashboardGrid: DashboardGridViewComponent;
@@ -193,6 +201,7 @@ export class DashboardPanelComponent
const dashboardItem = {} as ClientDashboardItem;
dashboardItem.id =
this.dataExplorerDashboardService.makeUniqueWidgetId();
+ dashboardItem.component = 'chart';
dashboardItem.cols = 3;
dashboardItem.rows = 4;
dashboardItem.w = 3;
@@ -200,7 +209,42 @@ export class DashboardPanelComponent
dashboardItem.x = 0;
dashboardItem.y = this.getNextWidgetY();
dashboardItem.dataViewElementId = dataViewElementId;
+ applyDashboardItemGridConstraints(dashboardItem);
this.dashboard.widgets.push(dashboardItem);
+ this.clearSelectedDashboardItem();
+ setTimeout(() => {
+ if (this.viewMode === 'grid') {
+ this.dashboardGrid.loadWidgetConfig(dashboardItem);
+ } else {
+ this.dashboardSlide.loadWidgetConfig(dashboardItem);
+ }
+ });
+ }
+
+ addLayoutElementToDashboard(type: Exclude<DashboardItemType, 'chart'>) {
+ const definition = getLayoutDefinition(type);
+ const dashboardItem = {} as ClientDashboardItem;
+
+ dashboardItem.id =
+ this.dataExplorerDashboardService.makeUniqueWidgetId();
+ dashboardItem.component = type;
+ dashboardItem.name = definition.defaultName;
+ dashboardItem.cols = definition.defaultWidth;
+ dashboardItem.rows = definition.defaultHeight;
+ dashboardItem.w = definition.defaultWidth;
+ dashboardItem.h = definition.defaultHeight;
+ dashboardItem.x = 0;
+ dashboardItem.y = this.getNextWidgetY();
+
+ if (definition.defaultContent) {
+ writeDashboardLayoutSettings(dashboardItem, {
+ content: definition.defaultContent,
+ });
+ }
+
+ applyDashboardItemGridConstraints(dashboardItem);
+ this.dashboard.widgets.push(dashboardItem);
+ this.selectDashboardItem(dashboardItem.id);
setTimeout(() => {
if (this.viewMode === 'grid') {
this.dashboardGrid.loadWidgetConfig(dashboardItem);
@@ -256,9 +300,22 @@ export class DashboardPanelComponent
this.routingService.navigateToChart(true, widgetModel.elementId, true);
}
- removeChartFromDashboard(widgetIndex: number) {
+ removeDashboardItem(widgetIndex: number) {
+ const removedItem = this.dashboard.widgets[widgetIndex];
this.dashboard.widgets.splice(widgetIndex, 1);
- this.widgets.splice(widgetIndex, 1);
+ if (removedItem?.id === this.selectedDashboardItemId) {
+ this.clearSelectedDashboardItem();
+ }
+
+ if (isChartDashboardItem(removedItem)) {
+ const chartIndex = this.widgets.findIndex(
+ widget => widget.elementId === removedItem?.dataViewElementId,
+ );
+
+ if (chartIndex >= 0) {
+ this.widgets.splice(chartIndex, 1);
+ }
+ }
}
updateDateRange(timeSettings: TimeSettings) {
@@ -280,6 +337,30 @@ export class DashboardPanelComponent
this.chartSelectionPanelExpanded = true;
}
+ selectDashboardItem(itemId: string | undefined): void {
+ if (!itemId) {
+ this.clearSelectedDashboardItem();
+ return;
+ }
+
+ if (!this.editMode) {
+ return;
+ }
+
+ this.selectedDashboardItemId = itemId;
+ this.chartSelectionPanelExpanded = true;
+ }
+
+ clearSelectedDashboardItem(): void {
+ this.selectedDashboardItemId = undefined;
+ }
+
+ get selectedDashboardItem(): ClientDashboardItem | undefined {
+ return this.dashboard?.widgets?.find(
+ item => item.id === this.selectedDashboardItemId,
+ );
+ }
+
toggleChartSelectionPanel() {
this.chartSelectionPanelExpanded = !this.chartSelectionPanelExpanded;
}