Commit 148e4ae7e81af03bd4ca497fbc75463129fedfa6
Committed by
mp-loki
1 parent
306ad5a4
Ability to ignore loading state for some device API calls
Showing
2 changed files
with
16 additions
and
9 deletions
@@ -51,7 +51,7 @@ function DeviceService($http, $q, $filter, userService, telemetryWebsocketServic | @@ -51,7 +51,7 @@ function DeviceService($http, $q, $filter, userService, telemetryWebsocketServic | ||
51 | 51 | ||
52 | return service; | 52 | return service; |
53 | 53 | ||
54 | - function getTenantDevices(pageLink) { | 54 | + function getTenantDevices(pageLink, config) { |
55 | var deferred = $q.defer(); | 55 | var deferred = $q.defer(); |
56 | var url = '/api/tenant/devices?limit=' + pageLink.limit; | 56 | var url = '/api/tenant/devices?limit=' + pageLink.limit; |
57 | if (angular.isDefined(pageLink.textSearch)) { | 57 | if (angular.isDefined(pageLink.textSearch)) { |
@@ -63,7 +63,7 @@ function DeviceService($http, $q, $filter, userService, telemetryWebsocketServic | @@ -63,7 +63,7 @@ function DeviceService($http, $q, $filter, userService, telemetryWebsocketServic | ||
63 | if (angular.isDefined(pageLink.textOffset)) { | 63 | if (angular.isDefined(pageLink.textOffset)) { |
64 | url += '&textOffset=' + pageLink.textOffset; | 64 | url += '&textOffset=' + pageLink.textOffset; |
65 | } | 65 | } |
66 | - $http.get(url, null).then(function success(response) { | 66 | + $http.get(url, config).then(function success(response) { |
67 | deferred.resolve(response.data); | 67 | deferred.resolve(response.data); |
68 | }, function fail() { | 68 | }, function fail() { |
69 | deferred.reject(); | 69 | deferred.reject(); |
@@ -425,7 +425,7 @@ function DeviceService($http, $q, $filter, userService, telemetryWebsocketServic | @@ -425,7 +425,7 @@ function DeviceService($http, $q, $filter, userService, telemetryWebsocketServic | ||
425 | } | 425 | } |
426 | } | 426 | } |
427 | 427 | ||
428 | - function getDeviceAttributes(deviceId, attributeScope, query, successCallback) { | 428 | + function getDeviceAttributes(deviceId, attributeScope, query, successCallback, config) { |
429 | var deferred = $q.defer(); | 429 | var deferred = $q.defer(); |
430 | var subscriptionId = deviceId + attributeScope; | 430 | var subscriptionId = deviceId + attributeScope; |
431 | var das = deviceAttributesSubscriptionMap[subscriptionId]; | 431 | var das = deviceAttributesSubscriptionMap[subscriptionId]; |
@@ -445,7 +445,7 @@ function DeviceService($http, $q, $filter, userService, telemetryWebsocketServic | @@ -445,7 +445,7 @@ function DeviceService($http, $q, $filter, userService, telemetryWebsocketServic | ||
445 | } | 445 | } |
446 | } else { | 446 | } else { |
447 | var url = '/api/plugins/telemetry/' + deviceId + '/values/attributes/' + attributeScope; | 447 | var url = '/api/plugins/telemetry/' + deviceId + '/values/attributes/' + attributeScope; |
448 | - $http.get(url, null).then(function success(response) { | 448 | + $http.get(url, config).then(function success(response) { |
449 | processDeviceAttributes(response.data, query, deferred, successCallback); | 449 | processDeviceAttributes(response.data, query, deferred, successCallback); |
450 | }, function fail() { | 450 | }, function fail() { |
451 | deferred.reject(); | 451 | deferred.reject(); |
@@ -111,11 +111,12 @@ export default function GlobalInterceptor($rootScope, $q, $injector) { | @@ -111,11 +111,12 @@ export default function GlobalInterceptor($rootScope, $q, $injector) { | ||
111 | function request(config) { | 111 | function request(config) { |
112 | var rejected = false; | 112 | var rejected = false; |
113 | if (config.url.startsWith('/api/')) { | 113 | if (config.url.startsWith('/api/')) { |
114 | - $rootScope.loading = !isInternalUrlPrefix(config.url); | 114 | + var isLoading = !isInternalUrlPrefix(config.url); |
115 | + updateLoadingState(config, isLoading); | ||
115 | if (isTokenBasedAuthEntryPoint(config.url)) { | 116 | if (isTokenBasedAuthEntryPoint(config.url)) { |
116 | if (!getUserService().updateAuthorizationHeader(config.headers) && | 117 | if (!getUserService().updateAuthorizationHeader(config.headers) && |
117 | !getUserService().refreshTokenPending()) { | 118 | !getUserService().refreshTokenPending()) { |
118 | - $rootScope.loading = false; | 119 | + updateLoadingState(config, false); |
119 | rejected = true; | 120 | rejected = true; |
120 | getUserService().clearJwtToken(false); | 121 | getUserService().clearJwtToken(false); |
121 | return $q.reject({ data: {message: getTranslate().instant('access.unauthorized')}, status: 401, config: config}); | 122 | return $q.reject({ data: {message: getTranslate().instant('access.unauthorized')}, status: 401, config: config}); |
@@ -131,21 +132,21 @@ export default function GlobalInterceptor($rootScope, $q, $injector) { | @@ -131,21 +132,21 @@ export default function GlobalInterceptor($rootScope, $q, $injector) { | ||
131 | 132 | ||
132 | function requestError(rejection) { | 133 | function requestError(rejection) { |
133 | if (rejection.config.url.startsWith('/api/')) { | 134 | if (rejection.config.url.startsWith('/api/')) { |
134 | - $rootScope.loading = false; | 135 | + updateLoadingState(rejection.config, false); |
135 | } | 136 | } |
136 | return $q.reject(rejection); | 137 | return $q.reject(rejection); |
137 | } | 138 | } |
138 | 139 | ||
139 | function response(response) { | 140 | function response(response) { |
140 | if (response.config.url.startsWith('/api/')) { | 141 | if (response.config.url.startsWith('/api/')) { |
141 | - $rootScope.loading = false; | 142 | + updateLoadingState(response.config, false); |
142 | } | 143 | } |
143 | return response; | 144 | return response; |
144 | } | 145 | } |
145 | 146 | ||
146 | function responseError(rejection) { | 147 | function responseError(rejection) { |
147 | if (rejection.config.url.startsWith('/api/')) { | 148 | if (rejection.config.url.startsWith('/api/')) { |
148 | - $rootScope.loading = false; | 149 | + updateLoadingState(rejection.config, false); |
149 | } | 150 | } |
150 | var unhandled = false; | 151 | var unhandled = false; |
151 | var ignoreErrors = rejection.config.ignoreErrors; | 152 | var ignoreErrors = rejection.config.ignoreErrors; |
@@ -184,4 +185,10 @@ export default function GlobalInterceptor($rootScope, $q, $injector) { | @@ -184,4 +185,10 @@ export default function GlobalInterceptor($rootScope, $q, $injector) { | ||
184 | } | 185 | } |
185 | return $q.reject(rejection); | 186 | return $q.reject(rejection); |
186 | } | 187 | } |
188 | + | ||
189 | + function updateLoadingState(config, isLoading) { | ||
190 | + if (!config || angular.isUndefined(config.ignoreLoading) || !config.ignoreLoading) { | ||
191 | + $rootScope.loading = isLoading; | ||
192 | + } | ||
193 | + } | ||
187 | } | 194 | } |