Browse Source

finish refactored JS code

pull/1776/head
Vladyslav Prykhodko 7 years ago
parent
commit
62186267e4
  1. 6
      ui/src/app/api/entity.service.js
  2. 42
      ui/src/app/common/types.constant.js
  3. 39
      ui/src/app/import-export/import-dialog-csv.controller.js
  4. 18
      ui/src/app/import-export/import-dialog-csv.tpl.html
  5. 2
      ui/src/app/import-export/import-export.service.js
  6. 75
      ui/src/app/import-export/table-columns-assignment.directive.js
  7. 14
      ui/src/app/import-export/table-columns-assignment.tpl.html

6
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;
}

42
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"
},

39
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();
}
}

18
ui/src/app/import-export/import-dialog-csv.tpl.html

@ -147,14 +147,14 @@
<md-step md-label="Done">
<md-step-body layout="column">
<div>
<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.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.entity}} entities.</p>
<p class="md-body-1" ng-if="vm.statistical.create && vm.statistical.create.entity">{{vm.statistical.create.entity}} new entities were successfully created.</p>
<p class="md-body-1" ng-if="vm.statistical.update && vm.statistical.update.entity">{{vm.statistical.update.entity}} entities were successfully updated.</p>
<p class="md-body-1" ng-if="vm.statistical.error && vm.statistical.error.entity">There was an error creating {{vm.statistical.error.entity}} entities.</p>
</div>
</md-step-body>
<md-step-actions layout="row">
<span flex></span>
<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.nextStep(6);">
Ok
</md-button>
</md-step-actions>
@ -162,14 +162,4 @@
</md-stepper>
</md-dialog-content>
<!--<md-dialog-actions layout="row">-->
<!--<span flex></span>-->
<!--<md-button ng-disabled="$root.loading || !theForm.$dirty || !theForm.$valid || !vm.importData" type="submit"-->
<!--class="md-raised md-primary">-->
<!--{{ 'action.import' | translate }}-->
<!--</md-button>-->
<!--<md-button ng-disabled="$root.loading" ng-click="vm.cancel()" style="margin-right:20px;">{{ 'action.cancel'-->
<!--| translate }}-->
<!--</md-button>-->
<!--</md-dialog-actions>-->
</md-dialog>

2
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);

75
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);
}

14
ui/src/app/import-export/table-columns-assignment.tpl.html

@ -22,7 +22,7 @@
<th md-column>&nbsp</th>
<th md-column>Example value data</th>
<th md-column>Column type</th>
<th md-column>Value</th>
<th md-column>Name attributes/telemetry</th>
</tr>
</thead>
<tbody md-body>
@ -38,16 +38,10 @@
</md-select>
</td>
<td md-cell>
<md-select ng-if="column.type == vm.columnTypes.entityField.value"
required name="columnKey" ng-model="column.key"
aria-label="{{ 'entity-group.column-value' | translate }}">
<md-option ng-repeat="field in vm.entityField" ng-value="field.value" ng-disabled="field.disable">
{{field.name | translate}}
</md-option>
</md-select>
<md-input-container md-no-float
ng-if="column.type != vm.columnTypes.entityField.value &&
column.type != vm.columnTypes.accessToken.value">
ng-if="column.type != vm.columnTypes.name.value &&
column.type != vm.columnTypes.type.value &&
column.type != vm.columnTypes.accessToken.value">
<input required name="columnKeyName"
placeholder="{{ 'entity-group.column-value' | translate }}"
ng-model="column.key"

Loading…
Cancel
Save