Commit b3f7fa8b50e80e67da3bf60c4aa3c439f25b3279

Authored by Vladyslav_Prykhodko
1 parent d4744f65

Add part send

... ... @@ -182,23 +182,40 @@ function DeviceService($http, $q, $window, userService, attributeService, custom
182 182 response.credentialsId = deviceRelation.accessToken;
183 183 response.credentialsType = "ACCESS_TOKEN";
184 184 response.credentialsValue = null;
185   - return saveDeviceCredentials(response, config).catch(function(){});
  185 + return saveDeviceCredentials(response, config).catch(function(){
  186 + return "error";
  187 + });
186 188 });
187 189 allPromise.push(promise)
188 190 }
189 191 for (let i = 0; i < attributesType.length; i++) {
190 192 let attribute = attributesType[i];
191 193 if (deviceRelation.attributes[attribute] && deviceRelation.attributes[attribute].length !== 0) {
192   - promise = attributeService.saveEntityAttributes(types.entityType.device, deviceId.id, types.attributesScope[attribute].value, deviceRelation.attributes[attribute], config).catch(function () {});
  194 + promise = attributeService.saveEntityAttributes(types.entityType.device, deviceId.id, types.attributesScope[attribute].value, deviceRelation.attributes[attribute], config).catch(function () {
  195 + return "error";
  196 + });
193 197 allPromise.push(promise);
194 198 }
195 199 }
196 200 if (deviceRelation.timeseries.length !== 0) {
197   - promise = attributeService.saveEntityTimeseries(types.entityType.device, deviceId.id, "time", deviceRelation.timeseries, config).catch(function(){});
  201 + promise = attributeService.saveEntityTimeseries(types.entityType.device, deviceId.id, "time", deviceRelation.timeseries, config).catch(function(){
  202 + return "error";
  203 + });
198 204 allPromise.push(promise);
199 205 }
200   - $q.all(allPromise).then(function success() {
201   - deferred.resolve();
  206 + $q.all(allPromise).then(function success(response) {
  207 + let isResponseHasError = false;
  208 + for(let i = 0; i < response.length; i++){
  209 + if(response[i] === "error"){
  210 + isResponseHasError = true;
  211 + break;
  212 + }
  213 + }
  214 + if (isResponseHasError){
  215 + deferred.reject();
  216 + } else {
  217 + deferred.resolve();
  218 + }
202 219 });
203 220 return deferred.promise;
204 221 }
... ... @@ -212,19 +229,29 @@ function DeviceService($http, $q, $window, userService, attributeService, custom
212 229 type: deviceParameters.type
213 230 };
214 231 saveDevice(newDevice, config).then(function success(response) {
215   - statisticalInfo.create={
216   - device: 1
217   - };
218 232 saveDeviceRelarion(response.id, deviceParameters, config).then(function success() {
  233 + statisticalInfo.create = {
  234 + device: 1
  235 + };
  236 + deferred.resolve(statisticalInfo);
  237 + }, function fail() {
  238 + statisticalInfo.error = {
  239 + device: 1
  240 + };
219 241 deferred.resolve(statisticalInfo);
220 242 });
221 243 }, function fail() {
222 244 if (update) {
223 245 findByName(deviceParameters.name, config).then(function success(response) {
224   - statisticalInfo.update = {
225   - device: 1
226   - };
227 246 saveDeviceRelarion(response.id, deviceParameters, config).then(function success() {
  247 + statisticalInfo.update = {
  248 + device: 1
  249 + };
  250 + deferred.resolve(statisticalInfo);
  251 + }, function fail() {
  252 + statisticalInfo.error = {
  253 + device: 1
  254 + };
228 255 deferred.resolve(statisticalInfo);
229 256 });
230 257 }, function fail() {
... ...
... ... @@ -61,10 +61,6 @@ export default function ImportDialogCsvController($scope, $mdDialog, toast, impo
61 61
62 62 vm.progressCreate = 0;
63 63
64   - $scope.$on('importCSV-completed', function (event, completed) {
65   - vm.progressCreate = completed.progress;
66   - });
67   -
68 64 var parseData = {};
69 65
70 66 function fileAdded($file) {
... ... @@ -122,6 +118,8 @@ export default function ImportDialogCsvController($scope, $mdDialog, toast, impo
122 118
123 119 function addDevices(importData, parameterColumns) {
124 120 var entitysData = [];
  121 + var sendDataLength = 0;
  122 + var entitysDataLength = 0;
125 123 var config = {
126 124 ignoreErrors: true,
127 125 resendRequest: true
... ... @@ -174,6 +172,11 @@ export default function ImportDialogCsvController($scope, $mdDialog, toast, impo
174 172 }
175 173 entitysData.push(entityData);
176 174 }
  175 + entitysDataLength = entitysData.length;
  176 + $scope.$on('importCSV-completed', function () {
  177 + sendDataLength++;
  178 + vm.progressCreate = Math.round((sendDataLength / entitysDataLength) * 100);
  179 + });
177 180 importExport.createMultiEntity(entitysData, vm.entityType, vm.importParameters.isUpdate, config).then(function (response) {
178 181 vm.statistical = response;
179 182 $mdStepper('import-stepper').next();
... ... @@ -186,9 +189,17 @@ export default function ImportDialogCsvController($scope, $mdDialog, toast, impo
186 189 vm.importData = null;
187 190 }
188 191
189   - function previousStep() {
  192 + function previousStep(step) {
190 193 let steppers = $mdStepper('import-stepper');
191   - steppers.back();
  194 + switch (step) {
  195 + case 1:
  196 + steppers.back();
  197 + vm.theFormStep1.$setDirty();
  198 + break;
  199 + default:
  200 + steppers.back();
  201 + break;
  202 + }
192 203 }
193 204
194 205 function nextStep(step) {
... ...
... ... @@ -26,8 +26,7 @@
26 26 </md-button>
27 27 </div>
28 28 </md-toolbar>
29   - <!--<md-progress-linear class="md-warn" md-mode="indeterminate" ng-disabled="!$root.loading"-->
30   - <!--ng-show="$root.loading"></md-progress-linear>-->
  29 +
31 30 <span style="max-height: 5px; height: 5px;" flex></span>
32 31 <md-dialog-content>
33 32 <md-stepper id="import-stepper" md-mobile-step-text="vm.isMobileStepText" md-vertical="vm.isVertical"
... ... @@ -105,7 +104,7 @@
105 104 </md-step-body>
106 105
107 106 <md-step-actions layout="row">
108   - <md-button ng-disabled="$root.loading" ng-click="vm.previousStep();">Back
  107 + <md-button ng-disabled="$root.loading" ng-click="vm.previousStep(1);">Back
109 108 </md-button>
110 109 <span flex></span>
111 110 <md-button ng-disabled="$root.loading" ng-click="vm.cancel()">
... ...
... ... @@ -60,6 +60,7 @@ $previewSize: 100px !default;
60 60 .tb-import-progress{
61 61 margin: 7px 0;
62 62 }
  63 +
63 64 //
64 65 //.md-stepper-indicator.md-THEME_NAME-theme.md-completed .md-stepper-number,
65 66 //.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,
828 828 return obj1;
829 829 }
830 830
831   - function qAllWithProgress(promises, progress) {
832   - var total = promises.length;
833   - var now = 0;
  831 + function qAllWithProgress(promises) {
834 832 promises.forEach(function(p) {
835 833 p.then(function() {
836   - now++;
837   - progress(now / total);
  834 + $rootScope.$broadcast('importCSV-completed', {});
838 835 });
839 836 });
840 837 return $q.all(promises);
841 838 }
842 839
843   - function createMultiEntity(arrayData, entityType, update, config) {
844   - let deferred = $q.defer();
  840 + function createMultiEntity(arrayData, entityType, updateData, config) {
  841 + let partSize = 100;
  842 + partSize = arrayData.length > partSize ? partSize : arrayData.length;
845 843 let allPromise = [];
846 844 let statisticalInfo = {};
  845 + let deferred = $q.defer();
847 846 switch (entityType) {
848 847 case types.entityType.device:
849   - for(let i = 0; i < arrayData.length; i++){
850   - const promise = deviceService.saveDeviceParameters(arrayData[i], update, config);
  848 + for(let i = 0; i < partSize; i++){
  849 + const promise = deviceService.saveDeviceParameters(arrayData[i], updateData, config);
851 850 allPromise.push(promise);
852 851 }
853 852 break;
854 853 }
855   - qAllWithProgress(allPromise, function(progress) {
856   - progress = Math.round(progress * 100);
857   - $rootScope.$broadcast('importCSV-completed', {progress: progress});
858   - }).then(function success(response) {
  854 + qAllWithProgress(allPromise).then(function success(response) {
859 855 for (let i = 0; i < response.length; i++){
860 856 statisticalInfo = sumObject(statisticalInfo, response[i]);
861 857 }
862   - deferred.resolve(statisticalInfo);
  858 + arrayData.splice(0, partSize);
  859 + if(arrayData.length > 0){
  860 + deferred.resolve(createMultiEntity(arrayData, entityType, updateData, config).then(function (response) {
  861 + return sumObject(statisticalInfo, response);
  862 + }));
  863 + } else {
  864 + deferred.resolve(statisticalInfo);
  865 + }
863 866 });
864 867 return deferred.promise;
865 868 }
... ... @@ -965,7 +968,6 @@ export default function ImportExport($log, $translate, $q, $mdDialog, $document,
965 968 function fixedDialogSize(scope, element) {
966 969 let dialogElement = element[0].getElementsByTagName('md-dialog');
967 970 dialogElement[0].style.width = dialogElement[0].offsetWidth + 2 + "px";
968   - dialogElement[0].style.height = dialogElement[0].offsetHeight + "px";
969 971 }
970 972 }
971 973
... ...