From e03d257930bc186f3e86bcf6abd71dc710562d7a Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Thu, 16 Nov 2017 13:47:18 +0100 Subject: [PATCH] Errores en spinner --- client/core/src/lib/app.js | 16 ++++++++++++++++ client/core/src/lib/interceptor.js | 11 +++++------ .../client/common/models/client-observation.js | 2 +- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/client/core/src/lib/app.js b/client/core/src/lib/app.js index dd6ef1f09..4830fead3 100644 --- a/client/core/src/lib/app.js +++ b/client/core/src/lib/app.js @@ -7,6 +7,10 @@ import {module} from '../module'; * @property {Snackbar} snackbar The main object to show messages. */ export default class App { + constructor($rootScope) { + this.loaderStatus = 0; + this.$rootScope = $rootScope; + } show(message) { if (this.snackbar) this.snackbar.show({message: message}); } @@ -16,5 +20,17 @@ export default class App { showError(message) { this.show(`Error: ${message}`); } + pushLoader() { + this.loaderStatus++; + if (this.loaderStatus === 1) + this.$rootScope.loading = true; + } + popLoader() { + this.loaderStatus--; + if (this.loaderStatus === 0) + this.$rootScope.loading = false; + } } +App.$inject = ['$rootScope'] + module.service('vnApp', App); diff --git a/client/core/src/lib/interceptor.js b/client/core/src/lib/interceptor.js index 9cd97d78a..6d9266018 100644 --- a/client/core/src/lib/interceptor.js +++ b/client/core/src/lib/interceptor.js @@ -1,11 +1,10 @@ import {module} from '../module'; -interceptor.$inject = ['$q', '$rootScope', '$window', 'vnApp', '$translate', '$cookies']; -function interceptor($q, $rootScope, $window, vnApp, $translate, $cookies) { - $rootScope.loading = false; +interceptor.$inject = ['$q', '$window', 'vnApp', '$translate', '$cookies']; +function interceptor($q, $window, vnApp, $translate, $cookies) { return { request: function(config) { - $rootScope.loading = true; + vnApp.pushLoader(); let token = $cookies.get('vnToken'); if (token) @@ -23,11 +22,11 @@ function interceptor($q, $rootScope, $window, vnApp, $translate, $cookies) { case 'PATCH': vnApp.showMessage($translate.instant('Data saved!')); } - $rootScope.loading = false; + vnApp.popLoader(); return response; }, responseError: function(rejection) { - $rootScope.loading = false; + vnApp.popLoader(); let data = rejection.data; let error; diff --git a/services/client/common/models/client-observation.js b/services/client/common/models/client-observation.js index 39470f4c7..cd1cba2a8 100644 --- a/services/client/common/models/client-observation.js +++ b/services/client/common/models/client-observation.js @@ -11,7 +11,7 @@ module.exports = function(Self) { let app = require('../../server/server'); let Employee = app.models.Employee; Employee.findOne({where: {userFk: userId}}, function (err, user){ - if (user){ + if (user) { ctx.instance.employeeFk = user.id; next(); }