Commit 5ab81b98a6c5f53d8691cd811c4d23b5fdd573cc

Authored by deaflynx
1 parent df629577

Edge Events Status Update

... ... @@ -56,7 +56,7 @@ function EdgeService($http, $q, customerService) {
56 56 deferred.reject();
57 57 });
58 58 return deferred.promise;
59   - } // TODO: deaflynx: check usage in UI
  59 + }
60 60
61 61 function getEdgesByIds(edgeIds, config) {
62 62 var deferred = $q.defer();
... ...
... ... @@ -32,5 +32,5 @@
32 32 </md-icon>
33 33 </md-button>
34 34 </div>
35   -<div class="tb-cell" flex="20">{{receiveStatus(event.createdTime)}}</div>
  35 +<div class="tb-cell" flex="20">{{updateStatus(event.createdTime)}}</div>
36 36
... ...
... ... @@ -27,12 +27,10 @@ import eventRowEdgeEventTemplate from './event-row-edge-event.tpl.html';
27 27
28 28 /*@ngInject*/
29 29 export default function EventRowDirective($compile, $templateCache, $mdDialog, $document, $translate,
30   - types, toast, entityService, ruleChainService, userService, attributeService) {
  30 + types, toast, entityService, ruleChainService) {
31 31
32 32 var linker = function (scope, element, attrs) {
33 33
34   - var lastDisconnectTime;
35   -
36 34 var getTemplate = function(eventType) {
37 35 var template = '';
38 36 switch(eventType) {
... ... @@ -52,7 +50,6 @@ export default function EventRowDirective($compile, $templateCache, $mdDialog, $
52 50 template = eventRowDebugRuleNodeTemplate;
53 51 break;
54 52 case types.eventType.edgeEvent.value:
55   - getLastDisconnectTime();
56 53 template = eventRowEdgeEventTemplate;
57 54 break;
58 55 }
... ... @@ -138,25 +135,6 @@ export default function EventRowDirective($compile, $templateCache, $mdDialog, $
138 135 });
139 136 }
140 137
141   - function getLastDisconnectTime() {
142   - let params = {
143   - entityType: types.entityType.edge,
144   - entityId: scope.entityId,
145   - attributeScope: types.attributesScope.server.value,
146   - query: {order: '', limit: 1, page: 1, search: "active"}
147   - };
148   - attributeService.getEntityAttributes(params.entityType, params.entityId, params.attributeScope, params.query,
149   - function (attribute) {
150   - if (attribute && attribute.data) {
151   - lastDisconnectTime = attribute.data[0].lastUpdateTs;
152   - }
153   - });
154   - }
155   -
156   - scope.receiveStatus = function(eventCreatedTime) {
157   - return (eventCreatedTime <= lastDisconnectTime) ? $translate.instant('event.success') : $translate.instant('event.failed');
158   - }
159   -
160 138 scope.checkTooltip = function($event) {
161 139 var el = $event.target;
162 140 var $el = angular.element(el);
... ... @@ -166,6 +144,12 @@ export default function EventRowDirective($compile, $templateCache, $mdDialog, $
166 144 }
167 145
168 146 $compile(element.contents())(scope);
  147 +
  148 + scope.updateStatus = function(eventCreatedTime) {
  149 + if (scope.queueStartTs) {
  150 + return (eventCreatedTime < scope.queueStartTs) ? $translate.instant('event.success') : $translate.instant('event.failed');
  151 + }
  152 + }
169 153 }
170 154
171 155 return {
... ...
... ... @@ -22,7 +22,8 @@ import eventTableTemplate from './event-table.tpl.html';
22 22 /* eslint-enable import/no-unresolved, import/default */
23 23
24 24 /*@ngInject*/
25   -export default function EventTableDirective($compile, $templateCache, $rootScope, types, eventService, edgeService) {
  25 +export default function EventTableDirective($compile, $templateCache, $rootScope, types, eventService, edgeService,
  26 + attributeService) {
26 27
27 28 var linker = function (scope, element, attrs) {
28 29
... ... @@ -106,6 +107,7 @@ export default function EventTableDirective($compile, $templateCache, $rootScope
106 107 scope.eventType, scope.tenantId, scope.events.nextPageLink);
107 108 } else {
108 109 promise = edgeService.getEdgeEvents(scope.entityId, scope.events.nextPageLink);
  110 + scope.loadEdgeInfo();
109 111 }
110 112 if (promise) {
111 113 scope.events.pending = true;
... ... @@ -135,6 +137,7 @@ export default function EventTableDirective($compile, $templateCache, $rootScope
135 137
136 138 scope.$watch("entityId", function(newVal, prevVal) {
137 139 if (newVal && !angular.equals(newVal, prevVal)) {
  140 + scope.loadEdgeInfo();
138 141 scope.resetFilter();
139 142 scope.reload();
140 143 }
... ... @@ -212,6 +215,53 @@ export default function EventTableDirective($compile, $templateCache, $rootScope
212 215 return false;
213 216 }
214 217
  218 + scope.subscriptionId = null;
  219 + scope.queueStartTs;
  220 +
  221 + scope.loadEdgeInfo = function() {
  222 + attributeService.getEntityAttributesValues(scope.entityType, scope.entityId, types.attributesScope.server.value,
  223 + ["queueStartTs"], {})
  224 + .then(function success(attributes) {
  225 + scope.onUpdate(attributes);
  226 + });
  227 +
  228 + scope.checkSubscription();
  229 +
  230 + attributeService.getEntityAttributes(scope.entityType, scope.entityId, types.attributesScope.server.value, {order: '', limit: 1, page: 1, search: ''},
  231 + function (attributes) {
  232 + if (attributes && attributes.data) {
  233 + scope.onUpdate(attributes.data);
  234 + }
  235 + });
  236 + }
  237 +
  238 + scope.onUpdate = function(attributes) {
  239 + let edge = attributes.reduce(function (map, attribute) {
  240 + map[attribute.key] = attribute;
  241 + return map;
  242 + }, {});
  243 + if (edge.queueStartTs) {
  244 + scope.queueStartTs = edge.queueStartTs.lastUpdateTs;
  245 + }
  246 + }
  247 +
  248 + scope.checkSubscription = function() {
  249 + var newSubscriptionId = null;
  250 + if (scope.entityId && scope.entityType && types.attributesScope.server.value) {
  251 + newSubscriptionId = attributeService.subscribeForEntityAttributes(scope.entityType, scope.entityId, types.attributesScope.server.value);
  252 + }
  253 + if (scope.subscriptionId && scope.subscriptionId != newSubscriptionId) {
  254 + attributeService.unsubscribeForEntityAttributes(scope.subscriptionId);
  255 + }
  256 + scope.subscriptionId = newSubscriptionId;
  257 + }
  258 +
  259 + scope.$on('$destroy', function () {
  260 + if (scope.subscriptionId) {
  261 + attributeService.unsubscribeForEntityAttributes(scope.subscriptionId);
  262 + }
  263 + });
  264 +
215 265 scope.reload();
216 266
217 267 $compile(element.contents())(scope);
... ...