Commit 9d4372dc0fbbc80cd5e3aaeaafc31e664ab143d8

Authored by deaflynx
1 parent 65b87cc8

Import edge implementation

... ... @@ -31,6 +31,7 @@ function EdgeService($http, $q, customerService) {
31 31 getCustomerEdges: getCustomerEdges,
32 32 assignEdgeToCustomer: assignEdgeToCustomer,
33 33 findByQuery: findByQuery,
  34 + findByName: findByName,
34 35 unassignEdgeFromCustomer: unassignEdgeFromCustomer,
35 36 makeEdgePublic: makeEdgePublic,
36 37 setRootRuleChain: setRootRuleChain,
... ... @@ -95,10 +96,14 @@ function EdgeService($http, $q, customerService) {
95 96 return deferred.promise;
96 97 }
97 98
98   - function saveEdge(edge) {
  99 + function saveEdge(edge, ignoreErrors, config) {
99 100 var deferred = $q.defer();
100 101 var url = '/api/edge';
101   - $http.post(url, edge).then(function success(response) {
  102 + if (!config) {
  103 + config = {};
  104 + }
  105 + config = Object.assign(config, { ignoreErrors: ignoreErrors });
  106 + $http.post(url, edge, config).then(function success(response) {
102 107 deferred.resolve(response.data);
103 108 }, function fail(response) {
104 109 deferred.reject(response.data);
... ... @@ -214,6 +219,18 @@ function EdgeService($http, $q, customerService) {
214 219 return deferred.promise;
215 220 }
216 221
  222 + function findByName(edgeName, config) {
  223 + config = config || {};
  224 + var deferred = $q.defer();
  225 + var url = '/api/tenant/edges?edgeName=' + edgeName;
  226 + $http.get(url, config).then(function success(response) {
  227 + deferred.resolve(response.data);
  228 + }, function fail() {
  229 + deferred.reject();
  230 + });
  231 + return deferred.promise;
  232 + }
  233 +
217 234 function assignEdgeToCustomer(customerId, edgeId) {
218 235 var deferred = $q.defer();
219 236 var url = '/api/customer/' + customerId + '/edge/' + edgeId;
... ...
... ... @@ -1277,6 +1277,13 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device
1277 1277 };
1278 1278 }
1279 1279
  1280 + if (entityType === types.entityType.edge) {
  1281 + newEntity.edgeLicenseKey = entityParameters.edgeLicenseKey;
  1282 + newEntity.cloudEndpoint = entityParameters.cloudEndpoint;
  1283 + newEntity.routingKey = entityParameters.routingKey;
  1284 + newEntity.secret = entityParameters.secret;
  1285 + }
  1286 +
1280 1287 let saveEntityPromise = getEntitySavePromise(entityType, newEntity, config);
1281 1288
1282 1289 saveEntityPromise.then(function success(response) {
... ... @@ -1301,6 +1308,9 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device
1301 1308 case types.entityType.asset:
1302 1309 findIdEntity = assetService.findByName(entityParameters.name, config);
1303 1310 break;
  1311 + case types.entityType.edge:
  1312 + findIdEntity = edgeService.findByName(entityParameters.name, config);
  1313 + break;
1304 1314 }
1305 1315 findIdEntity.then(function success(response) {
1306 1316 let promises = [];
... ... @@ -1347,6 +1357,9 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device
1347 1357 case types.entityType.asset:
1348 1358 promise = assetService.saveAsset(newEntity, true, config);
1349 1359 break;
  1360 + case types.entityType.edge:
  1361 + promise = edgeService.saveEdge(newEntity, true, config);
  1362 + break;
1350 1363 }
1351 1364 return promise;
1352 1365 }
... ...
... ... @@ -465,6 +465,22 @@ export default angular.module('thingsboard.types', [])
465 465 description: {
466 466 name: 'import.column-type.description',
467 467 value: 'description'
  468 + },
  469 + edgeLicenseKey: {
  470 + name: 'import.column-type.edgeLicenseKey',
  471 + value: 'edgeLicenseKey'
  472 + },
  473 + cloudEndpoint: {
  474 + name: 'import.column-type.cloudEndpoint',
  475 + value: 'cloudEndpoint'
  476 + },
  477 + routingKey: {
  478 + name: 'import.column-type.routingKey',
  479 + value: 'routingKey'
  480 + },
  481 + secret: {
  482 + name: 'import.column-type.secret',
  483 + value: 'secret'
468 484 }
469 485 },
470 486 aliasEntityType: {
... ...
... ... @@ -135,7 +135,11 @@ export default function ImportDialogCsvController($scope, $mdDialog, toast, impo
135 135 server: [],
136 136 shared: []
137 137 },
138   - timeseries: []
  138 + timeseries: [],
  139 + edgeLicenseKey: "",
  140 + cloudEndpoint: "",
  141 + routingKey: "",
  142 + secret: ""
139 143 };
140 144 for (var j = 0; j < parameterColumns.length; j++) {
141 145 switch (parameterColumns[j].type) {
... ... @@ -175,6 +179,18 @@ export default function ImportDialogCsvController($scope, $mdDialog, toast, impo
175 179 case types.importEntityColumnType.description.value:
176 180 entityData.description = importData.rows[i][j];
177 181 break;
  182 + case types.importEntityColumnType.edgeLicenseKey.value:
  183 + entityData.edgeLicenseKey = importData.rows[i][j];
  184 + break;
  185 + case types.importEntityColumnType.cloudEndpoint.value:
  186 + entityData.cloudEndpoint = importData.rows[i][j];
  187 + break;
  188 + case types.importEntityColumnType.routingKey.value:
  189 + entityData.routingKey = importData.rows[i][j];
  190 + break;
  191 + case types.importEntityColumnType.secret.value:
  192 + entityData.secret = importData.rows[i][j];
  193 + break;
178 194 }
179 195 }
180 196 entitiesData.push(entityData);
... ...
... ... @@ -58,6 +58,12 @@ function TableColumnsAssignmentController($scope, types, $timeout) {
58 58 vm.columnTypes.serverAttribute = types.importEntityColumnType.serverAttribute;
59 59 vm.columnTypes.timeseries = types.importEntityColumnType.timeseries;
60 60 break;
  61 + case types.entityType.edge:
  62 + vm.columnTypes.edgeLicenseKey = types.importEntityColumnType.edgeLicenseKey;
  63 + vm.columnTypes.cloudEndpoint = types.importEntityColumnType.cloudEndpoint;
  64 + vm.columnTypes.routingKey = types.importEntityColumnType.routingKey;
  65 + vm.columnTypes.secret = types.importEntityColumnType.secret;
  66 + break;
61 67 }
62 68
63 69 $scope.isColumnTypeDiffers = function(columnType) {
... ... @@ -66,7 +72,11 @@ function TableColumnsAssignmentController($scope, types, $timeout) {
66 72 columnType !== types.importEntityColumnType.label.value &&
67 73 columnType !== types.importEntityColumnType.accessToken.value&&
68 74 columnType !== types.importEntityColumnType.isGateway.value&&
69   - columnType !== types.importEntityColumnType.description.value;
  75 + columnType !== types.importEntityColumnType.description.value&&
  76 + columnType !== types.importEntityColumnType.edgeLicenseKey.value&&
  77 + columnType !== types.importEntityColumnType.cloudEndpoint.value&&
  78 + columnType !== types.importEntityColumnType.routingKey.value&&
  79 + columnType !== types.importEntityColumnType.secret.value;
70 80 };
71 81
72 82 $scope.$watch('vm.columns', function(newVal){
... ... @@ -77,6 +87,10 @@ function TableColumnsAssignmentController($scope, types, $timeout) {
77 87 var isSelectCredentials = false;
78 88 var isSelectGateway = false;
79 89 var isSelectDescription = false;
  90 + var isSelectEdgeLicenseKey = false;
  91 + var isSelectCloudEndpoint = false;
  92 + var isSelectRoutingKey = false;
  93 + var isSelectSecret = false;
80 94 for (var i = 0; i < newVal.length; i++) {
81 95 switch (newVal[i].type) {
82 96 case types.importEntityColumnType.name.value:
... ... @@ -94,6 +108,18 @@ function TableColumnsAssignmentController($scope, types, $timeout) {
94 108 case types.importEntityColumnType.isGateway.value:
95 109 isSelectGateway = true;
96 110 break;
  111 + case types.importEntityColumnType.edgeLicenseKey.value:
  112 + isSelectEdgeLicenseKey = true;
  113 + break;
  114 + case types.importEntityColumnType.cloudEndpoint.value:
  115 + isSelectCloudEndpoint = true;
  116 + break;
  117 + case types.importEntityColumnType.routingKey.value:
  118 + isSelectRoutingKey = true;
  119 + break;
  120 + case types.importEntityColumnType.secret.value:
  121 + isSelectSecret = true;
  122 + break;
97 123 case types.importEntityColumnType.description.value:
98 124 isSelectDescription = true;
99 125 }
... ... @@ -112,6 +138,10 @@ function TableColumnsAssignmentController($scope, types, $timeout) {
112 138 if (angular.isDefined(vm.columnTypes.accessToken)) {
113 139 vm.columnTypes.accessToken.disable = isSelectCredentials;
114 140 }
  141 + vm.columnTypes.edgeLicenseKey.disable = isSelectEdgeLicenseKey;
  142 + vm.columnTypes.cloudEndpoint.disable = isSelectCloudEndpoint;
  143 + vm.columnTypes.routingKey.disable = isSelectRoutingKey;
  144 + vm.columnTypes.secret.disable = isSelectSecret;
115 145 });
116 146 }
117 147 }, true);
... ...
... ... @@ -1404,7 +1404,11 @@
1404 1404 "entity-field": "Entity field",
1405 1405 "access-token": "Access token",
1406 1406 "isgateway": "Is Gateway",
1407   - "description": "Description"
  1407 + "description": "Description",
  1408 + "edgeLicenseKey": "Edge license key",
  1409 + "cloudEndpoint": "Cloud endpoint",
  1410 + "routingKey": "Edge routing key",
  1411 + "secret": "Edge secret"
1408 1412 },
1409 1413 "stepper-text":{
1410 1414 "select-file": "Select a file",
... ...
... ... @@ -41,8 +41,7 @@ function EntitiesHierarchyWidget() {
41 41 }
42 42
43 43 /*@ngInject*/
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*/) {
  44 +function EntitiesHierarchyWidgetController($element, $scope, $q, $timeout, toast, types, entityService, entityRelationService /*$filter, $mdMedia, $mdPanel, $document, $translate, $timeout, utils, types*/) {
46 45 var vm = this;
47 46
48 47 vm.showData = true;
... ... @@ -294,95 +293,27 @@ function EntitiesHierarchyWidgetController($element, $scope, $q, $timeout, toast
294 293 });
295 294 } else {
296 295 if (node.data && node.data.nodeCtx.entity && node.data.nodeCtx.entity.id && node.data.nodeCtx.entity.id.entityType !== 'function') {
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   - });
309   - }
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   - });
322   - }
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   - });
  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));
335 304 }
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   - });
  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!";
348 313 }
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   - }
  314 + showError(errorText);
  315 + }
  316 + );
386 317 } else {
387 318 cb([]);
388 319 }
... ... @@ -580,9 +511,6 @@ function EntitiesHierarchyWidgetController($element, $scope, $q, $timeout, toast
580 511 case types.entityType.edge:
581 512 materialIcon = 'router';
582 513 break;
583   - case types.entityType.rulechain:
584   - materialIcon = 'settings_ethernet';
585   - break;
586 514 }
587 515 }
588 516 return {
... ...