edges-overview-widget.models.ts
3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
///
/// Copyright © 2016-2024 The Thingsboard Authors
///
/// 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 { NavTreeNode } from '@shared/components/nav-tree.component';
import { Datasource } from '@shared/models/widget.models';
import { EntityType } from '@shared/models/entity-type.models';
import { TranslateService } from '@ngx-translate/core';
import { BaseData, HasId } from '@shared/models/base-data';
export interface EntityNodeDatasource extends Datasource {
nodeId: string;
}
export function edgeGroupsNodeText(translate: TranslateService, entityType: EntityType): string {
const nodeIcon = materialIconByEntityType(entityType);
const nodeText = textForEdgeGroupsType(translate, entityType);
return nodeIcon + nodeText;
}
export function entityNodeText(entity: any): string {
const nodeIcon = materialIconByEntityType(entity.id.entityType);
const nodeText = entity.name;
return nodeIcon + nodeText;
}
export function materialIconByEntityType(entityType: EntityType): string {
let materialIcon = 'insert_drive_file';
switch (entityType) {
case EntityType.DEVICE:
materialIcon = 'devices_other';
break;
case EntityType.ASSET:
materialIcon = 'domain';
break;
case EntityType.DASHBOARD:
materialIcon = 'dashboards';
break;
case EntityType.ENTITY_VIEW:
materialIcon = 'view_quilt';
break;
case EntityType.RULE_CHAIN:
materialIcon = 'settings_ethernet';
break;
}
return '<mat-icon class="node-icon material-icons" role="img" aria-hidden="false">' + materialIcon + '</mat-icon>';
}
export function textForEdgeGroupsType(translate: TranslateService, entityType: EntityType): string {
let textForEdgeGroupsType: string = '';
switch (entityType) {
case EntityType.DEVICE:
textForEdgeGroupsType = 'device.devices';
break;
case EntityType.ASSET:
textForEdgeGroupsType = 'asset.assets';
break;
case EntityType.DASHBOARD:
textForEdgeGroupsType = 'dashboard.dashboards';
break;
case EntityType.ENTITY_VIEW:
textForEdgeGroupsType = 'entity-view.entity-views';
break;
case EntityType.RULE_CHAIN:
textForEdgeGroupsType = 'rulechain.rulechains';
break;
}
return translate.instant(textForEdgeGroupsType);
}
export const edgeGroupsTypes: EntityType[] = [
EntityType.ASSET,
EntityType.DEVICE,
EntityType.ENTITY_VIEW,
EntityType.DASHBOARD,
EntityType.RULE_CHAIN
]
export interface EdgeOverviewNode extends NavTreeNode {
data?: EdgeOverviewNodeData;
}
export type EdgeOverviewNodeData = EdgeGroupNodeData | EntityNodeData;
export interface EdgeGroupNodeData extends BaseEdgeOverviewNodeData {
entityType: EntityType;
entity: BaseData<HasId>;
}
export interface EntityNodeData extends BaseEdgeOverviewNodeData {
entity: BaseData<HasId>;
}
export interface BaseEdgeOverviewNodeData {
internalId: string;
}