From 62186267e4303a4813b465111fc535ad7304230d Mon Sep 17 00:00:00 2001 From: Vladyslav Prykhodko Date: Fri, 7 Jun 2019 00:54:35 +0300 Subject: [PATCH] finish refactored JS code --- ui/src/app/api/entity.service.js | 6 +- ui/src/app/common/types.constant.js | 42 ----------- .../import-dialog-csv.controller.js | 39 +++++----- .../import-export/import-dialog-csv.tpl.html | 18 +---- .../import-export/import-export.service.js | 2 +- .../table-columns-assignment.directive.js | 75 ++++++++----------- .../table-columns-assignment.tpl.html | 14 +--- 7 files changed, 60 insertions(+), 136 deletions(-) diff --git a/ui/src/app/api/entity.service.js b/ui/src/app/api/entity.service.js index 8608dfc50e..df821368c2 100644 --- a/ui/src/app/api/entity.service.js +++ b/ui/src/app/api/entity.service.js @@ -1112,11 +1112,7 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device break; } } - if (isResponseHasError){ - deferred.reject(); - } else { - deferred.resolve(); - } + isResponseHasError ? deferred.reject() : deferred.resolve(); }); return deferred.promise; } diff --git a/ui/src/app/common/types.constant.js b/ui/src/app/common/types.constant.js index 9c2f07379f..65fd59eeb1 100644 --- a/ui/src/app/common/types.constant.js +++ b/ui/src/app/common/types.constant.js @@ -384,48 +384,6 @@ export default angular.module('thingsboard.types', []) value: 'ACCESS_TOKEN' } }, - // entityGroup: { - // columnType: { - // clientAttribute: { - // name: 'entity-group.column-type.client-attribute', - // value: 'CLIENT_ATTRIBUTE' - // }, - // sharedAttribute: { - // name: 'entity-group.column-type.shared-attribute', - // value: 'SHARED_ATTRIBUTE' - // }, - // serverAttribute: { - // 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: { current_customer: "CURRENT_CUSTOMER" }, diff --git a/ui/src/app/import-export/import-dialog-csv.controller.js b/ui/src/app/import-export/import-dialog-csv.controller.js index accc18ff2d..37f5caa74f 100644 --- a/ui/src/app/import-export/import-dialog-csv.controller.js +++ b/ui/src/app/import-export/import-dialog-csv.controller.js @@ -21,13 +21,11 @@ export default function ImportDialogCsvController($scope, $mdDialog, toast, impo var vm = this; vm.cancel = cancel; - vm.finishExport = finishExport; vm.fileAdded = fileAdded; vm.clearFile = clearFile; vm.nextStep = nextStep; vm.previousStep = previousStep; - vm.addDevices = addDevices; vm.importParameters = { delim: ',', isUpdate: true, @@ -101,7 +99,7 @@ export default function ImportDialogCsvController($scope, $mdDialog, toast, impo for (var i = 0; i < parseData.headers.length; i++) { if (vm.importParameters.isHeader && parseData.headers[i].search(/^(name|type)$/im) === 0) { columnParam = { - type: types.importEntityColumnType.entityField.value, + type: types.importEntityColumnType[parseData.headers[i].toLowerCase()].value, key: parseData.headers[i].toLowerCase(), sampleData: parseData.rows[0][i] }; @@ -116,10 +114,9 @@ export default function ImportDialogCsvController($scope, $mdDialog, toast, impo } } - function addDevices(importData, parameterColumns) { - var entitysData = []; - var sendDataLength = 0; - var entitysDataLength = 0; + function addEntities (importData, parameterColumns) { + var entitiesData = []; + var sentDataLength = 0; var config = { ignoreErrors: true, resendRequest: true @@ -143,14 +140,14 @@ export default function ImportDialogCsvController($scope, $mdDialog, toast, impo value: importData.rows[i][j] }); break; - case types.importEntityColumnType.sharedAttribute.value: - entityData.attributes.shared.push({ + case types.importEntityColumnType.timeseries.value: + entityData.timeseries.push({ key: parameterColumns[j].key, value: importData.rows[i][j] }); break; - case types.importEntityColumnType.timeseries.value: - entityData.timeseries.push({ + case types.importEntityColumnType.sharedAttribute.value: + entityData.attributes.shared.push({ key: parameterColumns[j].key, value: importData.rows[i][j] }); @@ -166,14 +163,13 @@ export default function ImportDialogCsvController($scope, $mdDialog, toast, impo break; } } - entitysData.push(entityData); + entitiesData.push(entityData); } - entitysDataLength = entitysData.length; - $scope.$on('importCSV-completed', function () { - sendDataLength++; - vm.progressCreate = Math.round((sendDataLength / entitysDataLength) * 100); + $scope.$on('createImportEntityCompleted', function () { + sentDataLength++; + vm.progressCreate = Math.round((sentDataLength / importData.rows.length) * 100); }); - importExport.createMultiEntity(entitysData, vm.entityType, vm.importParameters.isUpdate, config).then(function (response) { + importExport.createMultiEntity(entitiesData, vm.entityType, vm.importParameters.isUpdate, config).then(function (response) { vm.statistical = response; $mdStepper('import-stepper').next(); }); @@ -216,7 +212,10 @@ export default function ImportDialogCsvController($scope, $mdDialog, toast, impo break; case 4: steppers.next(); - addDevices(parseData, vm.columnsParam); + addEntities(parseData, vm.columnsParam); + break; + case 6: + $mdDialog.hide(); break; } @@ -229,8 +228,4 @@ export default function ImportDialogCsvController($scope, $mdDialog, toast, impo $mdDialog.cancel(); } } - - function finishExport() { - $mdDialog.hide(); - } } diff --git a/ui/src/app/import-export/import-dialog-csv.tpl.html b/ui/src/app/import-export/import-dialog-csv.tpl.html index e8557dbfcc..b10d1f6da9 100644 --- a/ui/src/app/import-export/import-dialog-csv.tpl.html +++ b/ui/src/app/import-export/import-dialog-csv.tpl.html @@ -147,14 +147,14 @@
-

{{vm.statistical.create.entity}} new entities were successfully created.

-

{{vm.statistical.update.entity}} entities were successfully updated.

-

There was an error creating {{vm.statistical.error.entity}} entities.

+

{{vm.statistical.create.entity}} new entities were successfully created.

+

{{vm.statistical.update.entity}} entities were successfully updated.

+

There was an error creating {{vm.statistical.error.entity}} entities.

- + Ok @@ -162,14 +162,4 @@ - - - - - - - - - - diff --git a/ui/src/app/import-export/import-export.service.js b/ui/src/app/import-export/import-export.service.js index c740b05659..c7f83a9b15 100644 --- a/ui/src/app/import-export/import-export.service.js +++ b/ui/src/app/import-export/import-export.service.js @@ -846,7 +846,7 @@ export default function ImportExport($log, $translate, $q, $mdDialog, $document, function qAllWithProgress(promises) { promises.forEach(function(p) { p.then(function() { - $rootScope.$broadcast('importCSV-completed', {}); + $rootScope.$broadcast('createImportEntityCompleted', {}); }); }); return $q.all(promises); diff --git a/ui/src/app/import-export/table-columns-assignment.directive.js b/ui/src/app/import-export/table-columns-assignment.directive.js index b0588ee477..6fad87339c 100644 --- a/ui/src/app/import-export/table-columns-assignment.directive.js +++ b/ui/src/app/import-export/table-columns-assignment.directive.js @@ -38,7 +38,7 @@ export default function TableColumnsAssignment() { } /*@ngInject*/ -function TableColumnsAssignmentController($scope, types) { +function TableColumnsAssignmentController($scope, types, $timeout) { var vm = this; vm.columnTypes = {}; @@ -59,45 +59,36 @@ function TableColumnsAssignmentController($scope, types) { break; } - // 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; - // } - - // $scope.$watch('vm.columns', function(newVal){ - // if (newVal) { - // var isSelectName = false; - // var isSelectType = false; - // // var isSelectCredentials = false; - // for (var i = 0; i < newVal.length; i++) { - // if (newVal[i].type === types.importEntityColumnType.entityField.value && - // newVal[i].key === types.entityGroup.entityField.name.value) { - // isSelectName = true; - // } - // if (newVal[i].type === types.importEntityColumnType.entityField.value && - // newVal[i].key === types.entityGroup.entityField.type.value) { - // isSelectType = true; - // } - // // if (newVal[i].type === types.entityGroup.columnType.accessToken.value) { - // // isSelectCredentials = true; - // // } - // } - // $timeout(function () { - // vm.entityField.name.disable = isSelectName; - // vm.entityField.type.disable = isSelectType; - // // vm.columnTypes.accessToken.disable = isSelectCredentials; - // }); - // if(isSelectName && isSelectType) { - // vm.theForm.$setDirty(); - // } else { - // vm.theForm.$setPristine(); - // } - // } - // }, true); + $scope.$watch('vm.columns', function(newVal){ + if (newVal) { + var isSelectName = false; + var isSelectType = false; + var isSelectCredentials = false; + for (var i = 0; i < newVal.length; i++) { + switch (newVal[i].type) { + case types.importEntityColumnType.name.value: + isSelectName = true; + break; + case types.importEntityColumnType.type.value: + isSelectType = true; + break; + case types.importEntityColumnType.accessToken.value: + isSelectCredentials = true; + break; + } + } + if(isSelectName && isSelectType) { + vm.theForm.$setDirty(); + } else { + vm.theForm.$setPristine(); + } + $timeout(function () { + vm.columnTypes.name.disable = isSelectName; + vm.columnTypes.type.disable = isSelectType; + if (angular.isDefined(vm.columnTypes.accessToken)) { + vm.columnTypes.accessToken.disable = isSelectCredentials; + } + }); + } + }, true); } diff --git a/ui/src/app/import-export/table-columns-assignment.tpl.html b/ui/src/app/import-export/table-columns-assignment.tpl.html index a1ee9598e7..66c34c7ea7 100644 --- a/ui/src/app/import-export/table-columns-assignment.tpl.html +++ b/ui/src/app/import-export/table-columns-assignment.tpl.html @@ -22,7 +22,7 @@   Example value data Column type - Value + Name attributes/telemetry @@ -38,16 +38,10 @@ - - - {{field.name | translate}} - - + ng-if="column.type != vm.columnTypes.name.value && + column.type != vm.columnTypes.type.value && + column.type != vm.columnTypes.accessToken.value">