Edge Events Status Update

This commit is contained in:
deaflynx 2020-07-13 17:13:18 +03:00
parent df62957780
commit 5ab81b98a6
4 changed files with 60 additions and 26 deletions

View File

@ -56,7 +56,7 @@ function EdgeService($http, $q, customerService) {
deferred.reject(); deferred.reject();
}); });
return deferred.promise; return deferred.promise;
} // TODO: deaflynx: check usage in UI }
function getEdgesByIds(edgeIds, config) { function getEdgesByIds(edgeIds, config) {
var deferred = $q.defer(); var deferred = $q.defer();

View File

@ -32,5 +32,5 @@
</md-icon> </md-icon>
</md-button> </md-button>
</div> </div>
<div class="tb-cell" flex="20">{{receiveStatus(event.createdTime)}}</div> <div class="tb-cell" flex="20">{{updateStatus(event.createdTime)}}</div>

View File

@ -27,12 +27,10 @@ import eventRowEdgeEventTemplate from './event-row-edge-event.tpl.html';
/*@ngInject*/ /*@ngInject*/
export default function EventRowDirective($compile, $templateCache, $mdDialog, $document, $translate, 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 linker = function (scope, element, attrs) {
var lastDisconnectTime;
var getTemplate = function(eventType) { var getTemplate = function(eventType) {
var template = ''; var template = '';
switch(eventType) { switch(eventType) {
@ -52,7 +50,6 @@ export default function EventRowDirective($compile, $templateCache, $mdDialog, $
template = eventRowDebugRuleNodeTemplate; template = eventRowDebugRuleNodeTemplate;
break; break;
case types.eventType.edgeEvent.value: case types.eventType.edgeEvent.value:
getLastDisconnectTime();
template = eventRowEdgeEventTemplate; template = eventRowEdgeEventTemplate;
break; 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) { scope.checkTooltip = function($event) {
var el = $event.target; var el = $event.target;
var $el = angular.element(el); var $el = angular.element(el);
@ -166,6 +144,12 @@ export default function EventRowDirective($compile, $templateCache, $mdDialog, $
} }
$compile(element.contents())(scope); $compile(element.contents())(scope);
scope.updateStatus = function(eventCreatedTime) {
if (scope.queueStartTs) {
return (eventCreatedTime < scope.queueStartTs) ? $translate.instant('event.success') : $translate.instant('event.failed');
}
}
} }
return { return {

View File

@ -22,7 +22,8 @@ import eventTableTemplate from './event-table.tpl.html';
/* eslint-enable import/no-unresolved, import/default */ /* eslint-enable import/no-unresolved, import/default */
/*@ngInject*/ /*@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) { var linker = function (scope, element, attrs) {
@ -106,6 +107,7 @@ export default function EventTableDirective($compile, $templateCache, $rootScope
scope.eventType, scope.tenantId, scope.events.nextPageLink); scope.eventType, scope.tenantId, scope.events.nextPageLink);
} else { } else {
promise = edgeService.getEdgeEvents(scope.entityId, scope.events.nextPageLink); promise = edgeService.getEdgeEvents(scope.entityId, scope.events.nextPageLink);
scope.loadEdgeInfo();
} }
if (promise) { if (promise) {
scope.events.pending = true; scope.events.pending = true;
@ -135,6 +137,7 @@ export default function EventTableDirective($compile, $templateCache, $rootScope
scope.$watch("entityId", function(newVal, prevVal) { scope.$watch("entityId", function(newVal, prevVal) {
if (newVal && !angular.equals(newVal, prevVal)) { if (newVal && !angular.equals(newVal, prevVal)) {
scope.loadEdgeInfo();
scope.resetFilter(); scope.resetFilter();
scope.reload(); scope.reload();
} }
@ -212,6 +215,53 @@ export default function EventTableDirective($compile, $templateCache, $rootScope
return false; 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(); scope.reload();
$compile(element.contents())(scope); $compile(element.contents())(scope);