Add import assets and start refactorin

This commit is contained in:
Vladyslav_Prykhodko 2019-06-06 19:43:07 +03:00
parent b3f7fa8b50
commit 15e74792f0
11 changed files with 339 additions and 232 deletions

View File

@ -32,7 +32,8 @@ function AssetService($http, $q, customerService, userService) {
getCustomerAssets: getCustomerAssets, getCustomerAssets: getCustomerAssets,
findByQuery: findByQuery, findByQuery: findByQuery,
fetchAssetsByNameFilter: fetchAssetsByNameFilter, fetchAssetsByNameFilter: fetchAssetsByNameFilter,
getAssetTypes: getAssetTypes getAssetTypes: getAssetTypes,
findByName: findByName
} }
return service; return service;
@ -276,4 +277,16 @@ function AssetService($http, $q, customerService, userService) {
return deferred.promise; return deferred.promise;
} }
function findByName(assetName, config) {
config = config || {};
var deferred = $q.defer();
var url = '/api/tenant/assets?assetName=' + assetName;
$http.get(url, config).then(function success(response) {
deferred.resolve(response.data);
}, function fail() {
deferred.reject();
});
return deferred.promise;
}
} }

View File

@ -31,7 +31,6 @@ function DeviceService($http, $q, $window, userService, attributeService, custom
getDeviceCredentials: getDeviceCredentials, getDeviceCredentials: getDeviceCredentials,
getTenantDevices: getTenantDevices, getTenantDevices: getTenantDevices,
saveDevice: saveDevice, saveDevice: saveDevice,
saveDeviceParameters: saveDeviceParameters,
saveDeviceCredentials: saveDeviceCredentials, saveDeviceCredentials: saveDeviceCredentials,
unassignDeviceFromCustomer: unassignDeviceFromCustomer, unassignDeviceFromCustomer: unassignDeviceFromCustomer,
makeDevicePublic: makeDevicePublic, makeDevicePublic: makeDevicePublic,
@ -43,8 +42,9 @@ function DeviceService($http, $q, $window, userService, attributeService, custom
sendOneWayRpcCommand: sendOneWayRpcCommand, sendOneWayRpcCommand: sendOneWayRpcCommand,
sendTwoWayRpcCommand: sendTwoWayRpcCommand, sendTwoWayRpcCommand: sendTwoWayRpcCommand,
findByQuery: findByQuery, findByQuery: findByQuery,
getDeviceTypes: getDeviceTypes getDeviceTypes: getDeviceTypes,
} findByName: findByName
};
return service; return service;
@ -172,104 +172,6 @@ function DeviceService($http, $q, $window, userService, attributeService, custom
return deferred.promise; return deferred.promise;
} }
function saveDeviceRelarion(deviceId, deviceRelation, config) {
const deferred = $q.defer();
let attributesType = Object.keys(types.attributesScope);
let allPromise = [];
let promise = "";
if (deviceRelation.accessToken !== "") {
promise = getDeviceCredentials(deviceId.id,null,config).then(function (response){
response.credentialsId = deviceRelation.accessToken;
response.credentialsType = "ACCESS_TOKEN";
response.credentialsValue = null;
return saveDeviceCredentials(response, config).catch(function(){
return "error";
});
});
allPromise.push(promise)
}
for (let i = 0; i < attributesType.length; i++) {
let attribute = attributesType[i];
if (deviceRelation.attributes[attribute] && deviceRelation.attributes[attribute].length !== 0) {
promise = attributeService.saveEntityAttributes(types.entityType.device, deviceId.id, types.attributesScope[attribute].value, deviceRelation.attributes[attribute], config).catch(function () {
return "error";
});
allPromise.push(promise);
}
}
if (deviceRelation.timeseries.length !== 0) {
promise = attributeService.saveEntityTimeseries(types.entityType.device, deviceId.id, "time", deviceRelation.timeseries, config).catch(function(){
return "error";
});
allPromise.push(promise);
}
$q.all(allPromise).then(function success(response) {
let isResponseHasError = false;
for(let i = 0; i < response.length; i++){
if(response[i] === "error"){
isResponseHasError = true;
break;
}
}
if (isResponseHasError){
deferred.reject();
} else {
deferred.resolve();
}
});
return deferred.promise;
}
function saveDeviceParameters(deviceParameters, update, config) {
config = config || {};
const deferred = $q.defer();
let statisticalInfo = {};
let newDevice = {
name: deviceParameters.name,
type: deviceParameters.type
};
saveDevice(newDevice, config).then(function success(response) {
saveDeviceRelarion(response.id, deviceParameters, config).then(function success() {
statisticalInfo.create = {
device: 1
};
deferred.resolve(statisticalInfo);
}, function fail() {
statisticalInfo.error = {
device: 1
};
deferred.resolve(statisticalInfo);
});
}, function fail() {
if (update) {
findByName(deviceParameters.name, config).then(function success(response) {
saveDeviceRelarion(response.id, deviceParameters, config).then(function success() {
statisticalInfo.update = {
device: 1
};
deferred.resolve(statisticalInfo);
}, function fail() {
statisticalInfo.error = {
device: 1
};
deferred.resolve(statisticalInfo);
});
}, function fail() {
statisticalInfo.error = {
device: 1
};
deferred.resolve(statisticalInfo);
});
} else {
statisticalInfo.error = {
device: 1
};
deferred.resolve(statisticalInfo);
}
});
return deferred.promise;
}
function deleteDevice(deviceId) { function deleteDevice(deviceId) {
var deferred = $q.defer(); var deferred = $q.defer();
var url = '/api/device/' + deviceId; var url = '/api/device/' + deviceId;

View File

@ -38,6 +38,7 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device
createAlarmSourceFromSubscriptionInfo: createAlarmSourceFromSubscriptionInfo, createAlarmSourceFromSubscriptionInfo: createAlarmSourceFromSubscriptionInfo,
getRelatedEntities: getRelatedEntities, getRelatedEntities: getRelatedEntities,
saveRelatedEntity: saveRelatedEntity, saveRelatedEntity: saveRelatedEntity,
saveEntityParameters: saveEntityParameters,
getRelatedEntity: getRelatedEntity, getRelatedEntity: getRelatedEntity,
deleteRelatedEntity: deleteRelatedEntity, deleteRelatedEntity: deleteRelatedEntity,
moveEntity: moveEntity, moveEntity: moveEntity,
@ -1072,6 +1073,123 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device
return deferred.promise; return deferred.promise;
} }
function saveEntityRelarion(entityType, entityId, entityRelation, config) {
const deferred = $q.defer();
let attributesType = Object.keys(types.attributesScope);
let allPromise = [];
let promise = "";
if (entityRelation.accessToken !== "") {
promise = deviceService.getDeviceCredentials(entityId.id, null, config).then(function (response) {
response.credentialsId = entityRelation.accessToken;
response.credentialsType = "ACCESS_TOKEN";
response.credentialsValue = null;
return deviceService.saveDeviceCredentials(response, config).catch(function () {
return "error";
});
});
allPromise.push(promise)
}
for (let i = 0; i < attributesType.length; i++) {
let attribute = attributesType[i];
if (entityRelation.attributes[attribute] && entityRelation.attributes[attribute].length !== 0) {
promise = attributeService.saveEntityAttributes(entityType, entityId.id, types.attributesScope[attribute].value, entityRelation.attributes[attribute], config).catch(function () {
return "error";
});
allPromise.push(promise);
}
}
if (entityRelation.timeseries.length !== 0) {
promise = attributeService.saveEntityTimeseries(entityType, entityId.id, "time", entityRelation.timeseries, config).catch(function(){
return "error";
});
allPromise.push(promise);
}
$q.all(allPromise).then(function success(response) {
let isResponseHasError = false;
for(let i = 0; i < response.length; i++){
if(response[i] === "error"){
isResponseHasError = true;
break;
}
}
if (isResponseHasError){
deferred.reject();
} else {
deferred.resolve();
}
});
return deferred.promise;
}
function saveEntityParameters(entityType, entityParameters, update, config) {
config = config || {};
const deferred = $q.defer();
let statisticalInfo = {};
let newEntity = {
name: entityParameters.name,
type: entityParameters.type
};
let promise;
switch (entityType) {
case types.entityType.device:
promise = deviceService.saveDevice(newEntity, config);
break;
case types.entityType.asset:
promise = assetService.saveAsset(newEntity, true, config);
break;
}
promise.then(function success(response) {
saveEntityRelarion(entityType, response.id, entityParameters, config).then(function success() {
statisticalInfo.create = {
entity: 1
};
deferred.resolve(statisticalInfo);
}, function fail() {
statisticalInfo.error = {
entity: 1
};
deferred.resolve(statisticalInfo);
});
}, function fail() {
if (update) {
let findIdEntity;
switch (entityType) {
case types.entityType.device:
findIdEntity = deviceService.findByName(entityParameters.name, config);
break;
case types.entityType.asset:
findIdEntity = assetService.findByName(entityParameters.name, config);
break;
}
findIdEntity.then(function success(response) {
saveEntityRelarion(response.id, entityType, entityParameters, config).then(function success() {
statisticalInfo.update = {
entity: 1
};
deferred.resolve(statisticalInfo);
}, function fail() {
statisticalInfo.error = {
entity: 1
};
deferred.resolve(statisticalInfo);
});
}, function fail() {
statisticalInfo.error = {
entity: 1
};
deferred.resolve(statisticalInfo);
});
} else {
statisticalInfo.error = {
entity: 1
};
deferred.resolve(statisticalInfo);
}
});
return deferred.promise;
}
function getRelatedEntity(entityId, keys, typeTranslatePrefix) { function getRelatedEntity(entityId, keys, typeTranslatePrefix) {
var deferred = $q.defer(); var deferred = $q.defer();
getEntityPromise(entityId.entityType, entityId.id, {ignoreLoading: true}).then( getEntityPromise(entityId.entityType, entityId.id, {ignoreLoading: true}).then(

View File

@ -48,7 +48,7 @@ export function AssetCardController(types) {
/*@ngInject*/ /*@ngInject*/
export function AssetController($rootScope, userService, assetService, customerService, $state, $stateParams, export function AssetController($rootScope, userService, assetService, customerService, $state, $stateParams,
$document, $mdDialog, $q, $translate, types) { $document, $mdDialog, $q, $translate, types, importExport) {
var customerId = $stateParams.customerId; var customerId = $stateParams.customerId;
@ -56,6 +56,29 @@ export function AssetController($rootScope, userService, assetService, customerS
var assetGroupActionsList = []; var assetGroupActionsList = [];
var assetAddItemActionsList = [
{
onAction: function ($event) {
vm.grid.addItem($event);
},
name: function() { return $translate.instant('action.add') },
details: function() { return $translate.instant('asset.add-asset-text') },
icon: "insert_drive_file"
},
{
onAction: function ($event) {
importExport.importEntities($event, types.entityType.asset).then(
function() {
vm.grid.refreshList();
}
);
},
name: function() { return $translate.instant('action.import') },
details: function() { return $translate.instant('asset.import') },
icon: "file_upload"
}
];
var vm = this; var vm = this;
vm.types = types; vm.types = types;
@ -77,6 +100,7 @@ export function AssetController($rootScope, userService, assetService, customerS
actionsList: assetActionsList, actionsList: assetActionsList,
groupActionsList: assetGroupActionsList, groupActionsList: assetGroupActionsList,
addItemActions: assetAddItemActionsList,
onGridInited: gridInited, onGridInited: gridInited,
@ -294,6 +318,8 @@ export function AssetController($rootScope, userService, assetService, customerS
} else if (vm.assetsScope === 'customer_user') { } else if (vm.assetsScope === 'customer_user') {
vm.assetGridConfig.addItemAction = {}; vm.assetGridConfig.addItemAction = {};
} }
vm.assetGridConfig.addItemActions = [];
} }
vm.assetGridConfig.refreshParamsFunc = refreshAssetsParamsFunction; vm.assetGridConfig.refreshParamsFunc = refreshAssetsParamsFunction;

View File

@ -350,8 +350,15 @@ export default angular.module('thingsboard.types', [])
rulenode: "RULE_NODE", rulenode: "RULE_NODE",
entityView: "ENTITY_VIEW" entityView: "ENTITY_VIEW"
}, },
entityGroup: { importEntityColumnType: {
columnType: { name: {
name: 'entity-group.entity-field.name',
value: 'name'
},
type: {
name: 'entity-group.entity-field.type',
value: 'type'
},
clientAttribute: { clientAttribute: {
name: 'entity-group.column-type.client-attribute', name: 'entity-group.column-type.client-attribute',
value: 'CLIENT_ATTRIBUTE' value: 'CLIENT_ATTRIBUTE'
@ -377,21 +384,48 @@ export default angular.module('thingsboard.types', [])
value: 'ACCESS_TOKEN' value: 'ACCESS_TOKEN'
} }
}, },
entityField: { // entityGroup: {
name: { // columnType: {
name: 'entity-group.entity-field.name', // clientAttribute: {
value: 'name' // name: 'entity-group.column-type.client-attribute',
}, // value: 'CLIENT_ATTRIBUTE'
type: { // },
name: 'entity-group.entity-field.type', // sharedAttribute: {
value: 'type' // name: 'entity-group.column-type.shared-attribute',
}, // value: 'SHARED_ATTRIBUTE'
assigned_customer: { // },
name: 'entity-group.entity-field.assigned_customer', // serverAttribute: {
value: 'assigned_customer' // name: 'entity-group.column-type.server-attribute',
} // value: 'SERVER_ATTRIBUTE'
} // },
}, // timeseries: {
// name: 'entity-group.column-type.timeseries',
// value: 'TIMESERIES'
// },
// entityField: {
// name: 'entity-group.column-type.entity-field',
// value: 'ENTITY_FIELD'
// },
// accessToken: {
// name: 'entity-group.column-type.access-token',
// value: 'ACCESS_TOKEN'
// }
// },
// entityField: {
// name: {
// name: 'entity-group.entity-field.name',
// value: 'name'
// },
// type: {
// name: 'entity-group.entity-field.type',
// value: 'type'
// },
// assigned_customer: {
// name: 'entity-group.entity-field.assigned_customer',
// value: 'assigned_customer'
// }
// }
// },
aliasEntityType: { aliasEntityType: {
current_customer: "CURRENT_CUSTOMER" current_customer: "CURRENT_CUSTOMER"
}, },

View File

@ -68,7 +68,7 @@ export function DeviceController($rootScope, userService, deviceService, custome
}, },
{ {
onAction: function ($event) { onAction: function ($event) {
importExport.importDevices($event, types.entityType.device).then( importExport.importEntities($event, types.entityType.device).then(
function() { function() {
vm.grid.refreshList(); vm.grid.refreshList();
} }
@ -337,8 +337,6 @@ export function DeviceController($rootScope, userService, deviceService, custome
icon: "add" icon: "add"
}; };
vm.deviceGridConfig.addItemActions = [];
} else if (vm.devicesScope === 'customer_user') { } else if (vm.devicesScope === 'customer_user') {
deviceActionsList.push( deviceActionsList.push(
{ {
@ -352,8 +350,9 @@ export function DeviceController($rootScope, userService, deviceService, custome
); );
vm.deviceGridConfig.addItemAction = {}; vm.deviceGridConfig.addItemAction = {};
vm.deviceGridConfig.addItemActions = [];
} }
vm.deviceGridConfig.addItemActions = [];
} }
vm.deviceGridConfig.refreshParamsFunc = refreshDevicesParamsFunction; vm.deviceGridConfig.refreshParamsFunc = refreshDevicesParamsFunction;

View File

@ -101,13 +101,13 @@ export default function ImportDialogCsvController($scope, $mdDialog, toast, impo
for (var i = 0; i < parseData.headers.length; i++) { for (var i = 0; i < parseData.headers.length; i++) {
if (vm.importParameters.isHeader && parseData.headers[i].search(/^(name|type)$/im) === 0) { if (vm.importParameters.isHeader && parseData.headers[i].search(/^(name|type)$/im) === 0) {
columnParam = { columnParam = {
type: types.entityGroup.columnType.entityField.value, type: types.importEntityColumnType.entityField.value,
key: parseData.headers[i].toLowerCase(), key: parseData.headers[i].toLowerCase(),
sampleData: parseData.rows[0][i] sampleData: parseData.rows[0][i]
}; };
} else { } else {
columnParam = { columnParam = {
type: types.entityGroup.columnType.serverAttribute.value, type: types.importEntityColumnType.serverAttribute.value,
key: vm.importParameters.isHeader ? parseData.headers[i] : "", key: vm.importParameters.isHeader ? parseData.headers[i] : "",
sampleData: parseData.rows[0][i] sampleData: parseData.rows[0][i]
}; };
@ -137,38 +137,34 @@ export default function ImportDialogCsvController($scope, $mdDialog, toast, impo
}; };
for (var j = 0; j < parameterColumns.length; j++) { for (var j = 0; j < parameterColumns.length; j++) {
switch (parameterColumns[j].type) { switch (parameterColumns[j].type) {
case types.entityGroup.columnType.serverAttribute.value: case types.importEntityColumnType.serverAttribute.value:
entityData.attributes.server.push({ entityData.attributes.server.push({
key: parameterColumns[j].key, key: parameterColumns[j].key,
value: importData.rows[i][j] value: importData.rows[i][j]
}); });
break; break;
case types.entityGroup.columnType.sharedAttribute.value: case types.importEntityColumnType.sharedAttribute.value:
entityData.attributes.shared.push({ entityData.attributes.shared.push({
key: parameterColumns[j].key, key: parameterColumns[j].key,
value: importData.rows[i][j] value: importData.rows[i][j]
}); });
break; break;
case types.entityGroup.columnType.timeseries.value: case types.importEntityColumnType.timeseries.value:
entityData.timeseries.push({ entityData.timeseries.push({
key: parameterColumns[j].key, key: parameterColumns[j].key,
value: importData.rows[i][j] value: importData.rows[i][j]
}); });
break; break;
case types.entityGroup.columnType.accessToken.value: case types.importEntityColumnType.accessToken.value:
entityData.accessToken = importData.rows[i][j]; entityData.accessToken = importData.rows[i][j];
break; break;
case types.entityGroup.columnType.entityField.value: case types.importEntityColumnType.name.value:
switch (parameterColumns[j].key) {
case types.entityGroup.entityField.name.value:
entityData.name = importData.rows[i][j]; entityData.name = importData.rows[i][j];
break; break;
case types.entityGroup.entityField.type.value: case types.importEntityColumnType.type.value:
entityData.type = importData.rows[i][j]; entityData.type = importData.rows[i][j];
break; break;
} }
break;
}
} }
entitysData.push(entityData); entitysData.push(entityData);
} }

View File

@ -147,16 +147,13 @@
<md-step md-label="Done"> <md-step md-label="Done">
<md-step-body layout="column"> <md-step-body layout="column">
<div> <div>
<p class="md-body-1" ng-if="vm.statistical.create && vm.statistical.create.device">{{vm.statistical.create.device}} new devices were successfully created.</p> <p class="md-body-1" ng-if="vm.statistical.create && vm.statistical.create.device">{{vm.statistical.create.entity}} new entities were successfully created.</p>
<p class="md-body-1" ng-if="vm.statistical.update && vm.statistical.update.device">{{vm.statistical.update.device}} devices were successfully updated.</p> <p class="md-body-1" ng-if="vm.statistical.update && vm.statistical.update.device">{{vm.statistical.update.entity}} entities were successfully updated.</p>
<p class="md-body-1" ng-if="vm.statistical.error && vm.statistical.error.device">There was an error creating {{vm.statistical.error.device}} devices.</p> <p class="md-body-1" ng-if="vm.statistical.error && vm.statistical.error.device">There was an error creating {{vm.statistical.error.entity}} entities.</p>
</div> </div>
</md-step-body> </md-step-body>
<md-step-actions layout="row"> <md-step-actions layout="row">
<span flex></span> <span flex></span>
<!--<md-button ng-disabled="$root.loading" ng-click="vm.cancel()">-->
<!--{{ 'action.cancel' | translate }}-->
<!--</md-button>-->
<md-button class="md-primary md-raised" ng-disabled="$root.loading" ng-click="vm.finishExport();"> <md-button class="md-primary md-raised" ng-disabled="$root.loading" ng-click="vm.finishExport();">
Ok Ok
</md-button> </md-button>

View File

@ -25,7 +25,7 @@ import entityAliasesTemplate from '../entity/alias/entity-aliases.tpl.html';
/* eslint-disable no-undef, angular/window-service, angular/document-service */ /* eslint-disable no-undef, angular/window-service, angular/document-service */
/*@ngInject*/ /*@ngInject*/
export default function ImportExport($log, $translate, $q, $mdDialog, $document, $http, itembuffer, utils, types, $timeout, deviceService, $rootScope, export default function ImportExport($log, $translate, $q, $mdDialog, $document, $http, itembuffer, utils, types, $rootScope,
dashboardUtils, entityService, dashboardService, ruleChainService, widgetService, toast, attributeService) { dashboardUtils, entityService, dashboardService, ruleChainService, widgetService, toast, attributeService) {
@ -42,7 +42,7 @@ export default function ImportExport($log, $translate, $q, $mdDialog, $document,
importWidgetsBundle: importWidgetsBundle, importWidgetsBundle: importWidgetsBundle,
exportExtension: exportExtension, exportExtension: exportExtension,
importExtension: importExtension, importExtension: importExtension,
importDevices: importDevices, importEntities: importEntities,
convertCSVToJson: convertCSVToJson, convertCSVToJson: convertCSVToJson,
exportToPc: exportToPc, exportToPc: exportToPc,
createMultiEntity: createMultiEntity createMultiEntity: createMultiEntity
@ -578,8 +578,11 @@ export default function ImportExport($log, $translate, $q, $mdDialog, $document,
return deferred.promise; return deferred.promise;
} }
function importDevices($event, entityType) { function importEntities($event, entityType) {
var deferred = $q.defer(); var deferred = $q.defer();
switch (entityType) {
case types.entityType.device:
openImportDialogCSV($event, entityType, 'device.import', 'device.device-file').then( openImportDialogCSV($event, entityType, 'device.import', 'device.device-file').then(
function success() { function success() {
deferred.resolve(); deferred.resolve();
@ -589,6 +592,18 @@ export default function ImportExport($log, $translate, $q, $mdDialog, $document,
} }
); );
return deferred.promise; return deferred.promise;
case types.entityType.asset:
openImportDialogCSV($event, entityType, 'asset.import', 'asset.asset-file').then(
function success() {
deferred.resolve();
},
function fail() {
deferred.reject();
}
);
return deferred.promise;
}
} }
function saveImportedDashboard(dashboard, deferred) { function saveImportedDashboard(dashboard, deferred) {
@ -843,14 +858,12 @@ export default function ImportExport($log, $translate, $q, $mdDialog, $document,
let allPromise = []; let allPromise = [];
let statisticalInfo = {}; let statisticalInfo = {};
let deferred = $q.defer(); let deferred = $q.defer();
switch (entityType) {
case types.entityType.device:
for(let i = 0; i < partSize; i++){ for(let i = 0; i < partSize; i++){
const promise = deviceService.saveDeviceParameters(arrayData[i], updateData, config); const promise = entityService.saveEntityParameters(entityType, arrayData[i], updateData, config);
allPromise.push(promise); allPromise.push(promise);
} }
break;
}
qAllWithProgress(allPromise).then(function success(response) { qAllWithProgress(allPromise).then(function success(response) {
for (let i = 0; i < response.length; i++){ for (let i = 0; i < response.length; i++){
statisticalInfo = sumObject(statisticalInfo, response[i]); statisticalInfo = sumObject(statisticalInfo, response[i]);

View File

@ -38,59 +38,66 @@ export default function TableColumnsAssignment() {
} }
/*@ngInject*/ /*@ngInject*/
function TableColumnsAssignmentController($scope, types, $timeout) { function TableColumnsAssignmentController($scope, types) {
var vm = this; var vm = this;
vm.columnTypes = {}; vm.columnTypes = {};
vm.entityField = {};
vm.columnTypes.name = types.importEntityColumnType.name;
vm.columnTypes.type = types.importEntityColumnType.type;
switch (vm.entityType) { switch (vm.entityType) {
case types.entityType.device: case types.entityType.device:
vm.columnTypes.sharedAttribute = types.entityGroup.columnType.sharedAttribute; vm.columnTypes.sharedAttribute = types.importEntityColumnType.sharedAttribute;
vm.columnTypes.serverAttribute = types.entityGroup.columnType.serverAttribute; vm.columnTypes.serverAttribute = types.importEntityColumnType.serverAttribute;
vm.columnTypes.timeseries = types.entityGroup.columnType.timeseries; vm.columnTypes.timeseries = types.importEntityColumnType.timeseries;
vm.columnTypes.entityField = types.entityGroup.columnType.entityField; vm.columnTypes.accessToken = types.importEntityColumnType.accessToken;
vm.columnTypes.accessToken = types.entityGroup.columnType.accessToken; break;
case types.entityType.asset:
vm.columnTypes.serverAttribute = types.importEntityColumnType.serverAttribute;
vm.columnTypes.timeseries = types.importEntityColumnType.timeseries;
break; break;
} }
vm.entityField.name = types.entityGroup.entityField.name; // switch (vm.entityType) {
// case types.entityType.device:
// vm.entityField.type = types.entityGroup.entityField.type;
// // vm.entityField.assigned_customer = types.entityGroup.entityField.assigned_customer;
// break;
// case types.entityType.asset:
// vm.entityField.type = types.entityGroup.entityField.type;
// // vm.entityField.assigned_customer = types.entityGroup.entityField.assigned_customer;
// break;
// }
switch (vm.entityType) { // $scope.$watch('vm.columns', function(newVal){
case types.entityType.device: // if (newVal) {
vm.entityField.type = types.entityGroup.entityField.type; // var isSelectName = false;
// vm.entityField.assigned_customer = types.entityGroup.entityField.assigned_customer; // var isSelectType = false;
break; // // var isSelectCredentials = false;
} // for (var i = 0; i < newVal.length; i++) {
// if (newVal[i].type === types.importEntityColumnType.entityField.value &&
$scope.$watch('vm.columns', function(newVal){ // newVal[i].key === types.entityGroup.entityField.name.value) {
if (newVal) { // isSelectName = true;
var isSelectName = false; // }
var isSelectType = false; // if (newVal[i].type === types.importEntityColumnType.entityField.value &&
var isSelectCredentials = false; // newVal[i].key === types.entityGroup.entityField.type.value) {
for (var i = 0; i < newVal.length; i++) { // isSelectType = true;
if (newVal[i].type === types.entityGroup.columnType.entityField.value && // }
newVal[i].key === types.entityGroup.entityField.name.value) { // // if (newVal[i].type === types.entityGroup.columnType.accessToken.value) {
isSelectName = true; // // isSelectCredentials = true;
} // // }
if (newVal[i].type === types.entityGroup.columnType.entityField.value && // }
newVal[i].key === types.entityGroup.entityField.type.value) { // $timeout(function () {
isSelectType = true; // vm.entityField.name.disable = isSelectName;
} // vm.entityField.type.disable = isSelectType;
if (newVal[i].type === types.entityGroup.columnType.accessToken.value) { // // vm.columnTypes.accessToken.disable = isSelectCredentials;
isSelectCredentials = true; // });
} // if(isSelectName && isSelectType) {
} // vm.theForm.$setDirty();
$timeout(function () { // } else {
vm.entityField.name.disable = isSelectName; // vm.theForm.$setPristine();
vm.entityField.type.disable = isSelectType; // }
vm.columnTypes.accessToken.disable = isSelectCredentials; // }
}); // }, true);
if(isSelectName && isSelectType) {
vm.theForm.$setDirty();
} else {
vm.theForm.$setPristine();
}
}
}, true);
} }

View File

@ -246,7 +246,9 @@
"select-asset": "Select asset", "select-asset": "Select asset",
"no-assets-matching": "No assets matching '{{entity}}' were found.", "no-assets-matching": "No assets matching '{{entity}}' were found.",
"asset-required": "Asset is required", "asset-required": "Asset is required",
"name-starts-with": "Asset name starts with" "name-starts-with": "Asset name starts with",
"import": "Import assets",
"asset-file": "Asset file"
}, },
"attribute": { "attribute": {
"attributes": "Attributes", "attributes": "Attributes",