edge-downlinks-row.directive.js
4.78 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
/*
* Copyright © 2016-2020 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.
*/
/* eslint-disable import/no-unresolved, import/default */
import edgeDownlinksContentTemplate from './edge-downlinks-content-dialog.tpl.html';
import edgeDownlinlsRowTemplate from './edge-downlinks-row.tpl.html';
/* eslint-enable import/no-unresolved, import/default */
/*@ngInject*/
export default function EdgeDownlinksRowDirective($compile, $templateCache, $mdDialog, $document, $translate,
types, utils, toast, entityService, ruleChainService) {
var linker = function (scope, element, attrs) {
var template = edgeDownlinlsRowTemplate;
element.html($templateCache.get(template));
$compile(element.contents())(scope);
scope.types = types;
scope.downlink = attrs.downlink;
scope.showEdgeEntityContent = function($event, title, contentType) {
var onShowingCallback = {
onShowing: function(){}
}
if (!contentType) {
contentType = null;
}
var content = '';
switch(scope.downlink.type) {
case types.edgeEventType.relation:
content = angular.toJson(scope.downlink.body);
showDialog();
break;
case types.edgeEventType.ruleChainMetaData:
content = ruleChainService.getRuleChainMetaData(scope.downlink.entityId, {ignoreErrors: true}).then(
function success(info) {
showDialog();
return angular.toJson(info);
}, function fail() {
showError();
});
break;
default:
content = entityService.getEntity(scope.downlink.type, scope.downlink.entityId, {ignoreErrors: true}).then(
function success(info) {
showDialog();
return angular.toJson(info);
}, function fail() {
showError();
});
break;
}
function showDialog() {
$mdDialog.show({
controller: 'EdgeDownlinksContentDialogController',
controllerAs: 'vm',
templateUrl: edgeDownlinksContentTemplate,
locals: {content: content, title: title, contentType: contentType, showingCallback: onShowingCallback},
parent: angular.element($document[0].body),
fullscreen: true,
targetEvent: $event,
multiple: true,
onShowing: function(scope, element) {
onShowingCallback.onShowing(scope, element);
}
});
}
function showError() {
toast.showError($translate.instant('edge.load-entity-error'));
}
}
scope.checkEdgeDownlinksType = function (type) {
return !(type === types.edgeEventType.widgetType ||
type === types.edgeEventType.adminSettings ||
type === types.edgeEventType.widgetsBundle );
}
scope.checkTooltip = function($event) {
var el = $event.target;
var $el = angular.element(el);
if(el.offsetWidth < el.scrollWidth && !$el.attr('title')){
$el.attr('title', $el.text());
}
}
$compile(element.contents())(scope);
scope.updateStatus = function(downlinkCreatedTime) {
var status;
if (downlinkCreatedTime < scope.queueStartTs) {
status = $translate.instant(types.edgeEventStatus.DEPLOYED.name);
scope.statusColor = types.edgeEventStatus.DEPLOYED.color;
} else {
status = $translate.instant(types.edgeEventStatus.PENDING.name);
scope.statusColor = types.edgeEventStatus.PENDING.color;
}
return status;
}
}
return {
restrict: "A",
replace: false,
link: linker,
scope: false
};
}