Commit 15e74792f0a409bda4359e3b92496d7738f43e97

Authored by Vladyslav_Prykhodko
1 parent b3f7fa8b

Add import assets and start refactorin

... ... @@ -32,7 +32,8 @@ function AssetService($http, $q, customerService, userService) {
32 32 getCustomerAssets: getCustomerAssets,
33 33 findByQuery: findByQuery,
34 34 fetchAssetsByNameFilter: fetchAssetsByNameFilter,
35   - getAssetTypes: getAssetTypes
  35 + getAssetTypes: getAssetTypes,
  36 + findByName: findByName
36 37 }
37 38
38 39 return service;
... ... @@ -276,4 +277,16 @@ function AssetService($http, $q, customerService, userService) {
276 277 return deferred.promise;
277 278 }
278 279
  280 + function findByName(assetName, config) {
  281 + config = config || {};
  282 + var deferred = $q.defer();
  283 + var url = '/api/tenant/assets?assetName=' + assetName;
  284 + $http.get(url, config).then(function success(response) {
  285 + deferred.resolve(response.data);
  286 + }, function fail() {
  287 + deferred.reject();
  288 + });
  289 + return deferred.promise;
  290 + }
  291 +
279 292 }
... ...
... ... @@ -31,7 +31,6 @@ function DeviceService($http, $q, $window, userService, attributeService, custom
31 31 getDeviceCredentials: getDeviceCredentials,
32 32 getTenantDevices: getTenantDevices,
33 33 saveDevice: saveDevice,
34   - saveDeviceParameters: saveDeviceParameters,
35 34 saveDeviceCredentials: saveDeviceCredentials,
36 35 unassignDeviceFromCustomer: unassignDeviceFromCustomer,
37 36 makeDevicePublic: makeDevicePublic,
... ... @@ -43,8 +42,9 @@ function DeviceService($http, $q, $window, userService, attributeService, custom
43 42 sendOneWayRpcCommand: sendOneWayRpcCommand,
44 43 sendTwoWayRpcCommand: sendTwoWayRpcCommand,
45 44 findByQuery: findByQuery,
46   - getDeviceTypes: getDeviceTypes
47   - }
  45 + getDeviceTypes: getDeviceTypes,
  46 + findByName: findByName
  47 + };
48 48
49 49 return service;
50 50
... ... @@ -172,104 +172,6 @@ function DeviceService($http, $q, $window, userService, attributeService, custom
172 172 return deferred.promise;
173 173 }
174 174
175   - function saveDeviceRelarion(deviceId, deviceRelation, config) {
176   - const deferred = $q.defer();
177   - let attributesType = Object.keys(types.attributesScope);
178   - let allPromise = [];
179   - let promise = "";
180   - if (deviceRelation.accessToken !== "") {
181   - promise = getDeviceCredentials(deviceId.id,null,config).then(function (response){
182   - response.credentialsId = deviceRelation.accessToken;
183   - response.credentialsType = "ACCESS_TOKEN";
184   - response.credentialsValue = null;
185   - return saveDeviceCredentials(response, config).catch(function(){
186   - return "error";
187   - });
188   - });
189   - allPromise.push(promise)
190   - }
191   - for (let i = 0; i < attributesType.length; i++) {
192   - let attribute = attributesType[i];
193   - if (deviceRelation.attributes[attribute] && deviceRelation.attributes[attribute].length !== 0) {
194   - promise = attributeService.saveEntityAttributes(types.entityType.device, deviceId.id, types.attributesScope[attribute].value, deviceRelation.attributes[attribute], config).catch(function () {
195   - return "error";
196   - });
197   - allPromise.push(promise);
198   - }
199   - }
200   - if (deviceRelation.timeseries.length !== 0) {
201   - promise = attributeService.saveEntityTimeseries(types.entityType.device, deviceId.id, "time", deviceRelation.timeseries, config).catch(function(){
202   - return "error";
203   - });
204   - allPromise.push(promise);
205   - }
206   - $q.all(allPromise).then(function success(response) {
207   - let isResponseHasError = false;
208   - for(let i = 0; i < response.length; i++){
209   - if(response[i] === "error"){
210   - isResponseHasError = true;
211   - break;
212   - }
213   - }
214   - if (isResponseHasError){
215   - deferred.reject();
216   - } else {
217   - deferred.resolve();
218   - }
219   - });
220   - return deferred.promise;
221   - }
222   -
223   - function saveDeviceParameters(deviceParameters, update, config) {
224   - config = config || {};
225   - const deferred = $q.defer();
226   - let statisticalInfo = {};
227   - let newDevice = {
228   - name: deviceParameters.name,
229   - type: deviceParameters.type
230   - };
231   - saveDevice(newDevice, config).then(function success(response) {
232   - saveDeviceRelarion(response.id, deviceParameters, config).then(function success() {
233   - statisticalInfo.create = {
234   - device: 1
235   - };
236   - deferred.resolve(statisticalInfo);
237   - }, function fail() {
238   - statisticalInfo.error = {
239   - device: 1
240   - };
241   - deferred.resolve(statisticalInfo);
242   - });
243   - }, function fail() {
244   - if (update) {
245   - findByName(deviceParameters.name, config).then(function success(response) {
246   - saveDeviceRelarion(response.id, deviceParameters, config).then(function success() {
247   - statisticalInfo.update = {
248   - device: 1
249   - };
250   - deferred.resolve(statisticalInfo);
251   - }, function fail() {
252   - statisticalInfo.error = {
253   - device: 1
254   - };
255   - deferred.resolve(statisticalInfo);
256   - });
257   - }, function fail() {
258   - statisticalInfo.error = {
259   - device: 1
260   - };
261   - deferred.resolve(statisticalInfo);
262   - });
263   - } else {
264   - statisticalInfo.error = {
265   - device: 1
266   - };
267   - deferred.resolve(statisticalInfo);
268   - }
269   - });
270   - return deferred.promise;
271   - }
272   -
273 175 function deleteDevice(deviceId) {
274 176 var deferred = $q.defer();
275 177 var url = '/api/device/' + deviceId;
... ...
... ... @@ -38,6 +38,7 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device
38 38 createAlarmSourceFromSubscriptionInfo: createAlarmSourceFromSubscriptionInfo,
39 39 getRelatedEntities: getRelatedEntities,
40 40 saveRelatedEntity: saveRelatedEntity,
  41 + saveEntityParameters: saveEntityParameters,
41 42 getRelatedEntity: getRelatedEntity,
42 43 deleteRelatedEntity: deleteRelatedEntity,
43 44 moveEntity: moveEntity,
... ... @@ -1072,6 +1073,123 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device
1072 1073 return deferred.promise;
1073 1074 }
1074 1075
  1076 + function saveEntityRelarion(entityType, entityId, entityRelation, config) {
  1077 + const deferred = $q.defer();
  1078 + let attributesType = Object.keys(types.attributesScope);
  1079 + let allPromise = [];
  1080 + let promise = "";
  1081 + if (entityRelation.accessToken !== "") {
  1082 + promise = deviceService.getDeviceCredentials(entityId.id, null, config).then(function (response) {
  1083 + response.credentialsId = entityRelation.accessToken;
  1084 + response.credentialsType = "ACCESS_TOKEN";
  1085 + response.credentialsValue = null;
  1086 + return deviceService.saveDeviceCredentials(response, config).catch(function () {
  1087 + return "error";
  1088 + });
  1089 + });
  1090 + allPromise.push(promise)
  1091 + }
  1092 + for (let i = 0; i < attributesType.length; i++) {
  1093 + let attribute = attributesType[i];
  1094 + if (entityRelation.attributes[attribute] && entityRelation.attributes[attribute].length !== 0) {
  1095 + promise = attributeService.saveEntityAttributes(entityType, entityId.id, types.attributesScope[attribute].value, entityRelation.attributes[attribute], config).catch(function () {
  1096 + return "error";
  1097 + });
  1098 + allPromise.push(promise);
  1099 + }
  1100 + }
  1101 + if (entityRelation.timeseries.length !== 0) {
  1102 + promise = attributeService.saveEntityTimeseries(entityType, entityId.id, "time", entityRelation.timeseries, config).catch(function(){
  1103 + return "error";
  1104 + });
  1105 + allPromise.push(promise);
  1106 + }
  1107 + $q.all(allPromise).then(function success(response) {
  1108 + let isResponseHasError = false;
  1109 + for(let i = 0; i < response.length; i++){
  1110 + if(response[i] === "error"){
  1111 + isResponseHasError = true;
  1112 + break;
  1113 + }
  1114 + }
  1115 + if (isResponseHasError){
  1116 + deferred.reject();
  1117 + } else {
  1118 + deferred.resolve();
  1119 + }
  1120 + });
  1121 + return deferred.promise;
  1122 + }
  1123 +
  1124 + function saveEntityParameters(entityType, entityParameters, update, config) {
  1125 + config = config || {};
  1126 + const deferred = $q.defer();
  1127 + let statisticalInfo = {};
  1128 + let newEntity = {
  1129 + name: entityParameters.name,
  1130 + type: entityParameters.type
  1131 + };
  1132 + let promise;
  1133 + switch (entityType) {
  1134 + case types.entityType.device:
  1135 + promise = deviceService.saveDevice(newEntity, config);
  1136 + break;
  1137 + case types.entityType.asset:
  1138 + promise = assetService.saveAsset(newEntity, true, config);
  1139 + break;
  1140 + }
  1141 +
  1142 + promise.then(function success(response) {
  1143 + saveEntityRelarion(entityType, response.id, entityParameters, config).then(function success() {
  1144 + statisticalInfo.create = {
  1145 + entity: 1
  1146 + };
  1147 + deferred.resolve(statisticalInfo);
  1148 + }, function fail() {
  1149 + statisticalInfo.error = {
  1150 + entity: 1
  1151 + };
  1152 + deferred.resolve(statisticalInfo);
  1153 + });
  1154 + }, function fail() {
  1155 + if (update) {
  1156 + let findIdEntity;
  1157 + switch (entityType) {
  1158 + case types.entityType.device:
  1159 + findIdEntity = deviceService.findByName(entityParameters.name, config);
  1160 + break;
  1161 + case types.entityType.asset:
  1162 + findIdEntity = assetService.findByName(entityParameters.name, config);
  1163 + break;
  1164 + }
  1165 + findIdEntity.then(function success(response) {
  1166 + saveEntityRelarion(response.id, entityType, entityParameters, config).then(function success() {
  1167 + statisticalInfo.update = {
  1168 + entity: 1
  1169 + };
  1170 + deferred.resolve(statisticalInfo);
  1171 + }, function fail() {
  1172 + statisticalInfo.error = {
  1173 + entity: 1
  1174 + };
  1175 + deferred.resolve(statisticalInfo);
  1176 + });
  1177 + }, function fail() {
  1178 + statisticalInfo.error = {
  1179 + entity: 1
  1180 + };
  1181 + deferred.resolve(statisticalInfo);
  1182 + });
  1183 + } else {
  1184 + statisticalInfo.error = {
  1185 + entity: 1
  1186 + };
  1187 + deferred.resolve(statisticalInfo);
  1188 + }
  1189 + });
  1190 + return deferred.promise;
  1191 + }
  1192 +
1075 1193 function getRelatedEntity(entityId, keys, typeTranslatePrefix) {
1076 1194 var deferred = $q.defer();
1077 1195 getEntityPromise(entityId.entityType, entityId.id, {ignoreLoading: true}).then(
... ...
... ... @@ -48,7 +48,7 @@ export function AssetCardController(types) {
48 48
49 49 /*@ngInject*/
50 50 export function AssetController($rootScope, userService, assetService, customerService, $state, $stateParams,
51   - $document, $mdDialog, $q, $translate, types) {
  51 + $document, $mdDialog, $q, $translate, types, importExport) {
52 52
53 53 var customerId = $stateParams.customerId;
54 54
... ... @@ -56,6 +56,29 @@ export function AssetController($rootScope, userService, assetService, customerS
56 56
57 57 var assetGroupActionsList = [];
58 58
  59 + var assetAddItemActionsList = [
  60 + {
  61 + onAction: function ($event) {
  62 + vm.grid.addItem($event);
  63 + },
  64 + name: function() { return $translate.instant('action.add') },
  65 + details: function() { return $translate.instant('asset.add-asset-text') },
  66 + icon: "insert_drive_file"
  67 + },
  68 + {
  69 + onAction: function ($event) {
  70 + importExport.importEntities($event, types.entityType.asset).then(
  71 + function() {
  72 + vm.grid.refreshList();
  73 + }
  74 + );
  75 + },
  76 + name: function() { return $translate.instant('action.import') },
  77 + details: function() { return $translate.instant('asset.import') },
  78 + icon: "file_upload"
  79 + }
  80 + ];
  81 +
59 82 var vm = this;
60 83
61 84 vm.types = types;
... ... @@ -77,6 +100,7 @@ export function AssetController($rootScope, userService, assetService, customerS
77 100
78 101 actionsList: assetActionsList,
79 102 groupActionsList: assetGroupActionsList,
  103 + addItemActions: assetAddItemActionsList,
80 104
81 105 onGridInited: gridInited,
82 106
... ... @@ -294,6 +318,8 @@ export function AssetController($rootScope, userService, assetService, customerS
294 318 } else if (vm.assetsScope === 'customer_user') {
295 319 vm.assetGridConfig.addItemAction = {};
296 320 }
  321 + vm.assetGridConfig.addItemActions = [];
  322 +
297 323 }
298 324
299 325 vm.assetGridConfig.refreshParamsFunc = refreshAssetsParamsFunction;
... ...
... ... @@ -350,48 +350,82 @@ export default angular.module('thingsboard.types', [])
350 350 rulenode: "RULE_NODE",
351 351 entityView: "ENTITY_VIEW"
352 352 },
353   - entityGroup: {
354   - columnType: {
355   - clientAttribute: {
356   - name: 'entity-group.column-type.client-attribute',
357   - value: 'CLIENT_ATTRIBUTE'
358   - },
359   - sharedAttribute: {
360   - name: 'entity-group.column-type.shared-attribute',
361   - value: 'SHARED_ATTRIBUTE'
362   - },
363   - serverAttribute: {
364   - name: 'entity-group.column-type.server-attribute',
365   - value: 'SERVER_ATTRIBUTE'
366   - },
367   - timeseries: {
368   - name: 'entity-group.column-type.timeseries',
369   - value: 'TIMESERIES'
370   - },
371   - entityField: {
372   - name: 'entity-group.column-type.entity-field',
373   - value: 'ENTITY_FIELD'
374   - },
375   - accessToken: {
376   - name: 'entity-group.column-type.access-token',
377   - value: 'ACCESS_TOKEN'
378   - }
  353 + importEntityColumnType: {
  354 + name: {
  355 + name: 'entity-group.entity-field.name',
  356 + value: 'name'
  357 + },
  358 + type: {
  359 + name: 'entity-group.entity-field.type',
  360 + value: 'type'
  361 + },
  362 + clientAttribute: {
  363 + name: 'entity-group.column-type.client-attribute',
  364 + value: 'CLIENT_ATTRIBUTE'
  365 + },
  366 + sharedAttribute: {
  367 + name: 'entity-group.column-type.shared-attribute',
  368 + value: 'SHARED_ATTRIBUTE'
  369 + },
  370 + serverAttribute: {
  371 + name: 'entity-group.column-type.server-attribute',
  372 + value: 'SERVER_ATTRIBUTE'
  373 + },
  374 + timeseries: {
  375 + name: 'entity-group.column-type.timeseries',
  376 + value: 'TIMESERIES'
379 377 },
380 378 entityField: {
381   - name: {
382   - name: 'entity-group.entity-field.name',
383   - value: 'name'
384   - },
385   - type: {
386   - name: 'entity-group.entity-field.type',
387   - value: 'type'
388   - },
389   - assigned_customer: {
390   - name: 'entity-group.entity-field.assigned_customer',
391   - value: 'assigned_customer'
392   - }
  379 + name: 'entity-group.column-type.entity-field',
  380 + value: 'ENTITY_FIELD'
  381 + },
  382 + accessToken: {
  383 + name: 'entity-group.column-type.access-token',
  384 + value: 'ACCESS_TOKEN'
393 385 }
394 386 },
  387 + // entityGroup: {
  388 + // columnType: {
  389 + // clientAttribute: {
  390 + // name: 'entity-group.column-type.client-attribute',
  391 + // value: 'CLIENT_ATTRIBUTE'
  392 + // },
  393 + // sharedAttribute: {
  394 + // name: 'entity-group.column-type.shared-attribute',
  395 + // value: 'SHARED_ATTRIBUTE'
  396 + // },
  397 + // serverAttribute: {
  398 + // name: 'entity-group.column-type.server-attribute',
  399 + // value: 'SERVER_ATTRIBUTE'
  400 + // },
  401 + // timeseries: {
  402 + // name: 'entity-group.column-type.timeseries',
  403 + // value: 'TIMESERIES'
  404 + // },
  405 + // entityField: {
  406 + // name: 'entity-group.column-type.entity-field',
  407 + // value: 'ENTITY_FIELD'
  408 + // },
  409 + // accessToken: {
  410 + // name: 'entity-group.column-type.access-token',
  411 + // value: 'ACCESS_TOKEN'
  412 + // }
  413 + // },
  414 + // entityField: {
  415 + // name: {
  416 + // name: 'entity-group.entity-field.name',
  417 + // value: 'name'
  418 + // },
  419 + // type: {
  420 + // name: 'entity-group.entity-field.type',
  421 + // value: 'type'
  422 + // },
  423 + // assigned_customer: {
  424 + // name: 'entity-group.entity-field.assigned_customer',
  425 + // value: 'assigned_customer'
  426 + // }
  427 + // }
  428 + // },
395 429 aliasEntityType: {
396 430 current_customer: "CURRENT_CUSTOMER"
397 431 },
... ...
... ... @@ -68,7 +68,7 @@ export function DeviceController($rootScope, userService, deviceService, custome
68 68 },
69 69 {
70 70 onAction: function ($event) {
71   - importExport.importDevices($event, types.entityType.device).then(
  71 + importExport.importEntities($event, types.entityType.device).then(
72 72 function() {
73 73 vm.grid.refreshList();
74 74 }
... ... @@ -337,8 +337,6 @@ export function DeviceController($rootScope, userService, deviceService, custome
337 337 icon: "add"
338 338 };
339 339
340   - vm.deviceGridConfig.addItemActions = [];
341   -
342 340 } else if (vm.devicesScope === 'customer_user') {
343 341 deviceActionsList.push(
344 342 {
... ... @@ -352,8 +350,9 @@ export function DeviceController($rootScope, userService, deviceService, custome
352 350 );
353 351
354 352 vm.deviceGridConfig.addItemAction = {};
355   - vm.deviceGridConfig.addItemActions = [];
356 353 }
  354 + vm.deviceGridConfig.addItemActions = [];
  355 +
357 356 }
358 357
359 358 vm.deviceGridConfig.refreshParamsFunc = refreshDevicesParamsFunction;
... ...
... ... @@ -101,13 +101,13 @@ export default function ImportDialogCsvController($scope, $mdDialog, toast, impo
101 101 for (var i = 0; i < parseData.headers.length; i++) {
102 102 if (vm.importParameters.isHeader && parseData.headers[i].search(/^(name|type)$/im) === 0) {
103 103 columnParam = {
104   - type: types.entityGroup.columnType.entityField.value,
  104 + type: types.importEntityColumnType.entityField.value,
105 105 key: parseData.headers[i].toLowerCase(),
106 106 sampleData: parseData.rows[0][i]
107 107 };
108 108 } else {
109 109 columnParam = {
110   - type: types.entityGroup.columnType.serverAttribute.value,
  110 + type: types.importEntityColumnType.serverAttribute.value,
111 111 key: vm.importParameters.isHeader ? parseData.headers[i] : "",
112 112 sampleData: parseData.rows[0][i]
113 113 };
... ... @@ -137,36 +137,32 @@ export default function ImportDialogCsvController($scope, $mdDialog, toast, impo
137 137 };
138 138 for (var j = 0; j < parameterColumns.length; j++) {
139 139 switch (parameterColumns[j].type) {
140   - case types.entityGroup.columnType.serverAttribute.value:
  140 + case types.importEntityColumnType.serverAttribute.value:
141 141 entityData.attributes.server.push({
142 142 key: parameterColumns[j].key,
143 143 value: importData.rows[i][j]
144 144 });
145 145 break;
146   - case types.entityGroup.columnType.sharedAttribute.value:
  146 + case types.importEntityColumnType.sharedAttribute.value:
147 147 entityData.attributes.shared.push({
148 148 key: parameterColumns[j].key,
149 149 value: importData.rows[i][j]
150 150 });
151 151 break;
152   - case types.entityGroup.columnType.timeseries.value:
  152 + case types.importEntityColumnType.timeseries.value:
153 153 entityData.timeseries.push({
154 154 key: parameterColumns[j].key,
155 155 value: importData.rows[i][j]
156 156 });
157 157 break;
158   - case types.entityGroup.columnType.accessToken.value:
  158 + case types.importEntityColumnType.accessToken.value:
159 159 entityData.accessToken = importData.rows[i][j];
160 160 break;
161   - case types.entityGroup.columnType.entityField.value:
162   - switch (parameterColumns[j].key) {
163   - case types.entityGroup.entityField.name.value:
164   - entityData.name = importData.rows[i][j];
165   - break;
166   - case types.entityGroup.entityField.type.value:
167   - entityData.type = importData.rows[i][j];
168   - break;
169   - }
  161 + case types.importEntityColumnType.name.value:
  162 + entityData.name = importData.rows[i][j];
  163 + break;
  164 + case types.importEntityColumnType.type.value:
  165 + entityData.type = importData.rows[i][j];
170 166 break;
171 167 }
172 168 }
... ...
... ... @@ -147,16 +147,13 @@
147 147 <md-step md-label="Done">
148 148 <md-step-body layout="column">
149 149 <div>
150   - <p class="md-body-1" ng-if="vm.statistical.create && vm.statistical.create.device">{{vm.statistical.create.device}} new devices were successfully created.</p>
151   - <p class="md-body-1" ng-if="vm.statistical.update && vm.statistical.update.device">{{vm.statistical.update.device}} devices were successfully updated.</p>
152   - <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>
  150 + <p class="md-body-1" ng-if="vm.statistical.create && vm.statistical.create.device">{{vm.statistical.create.entity}} new entities were successfully created.</p>
  151 + <p class="md-body-1" ng-if="vm.statistical.update && vm.statistical.update.device">{{vm.statistical.update.entity}} entities were successfully updated.</p>
  152 + <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>
153 153 </div>
154 154 </md-step-body>
155 155 <md-step-actions layout="row">
156 156 <span flex></span>
157   - <!--<md-button ng-disabled="$root.loading" ng-click="vm.cancel()">-->
158   - <!--{{ 'action.cancel' | translate }}-->
159   - <!--</md-button>-->
160 157 <md-button class="md-primary md-raised" ng-disabled="$root.loading" ng-click="vm.finishExport();">
161 158 Ok
162 159 </md-button>
... ...
... ... @@ -13,7 +13,7 @@
13 13 * See the License for the specific language governing permissions and
14 14 * limitations under the License.
15 15 */
16   -/* eslint-disable import/no-unresolved, import/default */
  16 +/* eslint-disable import/no-unresolved, import/default*/
17 17
18 18 import importDialogTemplate from './import-dialog.tpl.html';
19 19 import importDialogCSVTemplate from './import-dialog-csv.tpl.html';
... ... @@ -25,7 +25,7 @@ import entityAliasesTemplate from '../entity/alias/entity-aliases.tpl.html';
25 25 /* eslint-disable no-undef, angular/window-service, angular/document-service */
26 26
27 27 /*@ngInject*/
28   -export default function ImportExport($log, $translate, $q, $mdDialog, $document, $http, itembuffer, utils, types, $timeout, deviceService, $rootScope,
  28 +export default function ImportExport($log, $translate, $q, $mdDialog, $document, $http, itembuffer, utils, types, $rootScope,
29 29 dashboardUtils, entityService, dashboardService, ruleChainService, widgetService, toast, attributeService) {
30 30
31 31
... ... @@ -42,7 +42,7 @@ export default function ImportExport($log, $translate, $q, $mdDialog, $document,
42 42 importWidgetsBundle: importWidgetsBundle,
43 43 exportExtension: exportExtension,
44 44 importExtension: importExtension,
45   - importDevices: importDevices,
  45 + importEntities: importEntities,
46 46 convertCSVToJson: convertCSVToJson,
47 47 exportToPc: exportToPc,
48 48 createMultiEntity: createMultiEntity
... ... @@ -578,17 +578,32 @@ export default function ImportExport($log, $translate, $q, $mdDialog, $document,
578 578 return deferred.promise;
579 579 }
580 580
581   - function importDevices($event, entityType) {
  581 + function importEntities($event, entityType) {
582 582 var deferred = $q.defer();
583   - openImportDialogCSV($event, entityType,'device.import', 'device.device-file').then(
584   - function success() {
585   - deferred.resolve();
586   - },
587   - function fail() {
588   - deferred.reject();
589   - }
590   - );
591   - return deferred.promise;
  583 +
  584 + switch (entityType) {
  585 + case types.entityType.device:
  586 + openImportDialogCSV($event, entityType, 'device.import', 'device.device-file').then(
  587 + function success() {
  588 + deferred.resolve();
  589 + },
  590 + function fail() {
  591 + deferred.reject();
  592 + }
  593 + );
  594 + return deferred.promise;
  595 + case types.entityType.asset:
  596 + openImportDialogCSV($event, entityType, 'asset.import', 'asset.asset-file').then(
  597 + function success() {
  598 + deferred.resolve();
  599 + },
  600 + function fail() {
  601 + deferred.reject();
  602 + }
  603 + );
  604 + return deferred.promise;
  605 + }
  606 +
592 607 }
593 608
594 609 function saveImportedDashboard(dashboard, deferred) {
... ... @@ -843,14 +858,12 @@ export default function ImportExport($log, $translate, $q, $mdDialog, $document,
843 858 let allPromise = [];
844 859 let statisticalInfo = {};
845 860 let deferred = $q.defer();
846   - switch (entityType) {
847   - case types.entityType.device:
848   - for(let i = 0; i < partSize; i++){
849   - const promise = deviceService.saveDeviceParameters(arrayData[i], updateData, config);
850   - allPromise.push(promise);
851   - }
852   - break;
  861 +
  862 + for(let i = 0; i < partSize; i++){
  863 + const promise = entityService.saveEntityParameters(entityType, arrayData[i], updateData, config);
  864 + allPromise.push(promise);
853 865 }
  866 +
854 867 qAllWithProgress(allPromise).then(function success(response) {
855 868 for (let i = 0; i < response.length; i++){
856 869 statisticalInfo = sumObject(statisticalInfo, response[i]);
... ...
... ... @@ -38,59 +38,66 @@ export default function TableColumnsAssignment() {
38 38 }
39 39
40 40 /*@ngInject*/
41   -function TableColumnsAssignmentController($scope, types, $timeout) {
  41 +function TableColumnsAssignmentController($scope, types) {
42 42 var vm = this;
43 43
44 44 vm.columnTypes = {};
45   - vm.entityField = {};
46 45
47   - switch (vm.entityType) {
48   - case types.entityType.device:
49   - vm.columnTypes.sharedAttribute = types.entityGroup.columnType.sharedAttribute;
50   - vm.columnTypes.serverAttribute = types.entityGroup.columnType.serverAttribute;
51   - vm.columnTypes.timeseries = types.entityGroup.columnType.timeseries;
52   - vm.columnTypes.entityField = types.entityGroup.columnType.entityField;
53   - vm.columnTypes.accessToken = types.entityGroup.columnType.accessToken;
54   - break;
55   - }
56   -
57   - vm.entityField.name = types.entityGroup.entityField.name;
  46 + vm.columnTypes.name = types.importEntityColumnType.name;
  47 + vm.columnTypes.type = types.importEntityColumnType.type;
58 48
59 49 switch (vm.entityType) {
60 50 case types.entityType.device:
61   - vm.entityField.type = types.entityGroup.entityField.type;
62   - // vm.entityField.assigned_customer = types.entityGroup.entityField.assigned_customer;
  51 + vm.columnTypes.sharedAttribute = types.importEntityColumnType.sharedAttribute;
  52 + vm.columnTypes.serverAttribute = types.importEntityColumnType.serverAttribute;
  53 + vm.columnTypes.timeseries = types.importEntityColumnType.timeseries;
  54 + vm.columnTypes.accessToken = types.importEntityColumnType.accessToken;
  55 + break;
  56 + case types.entityType.asset:
  57 + vm.columnTypes.serverAttribute = types.importEntityColumnType.serverAttribute;
  58 + vm.columnTypes.timeseries = types.importEntityColumnType.timeseries;
63 59 break;
64 60 }
65 61
66   - $scope.$watch('vm.columns', function(newVal){
67   - if (newVal) {
68   - var isSelectName = false;
69   - var isSelectType = false;
70   - var isSelectCredentials = false;
71   - for (var i = 0; i < newVal.length; i++) {
72   - if (newVal[i].type === types.entityGroup.columnType.entityField.value &&
73   - newVal[i].key === types.entityGroup.entityField.name.value) {
74   - isSelectName = true;
75   - }
76   - if (newVal[i].type === types.entityGroup.columnType.entityField.value &&
77   - newVal[i].key === types.entityGroup.entityField.type.value) {
78   - isSelectType = true;
79   - }
80   - if (newVal[i].type === types.entityGroup.columnType.accessToken.value) {
81   - isSelectCredentials = true;
82   - }
83   - }
84   - $timeout(function () {
85   - vm.entityField.name.disable = isSelectName;
86   - vm.entityField.type.disable = isSelectType;
87   - vm.columnTypes.accessToken.disable = isSelectCredentials;
88   - });
89   - if(isSelectName && isSelectType) {
90   - vm.theForm.$setDirty();
91   - } else {
92   - vm.theForm.$setPristine();
93   - }
94   - }
95   - }, true);
  62 + // switch (vm.entityType) {
  63 + // case types.entityType.device:
  64 + // vm.entityField.type = types.entityGroup.entityField.type;
  65 + // // vm.entityField.assigned_customer = types.entityGroup.entityField.assigned_customer;
  66 + // break;
  67 + // case types.entityType.asset:
  68 + // vm.entityField.type = types.entityGroup.entityField.type;
  69 + // // vm.entityField.assigned_customer = types.entityGroup.entityField.assigned_customer;
  70 + // break;
  71 + // }
  72 +
  73 + // $scope.$watch('vm.columns', function(newVal){
  74 + // if (newVal) {
  75 + // var isSelectName = false;
  76 + // var isSelectType = false;
  77 + // // var isSelectCredentials = false;
  78 + // for (var i = 0; i < newVal.length; i++) {
  79 + // if (newVal[i].type === types.importEntityColumnType.entityField.value &&
  80 + // newVal[i].key === types.entityGroup.entityField.name.value) {
  81 + // isSelectName = true;
  82 + // }
  83 + // if (newVal[i].type === types.importEntityColumnType.entityField.value &&
  84 + // newVal[i].key === types.entityGroup.entityField.type.value) {
  85 + // isSelectType = true;
  86 + // }
  87 + // // if (newVal[i].type === types.entityGroup.columnType.accessToken.value) {
  88 + // // isSelectCredentials = true;
  89 + // // }
  90 + // }
  91 + // $timeout(function () {
  92 + // vm.entityField.name.disable = isSelectName;
  93 + // vm.entityField.type.disable = isSelectType;
  94 + // // vm.columnTypes.accessToken.disable = isSelectCredentials;
  95 + // });
  96 + // if(isSelectName && isSelectType) {
  97 + // vm.theForm.$setDirty();
  98 + // } else {
  99 + // vm.theForm.$setPristine();
  100 + // }
  101 + // }
  102 + // }, true);
96 103 }
... ...
... ... @@ -246,7 +246,9 @@
246 246 "select-asset": "Select asset",
247 247 "no-assets-matching": "No assets matching '{{entity}}' were found.",
248 248 "asset-required": "Asset is required",
249   - "name-starts-with": "Asset name starts with"
  249 + "name-starts-with": "Asset name starts with",
  250 + "import": "Import assets",
  251 + "asset-file": "Asset file"
250 252 },
251 253 "attribute": {
252 254 "attributes": "Attributes",
... ...