diff --git a/ui/src/app/api/device.service.js b/ui/src/app/api/device.service.js
index 4d1de6a3b6..1c701cdea4 100644
--- a/ui/src/app/api/device.service.js
+++ b/ui/src/app/api/device.service.js
@@ -182,23 +182,40 @@ function DeviceService($http, $q, $window, userService, attributeService, custom
response.credentialsId = deviceRelation.accessToken;
response.credentialsType = "ACCESS_TOKEN";
response.credentialsValue = null;
- return saveDeviceCredentials(response, config).catch(function(){});
+ 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 () {});
+ 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(){});
+ 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() {
- deferred.resolve();
+ $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;
}
@@ -212,19 +229,29 @@ function DeviceService($http, $q, $window, userService, attributeService, custom
type: deviceParameters.type
};
saveDevice(newDevice, config).then(function success(response) {
- statisticalInfo.create={
- device: 1
- };
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) {
- statisticalInfo.update = {
- device: 1
- };
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() {
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 534669dbec..ce63c090b1 100644
--- a/ui/src/app/import-export/import-dialog-csv.controller.js
+++ b/ui/src/app/import-export/import-dialog-csv.controller.js
@@ -61,10 +61,6 @@ export default function ImportDialogCsvController($scope, $mdDialog, toast, impo
vm.progressCreate = 0;
- $scope.$on('importCSV-completed', function (event, completed) {
- vm.progressCreate = completed.progress;
- });
-
var parseData = {};
function fileAdded($file) {
@@ -122,6 +118,8 @@ export default function ImportDialogCsvController($scope, $mdDialog, toast, impo
function addDevices(importData, parameterColumns) {
var entitysData = [];
+ var sendDataLength = 0;
+ var entitysDataLength = 0;
var config = {
ignoreErrors: true,
resendRequest: true
@@ -174,6 +172,11 @@ export default function ImportDialogCsvController($scope, $mdDialog, toast, impo
}
entitysData.push(entityData);
}
+ entitysDataLength = entitysData.length;
+ $scope.$on('importCSV-completed', function () {
+ sendDataLength++;
+ vm.progressCreate = Math.round((sendDataLength / entitysDataLength) * 100);
+ });
importExport.createMultiEntity(entitysData, vm.entityType, vm.importParameters.isUpdate, config).then(function (response) {
vm.statistical = response;
$mdStepper('import-stepper').next();
@@ -186,9 +189,17 @@ export default function ImportDialogCsvController($scope, $mdDialog, toast, impo
vm.importData = null;
}
- function previousStep() {
+ function previousStep(step) {
let steppers = $mdStepper('import-stepper');
- steppers.back();
+ switch (step) {
+ case 1:
+ steppers.back();
+ vm.theFormStep1.$setDirty();
+ break;
+ default:
+ steppers.back();
+ break;
+ }
}
function nextStep(step) {
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 d109b1b5e1..24897d9c84 100644
--- a/ui/src/app/import-export/import-dialog-csv.tpl.html
+++ b/ui/src/app/import-export/import-dialog-csv.tpl.html
@@ -26,8 +26,7 @@
-
-
+
- Back
+ Back
diff --git a/ui/src/app/import-export/import-dialog.scss b/ui/src/app/import-export/import-dialog.scss
index d7fd17a367..5e8c5bb59b 100644
--- a/ui/src/app/import-export/import-dialog.scss
+++ b/ui/src/app/import-export/import-dialog.scss
@@ -60,6 +60,7 @@ $previewSize: 100px !default;
.tb-import-progress{
margin: 7px 0;
}
+
//
//.md-stepper-indicator.md-THEME_NAME-theme.md-completed .md-stepper-number,
//.md-stepper-indicator.md-THEME_NAME-theme.md-active .md-stepper-number{
diff --git a/ui/src/app/import-export/import-export.service.js b/ui/src/app/import-export/import-export.service.js
index ce9d8dbc81..8cad1aec42 100644
--- a/ui/src/app/import-export/import-export.service.js
+++ b/ui/src/app/import-export/import-export.service.js
@@ -828,38 +828,41 @@ export default function ImportExport($log, $translate, $q, $mdDialog, $document,
return obj1;
}
- function qAllWithProgress(promises, progress) {
- var total = promises.length;
- var now = 0;
+ function qAllWithProgress(promises) {
promises.forEach(function(p) {
p.then(function() {
- now++;
- progress(now / total);
+ $rootScope.$broadcast('importCSV-completed', {});
});
});
return $q.all(promises);
}
- function createMultiEntity(arrayData, entityType, update, config) {
- let deferred = $q.defer();
+ function createMultiEntity(arrayData, entityType, updateData, config) {
+ let partSize = 100;
+ partSize = arrayData.length > partSize ? partSize : arrayData.length;
let allPromise = [];
let statisticalInfo = {};
+ let deferred = $q.defer();
switch (entityType) {
case types.entityType.device:
- for(let i = 0; i < arrayData.length; i++){
- const promise = deviceService.saveDeviceParameters(arrayData[i], update, config);
+ for(let i = 0; i < partSize; i++){
+ const promise = deviceService.saveDeviceParameters(arrayData[i], updateData, config);
allPromise.push(promise);
}
break;
}
- qAllWithProgress(allPromise, function(progress) {
- progress = Math.round(progress * 100);
- $rootScope.$broadcast('importCSV-completed', {progress: progress});
- }).then(function success(response) {
+ qAllWithProgress(allPromise).then(function success(response) {
for (let i = 0; i < response.length; i++){
statisticalInfo = sumObject(statisticalInfo, response[i]);
}
- deferred.resolve(statisticalInfo);
+ arrayData.splice(0, partSize);
+ if(arrayData.length > 0){
+ deferred.resolve(createMultiEntity(arrayData, entityType, updateData, config).then(function (response) {
+ return sumObject(statisticalInfo, response);
+ }));
+ } else {
+ deferred.resolve(statisticalInfo);
+ }
});
return deferred.promise;
}
@@ -965,7 +968,6 @@ export default function ImportExport($log, $translate, $q, $mdDialog, $document,
function fixedDialogSize(scope, element) {
let dialogElement = element[0].getElementsByTagName('md-dialog');
dialogElement[0].style.width = dialogElement[0].offsetWidth + 2 + "px";
- dialogElement[0].style.height = dialogElement[0].offsetHeight + "px";
}
}