2019-09-19 20:10:52 +03:00
|
|
|
///
|
2023-01-31 10:43:56 +02:00
|
|
|
/// Copyright © 2016-2023 The Thingsboard Authors
|
2019-09-19 20:10:52 +03:00
|
|
|
///
|
|
|
|
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
/// you may not use this file except in compliance with the License.
|
|
|
|
|
/// You may obtain a copy of the License at
|
|
|
|
|
///
|
|
|
|
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
///
|
|
|
|
|
/// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
/// See the License for the specific language governing permissions and
|
|
|
|
|
/// limitations under the License.
|
|
|
|
|
///
|
|
|
|
|
|
2020-04-02 11:01:13 +03:00
|
|
|
import { Dashboard, DashboardLayoutId, GridSettings, WidgetLayouts } from '@app/shared/models/dashboard.models';
|
2019-10-31 10:06:57 +02:00
|
|
|
import { Widget, WidgetPosition } from '@app/shared/models/widget.models';
|
2019-09-19 20:10:52 +03:00
|
|
|
import { Timewindow } from '@shared/models/time/time.models';
|
|
|
|
|
import { IAliasController, IStateController } from '@core/api/widget-api.models';
|
2019-09-20 20:30:43 +03:00
|
|
|
import { ILayoutController } from './layout/layout.models';
|
2020-04-02 11:01:13 +03:00
|
|
|
import { DashboardContextMenuItem, WidgetContextMenuItem } from '@home/models/dashboard-component.models';
|
2021-12-24 15:53:18 +02:00
|
|
|
import { Observable } from 'rxjs';
|
2019-09-19 20:10:52 +03:00
|
|
|
|
|
|
|
|
export declare type DashboardPageScope = 'tenant' | 'customer';
|
|
|
|
|
|
2022-12-07 15:34:42 +02:00
|
|
|
export interface DashboardPageInitData {
|
|
|
|
|
dashboard: Dashboard;
|
|
|
|
|
currentDashboardId?: string;
|
|
|
|
|
widgetEditMode?: boolean;
|
|
|
|
|
singlePageMode?: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-19 20:10:52 +03:00
|
|
|
export interface DashboardContext {
|
2021-01-21 18:03:36 +02:00
|
|
|
instanceId: string;
|
2019-09-19 20:10:52 +03:00
|
|
|
state: string;
|
2019-11-04 15:47:36 +02:00
|
|
|
getDashboard: () => Dashboard;
|
2019-09-19 20:10:52 +03:00
|
|
|
dashboardTimewindow: Timewindow;
|
|
|
|
|
aliasController: IAliasController;
|
|
|
|
|
stateController: IStateController;
|
2021-12-24 15:53:18 +02:00
|
|
|
stateChanged: Observable<string>;
|
2019-10-24 19:52:19 +03:00
|
|
|
runChangeDetection: () => void;
|
2019-09-19 20:10:52 +03:00
|
|
|
}
|
|
|
|
|
|
2019-09-20 20:30:43 +03:00
|
|
|
export interface IDashboardController {
|
|
|
|
|
dashboardCtx: DashboardContext;
|
|
|
|
|
openRightLayout();
|
|
|
|
|
openDashboardState(stateId: string, openRightLayout: boolean);
|
2019-09-25 19:37:29 +03:00
|
|
|
addWidget($event: Event, layoutCtx: DashboardPageLayoutContext);
|
2019-10-31 10:06:57 +02:00
|
|
|
editWidget($event: Event, layoutCtx: DashboardPageLayoutContext, widget: Widget);
|
|
|
|
|
exportWidget($event: Event, layoutCtx: DashboardPageLayoutContext, widget: Widget);
|
2019-09-25 19:37:29 +03:00
|
|
|
removeWidget($event: Event, layoutCtx: DashboardPageLayoutContext, widget: Widget);
|
2019-10-31 10:06:57 +02:00
|
|
|
widgetMouseDown($event: Event, layoutCtx: DashboardPageLayoutContext, widget: Widget);
|
|
|
|
|
widgetClicked($event: Event, layoutCtx: DashboardPageLayoutContext, widget: Widget);
|
2019-09-25 19:37:29 +03:00
|
|
|
prepareDashboardContextMenu(layoutCtx: DashboardPageLayoutContext): Array<DashboardContextMenuItem>;
|
2019-10-31 10:06:57 +02:00
|
|
|
prepareWidgetContextMenu(layoutCtx: DashboardPageLayoutContext, widget: Widget): Array<WidgetContextMenuItem>;
|
2019-09-25 19:37:29 +03:00
|
|
|
copyWidget($event: Event, layoutCtx: DashboardPageLayoutContext, widget: Widget);
|
|
|
|
|
copyWidgetReference($event: Event, layoutCtx: DashboardPageLayoutContext, widget: Widget);
|
|
|
|
|
pasteWidget($event: Event, layoutCtx: DashboardPageLayoutContext, pos: WidgetPosition);
|
|
|
|
|
pasteWidgetReference($event: Event, layoutCtx: DashboardPageLayoutContext, pos: WidgetPosition);
|
2019-09-20 20:30:43 +03:00
|
|
|
}
|
|
|
|
|
|
2019-09-19 20:10:52 +03:00
|
|
|
export interface DashboardPageLayoutContext {
|
|
|
|
|
id: DashboardLayoutId;
|
2019-10-31 10:06:57 +02:00
|
|
|
widgets: LayoutWidgetsArray;
|
2019-09-20 20:30:43 +03:00
|
|
|
widgetLayouts: WidgetLayouts;
|
2019-09-19 20:10:52 +03:00
|
|
|
gridSettings: GridSettings;
|
2019-09-20 20:30:43 +03:00
|
|
|
ctrl: ILayoutController;
|
2019-09-25 19:37:29 +03:00
|
|
|
dashboardCtrl: IDashboardController;
|
2019-09-19 20:10:52 +03:00
|
|
|
ignoreLoading: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface DashboardPageLayout {
|
|
|
|
|
show: boolean;
|
|
|
|
|
layoutCtx: DashboardPageLayoutContext;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-20 20:30:43 +03:00
|
|
|
export declare type DashboardPageLayouts = {[key in DashboardLayoutId]: DashboardPageLayout};
|
|
|
|
|
|
2019-10-31 10:06:57 +02:00
|
|
|
export class LayoutWidgetsArray implements Iterable<Widget> {
|
|
|
|
|
|
|
|
|
|
private widgetIds: string[] = [];
|
|
|
|
|
|
2019-10-31 18:33:51 +02:00
|
|
|
private loaded = false;
|
|
|
|
|
|
2019-11-04 15:47:36 +02:00
|
|
|
constructor(private dashboardCtx: DashboardContext) {
|
2019-10-31 10:06:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size() {
|
|
|
|
|
return this.widgetIds.length;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-31 18:33:51 +02:00
|
|
|
isLoading() {
|
|
|
|
|
return !this.loaded;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
isEmpty() {
|
|
|
|
|
return this.loaded && this.widgetIds.length === 0;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-31 10:06:57 +02:00
|
|
|
setWidgetIds(widgetIds: string[]) {
|
|
|
|
|
this.widgetIds = widgetIds;
|
2019-10-31 18:33:51 +02:00
|
|
|
this.loaded = true;
|
2019-10-31 10:06:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
addWidgetId(widgetId: string) {
|
|
|
|
|
this.widgetIds.push(widgetId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
removeWidgetId(widgetId: string): boolean {
|
|
|
|
|
const index = this.widgetIds.indexOf(widgetId);
|
|
|
|
|
if (index > -1) {
|
|
|
|
|
this.widgetIds.splice(index, 1);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Symbol.iterator](): Iterator<Widget> {
|
|
|
|
|
let pointer = 0;
|
|
|
|
|
const widgetIds = this.widgetIds;
|
2019-11-04 15:47:36 +02:00
|
|
|
const dashboard = this.dashboardCtx.getDashboard();
|
2019-10-31 10:06:57 +02:00
|
|
|
return {
|
|
|
|
|
next(value?: any): IteratorResult<Widget> {
|
|
|
|
|
if (pointer < widgetIds.length) {
|
|
|
|
|
const widgetId = widgetIds[pointer++];
|
|
|
|
|
const widget = dashboard.configuration.widgets[widgetId];
|
|
|
|
|
return {
|
|
|
|
|
done: false,
|
|
|
|
|
value: widget
|
|
|
|
|
};
|
|
|
|
|
} else {
|
|
|
|
|
return {
|
|
|
|
|
done: true,
|
|
|
|
|
value: null
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public widgetByIndex(index: number): Widget {
|
|
|
|
|
const widgetId = this.widgetIds[index];
|
|
|
|
|
if (widgetId) {
|
|
|
|
|
return this.widgetById(widgetId);
|
|
|
|
|
} else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private widgetById(widgetId: string): Widget {
|
2019-11-04 15:47:36 +02:00
|
|
|
return this.dashboardCtx.getDashboard().configuration.widgets[widgetId];
|
2019-10-31 10:06:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|