Commit 148e4ae7e81af03bd4ca497fbc75463129fedfa6

Authored by Igor Kulikov
Committed by mp-loki
1 parent 306ad5a4

Ability to ignore loading state for some device API calls

... ... @@ -51,7 +51,7 @@ function DeviceService($http, $q, $filter, userService, telemetryWebsocketServic
51 51
52 52 return service;
53 53
54   - function getTenantDevices(pageLink) {
  54 + function getTenantDevices(pageLink, config) {
55 55 var deferred = $q.defer();
56 56 var url = '/api/tenant/devices?limit=' + pageLink.limit;
57 57 if (angular.isDefined(pageLink.textSearch)) {
... ... @@ -63,7 +63,7 @@ function DeviceService($http, $q, $filter, userService, telemetryWebsocketServic
63 63 if (angular.isDefined(pageLink.textOffset)) {
64 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 67 deferred.resolve(response.data);
68 68 }, function fail() {
69 69 deferred.reject();
... ... @@ -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 429 var deferred = $q.defer();
430 430 var subscriptionId = deviceId + attributeScope;
431 431 var das = deviceAttributesSubscriptionMap[subscriptionId];
... ... @@ -445,7 +445,7 @@ function DeviceService($http, $q, $filter, userService, telemetryWebsocketServic
445 445 }
446 446 } else {
447 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 449 processDeviceAttributes(response.data, query, deferred, successCallback);
450 450 }, function fail() {
451 451 deferred.reject();
... ...
... ... @@ -111,11 +111,12 @@ export default function GlobalInterceptor($rootScope, $q, $injector) {
111 111 function request(config) {
112 112 var rejected = false;
113 113 if (config.url.startsWith('/api/')) {
114   - $rootScope.loading = !isInternalUrlPrefix(config.url);
  114 + var isLoading = !isInternalUrlPrefix(config.url);
  115 + updateLoadingState(config, isLoading);
115 116 if (isTokenBasedAuthEntryPoint(config.url)) {
116 117 if (!getUserService().updateAuthorizationHeader(config.headers) &&
117 118 !getUserService().refreshTokenPending()) {
118   - $rootScope.loading = false;
  119 + updateLoadingState(config, false);
119 120 rejected = true;
120 121 getUserService().clearJwtToken(false);
121 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 132
132 133 function requestError(rejection) {
133 134 if (rejection.config.url.startsWith('/api/')) {
134   - $rootScope.loading = false;
  135 + updateLoadingState(rejection.config, false);
135 136 }
136 137 return $q.reject(rejection);
137 138 }
138 139
139 140 function response(response) {
140 141 if (response.config.url.startsWith('/api/')) {
141   - $rootScope.loading = false;
  142 + updateLoadingState(response.config, false);
142 143 }
143 144 return response;
144 145 }
145 146
146 147 function responseError(rejection) {
147 148 if (rejection.config.url.startsWith('/api/')) {
148   - $rootScope.loading = false;
  149 + updateLoadingState(rejection.config, false);
149 150 }
150 151 var unhandled = false;
151 152 var ignoreErrors = rejection.config.ignoreErrors;
... ... @@ -184,4 +185,10 @@ export default function GlobalInterceptor($rootScope, $q, $injector) {
184 185 }
185 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 }
... ...