Showing
5 changed files
with
75 additions
and
35 deletions
@@ -182,23 +182,40 @@ function DeviceService($http, $q, $window, userService, attributeService, custom | @@ -182,23 +182,40 @@ function DeviceService($http, $q, $window, userService, attributeService, custom | ||
182 | response.credentialsId = deviceRelation.accessToken; | 182 | response.credentialsId = deviceRelation.accessToken; |
183 | response.credentialsType = "ACCESS_TOKEN"; | 183 | response.credentialsType = "ACCESS_TOKEN"; |
184 | response.credentialsValue = null; | 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 | allPromise.push(promise) | 189 | allPromise.push(promise) |
188 | } | 190 | } |
189 | for (let i = 0; i < attributesType.length; i++) { | 191 | for (let i = 0; i < attributesType.length; i++) { |
190 | let attribute = attributesType[i]; | 192 | let attribute = attributesType[i]; |
191 | if (deviceRelation.attributes[attribute] && deviceRelation.attributes[attribute].length !== 0) { | 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 | allPromise.push(promise); | 197 | allPromise.push(promise); |
194 | } | 198 | } |
195 | } | 199 | } |
196 | if (deviceRelation.timeseries.length !== 0) { | 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 | allPromise.push(promise); | 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 | return deferred.promise; | 220 | return deferred.promise; |
204 | } | 221 | } |
@@ -212,19 +229,29 @@ function DeviceService($http, $q, $window, userService, attributeService, custom | @@ -212,19 +229,29 @@ function DeviceService($http, $q, $window, userService, attributeService, custom | ||
212 | type: deviceParameters.type | 229 | type: deviceParameters.type |
213 | }; | 230 | }; |
214 | saveDevice(newDevice, config).then(function success(response) { | 231 | saveDevice(newDevice, config).then(function success(response) { |
215 | - statisticalInfo.create={ | ||
216 | - device: 1 | ||
217 | - }; | ||
218 | saveDeviceRelarion(response.id, deviceParameters, config).then(function success() { | 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 | deferred.resolve(statisticalInfo); | 241 | deferred.resolve(statisticalInfo); |
220 | }); | 242 | }); |
221 | }, function fail() { | 243 | }, function fail() { |
222 | if (update) { | 244 | if (update) { |
223 | findByName(deviceParameters.name, config).then(function success(response) { | 245 | findByName(deviceParameters.name, config).then(function success(response) { |
224 | - statisticalInfo.update = { | ||
225 | - device: 1 | ||
226 | - }; | ||
227 | saveDeviceRelarion(response.id, deviceParameters, config).then(function success() { | 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 | deferred.resolve(statisticalInfo); | 255 | deferred.resolve(statisticalInfo); |
229 | }); | 256 | }); |
230 | }, function fail() { | 257 | }, function fail() { |
@@ -61,10 +61,6 @@ export default function ImportDialogCsvController($scope, $mdDialog, toast, impo | @@ -61,10 +61,6 @@ export default function ImportDialogCsvController($scope, $mdDialog, toast, impo | ||
61 | 61 | ||
62 | vm.progressCreate = 0; | 62 | vm.progressCreate = 0; |
63 | 63 | ||
64 | - $scope.$on('importCSV-completed', function (event, completed) { | ||
65 | - vm.progressCreate = completed.progress; | ||
66 | - }); | ||
67 | - | ||
68 | var parseData = {}; | 64 | var parseData = {}; |
69 | 65 | ||
70 | function fileAdded($file) { | 66 | function fileAdded($file) { |
@@ -122,6 +118,8 @@ export default function ImportDialogCsvController($scope, $mdDialog, toast, impo | @@ -122,6 +118,8 @@ export default function ImportDialogCsvController($scope, $mdDialog, toast, impo | ||
122 | 118 | ||
123 | function addDevices(importData, parameterColumns) { | 119 | function addDevices(importData, parameterColumns) { |
124 | var entitysData = []; | 120 | var entitysData = []; |
121 | + var sendDataLength = 0; | ||
122 | + var entitysDataLength = 0; | ||
125 | var config = { | 123 | var config = { |
126 | ignoreErrors: true, | 124 | ignoreErrors: true, |
127 | resendRequest: true | 125 | resendRequest: true |
@@ -174,6 +172,11 @@ export default function ImportDialogCsvController($scope, $mdDialog, toast, impo | @@ -174,6 +172,11 @@ export default function ImportDialogCsvController($scope, $mdDialog, toast, impo | ||
174 | } | 172 | } |
175 | entitysData.push(entityData); | 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 | importExport.createMultiEntity(entitysData, vm.entityType, vm.importParameters.isUpdate, config).then(function (response) { | 180 | importExport.createMultiEntity(entitysData, vm.entityType, vm.importParameters.isUpdate, config).then(function (response) { |
178 | vm.statistical = response; | 181 | vm.statistical = response; |
179 | $mdStepper('import-stepper').next(); | 182 | $mdStepper('import-stepper').next(); |
@@ -186,9 +189,17 @@ export default function ImportDialogCsvController($scope, $mdDialog, toast, impo | @@ -186,9 +189,17 @@ export default function ImportDialogCsvController($scope, $mdDialog, toast, impo | ||
186 | vm.importData = null; | 189 | vm.importData = null; |
187 | } | 190 | } |
188 | 191 | ||
189 | - function previousStep() { | 192 | + function previousStep(step) { |
190 | let steppers = $mdStepper('import-stepper'); | 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 | function nextStep(step) { | 205 | function nextStep(step) { |
@@ -26,8 +26,7 @@ | @@ -26,8 +26,7 @@ | ||
26 | </md-button> | 26 | </md-button> |
27 | </div> | 27 | </div> |
28 | </md-toolbar> | 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 | <span style="max-height: 5px; height: 5px;" flex></span> | 30 | <span style="max-height: 5px; height: 5px;" flex></span> |
32 | <md-dialog-content> | 31 | <md-dialog-content> |
33 | <md-stepper id="import-stepper" md-mobile-step-text="vm.isMobileStepText" md-vertical="vm.isVertical" | 32 | <md-stepper id="import-stepper" md-mobile-step-text="vm.isMobileStepText" md-vertical="vm.isVertical" |
@@ -105,7 +104,7 @@ | @@ -105,7 +104,7 @@ | ||
105 | </md-step-body> | 104 | </md-step-body> |
106 | 105 | ||
107 | <md-step-actions layout="row"> | 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 | </md-button> | 108 | </md-button> |
110 | <span flex></span> | 109 | <span flex></span> |
111 | <md-button ng-disabled="$root.loading" ng-click="vm.cancel()"> | 110 | <md-button ng-disabled="$root.loading" ng-click="vm.cancel()"> |
@@ -60,6 +60,7 @@ $previewSize: 100px !default; | @@ -60,6 +60,7 @@ $previewSize: 100px !default; | ||
60 | .tb-import-progress{ | 60 | .tb-import-progress{ |
61 | margin: 7px 0; | 61 | margin: 7px 0; |
62 | } | 62 | } |
63 | + | ||
63 | // | 64 | // |
64 | //.md-stepper-indicator.md-THEME_NAME-theme.md-completed .md-stepper-number, | 65 | //.md-stepper-indicator.md-THEME_NAME-theme.md-completed .md-stepper-number, |
65 | //.md-stepper-indicator.md-THEME_NAME-theme.md-active .md-stepper-number{ | 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,38 +828,41 @@ export default function ImportExport($log, $translate, $q, $mdDialog, $document, | ||
828 | return obj1; | 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 | promises.forEach(function(p) { | 832 | promises.forEach(function(p) { |
835 | p.then(function() { | 833 | p.then(function() { |
836 | - now++; | ||
837 | - progress(now / total); | 834 | + $rootScope.$broadcast('importCSV-completed', {}); |
838 | }); | 835 | }); |
839 | }); | 836 | }); |
840 | return $q.all(promises); | 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 | let allPromise = []; | 843 | let allPromise = []; |
846 | let statisticalInfo = {}; | 844 | let statisticalInfo = {}; |
845 | + let deferred = $q.defer(); | ||
847 | switch (entityType) { | 846 | switch (entityType) { |
848 | case types.entityType.device: | 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 | allPromise.push(promise); | 850 | allPromise.push(promise); |
852 | } | 851 | } |
853 | break; | 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 | for (let i = 0; i < response.length; i++){ | 855 | for (let i = 0; i < response.length; i++){ |
860 | statisticalInfo = sumObject(statisticalInfo, response[i]); | 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 | return deferred.promise; | 867 | return deferred.promise; |
865 | } | 868 | } |
@@ -965,7 +968,6 @@ export default function ImportExport($log, $translate, $q, $mdDialog, $document, | @@ -965,7 +968,6 @@ export default function ImportExport($log, $translate, $q, $mdDialog, $document, | ||
965 | function fixedDialogSize(scope, element) { | 968 | function fixedDialogSize(scope, element) { |
966 | let dialogElement = element[0].getElementsByTagName('md-dialog'); | 969 | let dialogElement = element[0].getElementsByTagName('md-dialog'); |
967 | dialogElement[0].style.width = dialogElement[0].offsetWidth + 2 + "px"; | 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 |