2020-01-22 20:05:30 +02:00
|
|
|
///
|
2023-01-31 10:43:56 +02:00
|
|
|
/// Copyright © 2016-2023 The Thingsboard Authors
|
2020-01-22 20:05:30 +02: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.
|
|
|
|
|
///
|
|
|
|
|
|
|
|
|
|
import { EntityId } from '@shared/models/id/entity-id';
|
2022-03-28 13:39:26 +03:00
|
|
|
import { DataKey, FormattedData, WidgetActionDescriptor, WidgetConfig } from '@shared/models/widget.models';
|
2021-09-28 17:58:32 +03:00
|
|
|
import { getDescendantProp, isDefined, isNotEmptyStr } from '@core/utils';
|
2020-07-03 18:33:06 +03:00
|
|
|
import { AlarmDataInfo, alarmFields } from '@shared/models/alarm.models';
|
2020-01-24 19:05:41 +02:00
|
|
|
import * as tinycolor_ from 'tinycolor2';
|
2020-06-22 18:55:15 +03:00
|
|
|
import { Direction, EntityDataSortOrder, EntityKey } from '@shared/models/query/query.models';
|
2020-07-03 18:33:06 +03:00
|
|
|
import { DataKeyType } from '@shared/models/telemetry/telemetry.models';
|
2021-09-28 17:58:32 +03:00
|
|
|
import { WidgetContext } from '@home/models/widget-component.models';
|
2021-11-03 17:57:00 +02:00
|
|
|
import { UtilsService } from '@core/services/utils.service';
|
|
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
2020-01-24 19:05:41 +02:00
|
|
|
|
|
|
|
|
const tinycolor = tinycolor_;
|
|
|
|
|
|
2022-09-20 14:08:02 +05:00
|
|
|
type ColumnVisibilityOptions = 'visible' | 'hidden' | 'hidden-mobile';
|
2021-03-12 12:15:35 +02:00
|
|
|
|
|
|
|
|
type ColumnSelectionOptions = 'enabled' | 'disabled';
|
|
|
|
|
|
2020-01-24 19:05:41 +02:00
|
|
|
export interface TableWidgetSettings {
|
|
|
|
|
enableSearch: boolean;
|
2021-03-12 12:15:35 +02:00
|
|
|
enableStickyAction: boolean;
|
|
|
|
|
enableStickyHeader: boolean;
|
2020-01-24 19:05:41 +02:00
|
|
|
displayPagination: boolean;
|
|
|
|
|
defaultPageSize: number;
|
2021-03-12 12:15:35 +02:00
|
|
|
useRowStyleFunction: boolean;
|
|
|
|
|
rowStyleFunction?: string;
|
2021-10-04 14:46:43 +03:00
|
|
|
reserveSpaceForHiddenAction?: boolean;
|
2020-01-24 19:05:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface TableWidgetDataKeySettings {
|
2022-10-06 19:32:19 +05:00
|
|
|
customTitle?: string;
|
2020-01-30 13:03:53 +02:00
|
|
|
columnWidth?: string;
|
2020-01-24 19:05:41 +02:00
|
|
|
useCellStyleFunction: boolean;
|
2021-03-12 12:15:35 +02:00
|
|
|
cellStyleFunction?: string;
|
2020-01-24 19:05:41 +02:00
|
|
|
useCellContentFunction: boolean;
|
2021-03-12 12:15:35 +02:00
|
|
|
cellContentFunction?: string;
|
2021-03-18 19:55:28 +02:00
|
|
|
defaultColumnVisibility?: ColumnVisibilityOptions;
|
|
|
|
|
columnSelectionToDisplay?: ColumnSelectionOptions;
|
2020-01-24 19:05:41 +02:00
|
|
|
}
|
2020-01-22 20:05:30 +02:00
|
|
|
|
2021-09-28 17:58:32 +03:00
|
|
|
export type ShowCellButtonActionFunction = (ctx: WidgetContext, data: EntityData | AlarmDataInfo | FormattedData) => boolean;
|
|
|
|
|
|
|
|
|
|
export interface TableCellButtonActionDescriptor extends WidgetActionDescriptor {
|
|
|
|
|
useShowActionCellButtonFunction: boolean;
|
|
|
|
|
showActionCellButtonFunction: ShowCellButtonActionFunction;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-22 20:05:30 +02:00
|
|
|
export interface EntityData {
|
|
|
|
|
id: EntityId;
|
|
|
|
|
entityName: string;
|
2020-02-25 11:43:35 +02:00
|
|
|
entityLabel?: string;
|
2020-01-22 20:05:30 +02:00
|
|
|
entityType?: string;
|
2021-09-28 17:58:32 +03:00
|
|
|
actionCellButtons?: TableCellButtonActionDescriptor[];
|
|
|
|
|
hasActions?: boolean;
|
2020-01-22 20:05:30 +02:00
|
|
|
[key: string]: any;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface EntityColumn extends DataKey {
|
2020-01-24 19:05:41 +02:00
|
|
|
def: string;
|
2020-01-22 20:05:30 +02:00
|
|
|
title: string;
|
2021-12-29 12:59:39 +02:00
|
|
|
sortable: boolean;
|
2020-06-22 18:55:15 +03:00
|
|
|
entityKey?: EntityKey;
|
2020-01-22 20:05:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface DisplayColumn {
|
|
|
|
|
title: string;
|
2020-01-24 19:05:41 +02:00
|
|
|
def: string;
|
2020-01-22 20:05:30 +02:00
|
|
|
display: boolean;
|
2021-03-12 12:15:35 +02:00
|
|
|
selectable: boolean;
|
2020-01-22 20:05:30 +02:00
|
|
|
}
|
|
|
|
|
|
2020-02-04 15:14:17 +02:00
|
|
|
export type CellContentFunction = (...args: any[]) => string;
|
|
|
|
|
|
2020-01-22 20:05:30 +02:00
|
|
|
export interface CellContentInfo {
|
|
|
|
|
useCellContentFunction: boolean;
|
2020-02-04 15:14:17 +02:00
|
|
|
cellContentFunction?: CellContentFunction;
|
2020-01-22 20:05:30 +02:00
|
|
|
units?: string;
|
|
|
|
|
decimals?: number;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-12 12:15:35 +02:00
|
|
|
export type CellStyleFunction = (...args: any[]) => any;
|
2020-02-04 15:14:17 +02:00
|
|
|
|
2020-01-22 20:05:30 +02:00
|
|
|
export interface CellStyleInfo {
|
|
|
|
|
useCellStyleFunction: boolean;
|
2020-02-04 15:14:17 +02:00
|
|
|
cellStyleFunction?: CellStyleFunction;
|
2020-01-22 20:05:30 +02:00
|
|
|
}
|
|
|
|
|
|
2021-03-12 12:15:35 +02:00
|
|
|
export type RowStyleFunction = (...args: any[]) => any;
|
|
|
|
|
|
|
|
|
|
export interface RowStyleInfo {
|
|
|
|
|
useRowStyleFunction: boolean;
|
|
|
|
|
rowStyleFunction?: RowStyleFunction;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-22 18:55:15 +03:00
|
|
|
|
|
|
|
|
export function entityDataSortOrderFromString(strSortOrder: string, columns: EntityColumn[]): EntityDataSortOrder {
|
|
|
|
|
if (!strSortOrder && !strSortOrder.length) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
let property: string;
|
|
|
|
|
let direction = Direction.ASC;
|
|
|
|
|
if (strSortOrder.startsWith('-')) {
|
|
|
|
|
direction = Direction.DESC;
|
|
|
|
|
property = strSortOrder.substring(1);
|
|
|
|
|
} else {
|
|
|
|
|
if (strSortOrder.startsWith('+')) {
|
|
|
|
|
property = strSortOrder.substring(1);
|
|
|
|
|
} else {
|
|
|
|
|
property = strSortOrder;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!property && !property.length) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2020-07-14 16:14:38 +03:00
|
|
|
let column = findColumnByLabel(property, columns);
|
|
|
|
|
if (!column) {
|
|
|
|
|
column = findColumnByName(property, columns);
|
|
|
|
|
}
|
2020-06-22 18:55:15 +03:00
|
|
|
if (column && column.entityKey) {
|
|
|
|
|
return {key: column.entityKey, direction};
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function findColumnByEntityKey(key: EntityKey, columns: EntityColumn[]): EntityColumn {
|
|
|
|
|
if (key) {
|
|
|
|
|
return columns.find(theColumn => theColumn.entityKey &&
|
|
|
|
|
theColumn.entityKey.type === key.type && theColumn.entityKey.key === key.key);
|
|
|
|
|
} else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function findEntityKeyByColumnDef(def: string, columns: EntityColumn[]): EntityKey {
|
2020-07-14 16:14:38 +03:00
|
|
|
if (def) {
|
|
|
|
|
const column = findColumnByDef(def, columns);
|
|
|
|
|
return column ? column.entityKey : null;
|
|
|
|
|
} else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2020-06-22 18:55:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function findColumn(searchProperty: string, searchValue: string, columns: EntityColumn[]): EntityColumn {
|
|
|
|
|
return columns.find(theColumn => theColumn[searchProperty] === searchValue);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-14 16:14:38 +03:00
|
|
|
export function findColumnByName(name: string, columns: EntityColumn[]): EntityColumn {
|
|
|
|
|
return findColumn('name', name, columns);
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-22 18:55:15 +03:00
|
|
|
export function findColumnByLabel(label: string, columns: EntityColumn[]): EntityColumn {
|
2020-07-03 18:33:06 +03:00
|
|
|
let column: EntityColumn;
|
|
|
|
|
const alarmColumns = columns.filter(c => c.type === DataKeyType.alarm);
|
|
|
|
|
if (alarmColumns.length) {
|
|
|
|
|
column = findColumn('name', label, alarmColumns);
|
|
|
|
|
}
|
|
|
|
|
if (!column) {
|
|
|
|
|
column = findColumn('label', label, columns);
|
|
|
|
|
}
|
|
|
|
|
return column;
|
2020-06-22 18:55:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function findColumnByDef(def: string, columns: EntityColumn[]): EntityColumn {
|
|
|
|
|
return findColumn('def', def, columns);
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-24 19:05:41 +02:00
|
|
|
export function findColumnProperty(searchProperty: string, searchValue: string, columnProperty: string, columns: EntityColumn[]): string {
|
|
|
|
|
let res = searchValue;
|
2020-02-04 15:14:17 +02:00
|
|
|
const column = columns.find(theColumn => theColumn[searchProperty] === searchValue);
|
2020-01-24 19:05:41 +02:00
|
|
|
if (column) {
|
|
|
|
|
res = column[columnProperty];
|
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-22 18:55:15 +03:00
|
|
|
export function toEntityKey(def: string, columns: EntityColumn[]): string {
|
|
|
|
|
return findColumnProperty('def', def, 'label', columns);
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-24 19:05:41 +02:00
|
|
|
export function toEntityColumnDef(label: string, columns: EntityColumn[]): string {
|
|
|
|
|
return findColumnProperty('label', label, 'def', columns);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function fromEntityColumnDef(def: string, columns: EntityColumn[]): string {
|
|
|
|
|
return findColumnProperty('def', def, 'label', columns);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function toAlarmColumnDef(name: string, columns: EntityColumn[]): string {
|
|
|
|
|
return findColumnProperty('name', name, 'def', columns);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function fromAlarmColumnDef(def: string, columns: EntityColumn[]): string {
|
|
|
|
|
return findColumnProperty('def', def, 'name', columns);
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-22 20:05:30 +02:00
|
|
|
export function getEntityValue(entity: any, key: DataKey): any {
|
|
|
|
|
return getDescendantProp(entity, key.label);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-03 18:33:06 +03:00
|
|
|
export function getAlarmValue(alarm: AlarmDataInfo, key: EntityColumn) {
|
2020-07-16 20:00:33 +03:00
|
|
|
let alarmField = null;
|
|
|
|
|
if (key.type === DataKeyType.alarm) {
|
2020-11-17 19:06:38 +02:00
|
|
|
alarmField = alarmFields[key.name]?.value;
|
|
|
|
|
if (!alarmField && key.name.startsWith('details.')) {
|
|
|
|
|
alarmField = key.name;
|
|
|
|
|
}
|
2020-07-16 20:00:33 +03:00
|
|
|
}
|
2020-01-24 19:05:41 +02:00
|
|
|
if (alarmField) {
|
2020-11-17 19:06:38 +02:00
|
|
|
return getDescendantProp(alarm, alarmField);
|
2020-01-24 19:05:41 +02:00
|
|
|
} else {
|
2020-10-19 19:05:34 +03:00
|
|
|
return getDescendantProp(alarm, key.label);
|
2020-01-24 19:05:41 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-12 12:15:35 +02:00
|
|
|
export function getRowStyleInfo(settings: TableWidgetSettings, ...args: string[]): RowStyleInfo {
|
|
|
|
|
let rowStyleFunction: RowStyleFunction = null;
|
|
|
|
|
let useRowStyleFunction = false;
|
|
|
|
|
|
|
|
|
|
if (settings.useRowStyleFunction === true) {
|
|
|
|
|
if (isDefined(settings.rowStyleFunction) && settings.rowStyleFunction.length > 0) {
|
|
|
|
|
try {
|
|
|
|
|
rowStyleFunction = new Function(...args, settings.rowStyleFunction) as RowStyleFunction;
|
|
|
|
|
useRowStyleFunction = true;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
rowStyleFunction = null;
|
|
|
|
|
useRowStyleFunction = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
useRowStyleFunction,
|
|
|
|
|
rowStyleFunction
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getCellStyleInfo(keySettings: TableWidgetDataKeySettings, ...args: string[]): CellStyleInfo {
|
2020-02-04 15:14:17 +02:00
|
|
|
let cellStyleFunction: CellStyleFunction = null;
|
2020-01-24 19:05:41 +02:00
|
|
|
let useCellStyleFunction = false;
|
|
|
|
|
|
|
|
|
|
if (keySettings.useCellStyleFunction === true) {
|
|
|
|
|
if (isDefined(keySettings.cellStyleFunction) && keySettings.cellStyleFunction.length > 0) {
|
|
|
|
|
try {
|
2021-03-12 12:15:35 +02:00
|
|
|
cellStyleFunction = new Function(...args, keySettings.cellStyleFunction) as CellStyleFunction;
|
2020-01-24 19:05:41 +02:00
|
|
|
useCellStyleFunction = true;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
cellStyleFunction = null;
|
|
|
|
|
useCellStyleFunction = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
useCellStyleFunction,
|
|
|
|
|
cellStyleFunction
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getCellContentInfo(keySettings: TableWidgetDataKeySettings, ...args: string[]): CellContentInfo {
|
2020-02-04 15:14:17 +02:00
|
|
|
let cellContentFunction: CellContentFunction = null;
|
2020-01-24 19:05:41 +02:00
|
|
|
let useCellContentFunction = false;
|
|
|
|
|
|
|
|
|
|
if (keySettings.useCellContentFunction === true) {
|
|
|
|
|
if (isDefined(keySettings.cellContentFunction) && keySettings.cellContentFunction.length > 0) {
|
|
|
|
|
try {
|
2020-02-04 15:14:17 +02:00
|
|
|
cellContentFunction = new Function(...args, keySettings.cellContentFunction) as CellContentFunction;
|
2020-01-24 19:05:41 +02:00
|
|
|
useCellContentFunction = true;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
cellContentFunction = null;
|
|
|
|
|
useCellContentFunction = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
cellContentFunction,
|
|
|
|
|
useCellContentFunction
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getColumnWidth(keySettings: TableWidgetDataKeySettings): string {
|
|
|
|
|
return isDefined(keySettings.columnWidth) ? keySettings.columnWidth : '0px';
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-04 19:50:18 +02:00
|
|
|
export function widthStyle(width: string): any {
|
|
|
|
|
const widthStyleObj: any = {width};
|
|
|
|
|
if (width !== '0px') {
|
|
|
|
|
widthStyleObj.minWidth = width;
|
|
|
|
|
widthStyleObj.maxWidth = width;
|
|
|
|
|
}
|
|
|
|
|
return widthStyleObj;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-20 14:08:02 +05:00
|
|
|
export function getColumnDefaultVisibility(keySettings: TableWidgetDataKeySettings, ctx?: WidgetContext): boolean {
|
|
|
|
|
return !(isDefined(keySettings.defaultColumnVisibility) && (keySettings.defaultColumnVisibility === 'hidden' ||
|
|
|
|
|
(ctx && ctx.isMobile && keySettings.defaultColumnVisibility === 'hidden-mobile')));
|
2021-03-12 12:15:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getColumnSelectionAvailability(keySettings: TableWidgetDataKeySettings): boolean {
|
|
|
|
|
return !(isDefined(keySettings.columnSelectionToDisplay) && keySettings.columnSelectionToDisplay === 'disabled');
|
|
|
|
|
}
|
2020-02-04 19:50:18 +02:00
|
|
|
|
2021-09-28 17:58:32 +03:00
|
|
|
export function getTableCellButtonActions(widgetContext: WidgetContext): TableCellButtonActionDescriptor[] {
|
|
|
|
|
return widgetContext.actionsApi.getActionDescriptors('actionCellButton').map(descriptor => {
|
|
|
|
|
let useShowActionCellButtonFunction = descriptor.useShowWidgetActionFunction || false;
|
|
|
|
|
let showActionCellButtonFunction: ShowCellButtonActionFunction = null;
|
|
|
|
|
if (useShowActionCellButtonFunction && isNotEmptyStr(descriptor.showWidgetActionFunction)) {
|
|
|
|
|
try {
|
|
|
|
|
showActionCellButtonFunction =
|
|
|
|
|
new Function('widgetContext', 'data', descriptor.showWidgetActionFunction) as ShowCellButtonActionFunction;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
useShowActionCellButtonFunction = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return {...descriptor, showActionCellButtonFunction, useShowActionCellButtonFunction};
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function checkHasActions(cellButtonActions: TableCellButtonActionDescriptor[]): boolean {
|
|
|
|
|
return cellButtonActions.some(action => action.icon);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function prepareTableCellButtonActions(widgetContext: WidgetContext, cellButtonActions: TableCellButtonActionDescriptor[],
|
2021-10-04 14:46:43 +03:00
|
|
|
data: EntityData | AlarmDataInfo | FormattedData,
|
|
|
|
|
reserveSpaceForHiddenAction = true): TableCellButtonActionDescriptor[] {
|
|
|
|
|
if (reserveSpaceForHiddenAction) {
|
|
|
|
|
return cellButtonActions.map(action =>
|
|
|
|
|
filterTableCellButtonAction(widgetContext, action, data) ? action : { id: action.id } as TableCellButtonActionDescriptor);
|
|
|
|
|
}
|
|
|
|
|
return cellButtonActions.filter(action => filterTableCellButtonAction(widgetContext, action, data));
|
2021-09-28 17:58:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function filterTableCellButtonAction(widgetContext: WidgetContext,
|
|
|
|
|
action: TableCellButtonActionDescriptor, data: EntityData | AlarmDataInfo | FormattedData): boolean {
|
|
|
|
|
if (action.useShowActionCellButtonFunction) {
|
|
|
|
|
try {
|
|
|
|
|
return action.showActionCellButtonFunction(widgetContext, data);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.warn('Failed to execute showActionCellButtonFunction', e);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-02-04 19:50:18 +02:00
|
|
|
|
2021-11-03 17:57:00 +02:00
|
|
|
export function noDataMessage(noDataDisplayMessage: string, defaultMessage: string,
|
|
|
|
|
utils: UtilsService, translate: TranslateService): string {
|
|
|
|
|
if (isNotEmptyStr(noDataDisplayMessage)) {
|
|
|
|
|
return utils.customTranslation(noDataDisplayMessage, noDataDisplayMessage);
|
|
|
|
|
}
|
|
|
|
|
return translate.instant(defaultMessage);
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-24 19:05:41 +02:00
|
|
|
export function constructTableCssString(widgetConfig: WidgetConfig): string {
|
|
|
|
|
const origColor = widgetConfig.color || 'rgba(0, 0, 0, 0.87)';
|
|
|
|
|
const origBackgroundColor = widgetConfig.backgroundColor || 'rgb(255, 255, 255)';
|
|
|
|
|
const currentEntityColor = 'rgba(221, 221, 221, 0.65)';
|
|
|
|
|
const currentEntityStickyColor = tinycolor.mix(origBackgroundColor,
|
|
|
|
|
tinycolor(currentEntityColor).setAlpha(1), 65).toRgbString();
|
|
|
|
|
const selectedColor = 'rgba(221, 221, 221, 0.5)';
|
|
|
|
|
const selectedStickyColor = tinycolor.mix(origBackgroundColor,
|
|
|
|
|
tinycolor(selectedColor).setAlpha(1), 50).toRgbString();
|
|
|
|
|
const hoverColor = 'rgba(221, 221, 221, 0.3)';
|
|
|
|
|
const hoverStickyColor = tinycolor.mix(origBackgroundColor,
|
|
|
|
|
tinycolor(hoverColor).setAlpha(1), 30).toRgbString();
|
|
|
|
|
const defaultColor = tinycolor(origColor);
|
|
|
|
|
const mdDark = defaultColor.setAlpha(0.87).toRgbString();
|
|
|
|
|
const mdDarkSecondary = defaultColor.setAlpha(0.54).toRgbString();
|
|
|
|
|
const mdDarkDisabled = defaultColor.setAlpha(0.26).toRgbString();
|
2020-01-30 13:03:53 +02:00
|
|
|
const mdDarkDisabled2 = defaultColor.setAlpha(0.38).toRgbString();
|
2020-01-24 19:05:41 +02:00
|
|
|
const mdDarkDivider = defaultColor.setAlpha(0.12).toRgbString();
|
|
|
|
|
|
|
|
|
|
const cssString =
|
2023-02-21 19:18:04 +02:00
|
|
|
'.mat-mdc-input-element::placeholder {\n' +
|
2020-02-04 15:14:17 +02:00
|
|
|
' color: ' + mdDarkSecondary + ';\n' +
|
2020-01-24 19:05:41 +02:00
|
|
|
'}\n' +
|
2023-02-21 19:18:04 +02:00
|
|
|
'.mat-mdc-input-element::-moz-placeholder {\n' +
|
2020-02-04 15:14:17 +02:00
|
|
|
' color: ' + mdDarkSecondary + ';\n' +
|
2020-01-24 19:05:41 +02:00
|
|
|
'}\n' +
|
2023-02-21 19:18:04 +02:00
|
|
|
'.mat-mdc-input-element::-webkit-input-placeholder {\n' +
|
2020-02-04 15:14:17 +02:00
|
|
|
' color: ' + mdDarkSecondary + ';\n' +
|
2020-01-24 19:05:41 +02:00
|
|
|
'}\n' +
|
2023-02-21 19:18:04 +02:00
|
|
|
'.mat-mdc-input-element:-ms-input-placeholder {\n' +
|
2020-02-04 15:14:17 +02:00
|
|
|
' color: ' + mdDarkSecondary + ';\n' +
|
|
|
|
|
'}\n' +
|
2023-02-17 19:24:01 +02:00
|
|
|
'mat-toolbar.mat-mdc-table-toolbar {\n' +
|
2020-02-04 15:14:17 +02:00
|
|
|
'color: ' + mdDark + ';\n' +
|
|
|
|
|
'}\n' +
|
2023-02-21 19:18:04 +02:00
|
|
|
'mat-toolbar.mat-mdc-table-toolbar:not([color="primary"]) button.mat-mdc-icon-button mat-icon {\n' +
|
2020-02-04 15:14:17 +02:00
|
|
|
'color: ' + mdDarkSecondary + ';\n' +
|
|
|
|
|
'}\n' +
|
2023-02-21 19:18:04 +02:00
|
|
|
'.mat-mdc-tab .mdc-tab__text-label {\n' +
|
2020-02-04 15:14:17 +02:00
|
|
|
'color: ' + mdDark + ';\n' +
|
|
|
|
|
'}\n' +
|
2023-02-21 19:18:04 +02:00
|
|
|
'.mat-mdc-tab-header-pagination-chevron {\n' +
|
2020-02-04 15:14:17 +02:00
|
|
|
'border-color: ' + mdDark + ';\n' +
|
|
|
|
|
'}\n' +
|
2023-02-21 19:18:04 +02:00
|
|
|
'.mat-mdc-tab-header-pagination-disabled .mat-mdc-tab-header-pagination-chevron {\n' +
|
2020-02-04 15:14:17 +02:00
|
|
|
'border-color: ' + mdDarkDisabled2 + ';\n' +
|
|
|
|
|
'}\n' +
|
2023-02-21 19:18:04 +02:00
|
|
|
'.mat-mdc-table .mat-mdc-header-row {\n' +
|
2020-02-04 15:14:17 +02:00
|
|
|
'background-color: ' + origBackgroundColor + ';\n' +
|
|
|
|
|
'}\n' +
|
2023-02-21 19:18:04 +02:00
|
|
|
'.mat-mdc-table .mat-mdc-header-cell {\n' +
|
2020-02-04 15:14:17 +02:00
|
|
|
'color: ' + mdDarkSecondary + ';\n' +
|
|
|
|
|
'}\n' +
|
2023-02-21 19:18:04 +02:00
|
|
|
'.mat-mdc-table .mat-mdc-header-cell .mat-sort-header-arrow {\n' +
|
2020-02-04 15:14:17 +02:00
|
|
|
'color: ' + mdDarkDisabled + ';\n' +
|
|
|
|
|
'}\n' +
|
2023-02-21 19:18:04 +02:00
|
|
|
'.mat-mdc-table .mat-mdc-cell, .mat-mdc-table .mat-mdc-header-cell {\n' +
|
2020-02-04 15:14:17 +02:00
|
|
|
'border-bottom-color: ' + mdDarkDivider + ';\n' +
|
|
|
|
|
'}\n' +
|
2023-02-21 19:18:04 +02:00
|
|
|
'.mat-mdc-table .mat-mdc-cell .mat-mdc-checkbox ' +
|
|
|
|
|
'.mdc-checkbox__native-control:focus:enabled:not(:checked):not(:indeterminate):not([data-indeterminate=true])'+
|
|
|
|
|
'~.mdc-checkbox__background, ' +
|
|
|
|
|
'.mat-table .mat-header-cell .mat-mdc-checkbox ' +
|
|
|
|
|
'.mdc-checkbox__native-control:focus:enabled:not(:checked):not(:indeterminate):not([data-indeterminate=true])'+
|
|
|
|
|
'~.mdc-checkbox__background {\n' +
|
2020-02-04 15:14:17 +02:00
|
|
|
'border-color: ' + mdDarkSecondary + ';\n' +
|
|
|
|
|
'}\n' +
|
2023-02-21 19:18:04 +02:00
|
|
|
'.mat-mdc-table .mat-mdc-row .mat-mdc-cell.mat-mdc-table-sticky {\n' +
|
2020-02-04 15:14:17 +02:00
|
|
|
'transition: background-color .2s;\n' +
|
|
|
|
|
'}\n' +
|
2023-02-21 19:18:04 +02:00
|
|
|
'.mat-mdc-table .mat-mdc-row.tb-current-entity {\n' +
|
2020-02-04 15:14:17 +02:00
|
|
|
'background-color: ' + currentEntityColor + ';\n' +
|
|
|
|
|
'}\n' +
|
2023-02-21 19:18:04 +02:00
|
|
|
'.mat-mdc-table .mat-mdc-row.tb-current-entity .mat-mdc-cell.mat-mdc-table-sticky {\n' +
|
2020-02-04 15:14:17 +02:00
|
|
|
'background-color: ' + currentEntityStickyColor + ';\n' +
|
|
|
|
|
'}\n' +
|
2023-02-21 19:18:04 +02:00
|
|
|
'.mat-mdc-table .mat-mdc-row:hover:not(.tb-current-entity) {\n' +
|
2020-02-04 15:14:17 +02:00
|
|
|
'background-color: ' + hoverColor + ';\n' +
|
|
|
|
|
'}\n' +
|
2023-02-21 19:18:04 +02:00
|
|
|
'.mat-mdc-table .mat-mdc-row:hover:not(.tb-current-entity) .mat-mdc-cell.mat-mdc-table-sticky {\n' +
|
2020-02-04 15:14:17 +02:00
|
|
|
'background-color: ' + hoverStickyColor + ';\n' +
|
|
|
|
|
'}\n' +
|
2023-02-21 19:18:04 +02:00
|
|
|
'.mat-mdc-table .mat-mdc-row.mat-row-select.mat-selected:not(.tb-current-entity) {\n' +
|
2020-02-04 15:14:17 +02:00
|
|
|
'background-color: ' + selectedColor + ';\n' +
|
|
|
|
|
'}\n' +
|
2023-02-21 19:18:04 +02:00
|
|
|
'.mat-mdc-table .mat-mdc-row.mat-row-select.mat-selected:not(.tb-current-entity) .mat-mdc-cell.mat-mdc-table-sticky {\n' +
|
2020-02-04 15:14:17 +02:00
|
|
|
'background-color: ' + selectedStickyColor + ';\n' +
|
|
|
|
|
'}\n' +
|
2023-02-21 19:18:04 +02:00
|
|
|
'.mat-mdc-table .mat-mdc-row .mat-mdc-cell.mat-mdc-table-sticky, .mat-mdc-table .mat-mdc-header-cell.mat-mdc-table-sticky {\n' +
|
2020-02-04 15:14:17 +02:00
|
|
|
'background-color: ' + origBackgroundColor + ';\n' +
|
|
|
|
|
'}\n' +
|
2023-02-21 19:18:04 +02:00
|
|
|
'.mat-mdc-table .mat-mdc-cell {\n' +
|
2020-02-04 15:14:17 +02:00
|
|
|
'color: ' + mdDark + ';\n' +
|
|
|
|
|
'}\n' +
|
2023-02-21 19:18:04 +02:00
|
|
|
'.mat-mdc-table .mat-mdc-cell button.mat-mdc-icon-button mat-icon {\n' +
|
2020-02-04 15:14:17 +02:00
|
|
|
'color: ' + mdDarkSecondary + ';\n' +
|
|
|
|
|
'}\n' +
|
2023-02-21 19:18:04 +02:00
|
|
|
'.mat-mdc-table .mat-mdc-cell button.mat-mdc-icon-button[disabled][disabled] mat-icon {\n' +
|
2020-02-04 15:14:17 +02:00
|
|
|
'color: ' + mdDarkDisabled + ';\n' +
|
|
|
|
|
'}\n' +
|
|
|
|
|
'.mat-divider {\n' +
|
|
|
|
|
'border-top-color: ' + mdDarkDivider + ';\n' +
|
|
|
|
|
'}\n' +
|
2023-02-21 19:18:04 +02:00
|
|
|
'.mat-mdc-paginator {\n' +
|
2020-02-04 15:14:17 +02:00
|
|
|
'color: ' + mdDarkSecondary + ';\n' +
|
|
|
|
|
'}\n' +
|
2023-02-21 19:18:04 +02:00
|
|
|
'.mat-mdc-paginator button.mat-mdc-icon-button {\n' +
|
2020-02-04 15:14:17 +02:00
|
|
|
'color: ' + mdDarkSecondary + ';\n' +
|
|
|
|
|
'}\n' +
|
2023-02-21 19:18:04 +02:00
|
|
|
'.mat-mdc-paginator button.mat-mdc-icon-button[disabled][disabled] {\n' +
|
2020-02-04 15:14:17 +02:00
|
|
|
'color: ' + mdDarkDisabled + ';\n' +
|
2020-01-24 19:05:41 +02:00
|
|
|
'}\n' +
|
2023-02-21 19:18:04 +02:00
|
|
|
'.mat-mdc-paginator .mat-mdc-select-value {\n' +
|
2020-02-04 15:14:17 +02:00
|
|
|
'color: ' + mdDarkSecondary + ';\n' +
|
2020-01-24 19:05:41 +02:00
|
|
|
'}';
|
|
|
|
|
return cssString;
|
2020-01-22 20:05:30 +02:00
|
|
|
}
|
2022-10-06 19:32:19 +05:00
|
|
|
|
|
|
|
|
export function getHeaderTitle(dataKey: DataKey, keySettings: TableWidgetDataKeySettings, utils: UtilsService) {
|
|
|
|
|
if (isDefined(keySettings.customTitle) && isNotEmptyStr(keySettings.customTitle)) {
|
|
|
|
|
return utils.customTranslation(keySettings.customTitle, keySettings.customTitle);
|
|
|
|
|
}
|
|
|
|
|
return dataKey.label;
|
|
|
|
|
}
|