Edge Events Status Update
This commit is contained in:
parent
df62957780
commit
5ab81b98a6
@ -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();
|
||||
|
||||
@ -32,5 +32,5 @@
|
||||
</md-icon>
|
||||
</md-button>
|
||||
</div>
|
||||
<div class="tb-cell" flex="20">{{receiveStatus(event.createdTime)}}</div>
|
||||
<div class="tb-cell" flex="20">{{updateStatus(event.createdTime)}}</div>
|
||||
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user