Browse Source

Import edge implementation

pull/3693/head
deaflynx 6 years ago
parent
commit
9d4372dc0f
  1. 21
      ui/src/app/api/edge.service.js
  2. 13
      ui/src/app/api/entity.service.js
  3. 16
      ui/src/app/common/types.constant.js
  4. 18
      ui/src/app/import-export/import-dialog-csv.controller.js
  5. 32
      ui/src/app/import-export/table-columns-assignment.directive.js
  6. 6
      ui/src/app/locale/locale.constant-en_US.json
  7. 112
      ui/src/app/widget/lib/entities-hierarchy-widget.js

21
ui/src/app/api/edge.service.js

@ -31,6 +31,7 @@ function EdgeService($http, $q, customerService) {
getCustomerEdges: getCustomerEdges, getCustomerEdges: getCustomerEdges,
assignEdgeToCustomer: assignEdgeToCustomer, assignEdgeToCustomer: assignEdgeToCustomer,
findByQuery: findByQuery, findByQuery: findByQuery,
findByName: findByName,
unassignEdgeFromCustomer: unassignEdgeFromCustomer, unassignEdgeFromCustomer: unassignEdgeFromCustomer,
makeEdgePublic: makeEdgePublic, makeEdgePublic: makeEdgePublic,
setRootRuleChain: setRootRuleChain, setRootRuleChain: setRootRuleChain,
@ -95,10 +96,14 @@ function EdgeService($http, $q, customerService) {
return deferred.promise; return deferred.promise;
} }
function saveEdge(edge) { function saveEdge(edge, ignoreErrors, config) {
var deferred = $q.defer(); var deferred = $q.defer();
var url = '/api/edge'; var url = '/api/edge';
$http.post(url, edge).then(function success(response) { if (!config) {
config = {};
}
config = Object.assign(config, { ignoreErrors: ignoreErrors });
$http.post(url, edge, config).then(function success(response) {
deferred.resolve(response.data); deferred.resolve(response.data);
}, function fail(response) { }, function fail(response) {
deferred.reject(response.data); deferred.reject(response.data);
@ -214,6 +219,18 @@ function EdgeService($http, $q, customerService) {
return deferred.promise; return deferred.promise;
} }
function findByName(edgeName, config) {
config = config || {};
var deferred = $q.defer();
var url = '/api/tenant/edges?edgeName=' + edgeName;
$http.get(url, config).then(function success(response) {
deferred.resolve(response.data);
}, function fail() {
deferred.reject();
});
return deferred.promise;
}
function assignEdgeToCustomer(customerId, edgeId) { function assignEdgeToCustomer(customerId, edgeId) {
var deferred = $q.defer(); var deferred = $q.defer();
var url = '/api/customer/' + customerId + '/edge/' + edgeId; var url = '/api/customer/' + customerId + '/edge/' + edgeId;

13
ui/src/app/api/entity.service.js

@ -1277,6 +1277,13 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device
}; };
} }
if (entityType === types.entityType.edge) {
newEntity.edgeLicenseKey = entityParameters.edgeLicenseKey;
newEntity.cloudEndpoint = entityParameters.cloudEndpoint;
newEntity.routingKey = entityParameters.routingKey;
newEntity.secret = entityParameters.secret;
}
let saveEntityPromise = getEntitySavePromise(entityType, newEntity, config); let saveEntityPromise = getEntitySavePromise(entityType, newEntity, config);
saveEntityPromise.then(function success(response) { saveEntityPromise.then(function success(response) {
@ -1301,6 +1308,9 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device
case types.entityType.asset: case types.entityType.asset:
findIdEntity = assetService.findByName(entityParameters.name, config); findIdEntity = assetService.findByName(entityParameters.name, config);
break; break;
case types.entityType.edge:
findIdEntity = edgeService.findByName(entityParameters.name, config);
break;
} }
findIdEntity.then(function success(response) { findIdEntity.then(function success(response) {
let promises = []; let promises = [];
@ -1347,6 +1357,9 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device
case types.entityType.asset: case types.entityType.asset:
promise = assetService.saveAsset(newEntity, true, config); promise = assetService.saveAsset(newEntity, true, config);
break; break;
case types.entityType.edge:
promise = edgeService.saveEdge(newEntity, true, config);
break;
} }
return promise; return promise;
} }

16
ui/src/app/common/types.constant.js

@ -465,6 +465,22 @@ export default angular.module('thingsboard.types', [])
description: { description: {
name: 'import.column-type.description', name: 'import.column-type.description',
value: 'description' value: 'description'
},
edgeLicenseKey: {
name: 'import.column-type.edgeLicenseKey',
value: 'edgeLicenseKey'
},
cloudEndpoint: {
name: 'import.column-type.cloudEndpoint',
value: 'cloudEndpoint'
},
routingKey: {
name: 'import.column-type.routingKey',
value: 'routingKey'
},
secret: {
name: 'import.column-type.secret',
value: 'secret'
} }
}, },
aliasEntityType: { aliasEntityType: {

18
ui/src/app/import-export/import-dialog-csv.controller.js

@ -135,7 +135,11 @@ export default function ImportDialogCsvController($scope, $mdDialog, toast, impo
server: [], server: [],
shared: [] shared: []
}, },
timeseries: [] timeseries: [],
edgeLicenseKey: "",
cloudEndpoint: "",
routingKey: "",
secret: ""
}; };
for (var j = 0; j < parameterColumns.length; j++) { for (var j = 0; j < parameterColumns.length; j++) {
switch (parameterColumns[j].type) { switch (parameterColumns[j].type) {
@ -175,6 +179,18 @@ export default function ImportDialogCsvController($scope, $mdDialog, toast, impo
case types.importEntityColumnType.description.value: case types.importEntityColumnType.description.value:
entityData.description = importData.rows[i][j]; entityData.description = importData.rows[i][j];
break; break;
case types.importEntityColumnType.edgeLicenseKey.value:
entityData.edgeLicenseKey = importData.rows[i][j];
break;
case types.importEntityColumnType.cloudEndpoint.value:
entityData.cloudEndpoint = importData.rows[i][j];
break;
case types.importEntityColumnType.routingKey.value:
entityData.routingKey = importData.rows[i][j];
break;
case types.importEntityColumnType.secret.value:
entityData.secret = importData.rows[i][j];
break;
} }
} }
entitiesData.push(entityData); entitiesData.push(entityData);

32
ui/src/app/import-export/table-columns-assignment.directive.js

@ -58,6 +58,12 @@ function TableColumnsAssignmentController($scope, types, $timeout) {
vm.columnTypes.serverAttribute = types.importEntityColumnType.serverAttribute; vm.columnTypes.serverAttribute = types.importEntityColumnType.serverAttribute;
vm.columnTypes.timeseries = types.importEntityColumnType.timeseries; vm.columnTypes.timeseries = types.importEntityColumnType.timeseries;
break; break;
case types.entityType.edge:
vm.columnTypes.edgeLicenseKey = types.importEntityColumnType.edgeLicenseKey;
vm.columnTypes.cloudEndpoint = types.importEntityColumnType.cloudEndpoint;
vm.columnTypes.routingKey = types.importEntityColumnType.routingKey;
vm.columnTypes.secret = types.importEntityColumnType.secret;
break;
} }
$scope.isColumnTypeDiffers = function(columnType) { $scope.isColumnTypeDiffers = function(columnType) {
@ -66,7 +72,11 @@ function TableColumnsAssignmentController($scope, types, $timeout) {
columnType !== types.importEntityColumnType.label.value && columnType !== types.importEntityColumnType.label.value &&
columnType !== types.importEntityColumnType.accessToken.value&& columnType !== types.importEntityColumnType.accessToken.value&&
columnType !== types.importEntityColumnType.isGateway.value&& columnType !== types.importEntityColumnType.isGateway.value&&
columnType !== types.importEntityColumnType.description.value; columnType !== types.importEntityColumnType.description.value&&
columnType !== types.importEntityColumnType.edgeLicenseKey.value&&
columnType !== types.importEntityColumnType.cloudEndpoint.value&&
columnType !== types.importEntityColumnType.routingKey.value&&
columnType !== types.importEntityColumnType.secret.value;
}; };
$scope.$watch('vm.columns', function(newVal){ $scope.$watch('vm.columns', function(newVal){
@ -77,6 +87,10 @@ function TableColumnsAssignmentController($scope, types, $timeout) {
var isSelectCredentials = false; var isSelectCredentials = false;
var isSelectGateway = false; var isSelectGateway = false;
var isSelectDescription = false; var isSelectDescription = false;
var isSelectEdgeLicenseKey = false;
var isSelectCloudEndpoint = false;
var isSelectRoutingKey = false;
var isSelectSecret = false;
for (var i = 0; i < newVal.length; i++) { for (var i = 0; i < newVal.length; i++) {
switch (newVal[i].type) { switch (newVal[i].type) {
case types.importEntityColumnType.name.value: case types.importEntityColumnType.name.value:
@ -94,6 +108,18 @@ function TableColumnsAssignmentController($scope, types, $timeout) {
case types.importEntityColumnType.isGateway.value: case types.importEntityColumnType.isGateway.value:
isSelectGateway = true; isSelectGateway = true;
break; break;
case types.importEntityColumnType.edgeLicenseKey.value:
isSelectEdgeLicenseKey = true;
break;
case types.importEntityColumnType.cloudEndpoint.value:
isSelectCloudEndpoint = true;
break;
case types.importEntityColumnType.routingKey.value:
isSelectRoutingKey = true;
break;
case types.importEntityColumnType.secret.value:
isSelectSecret = true;
break;
case types.importEntityColumnType.description.value: case types.importEntityColumnType.description.value:
isSelectDescription = true; isSelectDescription = true;
} }
@ -112,6 +138,10 @@ function TableColumnsAssignmentController($scope, types, $timeout) {
if (angular.isDefined(vm.columnTypes.accessToken)) { if (angular.isDefined(vm.columnTypes.accessToken)) {
vm.columnTypes.accessToken.disable = isSelectCredentials; vm.columnTypes.accessToken.disable = isSelectCredentials;
} }
vm.columnTypes.edgeLicenseKey.disable = isSelectEdgeLicenseKey;
vm.columnTypes.cloudEndpoint.disable = isSelectCloudEndpoint;
vm.columnTypes.routingKey.disable = isSelectRoutingKey;
vm.columnTypes.secret.disable = isSelectSecret;
}); });
} }
}, true); }, true);

6
ui/src/app/locale/locale.constant-en_US.json

@ -1404,7 +1404,11 @@
"entity-field": "Entity field", "entity-field": "Entity field",
"access-token": "Access token", "access-token": "Access token",
"isgateway": "Is Gateway", "isgateway": "Is Gateway",
"description": "Description" "description": "Description",
"edgeLicenseKey": "Edge license key",
"cloudEndpoint": "Cloud endpoint",
"routingKey": "Edge routing key",
"secret": "Edge secret"
}, },
"stepper-text":{ "stepper-text":{
"select-file": "Select a file", "select-file": "Select a file",

112
ui/src/app/widget/lib/entities-hierarchy-widget.js

@ -41,8 +41,7 @@ function EntitiesHierarchyWidget() {
} }
/*@ngInject*/ /*@ngInject*/
function EntitiesHierarchyWidgetController($element, $scope, $q, $timeout, toast, types, entityService, entityRelationService, function EntitiesHierarchyWidgetController($element, $scope, $q, $timeout, toast, types, entityService, entityRelationService /*$filter, $mdMedia, $mdPanel, $document, $translate, $timeout, utils, types*/) {
assetService, deviceService, entityViewService, dashboardService, ruleChainService /*$filter, $mdMedia, $mdPanel, $document, $translate, $timeout, utils, types*/) {
var vm = this; var vm = this;
vm.showData = true; vm.showData = true;
@ -294,95 +293,27 @@ function EntitiesHierarchyWidgetController($element, $scope, $q, $timeout, toast
}); });
} else { } else {
if (node.data && node.data.nodeCtx.entity && node.data.nodeCtx.entity.id && node.data.nodeCtx.entity.id.entityType !== 'function') { if (node.data && node.data.nodeCtx.entity && node.data.nodeCtx.entity.id && node.data.nodeCtx.entity.id.entityType !== 'function') {
if (node.data.nodeCtx.entity.id.entityType === types.entityType.edge) { var relationQuery = prepareNodeRelationQuery(node.data.nodeCtx);
assetService.getEdgeAssets(node.data.nodeCtx.entity.id.id, {limit: 20}, null).then( entityRelationService.findByQuery(relationQuery, {ignoreErrors: true, ignoreLoading: true}).then(
(entities) => { (entityRelations) => {
var tasks = []; var tasks = [];
for (var i=0;i<entities.data.length;i++) { for (var i=0;i<entityRelations.length;i++) {
var relation = entities.data[i]; var relation = entityRelations[i];
var targetId = node.data.nodeCtx.entity.id.entityType === types.entityType.edge ? relation.id : node.data.nodeCtx.entity.id; var targetId = relationQuery.parameters.direction === types.entitySearchDirection.from ? relation.to : relation.from;
tasks.push(entityIdToNode(targetId.entityType, targetId.id, node.data.datasource, node.data.nodeCtx)); tasks.push(entityIdToNode(targetId.entityType, targetId.id, node.data.datasource, node.data.nodeCtx));
}
$q.all(tasks).then((nodes) => {
cb(prepareNodes(nodes));
});
}
);
deviceService.getEdgeDevices(node.data.nodeCtx.entity.id.id, {limit: 20}, null).then(
(entities) => {
var tasks = [];
for (var i=0;i<entities.data.length;i++) {
var relation = entities.data[i];
var targetId = node.data.nodeCtx.entity.id.entityType === types.entityType.edge ? relation.id : node.data.nodeCtx.entity.id;
tasks.push(entityIdToNode(targetId.entityType, targetId.id, node.data.datasource, node.data.nodeCtx));
}
$q.all(tasks).then((nodes) => {
cb(prepareNodes(nodes));
});
}
);
entityViewService.getEdgeEntityViews(node.data.nodeCtx.entity.id.id, {limit: 20}, null).then(
(entities) => {
var tasks = [];
for (var i=0;i<entities.data.length;i++) {
var relation = entities.data[i];
var targetId = node.data.nodeCtx.entity.id.entityType === types.entityType.edge ? relation.id : node.data.nodeCtx.entity.id;
tasks.push(entityIdToNode(targetId.entityType, targetId.id, node.data.datasource, node.data.nodeCtx));
}
$q.all(tasks).then((nodes) => {
cb(prepareNodes(nodes));
});
} }
); $q.all(tasks).then((nodes) => {
dashboardService.getEdgeDashboards(node.data.nodeCtx.entity.id.id, {limit: 20}, null).then( cb(prepareNodes(nodes));
(entities) => { });
var tasks = []; },
for (var i=0;i<entities.data.length;i++) { (error) => {
var relation = entities.data[i]; var errorText = "Failed to get relations!";
var targetId = node.data.nodeCtx.entity.id.entityType === types.entityType.edge ? relation.id : node.data.nodeCtx.entity.id; if (error && error.status === 400) {
tasks.push(entityIdToNode(targetId.entityType, targetId.id, node.data.datasource, node.data.nodeCtx)); errorText = "Invalid relations query returned by 'Node relations query function'! Please check widget configuration!";
}
$q.all(tasks).then((nodes) => {
cb(prepareNodes(nodes));
});
} }
) showError(errorText);
ruleChainService.getEdgeRuleChains(node.data.nodeCtx.entity.id.id, {limit: 20}, null).then( }
(entities) => { );
var tasks = [];
for (var i=0;i<entities.data.length;i++) {
var relation = entities.data[i];
var targetId = node.data.nodeCtx.entity.id.entityType === types.entityType.edge ? relation.id : node.data.nodeCtx.entity.id;
tasks.push(entityIdToNode(targetId.entityType, targetId.id, node.data.datasource, node.data.nodeCtx));
}
$q.all(tasks).then((nodes) => {
cb(prepareNodes(nodes));
});
}
)
} else {
var relationQuery = prepareNodeRelationQuery(node.data.nodeCtx);
entityRelationService.findByQuery(relationQuery, {ignoreErrors: true, ignoreLoading: true}).then(
(entityRelations) => {
var tasks = [];
for (var i=0;i<entityRelations.length;i++) {
var relation = entityRelations[i];
var targetId = relationQuery.parameters.direction === types.entitySearchDirection.from ? relation.to : relation.from;
tasks.push(entityIdToNode(targetId.entityType, targetId.id, node.data.datasource, node.data.nodeCtx));
}
$q.all(tasks).then((nodes) => {
cb(prepareNodes(nodes));
});
},
(error) => {
var errorText = "Failed to get relations!";
if (error && error.status === 400) {
errorText = "Invalid relations query returned by 'Node relations query function'! Please check widget configuration!";
}
showError(errorText);
}
);
}
} else { } else {
cb([]); cb([]);
} }
@ -580,9 +511,6 @@ function EntitiesHierarchyWidgetController($element, $scope, $q, $timeout, toast
case types.entityType.edge: case types.entityType.edge:
materialIcon = 'router'; materialIcon = 'router';
break; break;
case types.entityType.rulechain:
materialIcon = 'settings_ethernet';
break;
} }
} }
return { return {

Loading…
Cancel
Save