Commit 6ff9ecc1 authored by Pedro Eduardo Trujillo's avatar Pedro Eduardo Trujillo
Browse files

Revisa estructura base y habilita destrucción

Resuelve una deuda técnica antigua, destruyendo las partes de la
aplicación cuando dejan de usarse (al hacer login o logout). Esto
ocasiona una destrucción de módulos en cascada, que debería mejorar el
comportamiento de la app.

Para que lo anterior sea posible, se ha replanteado el lugar que ocupan
"innerApp" y "outerApp" en la jerarquía de canales, así como los
diferentes módulos globales que existen (unos a nivel raíz y otros a
nivel de innerApp/outerApp).

Se trata de un progreso importante para el issue #51, ya que diferencia
los canales de innerApp y outerApp del canal principal, ocupado por
Router. Aun no lo resuelve, porque Router sigue sin separarse.
parent 93a55b89
Loading
Loading
Loading
Loading
+33 −13
Original line number Diff line number Diff line
@@ -42,7 +42,8 @@ define([
					GET_ALLOWED_MODULES: "getAllowedModules",
					AVAILABLE_ALLOWED_MODULES: "availableAllowedModules",
					GET_MODULE: "getModule",
					AVAILABLE_MODULE: "availableModule"
					AVAILABLE_MODULE: "availableModule",
					CLEAR_MODULE: 'clearModule'
				},
				events: {
					GET_ALLOWED_MODULES: "getAllowedModules",
@@ -72,6 +73,9 @@ define([
			},{
				channel : this.getChannel("GET_MODULE"),
				callback: "_subGetModule"
			},{
				channel : this.getChannel('CLEAR_MODULE'),
				callback: '_subClearModule'
			});
		},

@@ -238,7 +242,6 @@ define([
					copyPath = copyPath.replace("{" + arrayAux[3] + "}", this.parameterRegExp);
					results[arrayAux[3]] = true;

					regex.lastIndex;
					arrayAux = regex.exec(item.id);
				}

@@ -280,7 +283,7 @@ define([
				return;
			}

			moduleItem = moduleList[0];
			var moduleItem = moduleList[0];

			// Si aun no se ha creado la vista
			if (!moduleItem.instance) {
@@ -313,33 +316,50 @@ define([
			//	returns:
			//		Promesa de la instancia del módulo

			var dfd = new Deferred();
			var dfd = new Deferred(),
				parentChannel = redmicConfig.isOuterPath(moduleItem.id) ? this.outerAppChannel : this.innerAppChannel,
				moduleDefinitionPath = 'app' + moduleItem.internPath + 'View';

			require(["app" + moduleItem.internPath + "View"], lang.hitch(this, function(ModuleView) {
			require([moduleDefinitionPath], lang.hitch(this, function(moduleObj, ModuleView) {

				var moduleDefinition = declare([ModuleView, _View]);

				// Creamos el módulo
				var moduleInstance = new declare([ModuleView, _View])({
					parentChannel: this.parentChannel,
					ownChannel: this.viewSeparator + moduleItem.id,
					perms: moduleItem.perms,
				var moduleInstance = new moduleDefinition({
					parentChannel: parentChannel,
					ownChannel: this.viewSeparator + moduleObj.id,
					perms: moduleObj.perms,
					pathVariableId: this.pathVariableId !== "$1" ? this.pathVariableId : null
				});

				// Añadimos al store la instancia del módulo
				moduleItem.instance = moduleInstance;
				moduleItem.timeStamp = new Date().getTime();
				this.moduleStore.put(moduleItem);
				moduleObj.instance = moduleInstance;
				moduleObj.timeStamp = new Date().getTime();
				this.moduleStore.put(moduleObj);

				// Resolvemos para devolver la instancia creada
				dfd.resolve(moduleInstance);

				// Limpiamos las instancias antiguas
				this._clearOldInstances();
			}));
			}, moduleItem));

			return dfd;	// return Object
		},

		_subClearModule: function(/*Object*/ req) {

			var moduleKey = req.key,
				moduleList = this._findModuleByPath(moduleKey);

			if (!moduleList.length) {
				return;
			}

			var moduleItem = moduleList[0];
			this._updateClearedModuleInStore(moduleItem);
		},

		_clearOldInstances: function() {
			//	summary:
			//		Elimina la instancia del módulo que hace más tiempo que no se usa.
+36 −15
Original line number Diff line number Diff line
@@ -120,7 +120,8 @@ define([
				events: {
					GET_CREDENTIALS: 'getCredentials',
					GET_MODULE: 'getModule',
					GET_QUERY_PARAMS: 'getQueryParams'
					GET_QUERY_PARAMS: 'getQueryParams',
					CLEAR_MODULE: 'clearModule'
				},
				actions: {
					GET_QUERY_PARAMS: 'getQueryParams',
@@ -147,35 +148,35 @@ define([
		_initialize: function() {

			new RestManagerImpl({
				parentChannel: this.ownChannel
				parentChannel: this.getChannel()
			});

			new CommunicationCenter({
				parentChannel: this.ownChannel
				parentChannel: this.getChannel()
			});

			new Alert({
				parentChannel: this.ownChannel
				parentChannel: this.getChannel()
			});

			new Analytics({
				parentChannel: this.ownChannel
				parentChannel: this.getChannel()
			});

			new MetaTags({
				parentChannel: this.ownChannel
				parentChannel: this.getChannel()
			});

			this._credentials = new Credentials({
				parentChannel: this.ownChannel
				parentChannel: this.getChannel()
			});

			this._moduleStore = new ModuleStore({
				parentChannel: this.ownChannel
				parentChannel: this.getChannel()
			});

			this._loading = new Loading({
				parentChannel: this.ownChannel,
				parentChannel: this.getChannel(),
				globalNode: rootNode
			});
		},
@@ -208,6 +209,9 @@ define([
			},{
				event: 'GET_MODULE',
				channel: this._moduleStore.getChannel('GET_MODULE')
			},{
				event: 'CLEAR_MODULE',
				channel: this._moduleStore.getChannel('CLEAR_MODULE')
			},{
				event: 'GET_QUERY_PARAMS',
				channel: this.getChannel('GOT_QUERY_PARAMS')
@@ -475,6 +479,9 @@ define([

			this._currModuleInstance = instance;

			this._once(this._currModuleInstance.getChannel('DESTROYED'), lang.hitch(this, this._onModuleDestroyed,
				this._currModuleKey));

			this._once(this._currLayoutInstance.getChannel('MODULE_SHOWN'), lang.hitch(this, this._onModuleShown));

			this._publish(this._currLayoutInstance.getChannel('SHOW_MODULE'), {
@@ -513,7 +520,9 @@ define([

			this._deleteLayout();

			this._currLayoutInstance = new InnerApp();
			this._currLayoutInstance = new InnerApp({
				parentChannel: this.getChannel()
			});

			this._setCurrentLayout(this._currLayoutInstance);
		},
@@ -529,7 +538,9 @@ define([

			this._deleteLayout();

			this._currLayoutInstance = new OuterApp();
			this._currLayoutInstance = new OuterApp({
				parentChannel: this.getChannel()
			});

			this._setCurrentLayout(this._currLayoutInstance);
		},
@@ -579,12 +590,8 @@ define([
			//	tags:
			//		private

			// TODO utilizar destroy de módulos cuando la jerarquía de canales sea correcta
			this._onLayoutDestroyed();
			/*
			this._once(this._currLayoutInstance.getChannel('DESTROYED'), lang.hitch(this, this._onLayoutDestroyed));
			this._publish(this._currLayoutInstance.getChannel('DESTROY'));
			*/
		},

		_onLayoutDestroyed: function() {
@@ -609,6 +616,20 @@ define([

			this._once(this._currModuleInstance.getChannel('DISCONNECTED'), lang.hitch(this, this._openModule));
			this._publish(this._currModuleInstance.getChannel('DISCONNECT'));
		},

		_onModuleDestroyed: function(/*String*/ moduleKey) {
			//	summary:
			//		Se ejecuta cuando el módulo actual se ha terminado de destruir. Manda a borrar su instancia del
			//		almacén de modulos.
			//	tags:
			//		private
			//	moduleKey:
			//		Clave del módulo destruido

			this._emitEvt('CLEAR_MODULE', {
				key: moduleKey
			});
		}
	});
});
+2 −1
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ define([
		constructor: function(args) {

			this.config = {
				ownChannel: 'topbar',
				'class': 'topbar',

				collapseButtonClass: 'collapseSidebarButton',
@@ -126,7 +127,7 @@ define([

		_onCollapseClicked: function() {

			this._publish(this._buildChannel(this.rootChannel, 'toggleSidebar'));
			this._publish(this._buildChannel(this.innerAppChannel, 'toggleSidebar'));
		}
	});
});
+7 −20
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ define([
		constructor: function(args) {

			this.config = {
				ownChannel: this.innerAppOwnChannel,
				'class': 'mainContainer',
				reducedWidthClass: 'reducedWidth',
				contentContainerClass: 'contentContainer',
@@ -176,17 +177,17 @@ define([
			//		private

			new Selector({
				parentChannel: this.ownChannel
				parentChannel: this.getChannel()
			});

			var userRole = Credentials.get('userRole');
			if (userRole !== 'ROLE_GUEST') {
				new Notification({
					parentChannel: this.ownChannel
					parentChannel: this.getChannel()
				});

				new Socket({
					parentChannel: this.ownChannel
					parentChannel: this.getChannel()
				});
			}

@@ -197,16 +198,16 @@ define([
			}

			new definitionTask({
				parentChannel: this.ownChannel
				parentChannel: this.getChannel()
			});

			this.topbar = new Topbar({
				parentChannel: this.ownChannel,
				parentChannel: this.getChannel(),
				collapseButtonClass: this.collapseButtonClass
			});

			this.sidebar = new MainSidebarImpl({
				parentChannel: this.ownChannel
				parentChannel: this.getChannel()
			});
		},

@@ -240,11 +241,6 @@ define([

		_onAppResize: function(evt) {

			// TODO evita que entren instancias viejas (login, logout, login), cuando se destruya bien app, eliminar
			if (!this.domNode) {
				return;
			}

			this._appClickHandler.pause();

			this._evaluateAppSize();
@@ -286,15 +282,6 @@ define([
		_onAppHide: function() {

			this._appClickHandler.pause();

			// TODO reemplazo a destroy de todo 'app', eliminar cuando router no comparta canal y destruir solo 'app'
			this._publish(this.topbar.getChannel('DESTROY'));
			this._publish(this.sidebar.getChannel('DESTROY'));
			this._publish(this._buildChannel(this.selectorChannel, this.actions.DESTROY));
			this._publish(this._buildChannel(this.managerChannel, this.actions.DESTROY));
			this._publish(this._buildChannel(this.taskChannel, this.actions.DESTROY));
			this._publish(this._buildChannel(this.socketChannel, this.actions.DESTROY));
			this._publish(this._buildChannel(this.notificationChannel, this.actions.DESTROY));
		},

		_onAppClicked: function(evt) {
+3 −1
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ define([
	, declare
	, lang
) {

	return declare(App, {
		//	Summary:
		//		Implementación del módulo App, encargada de mostrar las vistas de la parte externa de la aplicación
@@ -14,6 +15,7 @@ define([
		constructor: function(args) {

			this.config = {
				ownChannel: this.outerAppOwnChannel,
				'class': 'outerApp',
				baseClass: ''
			};
Loading