Add part send

This commit is contained in:
Vladyslav_Prykhodko 2019-06-06 15:29:50 +03:00
parent d4744f6594
commit b3f7fa8b50
5 changed files with 75 additions and 35 deletions

View File

@ -182,23 +182,40 @@ function DeviceService($http, $q, $window, userService, attributeService, custom
response.credentialsId = deviceRelation.accessToken; response.credentialsId = deviceRelation.accessToken;
response.credentialsType = "ACCESS_TOKEN"; response.credentialsType = "ACCESS_TOKEN";
response.credentialsValue = null; response.credentialsValue = null;
return saveDeviceCredentials(response, config).catch(function(){}); return saveDeviceCredentials(response, config).catch(function(){
return "error";
});
}); });
allPromise.push(promise) allPromise.push(promise)
} }
for (let i = 0; i < attributesType.length; i++) { for (let i = 0; i < attributesType.length; i++) {
let attribute = attributesType[i]; let attribute = attributesType[i];
if (deviceRelation.attributes[attribute] && deviceRelation.attributes[attribute].length !== 0) { 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); allPromise.push(promise);
} }
} }
if (deviceRelation.timeseries.length !== 0) { 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); allPromise.push(promise);
} }
$q.all(allPromise).then(function success() { $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(); deferred.resolve();
}
}); });
return deferred.promise; return deferred.promise;
} }
@ -212,19 +229,29 @@ function DeviceService($http, $q, $window, userService, attributeService, custom
type: deviceParameters.type type: deviceParameters.type
}; };
saveDevice(newDevice, config).then(function success(response) { saveDevice(newDevice, config).then(function success(response) {
saveDeviceRelarion(response.id, deviceParameters, config).then(function success() {
statisticalInfo.create = { statisticalInfo.create = {
device: 1 device: 1
}; };
saveDeviceRelarion(response.id, deviceParameters, config).then(function success() { deferred.resolve(statisticalInfo);
}, function fail() {
statisticalInfo.error = {
device: 1
};
deferred.resolve(statisticalInfo); deferred.resolve(statisticalInfo);
}); });
}, function fail() { }, function fail() {
if (update) { if (update) {
findByName(deviceParameters.name, config).then(function success(response) { findByName(deviceParameters.name, config).then(function success(response) {
saveDeviceRelarion(response.id, deviceParameters, config).then(function success() {
statisticalInfo.update = { statisticalInfo.update = {
device: 1 device: 1
}; };
saveDeviceRelarion(response.id, deviceParameters, config).then(function success() { deferred.resolve(statisticalInfo);
}, function fail() {
statisticalInfo.error = {
device: 1
};
deferred.resolve(statisticalInfo); deferred.resolve(statisticalInfo);
}); });
}, function fail() { }, function fail() {

View File

@ -61,10 +61,6 @@ export default function ImportDialogCsvController($scope, $mdDialog, toast, impo
vm.progressCreate = 0; vm.progressCreate = 0;
$scope.$on('importCSV-completed', function (event, completed) {
vm.progressCreate = completed.progress;
});
var parseData = {}; var parseData = {};
function fileAdded($file) { function fileAdded($file) {
@ -122,6 +118,8 @@ export default function ImportDialogCsvController($scope, $mdDialog, toast, impo
function addDevices(importData, parameterColumns) { function addDevices(importData, parameterColumns) {
var entitysData = []; var entitysData = [];
var sendDataLength = 0;
var entitysDataLength = 0;
var config = { var config = {
ignoreErrors: true, ignoreErrors: true,
resendRequest: true resendRequest: true
@ -174,6 +172,11 @@ export default function ImportDialogCsvController($scope, $mdDialog, toast, impo
} }
entitysData.push(entityData); 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) { importExport.createMultiEntity(entitysData, vm.entityType, vm.importParameters.isUpdate, config).then(function (response) {
vm.statistical = response; vm.statistical = response;
$mdStepper('import-stepper').next(); $mdStepper('import-stepper').next();
@ -186,9 +189,17 @@ export default function ImportDialogCsvController($scope, $mdDialog, toast, impo
vm.importData = null; vm.importData = null;
} }
function previousStep() { function previousStep(step) {
let steppers = $mdStepper('import-stepper'); let steppers = $mdStepper('import-stepper');
switch (step) {
case 1:
steppers.back(); steppers.back();
vm.theFormStep1.$setDirty();
break;
default:
steppers.back();
break;
}
} }
function nextStep(step) { function nextStep(step) {

View File

@ -26,8 +26,7 @@
</md-button> </md-button>
</div> </div>
</md-toolbar> </md-toolbar>
<!--<md-progress-linear class="md-warn" md-mode="indeterminate" ng-disabled="!$root.loading"-->
<!--ng-show="$root.loading"></md-progress-linear>-->
<span style="max-height: 5px; height: 5px;" flex></span> <span style="max-height: 5px; height: 5px;" flex></span>
<md-dialog-content> <md-dialog-content>
<md-stepper id="import-stepper" md-mobile-step-text="vm.isMobileStepText" md-vertical="vm.isVertical" <md-stepper id="import-stepper" md-mobile-step-text="vm.isMobileStepText" md-vertical="vm.isVertical"
@ -105,7 +104,7 @@
</md-step-body> </md-step-body>
<md-step-actions layout="row"> <md-step-actions layout="row">
<md-button ng-disabled="$root.loading" ng-click="vm.previousStep();">Back <md-button ng-disabled="$root.loading" ng-click="vm.previousStep(1);">Back
</md-button> </md-button>
<span flex></span> <span flex></span>
<md-button ng-disabled="$root.loading" ng-click="vm.cancel()"> <md-button ng-disabled="$root.loading" ng-click="vm.cancel()">

View File

@ -60,6 +60,7 @@ $previewSize: 100px !default;
.tb-import-progress{ .tb-import-progress{
margin: 7px 0; margin: 7px 0;
} }
// //
//.md-stepper-indicator.md-THEME_NAME-theme.md-completed .md-stepper-number, //.md-stepper-indicator.md-THEME_NAME-theme.md-completed .md-stepper-number,
//.md-stepper-indicator.md-THEME_NAME-theme.md-active .md-stepper-number{ //.md-stepper-indicator.md-THEME_NAME-theme.md-active .md-stepper-number{

View File

@ -828,38 +828,41 @@ export default function ImportExport($log, $translate, $q, $mdDialog, $document,
return obj1; return obj1;
} }
function qAllWithProgress(promises, progress) { function qAllWithProgress(promises) {
var total = promises.length;
var now = 0;
promises.forEach(function(p) { promises.forEach(function(p) {
p.then(function() { p.then(function() {
now++; $rootScope.$broadcast('importCSV-completed', {});
progress(now / total);
}); });
}); });
return $q.all(promises); return $q.all(promises);
} }
function createMultiEntity(arrayData, entityType, update, config) { function createMultiEntity(arrayData, entityType, updateData, config) {
let deferred = $q.defer(); let partSize = 100;
partSize = arrayData.length > partSize ? partSize : arrayData.length;
let allPromise = []; let allPromise = [];
let statisticalInfo = {}; let statisticalInfo = {};
let deferred = $q.defer();
switch (entityType) { switch (entityType) {
case types.entityType.device: case types.entityType.device:
for(let i = 0; i < arrayData.length; i++){ for(let i = 0; i < partSize; i++){
const promise = deviceService.saveDeviceParameters(arrayData[i], update, config); const promise = deviceService.saveDeviceParameters(arrayData[i], updateData, config);
allPromise.push(promise); allPromise.push(promise);
} }
break; break;
} }
qAllWithProgress(allPromise, function(progress) { qAllWithProgress(allPromise).then(function success(response) {
progress = Math.round(progress * 100);
$rootScope.$broadcast('importCSV-completed', {progress: progress});
}).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]);
} }
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); deferred.resolve(statisticalInfo);
}
}); });
return deferred.promise; return deferred.promise;
} }
@ -965,7 +968,6 @@ export default function ImportExport($log, $translate, $q, $mdDialog, $document,
function fixedDialogSize(scope, element) { function fixedDialogSize(scope, element) {
let dialogElement = element[0].getElementsByTagName('md-dialog'); let dialogElement = element[0].getElementsByTagName('md-dialog');
dialogElement[0].style.width = dialogElement[0].offsetWidth + 2 + "px"; dialogElement[0].style.width = dialogElement[0].offsetWidth + 2 + "px";
dialogElement[0].style.height = dialogElement[0].offsetHeight + "px";
} }
} }