...
|
...
|
@@ -20,7 +20,7 @@ export default angular.module('thingsboard.api.device', [thingsboardTypes]) |
20
|
20
|
.name;
|
21
|
21
|
|
22
|
22
|
/*@ngInject*/
|
23
|
|
-function DeviceService($http, $q, $window, userService, attributeService, customerService, types, $timeout) {
|
|
23
|
+function DeviceService($http, $q, $window, userService, attributeService, customerService, types) {
|
24
|
24
|
|
25
|
25
|
var service = {
|
26
|
26
|
assignDeviceToCustomer: assignDeviceToCustomer,
|
...
|
...
|
@@ -173,23 +173,6 @@ function DeviceService($http, $q, $window, userService, attributeService, custom |
173
|
173
|
return deferred.promise;
|
174
|
174
|
}
|
175
|
175
|
|
176
|
|
- function resendRequest(callback){
|
177
|
|
- const deferred = $q.defer();
|
178
|
|
- let request = callback();
|
179
|
|
- request.then(function success(response) {
|
180
|
|
- deferred.resolve(response);
|
181
|
|
- }, function fail(response) {
|
182
|
|
- if (response.status === 429) {
|
183
|
|
- $timeout(function () {
|
184
|
|
- request = callback();
|
185
|
|
- }, 1000 + Math.random() * 10000);
|
186
|
|
- } else {
|
187
|
|
- deferred.reject(response);
|
188
|
|
- }
|
189
|
|
- });
|
190
|
|
- return deferred.promise;
|
191
|
|
- }
|
192
|
|
-
|
193
|
176
|
function saveDeviceRelarion(deviceId, deviceRelation, config) {
|
194
|
177
|
const deferred = $q.defer();
|
195
|
178
|
let attributesType = Object.keys(types.attributesScope);
|
...
|
...
|
@@ -197,16 +180,12 @@ function DeviceService($http, $q, $window, userService, attributeService, custom |
197
|
180
|
let promise = "";
|
198
|
181
|
for (let i = 0; i < attributesType.length; i++) {
|
199
|
182
|
if (deviceRelation.attributes[attributesType[i]] && deviceRelation.attributes[attributesType[i]].length !== 0) {
|
200
|
|
- promise = resendRequest(function () {
|
201
|
|
- return attributeService.saveEntityAttributes(types.entityType.device, deviceId, types.attributesScope[attributesType[i]].value, deviceRelation.attributes[attributesType[i]], config);
|
202
|
|
- });
|
|
183
|
+ promise = attributeService.saveEntityAttributes(types.entityType.device, deviceId, types.attributesScope[attributesType[i]].value, deviceRelation.attributes[attributesType[i]], config);
|
203
|
184
|
allPromise.push(promise);
|
204
|
185
|
}
|
205
|
186
|
}
|
206
|
187
|
if (deviceRelation.timeseries.length !== 0) {
|
207
|
|
- promise = resendRequest(function () {
|
208
|
|
- return attributeService.saveEntityTimeseries(types.entityType.device, deviceId, "time", deviceRelation.timeseries, config);
|
209
|
|
- });
|
|
188
|
+ promise = attributeService.saveEntityTimeseries(types.entityType.device, deviceId, "time", deviceRelation.timeseries, config);
|
210
|
189
|
allPromise.push(promise);
|
211
|
190
|
}
|
212
|
191
|
$q.all(allPromise).then(function success() {
|
...
|
...
|
@@ -227,9 +206,7 @@ function DeviceService($http, $q, $window, userService, attributeService, custom |
227
|
206
|
name: deviceParameters.name,
|
228
|
207
|
type: deviceParameters.type
|
229
|
208
|
};
|
230
|
|
- resendRequest(function () {
|
231
|
|
- return saveDevice(newDevice, config);
|
232
|
|
- }).then(function success(response) {
|
|
209
|
+ saveDevice(newDevice, config).then(function success(response) {
|
233
|
210
|
statisticalInfo.create.device = 1;
|
234
|
211
|
saveDeviceRelarion(response.id.id, deviceParameters, config).then(function success() {
|
235
|
212
|
deferred.resolve(statisticalInfo);
|
...
|
...
|
@@ -237,9 +214,7 @@ function DeviceService($http, $q, $window, userService, attributeService, custom |
237
|
214
|
}, function fail(response) {
|
238
|
215
|
console.log(response); // eslint-disable-line
|
239
|
216
|
if (update) {
|
240
|
|
- resendRequest(function () {
|
241
|
|
- return findByName(deviceParameters.name, config);
|
242
|
|
- }).then(function success(response) {
|
|
217
|
+ findByName(deviceParameters.name, config).then(function success(response) {
|
243
|
218
|
statisticalInfo.update.device = 1;
|
244
|
219
|
saveDeviceRelarion(response.id.id, deviceParameters, config).then(function success() {
|
245
|
220
|
deferred.resolve(statisticalInfo);
|
...
|
...
|
|