diff --git a/ui/src/app/api/edge.service.js b/ui/src/app/api/edge.service.js index 858dff3d18..7814e1d826 100644 --- a/ui/src/app/api/edge.service.js +++ b/ui/src/app/api/edge.service.js @@ -56,7 +56,7 @@ function EdgeService($http, $q, customerService) { deferred.reject(); }); return deferred.promise; - } // TODO: deaflynx: check usage in UI + } function getEdgesByIds(edgeIds, config) { var deferred = $q.defer(); diff --git a/ui/src/app/event/event-row-edge-event.tpl.html b/ui/src/app/event/event-row-edge-event.tpl.html index 7dea0aa804..0b088d8570 100644 --- a/ui/src/app/event/event-row-edge-event.tpl.html +++ b/ui/src/app/event/event-row-edge-event.tpl.html @@ -32,5 +32,5 @@ -
{{receiveStatus(event.createdTime)}}
+
{{updateStatus(event.createdTime)}}
diff --git a/ui/src/app/event/event-row.directive.js b/ui/src/app/event/event-row.directive.js index 2e4163d694..fd9756a697 100644 --- a/ui/src/app/event/event-row.directive.js +++ b/ui/src/app/event/event-row.directive.js @@ -27,12 +27,10 @@ import eventRowEdgeEventTemplate from './event-row-edge-event.tpl.html'; /*@ngInject*/ export default function EventRowDirective($compile, $templateCache, $mdDialog, $document, $translate, - types, toast, entityService, ruleChainService, userService, attributeService) { + types, toast, entityService, ruleChainService) { var linker = function (scope, element, attrs) { - var lastDisconnectTime; - var getTemplate = function(eventType) { var template = ''; switch(eventType) { @@ -52,7 +50,6 @@ export default function EventRowDirective($compile, $templateCache, $mdDialog, $ template = eventRowDebugRuleNodeTemplate; break; case types.eventType.edgeEvent.value: - getLastDisconnectTime(); template = eventRowEdgeEventTemplate; break; } @@ -138,25 +135,6 @@ export default function EventRowDirective($compile, $templateCache, $mdDialog, $ }); } - function getLastDisconnectTime() { - let params = { - entityType: types.entityType.edge, - entityId: scope.entityId, - attributeScope: types.attributesScope.server.value, - query: {order: '', limit: 1, page: 1, search: "active"} - }; - attributeService.getEntityAttributes(params.entityType, params.entityId, params.attributeScope, params.query, - function (attribute) { - if (attribute && attribute.data) { - lastDisconnectTime = attribute.data[0].lastUpdateTs; - } - }); - } - - scope.receiveStatus = function(eventCreatedTime) { - return (eventCreatedTime <= lastDisconnectTime) ? $translate.instant('event.success') : $translate.instant('event.failed'); - } - scope.checkTooltip = function($event) { var el = $event.target; var $el = angular.element(el); @@ -166,6 +144,12 @@ export default function EventRowDirective($compile, $templateCache, $mdDialog, $ } $compile(element.contents())(scope); + + scope.updateStatus = function(eventCreatedTime) { + if (scope.queueStartTs) { + return (eventCreatedTime < scope.queueStartTs) ? $translate.instant('event.success') : $translate.instant('event.failed'); + } + } } return { diff --git a/ui/src/app/event/event-table.directive.js b/ui/src/app/event/event-table.directive.js index 4e8ae226b7..df300dd8e1 100644 --- a/ui/src/app/event/event-table.directive.js +++ b/ui/src/app/event/event-table.directive.js @@ -22,7 +22,8 @@ import eventTableTemplate from './event-table.tpl.html'; /* eslint-enable import/no-unresolved, import/default */ /*@ngInject*/ -export default function EventTableDirective($compile, $templateCache, $rootScope, types, eventService, edgeService) { +export default function EventTableDirective($compile, $templateCache, $rootScope, types, eventService, edgeService, + attributeService) { var linker = function (scope, element, attrs) { @@ -106,6 +107,7 @@ export default function EventTableDirective($compile, $templateCache, $rootScope scope.eventType, scope.tenantId, scope.events.nextPageLink); } else { promise = edgeService.getEdgeEvents(scope.entityId, scope.events.nextPageLink); + scope.loadEdgeInfo(); } if (promise) { scope.events.pending = true; @@ -135,6 +137,7 @@ export default function EventTableDirective($compile, $templateCache, $rootScope scope.$watch("entityId", function(newVal, prevVal) { if (newVal && !angular.equals(newVal, prevVal)) { + scope.loadEdgeInfo(); scope.resetFilter(); scope.reload(); } @@ -212,6 +215,53 @@ export default function EventTableDirective($compile, $templateCache, $rootScope return false; } + scope.subscriptionId = null; + scope.queueStartTs; + + scope.loadEdgeInfo = function() { + attributeService.getEntityAttributesValues(scope.entityType, scope.entityId, types.attributesScope.server.value, + ["queueStartTs"], {}) + .then(function success(attributes) { + scope.onUpdate(attributes); + }); + + scope.checkSubscription(); + + attributeService.getEntityAttributes(scope.entityType, scope.entityId, types.attributesScope.server.value, {order: '', limit: 1, page: 1, search: ''}, + function (attributes) { + if (attributes && attributes.data) { + scope.onUpdate(attributes.data); + } + }); + } + + scope.onUpdate = function(attributes) { + let edge = attributes.reduce(function (map, attribute) { + map[attribute.key] = attribute; + return map; + }, {}); + if (edge.queueStartTs) { + scope.queueStartTs = edge.queueStartTs.lastUpdateTs; + } + } + + scope.checkSubscription = function() { + var newSubscriptionId = null; + if (scope.entityId && scope.entityType && types.attributesScope.server.value) { + newSubscriptionId = attributeService.subscribeForEntityAttributes(scope.entityType, scope.entityId, types.attributesScope.server.value); + } + if (scope.subscriptionId && scope.subscriptionId != newSubscriptionId) { + attributeService.unsubscribeForEntityAttributes(scope.subscriptionId); + } + scope.subscriptionId = newSubscriptionId; + } + + scope.$on('$destroy', function () { + if (scope.subscriptionId) { + attributeService.unsubscribeForEntityAttributes(scope.subscriptionId); + } + }); + scope.reload(); $compile(element.contents())(scope);