thingsboard/ui-ngx/src/app/shared/models/dashboard.models.ts

169 lines
4.8 KiB
TypeScript
Raw Normal View History

2019-08-12 19:34:23 +03:00
///
2023-01-31 10:43:56 +02:00
/// Copyright © 2016-2023 The Thingsboard Authors
2019-08-12 19:34:23 +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.
///
2022-05-25 12:26:23 +03:00
import { BaseData, ExportableEntity } from '@shared/models/base-data';
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 { Timewindow } from '@shared/models/time/time.models';
import { EntityAliases } from './alias.models';
import { Filters } from '@shared/models/query/query.models';
import { MatDialogRef } from '@angular/material/dialog';
2019-08-12 19:34:23 +03:00
2022-05-25 12:26:23 +03:00
export interface DashboardInfo extends BaseData<DashboardId>, ExportableEntity<DashboardId> {
tenantId?: TenantId;
title?: string;
image?: string;
assignedCustomers?: Array<ShortCustomerInfo>;
mobileHide?: boolean;
mobileOrder?: number;
2019-08-12 19:34:23 +03:00
}
2019-09-03 19:31:16 +03:00
export interface WidgetLayout {
sizeX?: number;
sizeY?: number;
desktopHide?: boolean;
mobileHide?: boolean;
mobileHeight?: number;
mobileOrder?: number;
col?: number;
row?: number;
2019-09-03 19:31:16 +03:00
}
export interface WidgetLayouts {
[id: string]: WidgetLayout;
}
export interface GridSettings {
backgroundColor?: string;
columns?: number;
margin?: number;
2023-04-13 12:59:01 +03:00
outerMargin?: boolean;
backgroundSizeMode?: string;
backgroundImageUrl?: string;
autoFillHeight?: boolean;
mobileAutoFillHeight?: boolean;
mobileRowHeight?: number;
2022-06-16 22:10:30 +03:00
layoutDimension?: LayoutDimension;
[key: string]: any;
}
export interface DashboardLayout {
widgets: WidgetLayouts;
gridSettings: GridSettings;
}
export interface DashboardLayoutInfo {
widgetIds?: string[];
widgetLayouts?: WidgetLayouts;
gridSettings?: GridSettings;
}
2022-04-05 13:56:44 +03:00
export interface LayoutDimension {
2023-08-18 16:14:21 +03:00
type?: LayoutType;
fixedWidth?: number;
fixedLayout?: DashboardLayoutId;
leftWidthPercentage?: number;
2022-04-05 13:56:44 +03:00
}
export declare type DashboardLayoutId = 'main' | 'right';
2022-04-05 13:56:44 +03:00
export declare type LayoutType = 'percentage' | 'fixed';
2022-06-16 22:23:14 +03:00
export declare type DashboardStateLayouts = {[key in DashboardLayoutId]?: DashboardLayout};
export declare type DashboardLayoutsInfo = {[key in DashboardLayoutId]?: DashboardLayoutInfo};
export interface DashboardState {
name: string;
root: boolean;
layouts: DashboardStateLayouts;
}
export declare type StateControllerId = 'entity' | 'default' | string;
export interface DashboardSettings {
stateControllerId?: StateControllerId;
showTitle?: boolean;
showDashboardsSelect?: boolean;
showEntitiesSelect?: boolean;
2020-07-01 20:09:25 +03:00
showFilters?: boolean;
2021-04-16 14:59:35 +03:00
showDashboardLogo?: boolean;
dashboardLogoUrl?: string;
showDashboardTimewindow?: boolean;
showDashboardExport?: boolean;
showUpdateDashboardImage?: boolean;
toolbarAlwaysOpen?: boolean;
hideToolbar?: boolean;
titleColor?: string;
dashboardCss?: string;
}
2019-08-12 19:34:23 +03:00
export interface DashboardConfiguration {
timewindow?: Timewindow;
settings?: DashboardSettings;
widgets?: {[id: string]: Widget } | Widget[];
states?: {[id: string]: DashboardState };
entityAliases?: EntityAliases;
filters?: Filters;
[key: string]: any;
2019-08-12 19:34:23 +03:00
}
export interface Dashboard extends DashboardInfo {
configuration?: DashboardConfiguration;
dialogRef?: MatDialogRef<any>;
assignedCustomerIds?: Array<string>;
2019-08-12 19:34:23 +03:00
}
export interface HomeDashboard extends Dashboard {
hideDashboardToolbar: boolean;
}
export interface HomeDashboardInfo {
dashboardId: DashboardId;
hideDashboardToolbar: boolean;
}
2023-08-18 16:14:21 +03:00
export const isPublicDashboard = (dashboard: DashboardInfo): boolean => {
if (dashboard && dashboard.assignedCustomers) {
return dashboard.assignedCustomers
.filter(customerInfo => customerInfo.public).length > 0;
} else {
return false;
}
2023-08-18 16:14:21 +03:00
};
2023-08-18 16:14:21 +03:00
export const getDashboardAssignedCustomersText = (dashboard: DashboardInfo): string => {
if (dashboard && dashboard.assignedCustomers && dashboard.assignedCustomers.length > 0) {
return dashboard.assignedCustomers
.filter(customerInfo => !customerInfo.public)
.map(customerInfo => customerInfo.title)
.join(', ');
} else {
2020-02-05 17:52:18 +02:00
return '';
}
2023-08-18 16:14:21 +03:00
};
2023-08-18 16:14:21 +03:00
export const isCurrentPublicDashboardCustomer = (dashboard: DashboardInfo, customerId: string): boolean => {
if (customerId && dashboard && dashboard.assignedCustomers) {
2023-08-18 16:14:21 +03:00
return dashboard.assignedCustomers.filter(customerInfo =>
customerInfo.public && customerId === customerInfo.customerId.id).length > 0;
} else {
return false;
}
2023-08-18 16:14:21 +03:00
};