Errores en spinner

This commit is contained in:
Juan Ferrer Toribio 2017-11-16 13:47:18 +01:00
parent 519a55fac7
commit e03d257930
3 changed files with 22 additions and 7 deletions

View File

@ -7,6 +7,10 @@ import {module} from '../module';
* @property {Snackbar} snackbar The main object to show messages. * @property {Snackbar} snackbar The main object to show messages.
*/ */
export default class App { export default class App {
constructor($rootScope) {
this.loaderStatus = 0;
this.$rootScope = $rootScope;
}
show(message) { show(message) {
if (this.snackbar) this.snackbar.show({message: message}); if (this.snackbar) this.snackbar.show({message: message});
} }
@ -16,5 +20,17 @@ export default class App {
showError(message) { showError(message) {
this.show(`Error: ${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); module.service('vnApp', App);

View File

@ -1,11 +1,10 @@
import {module} from '../module'; import {module} from '../module';
interceptor.$inject = ['$q', '$rootScope', '$window', 'vnApp', '$translate', '$cookies']; interceptor.$inject = ['$q', '$window', 'vnApp', '$translate', '$cookies'];
function interceptor($q, $rootScope, $window, vnApp, $translate, $cookies) { function interceptor($q, $window, vnApp, $translate, $cookies) {
$rootScope.loading = false;
return { return {
request: function(config) { request: function(config) {
$rootScope.loading = true; vnApp.pushLoader();
let token = $cookies.get('vnToken'); let token = $cookies.get('vnToken');
if (token) if (token)
@ -23,11 +22,11 @@ function interceptor($q, $rootScope, $window, vnApp, $translate, $cookies) {
case 'PATCH': case 'PATCH':
vnApp.showMessage($translate.instant('Data saved!')); vnApp.showMessage($translate.instant('Data saved!'));
} }
$rootScope.loading = false; vnApp.popLoader();
return response; return response;
}, },
responseError: function(rejection) { responseError: function(rejection) {
$rootScope.loading = false; vnApp.popLoader();
let data = rejection.data; let data = rejection.data;
let error; let error;

View File

@ -11,7 +11,7 @@ module.exports = function(Self) {
let app = require('../../server/server'); let app = require('../../server/server');
let Employee = app.models.Employee; let Employee = app.models.Employee;
Employee.findOne({where: {userFk: userId}}, function (err, user){ Employee.findOne({where: {userFk: userId}}, function (err, user){
if (user){ if (user) {
ctx.instance.employeeFk = user.id; ctx.instance.employeeFk = user.id;
next(); next();
} }