Skip to content

Commit

Permalink
feat(#3068): Add refresh interval to data explorer dashboard (#3069)
Browse files Browse the repository at this point in the history
* feat(#3068): Add refresh interval to data explorer dashboard

* Remove empty stylesheet
  • Loading branch information
dominikriemer authored Jul 30, 2024
1 parent 2990d7a commit 6d30ec0
Show file tree
Hide file tree
Showing 14 changed files with 226 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ public class DashboardModel implements Storable {

private Map<String, Object> dashboardTimeSettings;
private Map<String, Object> dashboardGeneralSettings;
private Map<String, Object> dashboardLiveSettings;

private List<DashboardItem> widgets;

public DashboardModel() {
this.dashboardTimeSettings = new HashMap<>();
this.dashboardGeneralSettings = new HashMap<>();
this.dashboardLiveSettings = new HashMap<>();
}

public String getId() {
Expand Down Expand Up @@ -133,4 +135,8 @@ public void setElementId(String elementId) {
public String getCouchDbId() {
return this.elementId;
}

public Map<String, Object> getDashboardLiveSettings() {
return dashboardLiveSettings;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ export class DataViewDataExplorerService {
}

getDashboard(dashboardId: string): Observable<Dashboard> {
return this.http.get(`${this.dashboardUrl}/${dashboardId}`);
return this.http
.get(`${this.dashboardUrl}/${dashboardId}`)
.pipe(map(data => data as Dashboard));
}

updateDashboard(dashboard: Dashboard): Observable<Dashboard> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ export interface ClientDashboardItem extends GridsterItem {
id: string;
}

export interface DashboardLiveSettings {
refreshModeActive: boolean;
refreshIntervalInSeconds?: number;
label: string;
}

export interface Dashboard {
id?: string;
name?: string;
Expand All @@ -36,6 +42,7 @@ export interface Dashboard {
widgets?: ClientDashboardItem[];
dashboardTimeSettings?: TimeSettings;
dashboardGeneralSettings?: any;
dashboardLiveSettings: DashboardLiveSettings;
elementId?: string;
rev?: string;
}
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-07-13 11:00:10.
// Generated using typescript-generator version 3.2.1263 on 2024-07-26 10:14:34.

export class NamedStreamPipesEntity implements Storable {
'@class':
Expand Down Expand Up @@ -1000,6 +1000,7 @@ export class DashboardItem {
export class DashboardModel implements Storable {
couchDbId: string;
dashboardGeneralSettings: { [index: string]: any };
dashboardLiveSettings: { [index: string]: any };
dashboardTimeSettings: { [index: string]: any };
description: string;
displayHeader: boolean;
Expand All @@ -1021,6 +1022,9 @@ export class DashboardModel implements Storable {
instance.dashboardGeneralSettings = __getCopyObjectFn(
__identity<any>(),
)(data.dashboardGeneralSettings);
instance.dashboardLiveSettings = __getCopyObjectFn(__identity<any>())(
data.dashboardLiveSettings,
);
instance.dashboardTimeSettings = __getCopyObjectFn(__identity<any>())(
data.dashboardTimeSettings,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,21 @@
fxLayout="row"
>
<sp-time-range-selector
[showTimeSelector]="(editMode || timeRangeVisible) && globalTimeEnabled"
[showTimeSelector]="
(editMode || timeRangeVisible) &&
dashboard.dashboardGeneralSettings.globalTimeEnabled
"
(dateRangeEmitter)="updateDateRangeEmitter.emit($event)"
[timeSettings]="timeSettings"
>
</sp-time-range-selector>

<sp-data-explorer-refresh-interval-settings-component
[dashboard]="dashboard"
(intervalSettingsChangedEmitter)="intervalSettingsChangedEmitter.emit()"
>
</sp-data-explorer-refresh-interval-settings-component>

<button
mat-icon-button
[matMenuTriggerFor]="optMenu"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@
*/

import { Component, EventEmitter, Input, Output } from '@angular/core';
import { TimeSettings } from '@streampipes/platform-services';
import { Dashboard, TimeSettings } from '@streampipes/platform-services';

@Component({
selector: 'sp-data-explorer-dashboard-toolbar',
templateUrl: './dashboard-toolbar.component.html',
styleUrls: ['./dashboard-toolbar.component.scss'],
})
export class DataExplorerDashboardToolbarComponent {
@Input()
dashboard: Dashboard;

@Input()
editMode: boolean;

Expand All @@ -43,9 +46,6 @@ export class DataExplorerDashboardToolbarComponent {
@Input()
timeSettings: TimeSettings;

@Input()
globalTimeEnabled = true;

@Output()
viewModeChange: EventEmitter<string> = new EventEmitter<string>();

Expand All @@ -63,4 +63,8 @@ export class DataExplorerDashboardToolbarComponent {

@Output()
updateDateRangeEmitter: EventEmitter<TimeSettings> = new EventEmitter();

@Output()
intervalSettingsChangedEmitter: EventEmitter<void> =
new EventEmitter<void>();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!--
~ 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="row">
<button
mat-button
color="accent"
[matMenuTriggerFor]="menu"
aria-label="Refresh interval"
matTooltip="Refresh interval"
>
<mat-icon>autorenew</mat-icon>
{{ dashboard.dashboardLiveSettings.label }}
</button>
<mat-menu #menu="matMenu">
<button
mat-menu-item
(click)="modifyRefreshInterval(option)"
*ngFor="let option of availableOptions"
>
<span>{{ option.label }}</span>
</button>
</mat-menu>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* 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, EventEmitter, Input, OnInit, Output } from '@angular/core';
import {
Dashboard,
DashboardLiveSettings,
} from '@streampipes/platform-services';

@Component({
selector: 'sp-data-explorer-refresh-interval-settings-component',
templateUrl: './refresh-interval-settings.component.html',
})
export class DataExplorerRefreshIntervalSettingsComponent implements OnInit {
@Input()
dashboard: Dashboard;

@Output()
intervalSettingsChangedEmitter: EventEmitter<void> =
new EventEmitter<void>();

availableOptions: DashboardLiveSettings[] = [
{
label: 'Off',
refreshModeActive: false,
},
{
label: '1 sec',
refreshModeActive: true,
refreshIntervalInSeconds: 1,
},
{
label: '2 sec',
refreshModeActive: true,
refreshIntervalInSeconds: 2,
},
{
label: '5 sec',
refreshModeActive: true,
refreshIntervalInSeconds: 5,
},
{
label: '10 sec',
refreshModeActive: true,
refreshIntervalInSeconds: 10,
},
{
label: '30 sec',
refreshModeActive: true,
refreshIntervalInSeconds: 30,
},
{
label: '1 min',
refreshModeActive: true,
refreshIntervalInSeconds: 60,
},
{
label: '5 min',
refreshModeActive: true,
refreshIntervalInSeconds: 300,
},
{
label: '30 min',
refreshModeActive: true,
refreshIntervalInSeconds: 60 * 30,
},
];

ngOnInit() {
if (!this.dashboard.dashboardLiveSettings?.label) {
this.dashboard.dashboardLiveSettings = this.availableOptions[0];
}
}

modifyRefreshInterval(option: DashboardLiveSettings): void {
this.dashboard.dashboardLiveSettings = option;
this.intervalSettingsChangedEmitter.emit();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
>
<div nav fxFlex="100" class="ml-10">
<sp-data-explorer-dashboard-toolbar
[globalTimeEnabled]="
dashboard.dashboardGeneralSettings.globalTimeEnabled
"
[dashboard]="dashboard"
[editMode]="editMode"
[(viewMode)]="viewMode"
[hasDataExplorerDeletePrivileges]="hasDataExplorerDeletePrivileges"
Expand All @@ -37,6 +35,7 @@
(deleteDashboardEmitter)="deleteDashboard()"
(triggerEditModeEmitter)="triggerEditMode()"
(updateDateRangeEmitter)="updateDateRange($event)"
(intervalSettingsChangedEmitter)="modifyRefreshInterval()"
>
</sp-data-explorer-dashboard-toolbar>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { Observable, of, Subscription } from 'rxjs';
import { Observable, of, Subscription, timer } from 'rxjs';
import { DataExplorerDashboardGridComponent } from '../widget-view/grid-view/data-explorer-dashboard-grid.component';
import {
ClientDashboardItem,
Expand All @@ -43,7 +43,7 @@ import {
SpBreadcrumbService,
} from '@streampipes/shared-ui';
import { MatDialog } from '@angular/material/dialog';
import { map } from 'rxjs/operators';
import { map, switchMap } from 'rxjs/operators';
import { SpDataExplorerRoutes } from '../../data-explorer.routes';
import { DataExplorerRoutingService } from '../../services/data-explorer-routing.service';

Expand Down Expand Up @@ -78,6 +78,7 @@ export class DataExplorerDashboardPanelComponent implements OnInit, OnDestroy {

dataLakeMeasure: DataLakeMeasure;
authSubscription: Subscription;
refreshSubscription: Subscription;

constructor(
private dataViewDataExplorerService: DataViewDataExplorerService,
Expand Down Expand Up @@ -116,6 +117,7 @@ export class DataExplorerDashboardPanelComponent implements OnInit, OnDestroy {

ngOnDestroy() {
this.authSubscription?.unsubscribe();
this.refreshSubscription?.unsubscribe();
}

addDataViewToDashboard(dataViewElementId: string) {
Expand Down Expand Up @@ -258,4 +260,30 @@ export class DataExplorerDashboardPanelComponent implements OnInit, OnDestroy {
return of(true);
}
}

modifyRefreshInterval(): void {
this.refreshSubscription?.unsubscribe();
if (this.dashboard.dashboardLiveSettings.refreshModeActive) {
this.createQuerySubscription();
}
}

createQuerySubscription() {
this.refreshSubscription = timer(
0,
this.dashboard.dashboardLiveSettings.refreshIntervalInSeconds *
1000,
)
.pipe(
switchMap(() => {
this.timeSelectionService.updateTimeSettings(
this.timeSettings,
new Date(),
);
this.updateDateRange(this.timeSettings);
return of(null);
}),
)
.subscribe();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,16 @@ export class DataExplorerOverviewComponent extends SpDataExplorerOverviewDirecti
}

openNewDashboardDialog() {
const dataViewDashboard: Dashboard = {};
dataViewDashboard.dashboardGeneralSettings = {};
dataViewDashboard.widgets = [];
dataViewDashboard.name = '';
const dataViewDashboard: Dashboard = {
dashboardGeneralSettings: {},
widgets: [],
name: '',
dashboardLiveSettings: {
refreshModeActive: false,
refreshIntervalInSeconds: 10,
label: 'Off',
},
};

this.openDashboardModificationDialog(true, dataViewDashboard);
}
Expand Down
Loading

0 comments on commit 6d30ec0

Please sign in to comment.