Add part send
This commit is contained in:
parent
d4744f6594
commit
b3f7fa8b50
@ -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() {
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -26,8 +26,7 @@
|
||||
</md-button>
|
||||
</div>
|
||||
</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>
|
||||
<md-dialog-content>
|
||||
<md-stepper id="import-stepper" md-mobile-step-text="vm.isMobileStepText" md-vertical="vm.isVertical"
|
||||
@ -105,7 +104,7 @@
|
||||
</md-step-body>
|
||||
|
||||
<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>
|
||||
<span flex></span>
|
||||
<md-button ng-disabled="$root.loading" ng-click="vm.cancel()">
|
||||
|
||||
@ -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{
|
||||
|
||||
@ -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";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user