Skip to content

Commit

Permalink
feat: Add time selection menu for single widgets in dashboard (#3240)
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcelfrueh authored Sep 27, 2024
1 parent af40c47 commit 472569d
Show file tree
Hide file tree
Showing 12 changed files with 134 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.streampipes.model.dashboard;

import java.util.List;
import java.util.Map;

public class DashboardItem {

Expand All @@ -31,6 +32,7 @@ public class DashboardItem {
private Integer rows;
private Integer x;
private Integer y;
private Map<String, Object> timeSettings;

public DashboardItem() {

Expand Down Expand Up @@ -99,4 +101,12 @@ public Integer getY() {
public void setY(Integer y) {
this.y = y;
}

public Map<String, Object> getTimeSettings() {
return timeSettings;
}

public void setTimeSettings(Map<String, Object> timeSettings) {
this.timeSettings = timeSettings;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface DashboardConfig extends GridsterConfig {}
export interface ClientDashboardItem extends GridsterItem {
widgetId: string;
widgetType: string;
timeSettings?: TimeSettings;
id: string;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ export interface TimeSettings {
timeSelectionId?: TimeSelectionId;
}

export interface WidgetTimeSettings {
timeSettings: TimeSettings;
widgetIndex?: number;
}

export interface TimeString {
startDate: string;
startTime: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/* tslint:disable */
/* eslint-disable */
// @ts-nocheck
// Generated using typescript-generator version 3.2.1263 on 2024-09-10 17:11:03.
// Generated using typescript-generator version 3.2.1263 on 2024-09-18 15:50:05.

export class NamedStreamPipesEntity implements Storable {
'@class':
Expand Down Expand Up @@ -970,6 +970,7 @@ export class DashboardItem {
name: string;
rows: number;
settings: string[];
timeSettings: { [index: string]: any };
x: number;
y: number;

Expand All @@ -989,6 +990,9 @@ export class DashboardItem {
instance.settings = __getCopyArrayFn(__identity<string>())(
data.settings,
);
instance.timeSettings = __getCopyObjectFn(__identity<any>())(
data.timeSettings,
);
instance.x = data.x;
instance.y = data.y;
return instance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
</div>
</div>
<div fxLayout="row" fxLayoutAlign="end center" class="mt-10">
<ng-content> </ng-content>
<button
mat-raised-button
color="accent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
(timeSettingsEmitter)="timeSettingsEmitter.emit($event)"
class="w-100"
>
<ng-content> </ng-content>
</sp-custom-time-range-selection>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,34 @@
>
<mat-icon>get_app</mat-icon>
</button>
<button
mat-icon-button
[matMenuTriggerFor]="optMenu"
*ngIf="!globalTimeEnabled"
aria-label="Options"
data-cy="options-data-explorer"
#menuTrigger="matMenuTrigger"
>
<mat-icon
[color]="timeSettingsModified ? 'primary' : 'default'"
>alarm_clock</mat-icon
>
</button>
<mat-menu #optMenu="matMenu" class="large-menu">
<sp-time-selector-menu
[timeSettings]="clonedTimeSettings"
(timeSettingsEmitter)="modifyWidgetTimeSettings($event)"
class="w-100"
>
<button
mat-raised-button
class="mat-basic"
(click)="resetWidgetTimeSettings()"
>
Reset
</button>
</sp-time-selector-menu>
</mat-menu>
<button
mat-icon-button
(click)="removeWidget()"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ import {
ComponentRef,
EventEmitter,
Input,
OnChanges,
OnDestroy,
OnInit,
Output,
SimpleChanges,
ViewChild,
} from '@angular/core';
import { GridsterItemComponent } from 'angular-gridster2';
Expand All @@ -45,13 +47,18 @@ import { UserPrivilege } from '../../../_enums/user-privilege.enum';
import { CurrentUserService } from '@streampipes/shared-ui';
import { BaseWidgetData } from '../../models/dataview-dashboard.model';
import { DataExplorerDashboardService } from '../../services/data-explorer-dashboard.service';
import { TimeSelectionService } from '../../services/time-selection.service';
import { MatMenuTrigger } from '@angular/material/menu';

@Component({
selector: 'sp-data-explorer-dashboard-widget',
templateUrl: './data-explorer-dashboard-widget.component.html',
styleUrls: ['./data-explorer-dashboard-widget.component.scss'],
})
export class DataExplorerDashboardWidgetComponent implements OnInit, OnDestroy {
export class DataExplorerDashboardWidgetComponent
implements OnInit, OnDestroy, OnChanges
{
@ViewChild('menuTrigger') menu: MatMenuTrigger;
@Input()
dashboardItem: DashboardItem;

Expand Down Expand Up @@ -97,6 +104,9 @@ export class DataExplorerDashboardWidgetComponent implements OnInit, OnDestroy {
timerActive = false;
loadingTime = 0;

clonedTimeSettings: TimeSettings;
timeSettingsModified: boolean = false;

hasDataExplorerWritePrivileges = false;

authSubscription: Subscription;
Expand All @@ -116,8 +126,16 @@ export class DataExplorerDashboardWidgetComponent implements OnInit, OnDestroy {
private widgetTypeService: WidgetTypeService,
private authService: AuthService,
private currentUserService: CurrentUserService,
private timeSelectionService: TimeSelectionService,
) {}

ngOnChanges(changes: SimpleChanges): void {
if (changes.widgetIndex && this.componentRef?.instance) {
this.componentRef.instance.widgetIndex =
changes.widgetIndex.currentValue;
}
}

ngOnInit(): void {
this.authSubscription = this.currentUserService.user$.subscribe(
user => {
Expand All @@ -139,6 +157,14 @@ export class DataExplorerDashboardWidgetComponent implements OnInit, OnDestroy {
},
);
this.chooseWidget(this.configuredWidget.widgetType);
this.clonedTimeSettings = {
startTime: this.timeSettings.startTime,
endTime: this.timeSettings.endTime,
timeSelectionId: this.timeSettings.timeSelectionId,
};
if (this.dashboardItem.timeSettings !== undefined) {
this.timeSettingsModified = true;
}
}

ngOnDestroy() {
Expand Down Expand Up @@ -176,6 +202,7 @@ export class DataExplorerDashboardWidgetComponent implements OnInit, OnDestroy {
this.componentRef.instance.dataExplorerWidget = this.configuredWidget;
this.componentRef.instance.previewMode = this.previewMode;
this.componentRef.instance.gridMode = this.gridMode;
this.componentRef.instance.widgetIndex = this.widgetIndex;
const removeSub =
this.componentRef.instance.removeWidgetCallback.subscribe(ev =>
this.removeWidget(),
Expand All @@ -196,9 +223,13 @@ export class DataExplorerDashboardWidgetComponent implements OnInit, OnDestroy {
}

getTimeSettings(): TimeSettings {
return this.globalTimeEnabled
? this.timeSettings
: (this.configuredWidget.timeSettings as TimeSettings);
if (this.globalTimeEnabled) {
return this.timeSettings;
} else if (this.dashboardItem.timeSettings !== undefined) {
return this.dashboardItem.timeSettings as TimeSettings;
} else {
return this.configuredWidget.timeSettings as TimeSettings;
}
}

removeWidget() {
Expand Down Expand Up @@ -233,4 +264,26 @@ export class DataExplorerDashboardWidgetComponent implements OnInit, OnDestroy {
this.configuredWidget,
);
}

modifyWidgetTimeSettings(timeSettings: TimeSettings): void {
this.dashboardItem.timeSettings = timeSettings;
this.timeSelectionService.notify(timeSettings, this.widgetIndex);
this.menu.closeMenu();
this.timeSettingsModified = true;
}

resetWidgetTimeSettings(): void {
this.dashboardItem.timeSettings = undefined;
this.clonedTimeSettings = {
startTime: this.timeSettings.startTime,
endTime: this.timeSettings.endTime,
timeSelectionId: this.timeSettings.timeSelectionId,
};
this.timeSelectionService.notify(
this.getTimeSettings(),
this.widgetIndex,
);
this.menu.closeMenu();
this.timeSettingsModified = false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ export abstract class BaseDataExplorerWidgetDirective<
@Input() dataViewDashboardItem: DashboardItem;
@Input() dataExplorerWidget: T;

@Input()
widgetIndex: number;

@HostBinding('class') className = 'h-100';

public selectedProperties: string[];
Expand Down Expand Up @@ -193,16 +196,21 @@ export abstract class BaseDataExplorerWidgetDirective<
}
this.timeSelectionSub =
this.timeSelectionService.timeSelectionChangeSubject.subscribe(
ts => {
if (ts) {
this.timeSettings = ts;
} else {
this.timeSelectionService.updateTimeSettings(
this.timeSettings,
new Date(),
);
widgetTimeSettings => {
if (
widgetTimeSettings.widgetIndex === undefined ||
widgetTimeSettings.widgetIndex === this.widgetIndex
) {
if (widgetTimeSettings.timeSettings) {
this.timeSettings = widgetTimeSettings.timeSettings;
} else {
this.timeSelectionService.updateTimeSettings(
this.timeSettings,
new Date(),
);
}
this.updateData();
}
this.updateData();
},
);
this.updateData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@
[(ngModel)]="
dashboard.dashboardGeneralSettings.globalTimeEnabled
"
>Use global time instead of widget time settings
>Use global time settings instead of widget time
settings
</mat-checkbox>
</div>
<!--<mat-checkbox [(ngModel)]="dashboard.displayHeader">Show name and description in dashboard</mat-checkbox>-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export interface BaseWidgetData<T extends DataExplorerWidgetModel> {
dataExplorerWidget: T;
previewMode: boolean;
gridMode: boolean;
widgetIndex?: number;

cleanupSubscriptions(): void;
}
Expand Down
10 changes: 6 additions & 4 deletions ui/src/app/data-explorer/services/time-selection.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
QuickTimeSelection,
TimeSelectionId,
TimeSettings,
WidgetTimeSettings,
} from '@streampipes/platform-services';
import {
startOfDay,
Expand Down Expand Up @@ -178,10 +179,11 @@ export class TimeSelectionService {
}
}

public timeSelectionChangeSubject: Subject<TimeSettings | undefined> =
new Subject<TimeSettings | undefined>();
public timeSelectionChangeSubject: Subject<WidgetTimeSettings | undefined> =
new Subject<WidgetTimeSettings | undefined>();

public notify(timeSettings?: TimeSettings): void {
this.timeSelectionChangeSubject.next(timeSettings);
public notify(timeSettings?: TimeSettings, widgetIndex?: number): void {
const widgetTimeSettings = { timeSettings, widgetIndex };
this.timeSelectionChangeSubject.next(widgetTimeSettings);
}
}

0 comments on commit 472569d

Please sign in to comment.