Commit d7667516 authored by Pedro Eduardo Trujillo's avatar Pedro Eduardo Trujillo
Browse files

Recarga app tras login

Se detectaron problemas de definiciones y permisos tras hacer login en
vistas de la aplicación. Las definiciones se calculan una sola vez por
carga, por lo que si cambian los permisos del usuario, este cálculo no
se repite a menos que se recargue la página.

Se refactoriza y redefine el flujo de enrutamiento para conseguir el
mismo comportamiento pero recargando la página al hacer login.
parent e92255d1
Loading
Loading
Loading
Loading
+10 −4
Original line number Diff line number Diff line
@@ -178,6 +178,9 @@ define([
			},{
				channel : this._credentials.getChannel('REMOVED'),
				callback: '_subCredentialsRemoved'
			},{
				channel : this._credentials.getChannel('ADDED'),
				callback: '_subCredentialsAdded'
			},{
				channel : this._credentials.getChannel('REQUEST_FAILED'),
				callback: '_subCredentialsRequestFailed'
@@ -211,16 +214,19 @@ define([

		_subCredentialsRemoved: function() {

			this._publish(this._router.getChannel('GO_TO_ROOT_ROUTE'), {
			this._publish(this._router.getChannel('GO_TO_PREV_OR_ROOT_ROUTE'), {
				userGone: true
			});
		},

		_subCredentialsAdded: function() {

			this._publish(this._router.getChannel('GO_TO_PREV_OR_ROOT_ROUTE'));
		},

		_subAvailableCredentials: function(res) {

			this._publish(this._router.getChannel('EVALUATE_ROUTE'), {
				userFound: res.found
			});
			this._publish(this._router.getChannel('EVALUATE_ROUTE'));
		},

		_subCredentialsRequestFailed: function() {
+9 −8
Original line number Diff line number Diff line
@@ -30,7 +30,8 @@ define([
				events: {
					GET_CREDENTIALS: 'getCredentials',
					GET_ALLOWED_MODULES: 'getAllowedModules',
					REMOVE: 'remove',
					REMOVED: 'removed',
					ADDED: 'added',
					ACCEPT_COOKIES: 'acceptCookies',
					REQUEST_FAILED: 'requestFailed'
				},
@@ -40,6 +41,7 @@ define([
					AVAILABLE: 'available',
					AVAILABLE_ALLOWED_MODULES: 'availableAllowedModules',
					REMOVED: 'removed',
					ADDED: 'added',
					COOKIES_ACCEPTED: 'cookiesAccepted',
					ACCEPT_COOKIES: 'acceptCookies',
					COOKIES_STATE: 'cookiesState',
@@ -102,8 +104,11 @@ define([
				event: 'GET_ALLOWED_MODULES',
				channel: this.getChannel('AVAILABLE_ALLOWED_MODULES')
			},{
				event: 'REMOVE',
				event: 'REMOVED',
				channel: this.getChannel('REMOVED')
			},{
				event: 'ADDED',
				channel: this.getChannel('ADDED')
			},{
				event: 'ACCEPT_COOKIES',
				channel: this.getChannel('COOKIES_ACCEPTED')
@@ -159,18 +164,14 @@ define([

			this._setEmptySelectionIds();

			if (globalThis.location.pathname === this._loginPath) {
				this._getCredentials();
			} else {
				globalThis.location.reload();
			}
			this._emitEvt('ADDED');
		},

		_onAccessTokenRemoved: function() {

			this._setEmptySelectionIds();

			this._emitEvt('REMOVE');
			this._emitEvt('REMOVED');
		},

		_cookiesAccepted: function(evt) {
+1 −17
Original line number Diff line number Diff line
@@ -42,14 +42,12 @@ define([
			this.config = {
				moduleStore: new Memory(),
				actions: {
					GET_ALLOWED_MODULES: "getAllowedModules",
					AVAILABLE_ALLOWED_MODULES: "availableAllowedModules",
					GET_MODULE: "getModule",
					AVAILABLE_MODULE: "availableModule",
					CLEAR_MODULE: 'clearModule'
				},
				events: {
					GET_ALLOWED_MODULES: "getAllowedModules",
					GET_MODULE: "getModule"
				},
				// mediator params
@@ -69,8 +67,7 @@ define([
		_defineSubscriptions: function () {

			this.subscriptionsConfig.push({
				channel : this._buildChannel(this.credentialsChannel,
					this.actions.AVAILABLE_ALLOWED_MODULES),
				channel : this._buildChannel(this.credentialsChannel, 'AVAILABLE_ALLOWED_MODULES'),
				callback: "_subAllowedModules",
				options: {
					predicate: lang.hitch(this, this._chkPublicationIsForMe)
@@ -87,24 +84,11 @@ define([
		_definePublications: function() {

			this.publicationsConfig.push({
				event: 'GET_ALLOWED_MODULES',
				channel: this._buildChannel(this.credentialsChannel,
					this.actions.GET_ALLOWED_MODULES)
			},{
				event: 'GET_MODULE',
				channel: this.getChannel("AVAILABLE_MODULE")
			});
		},

		postCreate: function() {

			this.inherited(arguments);

			this._emitEvt('GET_ALLOWED_MODULES', {
				id: this.getOwnChannel()
			});
		},

		_subAllowedModules: function(/*Object*/ res) {
			//	summary:
			//		Recibe nuevos módulos disponibles, por lo que limpia el module store
+14 −20
Original line number Diff line number Diff line
@@ -21,8 +21,6 @@ define([

		//	paths: Object
		//		Constantes de rutas base
		//	_userFound: Boolean
		//		Indica si hay presente algún token de usuario.

		constructor: function(args) {

@@ -36,7 +34,7 @@ define([
					CHANGE_MODULE: 'changeModule',
					MODULE_CHANGED: 'moduleChanged',
					EVALUATE_ROUTE: 'evaluateRoot',
					GO_TO_ROOT_ROUTE: 'goToRootRoute',
					GO_TO_PREV_OR_ROOT_ROUTE: 'goToPrevOrRootRoute',
					GO_TO_ERROR_ROUTE: 'goToErrorRoute',
					GET_QUERY_PARAMS: 'getQueryParams',
					GOT_QUERY_PARAMS: 'gotQueryParams'
@@ -64,8 +62,8 @@ define([
				channel : this.getChannel('EVALUATE_ROUTE'),
				callback: '_subEvaluateRoute'
			},{
				channel : this.getChannel('GO_TO_ROOT_ROUTE'),
				callback: '_subGoToRootRoute'
				channel : this.getChannel('GO_TO_PREV_OR_ROOT_ROUTE'),
				callback: '_subGoToPrevOrRootRoute'
			},{
				channel : this.getChannel('GO_TO_ERROR_ROUTE'),
				callback: '_subGoToErrorRoute'
@@ -167,13 +165,6 @@ define([
				this._replaceHistory(route);
			}

			if (route === this.paths.LOGIN && this._userFound) {
				var prevRouteExistsAndIsNotHome = this._prevRoute && this._prevRoute !== this.paths.HOME;

				route = prevRouteExistsAndIsNotHome ? this._prevRoute : this.paths.HOME;
				this._replaceHistory(route);
			}

			var locationQuery = locationObj.search;
			this._handleQueryParameters(locationQuery.slice(1));

@@ -192,20 +183,18 @@ define([
			this._onRouteChange();
		},

		_subEvaluateRoute: function(req) {

			this._userFound = req.userFound;
		_subEvaluateRoute: function() {

			this._onRouteChange();
		},

		_subGoToRootRoute: function(req) {

			if (req.userGone) {
				delete this._userFound;
			}
		_subGoToPrevOrRootRoute: function(req) {

			if (req.userGone || !this._prevRoute) {
				this._goToRootPage();
			} else {
				this._goToPreviousPage();
			}
		},

		_subGoToErrorRoute: function() {
@@ -240,6 +229,11 @@ define([
			globalThis.location.href = this.paths.ROOT;
		},

		_goToPreviousPage: function() {

			globalThis.location.href = this._prevRoute;
		},

		_goToErrorPage: function() {

			globalThis.location.href = this.paths.ERROR;