rulechain-page.component.html
14.3 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
<!--
    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.
-->
<div class="mat-content tb-rulechain" fxFlex tb-fullscreen [fullscreen]="isFullscreen" [tb-hotkeys]="hotKeys"
     [cheatSheet]="cheatSheetComponent" fxLayout="column">
  <tb-hotkeys-cheatsheet #cheatSheetComponent></tb-hotkeys-cheatsheet>
  <section class="tb-rulechain-container" fxFlex fxLayout="column">
    <div class="tb-rulechain-layout" fxFlex fxLayout="row">
      <mat-drawer-container style="width: 100%; height: 100%;">
        <mat-drawer class="tb-rulechain-library mat-elevation-z4"
                    disableClose="true"
                    mode="side"
                    #drawer
                    opened
                    position="start"
                    fxLayout="column">
          <mat-toolbar color="primary" class="tb-dark">
            <tb-rule-chain-select
              fxFlex
              *ngIf="!isImport"
              [ruleChainType]="ruleChainType"
              [disabled]="isDirtyValue"
              [(ngModel)]="ruleChain"
              (ngModelChange)="currentRuleChainIdChanged(ruleChain.id?.id)">
            </tb-rule-chain-select>
          </mat-toolbar>
          <mat-toolbar>
            <div class="mat-toolbar-tools">
              <mat-form-field fxFlex class="tb-appearance-transparent">
                <button mat-icon-button matPrefix class="tb-small"
                        matTooltip="{{'rulenode.search' | translate}}"
                        matTooltipPosition="above">
                  <mat-icon>search</mat-icon>
                </button>
                <input matInput
                       [formControl]="ruleNodeTypeSearch"
                       placeholder="{{'rulenode.search' | translate}}"/>
                <button mat-icon-button matSuffix class="tb-small"
                        [fxShow]="ruleNodeTypeSearch.value !== ''"
                        (click)="ruleNodeTypeSearch.reset()"
                        matTooltip="{{'action.clear-search' | translate}}"
                        matTooltipPosition="above">
                  <mat-icon>close</mat-icon>
                </button>
              </mat-form-field>
            </div>
          </mat-toolbar>
          <div class="tb-rulechain-library-panel-group">
            <mat-expansion-panel #ruleNodeTypeExpansionPanels
                                 class="mat-elevation-z2"
                                 [expanded]="true" *ngFor="let ruleNodeType of ruleNodeTypesLibraryArray">
              <mat-expansion-panel-header expandedHeight="48px"
                                          (mouseenter)="typeHeaderMouseEnter($event, ruleNodeType)"
                                          (mouseleave)="destroyTooltips()">
                <mat-panel-title>
                  <mat-icon>{{ ruleNodeTypeDescriptorsMap.get(ruleNodeType).icon }}</mat-icon>
                  <div class="tb-panel-title" translate>{{ ruleNodeTypeDescriptorsMap.get(ruleNodeType).name }}</div>
                </mat-panel-title>
              </mat-expansion-panel-header>
              <fc-canvas id="tb-rulchain-{{ruleNodeType}}"
                         [model]="ruleNodeTypesModel[ruleNodeType].model"
                         [selectedObjects]="ruleNodeTypesModel[ruleNodeType].selectedObjects"
                         [automaticResize]="false"
                         fitModelSizeByDefault
                         [userCallbacks]="nodeLibCallbacks"
                         [nodeWidth]="170"
                         [nodeHeight]="50"
                         [dropTargetId]="'tb-rulchain-canvas'">
              </fc-canvas>
            </mat-expansion-panel>
          </div>
        </mat-drawer>
        <mat-drawer class="tb-details-drawer"
                    [opened]="isEditingRuleNode || isEditingRuleNodeLink"
                    (closed)="onDetailsDrawerClosed()"
                    mode="over"
                    position="end">
          <tb-details-panel *ngIf="editingRuleNode" fxFlex
                            headerTitle="{{editingRuleNode.name}}"
                            headerSubtitle="{{
                              (ruleNodeTypeDescriptorsMap.get(editingRuleNode.component.type).name | translate)
                              + ' - ' + editingRuleNode.component.name
                            }}"
                            [isReadOnly]="selectedRuleNodeTabIndex > 0"
                            [isAlwaysEdit]="true"
                            (closeDetails)="onEditRuleNodeClosed()"
                            (toggleDetailsEditMode)="onRevertRuleNodeEdit()"
                            (applyDetails)="saveRuleNode()"
                            [theForm]="tbRuleNode.ruleNodeFormGroup">
            <div class="details-buttons">
              <div [tb-help]="helpLinkIdForRuleNodeType()"></div>
            </div>
            <mat-tab-group fxFlex mat-stretch-tabs="false" class="tb-absolute-fill tb-rulenode-details" [(selectedIndex)]="selectedRuleNodeTabIndex">
              <mat-tab label="{{ 'rulenode.details' | translate }}">
                <tb-rule-node #tbRuleNode
                              [ruleNode]="editingRuleNode"
                              [ruleChainId]="ruleChain.id?.id"
                              [ruleChainType]="ruleChainType"
                              (initRuleNode)="onRuleNodeInit()"
                              (changeScript)="switchToFirstTab()">
                </tb-rule-node>
              </mat-tab>
              <mat-tab *ngIf="editingRuleNode.ruleNodeId" label="{{ 'rulenode.events' | translate }}" #eventsTab="matTab">
                <tb-event-table [debugEventTypes]="[debugEventTypes.DEBUG_RULE_NODE]"
                                [defaultEventType]="debugEventTypes.DEBUG_RULE_NODE"
                                [active]="eventsTab.isActive"
                                [tenantId]="ruleChain.tenantId.id"
                                [entityId]="editingRuleNode.ruleNodeId"
                                [functionTestButtonLabel]="ruleNodeTestButtonLabel"
                                (debugEventSelected)="onDebugEventSelected($event)">
                </tb-event-table>
              </mat-tab>
              <mat-tab label="{{ 'rulenode.help' | translate }}">
                <div class="tb-rule-node-help">
                  <div id="tb-node-content" class="mat-padding" fxLayout="column">
                    <div class="tb-node-title">{{editingRuleNode.component.name}}</div>
                    <div> </div>
                    <div class="tb-node-description" [innerHtml]="editingRuleNode.component.configurationDescriptor.nodeDefinition.description | safe: 'html'"></div>
                    <div> </div>
                    <div class="tb-node-details" [innerHtml]="editingRuleNode.component.configurationDescriptor.nodeDefinition.details | safe: 'html'"></div>
                  </div>
                </div>
              </mat-tab>
            </mat-tab-group>
          </tb-details-panel>
          <tb-details-panel *ngIf="editingRuleNodeLink" fxFlex
                            headerTitle="{{editingRuleNodeLink.label}}"
                            headerSubtitle="{{'rulenode.link-details' | translate}}"
                            [isReadOnly]="false"
                            [isAlwaysEdit]="true"
                            (closeDetails)="onEditRuleNodeLinkClosed()"
                            (toggleDetailsEditMode)="onRevertRuleNodeLinkEdit()"
                            (applyDetails)="saveRuleNodeLink()"
                            [theForm]="tbRuleNodeLink.ruleNodeLinkFormGroup">
            <div class="details-buttons">
              <div [tb-help]="'ruleEngine'"></div>
            </div>
            <tb-rule-node-link
              fxFlex
              #tbRuleNodeLink
              [(ngModel)]="editingRuleNodeLink"
              [allowedLabels]="editingRuleNodeLinkLabels"
              [allowCustom]="editingRuleNodeAllowCustomLabels"
              [sourceRuleChainId]="editingRuleNodeSourceRuleChainId">
            </tb-rule-node-link>
          </tb-details-panel>
        </mat-drawer>
        <mat-drawer-content class="tb-rulechain-graph-content">
          <button color="primary"
                  mat-mini-fab
                  class="tb-library-node-btn"
                  (click)="drawer.toggle();"
                  matTooltip="{{ (drawer.opened ? 'rulenode.close-node-library' : 'rulenode.open-node-library') | translate }}"
                  matTooltipPosition="above">
            <mat-icon class="tb-library-node-btn-icon" [ngClass]="{'tb-library-node-btn-icon-toggled' : drawer.opened}">chevron_right</mat-icon>
          </button>
          <button #versionControlButton
                  *ngIf="!isImport"
                  color="primary"
                  type="button"
                  mat-mini-fab class="version-control-button"
                  (click)="toggleVersionControl($event, versionControlButton)"
                  matTooltip="{{'version-control.version-control' | translate}}"
                  matTooltipPosition="above">
            <mat-icon>history</mat-icon>
          </button>
          <button type="button"
                  mat-icon-button class="tb-fullscreen-button tb-mat-40"
                  (click)="isFullscreen = !isFullscreen"
                  matTooltip="{{(isFullscreen ? 'fullscreen.exit' : 'fullscreen.expand') | translate}}"
                  matTooltipPosition="above">
            <mat-icon>{{ isFullscreen ? 'fullscreen_exit' : 'fullscreen' }}</mat-icon>
          </button>
          <div class="tb-absolute-fill tb-rulechain-graph" (contextmenu)="openRuleChainContextMenu($event)">
            <div #ruleChainMenuTrigger="matMenuTrigger" style="visibility: hidden; position: fixed"
                 [style.left]="ruleChainMenuPosition.x"
                 [style.top]="ruleChainMenuPosition.y"
                 [matMenuTriggerFor]="ruleChainMenu">
            </div>
            <mat-menu #ruleChainMenu="matMenu" class="tb-rule-chain-context-menu"
                      [overlapTrigger]="true">
              <ng-template matMenuContent let-contextInfo="contextInfo">
                <div class="tb-rule-chain-context-menu-container" (mouseleave)="onRuleChainContextMenuMouseLeave()">
                  <div class="tb-context-menu-header {{contextInfo.headerClass}}">
                    <mat-icon *ngIf="!contextInfo.iconUrl">{{contextInfo.icon}}</mat-icon>
                    <img *ngIf="contextInfo.iconUrl" [src]="contextInfo.iconUrl"/>
                    <div fxFlex>
                      <div class="tb-context-menu-title">{{contextInfo.title}}</div>
                      <div class="tb-context-menu-subtitle">{{contextInfo.subtitle}}</div>
                    </div>
                  </div>
                  <div *ngFor="let menuItem of contextInfo.menuItems">
                    <mat-divider *ngIf="menuItem.divider"></mat-divider>
                    <button *ngIf="!menuItem.divider"
                            mat-menu-item
                            [disabled]="!menuItem.enabled"
                            (click)="menuItem.action(contextMenuEvent)">
                      <span *ngIf="menuItem.shortcut" class="tb-alt-text"> {{ menuItem.shortcut | keyboardShortcut }}</span>
                      <mat-icon *ngIf="menuItem.icon">{{menuItem.icon}}</mat-icon>
                      <span translate>{{menuItem.value}}</span>
                    </button>
                  </div>
                </div>
              </ng-template>
            </mat-menu>
            <fc-canvas #ruleChainCanvas
                       id="tb-rulchain-canvas"
                       [model]="ruleChainModel"
                       (modelChanged)="onModelChanged()"
                       [selectedObjects]="selectedObjects"
                       [edgeStyle]="flowchartConstants.curvedStyle"
                       [automaticResize]="true"
                       fitModelSizeByDefault="false"
                       [nodeWidth]="170"
                       [nodeHeight]="50"
                       [dragAnimation]="flowchartConstants.dragAnimationRepaint"
                       [userCallbacks]="editCallbacks">
            </fc-canvas>
          </div>
          <section fxLayout="row" class="layout-wrap tb-footer-buttons" fxLayoutAlign="start end">
            <button [disabled]="isLoading$ | async"
                    mat-fab color="accent" class="tb-btn-footer"
                    [ngClass]="{'tb-hide': !objectsSelected()}"
                    (click)="deleteSelected()"
                    matTooltip="{{ 'rulenode.delete-selected-objects' | translate }}"
                    matTooltipPosition="above">
              <mat-icon>delete</mat-icon>
            </button>
            <button [disabled]="(isLoading$ | async) || !isDebugModeEnabled()"
                    mat-fab color="accent" class="tb-btn-footer"
                    (click)="resetDebugModeInAllNodes()"
                    matTooltip="{{ 'rulenode.reset-debug-mode' | translate }}"
                    matTooltipPosition="above">
              <mat-icon>bug_report</mat-icon>
            </button>
            <button [disabled]="(isLoading$ | async) || isInvalid || (!isDirtyValue && !isImport)"
                    mat-fab color="accent" class="tb-btn-footer"
                    (click)="saveRuleChain()"
                    matTooltip="{{ 'action.apply-changes' | translate }}"
                    matTooltipPosition="above">
              <mat-icon>done</mat-icon>
            </button>
            <button [disabled]="(isLoading$ | async) || !isDirtyValue"
                    mat-fab color="accent" class="tb-btn-footer"
                    (click)="revertRuleChain()"
                    matTooltip="{{ 'action.decline-changes' | translate }}"
                    matTooltipPosition="above">
              <mat-icon>close</mat-icon>
            </button>
          </section>
        </mat-drawer-content>
      </mat-drawer-container>
    </div>
  </section>
</div>