Showing
1 changed file
with
190 additions
and
193 deletions
1 | -/* | ||
2 | - * Copyright © 2016-2020 The Thingsboard Authors | ||
3 | - * | ||
4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | - * you may not use this file except in compliance with the License. | ||
6 | - * You may obtain a copy of the License at | ||
7 | - * | ||
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | - * | ||
10 | - * Unless required by applicable law or agreed to in writing, software | ||
11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | - * See the License for the specific language governing permissions and | ||
14 | - * limitations under the License. | ||
15 | - */ | ||
16 | -/* eslint-disable import/no-unresolved, import/default */ | ||
17 | - | ||
18 | -import eventErrorDialogTemplate from './event-content-dialog.tpl.html'; | ||
19 | - | ||
20 | -import eventRowLcEventTemplate from './event-row-lc-event.tpl.html'; | ||
21 | -import eventRowStatsTemplate from './event-row-stats.tpl.html'; | ||
22 | -import eventRowErrorTemplate from './event-row-error.tpl.html'; | ||
23 | -import eventRowDebugRuleNodeTemplate from './event-row-debug-rulenode.tpl.html'; | ||
24 | -import eventRowEdgeEventTemplate from './event-row-edge-event.tpl.html'; | ||
25 | - | ||
26 | -/* eslint-enable import/no-unresolved, import/default */ | ||
27 | - | ||
28 | -/*@ngInject*/ | ||
29 | -export default function EventRowDirective($compile, $templateCache, $mdDialog, $document, $translate, | ||
30 | - types, utils, toast, entityService, ruleChainService) { | ||
31 | - | ||
32 | - var linker = function (scope, element, attrs) { | ||
33 | - | ||
34 | - var getTemplate = function(eventType) { | ||
35 | - var template = ''; | ||
36 | - switch(eventType) { | ||
37 | - case types.eventType.lcEvent.value: | ||
38 | - template = eventRowLcEventTemplate; | ||
39 | - break; | ||
40 | - case types.eventType.stats.value: | ||
41 | - template = eventRowStatsTemplate; | ||
42 | - break; | ||
43 | - case types.eventType.error.value: | ||
44 | - template = eventRowErrorTemplate; | ||
45 | - break; | ||
46 | - case types.debugEventType.debugRuleNode.value: | ||
47 | - template = eventRowDebugRuleNodeTemplate; | ||
48 | - break; | ||
49 | - case types.debugEventType.debugRuleChain.value: | ||
50 | - template = eventRowDebugRuleNodeTemplate; | ||
51 | - break; | ||
52 | - case types.eventType.edgeEvent.value: | ||
53 | - template = eventRowEdgeEventTemplate; | ||
54 | - break; | ||
55 | - } | ||
56 | - return $templateCache.get(template); | ||
57 | - } | ||
58 | - | ||
59 | - scope.loadTemplate = function() { | ||
60 | - element.html(getTemplate(attrs.eventType)); | ||
61 | - $compile(element.contents())(scope); | ||
62 | - } | ||
63 | - | ||
64 | - attrs.$observe('eventType', function() { | ||
65 | - scope.loadTemplate(); | ||
66 | - }); | ||
67 | - | ||
68 | - scope.types = types; | ||
69 | - | ||
70 | - scope.event = attrs.event; | ||
71 | - | ||
72 | - scope.showContent = function($event, content, title, contentType) { | ||
73 | - var onShowingCallback = { | ||
74 | - onShowing: function(){} | ||
75 | - } | ||
76 | - if (!contentType) { | ||
77 | - contentType = null; | ||
78 | - } | ||
79 | - var sortedContent; | ||
80 | - try { | ||
81 | - sortedContent = angular.toJson(utils.sortObjectKeys(angular.fromJson(content))); | ||
82 | - } | ||
83 | - catch(err) { | ||
84 | - sortedContent = content; | ||
85 | - } | ||
86 | - $mdDialog.show({ | ||
87 | - controller: 'EventContentDialogController', | ||
88 | - controllerAs: 'vm', | ||
89 | - templateUrl: eventErrorDialogTemplate, | ||
90 | - locals: {content: sortedContent, title: title, contentType: contentType, showingCallback: onShowingCallback}, | ||
91 | - parent: angular.element($document[0].body), | ||
92 | - fullscreen: true, | ||
93 | - targetEvent: $event, | ||
94 | - multiple: true, | ||
95 | - onShowing: function(scope, element) { | ||
96 | - onShowingCallback.onShowing(scope, element); | ||
97 | - } | ||
98 | - }); | ||
99 | - } | ||
100 | - | ||
101 | - scope.showEdgeEntityContent = function($event, title, contentType) { | ||
102 | - var onShowingCallback = { | ||
103 | - onShowing: function(){} | ||
104 | - } | ||
105 | - if (!contentType) { | ||
106 | - contentType = null; | ||
107 | - } | ||
108 | - var content = ''; | ||
109 | - switch(scope.event.type) { | ||
110 | - case types.edgeEventType.relation: | ||
111 | - case types.edgeEventType.whiteLabeling: | ||
112 | - case types.edgeEventType.loginWhiteLabeling: | ||
113 | - case types.edgeEventType.customTranslation: | ||
114 | - content = angular.toJson(scope.event.body); | ||
115 | - showDialog(); | ||
116 | - break; | ||
117 | - case types.edgeEventType.ruleChainMetaData: | ||
118 | - content = ruleChainService.getRuleChainMetaData(scope.event.entityId, {ignoreErrors: true}).then( | ||
119 | - function success(info) { | ||
120 | - showDialog(); | ||
121 | - return angular.toJson(info); | ||
122 | - }, function fail() { | ||
123 | - showError(); | ||
124 | - }); | ||
125 | - break; | ||
126 | - default: | ||
127 | - content = entityService.getEntity(scope.event.type, scope.event.entityId, {ignoreErrors: true}).then( | ||
128 | - function success(info) { | ||
129 | - showDialog(); | ||
130 | - return angular.toJson(info); | ||
131 | - }, function fail() { | ||
132 | - showError(); | ||
133 | - }); | ||
134 | - break; | ||
135 | - } | ||
136 | - function showDialog() { | ||
137 | - $mdDialog.show({ | ||
138 | - controller: 'EventContentDialogController', | ||
139 | - controllerAs: 'vm', | ||
140 | - templateUrl: eventErrorDialogTemplate, | ||
141 | - locals: {content: content, title: title, contentType: contentType, showingCallback: onShowingCallback}, | ||
142 | - parent: angular.element($document[0].body), | ||
143 | - fullscreen: true, | ||
144 | - targetEvent: $event, | ||
145 | - multiple: true, | ||
146 | - onShowing: function(scope, element) { | ||
147 | - onShowingCallback.onShowing(scope, element); | ||
148 | - } | ||
149 | - }); | ||
150 | - } | ||
151 | - function showError() { | ||
152 | - toast.showError($translate.instant('edge.load-entity-error')); | ||
153 | - } | ||
154 | - } | ||
155 | - | ||
156 | - scope.checkEdgeEventType = function (edgeEventType) { | ||
157 | - return !(edgeEventType === types.edgeEventType.widgetType || | ||
158 | - edgeEventType === types.edgeEventType.adminSettings || | ||
159 | - edgeEventType === types.edgeEventType.widgetsBundle ); | ||
160 | - } | ||
161 | - | ||
162 | - scope.checkTooltip = function($event) { | ||
163 | - var el = $event.target; | ||
164 | - var $el = angular.element(el); | ||
165 | - if(el.offsetWidth < el.scrollWidth && !$el.attr('title')){ | ||
166 | - $el.attr('title', $el.text()); | ||
167 | - } | ||
168 | - } | ||
169 | - | ||
170 | - $compile(element.contents())(scope); | ||
171 | - | ||
172 | - scope.updateStatus = function(eventCreatedTime) { | ||
173 | - if (scope.queueStartTs) { | ||
174 | - var status; | ||
175 | - if (eventCreatedTime < scope.queueStartTs) { | ||
176 | - status = $translate.instant('edge.success'); | ||
177 | - scope.isPending = false; | ||
178 | - } else { | ||
179 | - status = $translate.instant('edge.failed'); | ||
180 | - scope.isPending = true; | ||
181 | - } | ||
182 | - return status; | ||
183 | - } | ||
184 | - } | ||
185 | - } | ||
186 | - | ||
187 | - return { | ||
188 | - restrict: "A", | ||
189 | - replace: false, | ||
190 | - link: linker, | ||
191 | - scope: false | ||
192 | - }; | ||
193 | -} | 1 | +/* |
2 | + * Copyright © 2016-2020 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +/* eslint-disable import/no-unresolved, import/default */ | ||
17 | + | ||
18 | +import eventErrorDialogTemplate from './event-content-dialog.tpl.html'; | ||
19 | + | ||
20 | +import eventRowLcEventTemplate from './event-row-lc-event.tpl.html'; | ||
21 | +import eventRowStatsTemplate from './event-row-stats.tpl.html'; | ||
22 | +import eventRowErrorTemplate from './event-row-error.tpl.html'; | ||
23 | +import eventRowDebugRuleNodeTemplate from './event-row-debug-rulenode.tpl.html'; | ||
24 | +import eventRowEdgeEventTemplate from './event-row-edge-event.tpl.html'; | ||
25 | + | ||
26 | +/* eslint-enable import/no-unresolved, import/default */ | ||
27 | + | ||
28 | +/*@ngInject*/ | ||
29 | +export default function EventRowDirective($compile, $templateCache, $mdDialog, $document, $translate, | ||
30 | + types, utils, toast, entityService, ruleChainService) { | ||
31 | + | ||
32 | + var linker = function (scope, element, attrs) { | ||
33 | + | ||
34 | + var getTemplate = function(eventType) { | ||
35 | + var template = ''; | ||
36 | + switch(eventType) { | ||
37 | + case types.eventType.lcEvent.value: | ||
38 | + template = eventRowLcEventTemplate; | ||
39 | + break; | ||
40 | + case types.eventType.stats.value: | ||
41 | + template = eventRowStatsTemplate; | ||
42 | + break; | ||
43 | + case types.eventType.error.value: | ||
44 | + template = eventRowErrorTemplate; | ||
45 | + break; | ||
46 | + case types.debugEventType.debugRuleNode.value: | ||
47 | + template = eventRowDebugRuleNodeTemplate; | ||
48 | + break; | ||
49 | + case types.debugEventType.debugRuleChain.value: | ||
50 | + template = eventRowDebugRuleNodeTemplate; | ||
51 | + break; | ||
52 | + case types.eventType.edgeEvent.value: | ||
53 | + template = eventRowEdgeEventTemplate; | ||
54 | + break; | ||
55 | + } | ||
56 | + return $templateCache.get(template); | ||
57 | + } | ||
58 | + | ||
59 | + scope.loadTemplate = function() { | ||
60 | + element.html(getTemplate(attrs.eventType)); | ||
61 | + $compile(element.contents())(scope); | ||
62 | + } | ||
63 | + | ||
64 | + attrs.$observe('eventType', function() { | ||
65 | + scope.loadTemplate(); | ||
66 | + }); | ||
67 | + | ||
68 | + scope.types = types; | ||
69 | + | ||
70 | + scope.event = attrs.event; | ||
71 | + | ||
72 | + scope.showContent = function($event, content, title, contentType) { | ||
73 | + var onShowingCallback = { | ||
74 | + onShowing: function(){} | ||
75 | + } | ||
76 | + if (!contentType) { | ||
77 | + contentType = null; | ||
78 | + } | ||
79 | + var sortedContent; | ||
80 | + try { | ||
81 | + sortedContent = angular.toJson(utils.sortObjectKeys(angular.fromJson(content))); | ||
82 | + } | ||
83 | + catch(err) { | ||
84 | + sortedContent = content; | ||
85 | + } | ||
86 | + $mdDialog.show({ | ||
87 | + controller: 'EventContentDialogController', | ||
88 | + controllerAs: 'vm', | ||
89 | + templateUrl: eventErrorDialogTemplate, | ||
90 | + locals: {content: sortedContent, title: title, contentType: contentType, showingCallback: onShowingCallback}, | ||
91 | + parent: angular.element($document[0].body), | ||
92 | + fullscreen: true, | ||
93 | + targetEvent: $event, | ||
94 | + multiple: true, | ||
95 | + onShowing: function(scope, element) { | ||
96 | + onShowingCallback.onShowing(scope, element); | ||
97 | + } | ||
98 | + }); | ||
99 | + } | ||
100 | + | ||
101 | + scope.showEdgeEntityContent = function($event, title, contentType) { | ||
102 | + var onShowingCallback = { | ||
103 | + onShowing: function(){} | ||
104 | + } | ||
105 | + if (!contentType) { | ||
106 | + contentType = null; | ||
107 | + } | ||
108 | + var content = ''; | ||
109 | + switch(scope.event.type) { | ||
110 | + case types.edgeEventType.relation: | ||
111 | + content = angular.toJson(scope.event.body); | ||
112 | + showDialog(); | ||
113 | + break; | ||
114 | + case types.edgeEventType.ruleChainMetaData: | ||
115 | + content = ruleChainService.getRuleChainMetaData(scope.event.entityId, {ignoreErrors: true}).then( | ||
116 | + function success(info) { | ||
117 | + showDialog(); | ||
118 | + return angular.toJson(info); | ||
119 | + }, function fail() { | ||
120 | + showError(); | ||
121 | + }); | ||
122 | + break; | ||
123 | + default: | ||
124 | + content = entityService.getEntity(scope.event.type, scope.event.entityId, {ignoreErrors: true}).then( | ||
125 | + function success(info) { | ||
126 | + showDialog(); | ||
127 | + return angular.toJson(info); | ||
128 | + }, function fail() { | ||
129 | + showError(); | ||
130 | + }); | ||
131 | + break; | ||
132 | + } | ||
133 | + function showDialog() { | ||
134 | + $mdDialog.show({ | ||
135 | + controller: 'EventContentDialogController', | ||
136 | + controllerAs: 'vm', | ||
137 | + templateUrl: eventErrorDialogTemplate, | ||
138 | + locals: {content: content, title: title, contentType: contentType, showingCallback: onShowingCallback}, | ||
139 | + parent: angular.element($document[0].body), | ||
140 | + fullscreen: true, | ||
141 | + targetEvent: $event, | ||
142 | + multiple: true, | ||
143 | + onShowing: function(scope, element) { | ||
144 | + onShowingCallback.onShowing(scope, element); | ||
145 | + } | ||
146 | + }); | ||
147 | + } | ||
148 | + function showError() { | ||
149 | + toast.showError($translate.instant('edge.load-entity-error')); | ||
150 | + } | ||
151 | + } | ||
152 | + | ||
153 | + scope.checkEdgeEventType = function (edgeEventType) { | ||
154 | + return !(edgeEventType === types.edgeEventType.widgetType || | ||
155 | + edgeEventType === types.edgeEventType.adminSettings || | ||
156 | + edgeEventType === types.edgeEventType.widgetsBundle ); | ||
157 | + } | ||
158 | + | ||
159 | + scope.checkTooltip = function($event) { | ||
160 | + var el = $event.target; | ||
161 | + var $el = angular.element(el); | ||
162 | + if(el.offsetWidth < el.scrollWidth && !$el.attr('title')){ | ||
163 | + $el.attr('title', $el.text()); | ||
164 | + } | ||
165 | + } | ||
166 | + | ||
167 | + $compile(element.contents())(scope); | ||
168 | + | ||
169 | + scope.updateStatus = function(eventCreatedTime) { | ||
170 | + if (scope.queueStartTs) { | ||
171 | + var status; | ||
172 | + if (eventCreatedTime < scope.queueStartTs) { | ||
173 | + status = $translate.instant('edge.success'); | ||
174 | + scope.isPending = false; | ||
175 | + } else { | ||
176 | + status = $translate.instant('edge.failed'); | ||
177 | + scope.isPending = true; | ||
178 | + } | ||
179 | + return status; | ||
180 | + } | ||
181 | + } | ||
182 | + } | ||
183 | + | ||
184 | + return { | ||
185 | + restrict: "A", | ||
186 | + replace: false, | ||
187 | + link: linker, | ||
188 | + scope: false | ||
189 | + }; | ||
190 | +} |