Commit 65b87cc833472ba10a864d1f7d04830dd9065725

Authored by Artem Babak
1 parent 05771cd9

Entities hierarchy edge prototype

@@ -383,7 +383,7 @@ export function DashboardsController(userService, dashboardService, customerServ @@ -383,7 +383,7 @@ export function DashboardsController(userService, dashboardService, customerServ
383 } 383 }
384 } else if (vm.dashboardsScope === 'edge') { 384 } else if (vm.dashboardsScope === 'edge') {
385 fetchDashboardsFunction = function (pageLink) { 385 fetchDashboardsFunction = function (pageLink) {
386 - return dashboardService.getEdgeDashboards(edgeId, pageLink); 386 + return dashboardService.getEdgeDashboards(edgeId, pageLink, null);
387 }; 387 };
388 deleteDashboardFunction = function (dashboardId) { 388 deleteDashboardFunction = function (dashboardId) {
389 return dashboardService.unassignDashboardFromEdge(edgeId, dashboardId); 389 return dashboardService.unassignDashboardFromEdge(edgeId, dashboardId);
@@ -41,7 +41,8 @@ function EntitiesHierarchyWidget() { @@ -41,7 +41,8 @@ function EntitiesHierarchyWidget() {
41 } 41 }
42 42
43 /*@ngInject*/ 43 /*@ngInject*/
44 -function EntitiesHierarchyWidgetController($element, $scope, $q, $timeout, toast, types, entityService, entityRelationService /*$filter, $mdMedia, $mdPanel, $document, $translate, $timeout, utils, types*/) { 44 +function EntitiesHierarchyWidgetController($element, $scope, $q, $timeout, toast, types, entityService, entityRelationService,
  45 + assetService, deviceService, entityViewService, dashboardService, ruleChainService /*$filter, $mdMedia, $mdPanel, $document, $translate, $timeout, utils, types*/) {
45 var vm = this; 46 var vm = this;
46 47
47 vm.showData = true; 48 vm.showData = true;
@@ -293,27 +294,95 @@ function EntitiesHierarchyWidgetController($element, $scope, $q, $timeout, toast @@ -293,27 +294,95 @@ function EntitiesHierarchyWidgetController($element, $scope, $q, $timeout, toast
293 }); 294 });
294 } else { 295 } else {
295 if (node.data && node.data.nodeCtx.entity && node.data.nodeCtx.entity.id && node.data.nodeCtx.entity.id.entityType !== 'function') { 296 if (node.data && node.data.nodeCtx.entity && node.data.nodeCtx.entity.id && node.data.nodeCtx.entity.id.entityType !== 'function') {
296 - var relationQuery = prepareNodeRelationQuery(node.data.nodeCtx);  
297 - entityRelationService.findByQuery(relationQuery, {ignoreErrors: true, ignoreLoading: true}).then(  
298 - (entityRelations) => {  
299 - var tasks = [];  
300 - for (var i=0;i<entityRelations.length;i++) {  
301 - var relation = entityRelations[i];  
302 - var targetId = relationQuery.parameters.direction === types.entitySearchDirection.from ? relation.to : relation.from;  
303 - tasks.push(entityIdToNode(targetId.entityType, targetId.id, node.data.datasource, node.data.nodeCtx)); 297 + if (node.data.nodeCtx.entity.id.entityType === types.entityType.edge) {
  298 + assetService.getEdgeAssets(node.data.nodeCtx.entity.id.id, {limit: 20}, null).then(
  299 + (entities) => {
  300 + var tasks = [];
  301 + for (var i=0;i<entities.data.length;i++) {
  302 + var relation = entities.data[i];
  303 + var targetId = node.data.nodeCtx.entity.id.entityType === types.entityType.edge ? relation.id : node.data.nodeCtx.entity.id;
  304 + tasks.push(entityIdToNode(targetId.entityType, targetId.id, node.data.datasource, node.data.nodeCtx));
  305 + }
  306 + $q.all(tasks).then((nodes) => {
  307 + cb(prepareNodes(nodes));
  308 + });
304 } 309 }
305 - $q.all(tasks).then((nodes) => {  
306 - cb(prepareNodes(nodes));  
307 - });  
308 - },  
309 - (error) => {  
310 - var errorText = "Failed to get relations!";  
311 - if (error && error.status === 400) {  
312 - errorText = "Invalid relations query returned by 'Node relations query function'! Please check widget configuration!"; 310 + );
  311 + deviceService.getEdgeDevices(node.data.nodeCtx.entity.id.id, {limit: 20}, null).then(
  312 + (entities) => {
  313 + var tasks = [];
  314 + for (var i=0;i<entities.data.length;i++) {
  315 + var relation = entities.data[i];
  316 + var targetId = node.data.nodeCtx.entity.id.entityType === types.entityType.edge ? relation.id : node.data.nodeCtx.entity.id;
  317 + tasks.push(entityIdToNode(targetId.entityType, targetId.id, node.data.datasource, node.data.nodeCtx));
  318 + }
  319 + $q.all(tasks).then((nodes) => {
  320 + cb(prepareNodes(nodes));
  321 + });
313 } 322 }
314 - showError(errorText);  
315 - }  
316 - ); 323 + );
  324 + entityViewService.getEdgeEntityViews(node.data.nodeCtx.entity.id.id, {limit: 20}, null).then(
  325 + (entities) => {
  326 + var tasks = [];
  327 + for (var i=0;i<entities.data.length;i++) {
  328 + var relation = entities.data[i];
  329 + var targetId = node.data.nodeCtx.entity.id.entityType === types.entityType.edge ? relation.id : node.data.nodeCtx.entity.id;
  330 + tasks.push(entityIdToNode(targetId.entityType, targetId.id, node.data.datasource, node.data.nodeCtx));
  331 + }
  332 + $q.all(tasks).then((nodes) => {
  333 + cb(prepareNodes(nodes));
  334 + });
  335 + }
  336 + );
  337 + dashboardService.getEdgeDashboards(node.data.nodeCtx.entity.id.id, {limit: 20}, null).then(
  338 + (entities) => {
  339 + var tasks = [];
  340 + for (var i=0;i<entities.data.length;i++) {
  341 + var relation = entities.data[i];
  342 + var targetId = node.data.nodeCtx.entity.id.entityType === types.entityType.edge ? relation.id : node.data.nodeCtx.entity.id;
  343 + tasks.push(entityIdToNode(targetId.entityType, targetId.id, node.data.datasource, node.data.nodeCtx));
  344 + }
  345 + $q.all(tasks).then((nodes) => {
  346 + cb(prepareNodes(nodes));
  347 + });
  348 + }
  349 + )
  350 + ruleChainService.getEdgeRuleChains(node.data.nodeCtx.entity.id.id, {limit: 20}, null).then(
  351 + (entities) => {
  352 + var tasks = [];
  353 + for (var i=0;i<entities.data.length;i++) {
  354 + var relation = entities.data[i];
  355 + var targetId = node.data.nodeCtx.entity.id.entityType === types.entityType.edge ? relation.id : node.data.nodeCtx.entity.id;
  356 + tasks.push(entityIdToNode(targetId.entityType, targetId.id, node.data.datasource, node.data.nodeCtx));
  357 + }
  358 + $q.all(tasks).then((nodes) => {
  359 + cb(prepareNodes(nodes));
  360 + });
  361 + }
  362 + )
  363 + } else {
  364 + var relationQuery = prepareNodeRelationQuery(node.data.nodeCtx);
  365 + entityRelationService.findByQuery(relationQuery, {ignoreErrors: true, ignoreLoading: true}).then(
  366 + (entityRelations) => {
  367 + var tasks = [];
  368 + for (var i=0;i<entityRelations.length;i++) {
  369 + var relation = entityRelations[i];
  370 + var targetId = relationQuery.parameters.direction === types.entitySearchDirection.from ? relation.to : relation.from;
  371 + tasks.push(entityIdToNode(targetId.entityType, targetId.id, node.data.datasource, node.data.nodeCtx));
  372 + }
  373 + $q.all(tasks).then((nodes) => {
  374 + cb(prepareNodes(nodes));
  375 + });
  376 + },
  377 + (error) => {
  378 + var errorText = "Failed to get relations!";
  379 + if (error && error.status === 400) {
  380 + errorText = "Invalid relations query returned by 'Node relations query function'! Please check widget configuration!";
  381 + }
  382 + showError(errorText);
  383 + }
  384 + );
  385 + }
317 } else { 386 } else {
318 cb([]); 387 cb([]);
319 } 388 }
@@ -511,6 +580,9 @@ function EntitiesHierarchyWidgetController($element, $scope, $q, $timeout, toast @@ -511,6 +580,9 @@ function EntitiesHierarchyWidgetController($element, $scope, $q, $timeout, toast
511 case types.entityType.edge: 580 case types.entityType.edge:
512 materialIcon = 'router'; 581 materialIcon = 'router';
513 break; 582 break;
  583 + case types.entityType.rulechain:
  584 + materialIcon = 'settings_ethernet';
  585 + break;
514 } 586 }
515 } 587 }
516 return { 588 return {