Commit 1545a8cd762cff70428dcb1ba0b502c0b67c488e

Authored by deaflynx
1 parent 5ac2ca3a

Fixed EDGE_EVENT events fetch by edgeId

@@ -32,7 +32,8 @@ function EdgeService($http, $q, customerService) { @@ -32,7 +32,8 @@ function EdgeService($http, $q, customerService) {
32 assignEdgeToCustomer: assignEdgeToCustomer, 32 assignEdgeToCustomer: assignEdgeToCustomer,
33 unassignEdgeFromCustomer: unassignEdgeFromCustomer, 33 unassignEdgeFromCustomer: unassignEdgeFromCustomer,
34 makeEdgePublic: makeEdgePublic, 34 makeEdgePublic: makeEdgePublic,
35 - setRootRuleChain: setRootRuleChain 35 + setRootRuleChain: setRootRuleChain,
  36 + getEdgeEvents: getEdgeEvents
36 }; 37 };
37 38
38 return service; 39 return service;
@@ -241,4 +242,24 @@ function EdgeService($http, $q, customerService) { @@ -241,4 +242,24 @@ function EdgeService($http, $q, customerService) {
241 }); 242 });
242 return deferred.promise; 243 return deferred.promise;
243 } 244 }
  245 +
  246 + function getEdgeEvents(edgeId, pageLink) {
  247 + var deferred = $q.defer();
  248 + var url = '/api/edge/' + edgeId + '/events' + '?limit=' + pageLink.limit;
  249 + if (angular.isDefined(pageLink.startTime) && pageLink.startTime != null) {
  250 + url += '&startTime=' + pageLink.startTime;
  251 + }
  252 + if (angular.isDefined(pageLink.endTime) && pageLink.endTime != null) {
  253 + url += '&endTime=' + pageLink.endTime;
  254 + }
  255 + if (angular.isDefined(pageLink.idOffset) && pageLink.idOffset != null) {
  256 + url += '&offset=' + pageLink.idOffset;
  257 + }
  258 + $http.get(url, null).then(function success(response) {
  259 + deferred.resolve(response.data);
  260 + }, function fail(response) {
  261 + deferred.reject(response.data);
  262 + });
  263 + return deferred.promise;
  264 + }
244 } 265 }
@@ -15,9 +15,8 @@ @@ -15,9 +15,8 @@
15 limitations under the License. 15 limitations under the License.
16 16
17 --> 17 -->
18 -<div translate class="tb-cell" flex="30">event.event-time</div> 18 +<div translate class="tb-cell" flex="20">event.event-time</div>
19 <div translate class="tb-cell" flex="20">event.event-type</div> 19 <div translate class="tb-cell" flex="20">event.event-type</div>
20 -<div translate class="tb-cell" flex="20">edge.entity-id</div>  
21 <div translate class="tb-cell" flex="20">edge.event-action</div> 20 <div translate class="tb-cell" flex="20">edge.event-action</div>
22 -<div translate class="tb-cell" flex="20">event.success</div> 21 +<div translate class="tb-cell" flex="30">edge.entity-id</div>
23 <div translate class="tb-cell" flex="20">edge.entity-info</div> 22 <div translate class="tb-cell" flex="20">edge.entity-info</div>
@@ -15,11 +15,10 @@ @@ -15,11 +15,10 @@
15 limitations under the License. 15 limitations under the License.
16 16
17 --> 17 -->
18 -<div class="tb-cell" flex="30">{{event.createdTime | date : 'yyyy-MM-dd HH:mm:ss'}}</div> 18 +<div class="tb-cell" flex="20">{{event.createdTime | date : 'yyyy-MM-dd HH:mm:ss'}}</div>
  19 +<div class="tb-cell" flex="20">{{event.edgeEventType}}</div>
19 <div class="tb-cell" flex="20">{{event.edgeEventAction}}</div> 20 <div class="tb-cell" flex="20">{{event.edgeEventAction}}</div>
20 -<div class="tb-cell" flex="20">{{event.entityId}}</div>  
21 -<div class="tb-cell" flex="20">{{event.entityType}}</div>  
22 -<div translate class="tb-cell" flex="20">{{event.success ? 'event.success' : 'event.failed'}}</div> 21 +<div class="tb-cell" flex="30">{{event.entityId}}</div>
23 <div class="tb-cell" flex="20"> 22 <div class="tb-cell" flex="20">
24 <md-button class="md-icon-button md-primary" 23 <md-button class="md-icon-button md-primary"
25 ng-click="showEdgeEntityContent($event, 'edge.entity-info', 'JSON')" 24 ng-click="showEdgeEntityContent($event, 'edge.entity-info', 'JSON')"
@@ -26,7 +26,8 @@ import eventRowEdgeEventTemplate from './event-row-edge-event.tpl.html'; @@ -26,7 +26,8 @@ import eventRowEdgeEventTemplate from './event-row-edge-event.tpl.html';
26 /* eslint-enable import/no-unresolved, import/default */ 26 /* eslint-enable import/no-unresolved, import/default */
27 27
28 /*@ngInject*/ 28 /*@ngInject*/
29 -export default function EventRowDirective($compile, $templateCache, $mdDialog, $document, $translate, types, toast, entityService) { 29 +export default function EventRowDirective($compile, $templateCache, $mdDialog, $document, $translate,
  30 + types, toast, entityService, ruleChainService) {
30 31
31 var linker = function (scope, element, attrs) { 32 var linker = function (scope, element, attrs) {
32 33
@@ -97,27 +98,36 @@ export default function EventRowDirective($compile, $templateCache, $mdDialog, $ @@ -97,27 +98,36 @@ export default function EventRowDirective($compile, $templateCache, $mdDialog, $
97 if (!contentType) { 98 if (!contentType) {
98 contentType = null; 99 contentType = null;
99 } 100 }
100 - entityService.getEntity(scope.event.entityType, scope.event.entityId, {}).then(  
101 - function success(info) {  
102 - var content = angular.toJson(info);  
103 - $mdDialog.show({  
104 - controller: 'EventContentDialogController',  
105 - controllerAs: 'vm',  
106 - templateUrl: eventErrorDialogTemplate,  
107 - locals: {content: content, title: title, contentType: contentType, showingCallback: onShowingCallback},  
108 - parent: angular.element($document[0].body),  
109 - fullscreen: true,  
110 - targetEvent: $event,  
111 - multiple: true,  
112 - onShowing: function(scope, element) {  
113 - onShowingCallback.onShowing(scope, element);  
114 - } 101 + if (scope.event.edgeEventType === 'RELATION') {
  102 + var content = angular.toJson(scope.event.entityBody);
  103 + } else if (scope.event.edgeEventType === 'RULE_CHAIN_METADATA') {
  104 + content = ruleChainService.getRuleChainMetaData(scope.event.entityId, {}).then(
  105 + function success(info) {
  106 + return angular.toJson(info);
  107 + }, function fail() {
  108 + toast.showError($translate.instant('edge.load-entity-error'));
115 }); 109 });
116 - },  
117 - function fail() {  
118 - toast.showError($translate.instant('edge.load-entity-error')); 110 + } else {
  111 + content = entityService.getEntity(scope.event.edgeEventType, scope.event.entityId, {}).then(
  112 + function success(info) {
  113 + return angular.toJson(info);
  114 + }, function fail() {
  115 + toast.showError($translate.instant('edge.load-entity-error'));
  116 + });
  117 + }
  118 + $mdDialog.show({
  119 + controller: 'EventContentDialogController',
  120 + controllerAs: 'vm',
  121 + templateUrl: eventErrorDialogTemplate,
  122 + locals: {content: content, title: title, contentType: contentType, showingCallback: onShowingCallback},
  123 + parent: angular.element($document[0].body),
  124 + fullscreen: true,
  125 + targetEvent: $event,
  126 + multiple: true,
  127 + onShowing: function(scope, element) {
  128 + onShowingCallback.onShowing(scope, element);
119 } 129 }
120 - ); 130 + });
121 } 131 }
122 132
123 scope.checkTooltip = function($event) { 133 scope.checkTooltip = function($event) {
@@ -22,30 +22,9 @@ import eventTableTemplate from './event-table.tpl.html'; @@ -22,30 +22,9 @@ import eventTableTemplate from './event-table.tpl.html';
22 /* eslint-enable import/no-unresolved, import/default */ 22 /* eslint-enable import/no-unresolved, import/default */
23 23
24 /*@ngInject*/ 24 /*@ngInject*/
25 -export default function EventTableDirective($compile, $templateCache, $rootScope, types, eventService) {  
26 -  
27 - var edgeData = [  
28 - {  
29 - "createdTime": 1593592774537,  
30 - "tenantId": "63746950-bb76-11ea-9f96-69d7782607f7",  
31 - "edgeId": "85bb84b0-bb78-11ea-8472-c3dbdeb0fd97",  
32 - "edgeEventAction": "ASSIGNED_TO_EDGE",  
33 - "entityId": "640055a0-bb76-11ea-9f96-69d7782607f7",  
34 - "entityType": "DEVICE",  
35 - "success": true,  
36 - },  
37 - {  
38 - "createdTime": 1593592774538,  
39 - "tenantId": "63746950-bb76-11ea-9f96-69d7782607f7",  
40 - "edgeId": "85bb84b0-bb78-11ea-8472-c3dbdeb0fd97",  
41 - "edgeEventAction": "CREDENTIALS_UPDATED",  
42 - "entityId": "640055a0-bb76-11ea-9f96-69d7782607f8",  
43 - "entityType": "DEVICE",  
44 - "success": false  
45 - }  
46 - ] 25 +export default function EventTableDirective($compile, $templateCache, $rootScope, $stateParams, types, eventService, edgeService) {
47 26
48 - var linker = function (scope, element, attrs) { 27 + var linker = function (scope, element, attrs) {
49 28
50 var template = $templateCache.get(eventTableTemplate); 29 var template = $templateCache.get(eventTableTemplate);
51 30
@@ -119,10 +98,14 @@ export default function EventTableDirective($compile, $templateCache, $rootScope @@ -119,10 +98,14 @@ export default function EventTableDirective($compile, $templateCache, $rootScope
119 }, 98 },
120 99
121 fetchMoreItems_: function () { 100 fetchMoreItems_: function () {
122 - if (scope.events.hasNext && !scope.events.pending && scope.eventType !== "EDGE_EVENT") { 101 + if (scope.events.hasNext && !scope.events.pending) {
123 if (scope.entityType && scope.entityId && scope.eventType && scope.tenantId) { 102 if (scope.entityType && scope.entityId && scope.eventType && scope.tenantId) {
124 - var promise = eventService.getEvents(scope.entityType, scope.entityId,  
125 - scope.eventType, scope.tenantId, scope.events.nextPageLink); 103 + if (scope.eventType !== "EDGE_EVENT") {
  104 + var promise = eventService.getEvents(scope.entityType, scope.entityId,
  105 + scope.eventType, scope.tenantId, scope.events.nextPageLink);
  106 + } else {
  107 + promise = edgeService.getEdgeEvents(scope.entityId, scope.events.nextPageLink);
  108 + }
126 if (promise) { 109 if (promise) {
127 scope.events.pending = true; 110 scope.events.pending = true;
128 promise.then( 111 promise.then(
@@ -146,11 +129,6 @@ export default function EventTableDirective($compile, $templateCache, $rootScope @@ -146,11 +129,6 @@ export default function EventTableDirective($compile, $templateCache, $rootScope
146 scope.events.hasNext = false; 129 scope.events.hasNext = false;
147 } 130 }
148 } 131 }
149 - if (scope.eventType === "EDGE_EVENT") {  
150 - scope.events.data = edgeData;  
151 - scope.events.nextPageLink = false;  
152 - scope.events.hasNext = null;  
153 - }  
154 } 132 }
155 }; 133 };
156 134
@@ -243,7 +221,8 @@ export default function EventTableDirective($compile, $templateCache, $rootScope @@ -243,7 +221,8 @@ export default function EventTableDirective($compile, $templateCache, $rootScope
243 scope: { 221 scope: {
244 entityType: '=', 222 entityType: '=',
245 entityId: '=', 223 entityId: '=',
246 - tenantId: '=' 224 + tenantId: '=',
  225 + edge: '=?'
247 } 226 }
248 }; 227 };
249 } 228 }