Commit 19a27404 authored by Pedro Eduardo Trujillo's avatar Pedro Eduardo Trujillo
Browse files

Añade canal a módulos, corrige inicio de gráficas

Los módulos que heredan de _Filter ahora cuentan con un nuevo canal
'ADDED_TO_QUERY', que se dispara cuando reciben la respuesta del módulo
Filter tras pedirle que añadan algo a la query.

La petición inicial de datos de series temporales (gráficas) queda
resuelta empleando esta nueva publicación, esperando siempre a que acabe
la petición de datos anterior antes de pedir la siguiente serie.
parent 2f96b5c0
Loading
Loading
Loading
Loading
+65 −38
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@ define([
	, "dojo/_base/declare"
	, "dojo/_base/lang"
	, "dojo/aspect"
	, "dojo/Deferred"
	, "redmic/modules/base/_Filter"
	, "redmic/modules/base/_Store"
], function(
@@ -10,9 +11,11 @@ define([
	, declare
	, lang
	, aspect
	, Deferred
	, _Filter
	, _Store
) {

	return declare([_Filter, _Store], {
		//	summary:
		//		Extensión para procesar las estructuras de datos que representan a los
@@ -291,15 +294,13 @@ define([
				idsSplitted = ids.toString().split(this.idSeparator);

			for (var i = 0; i < idsSplitted.length; i++) {

				var idsComponent = idsSplitted[i];
				for (var path in this.categories) {

				for (var path in this.categories) {
					var pathSplitted = path.split(this.pathSeparator),
						id = pathSplitted.pop();

					if (id === idsComponent) {

						pathSplitted.splice(this._specificPathLengthLimit - 1, 1);

						var parentPath = pathSplitted.join(this.pathSeparator),
@@ -314,12 +315,37 @@ define([

		_buildQueryAndRequestData: function() {

			if (!this.chartsData) {
			if (!this.chartsData || this._dataRequestInProgress) {
				return;
			}

			// TODO cada item tiene que esperar por el ADDED_TO_QUERY del anterior, salvo el primero
			for (var cat in this.chartsData.definitionIndex) {
			this._dataRequestInProgress = true;

			var definitionIds = Object.keys(this.chartsData.definitionIndex),
				addedToQueryDfds = [];

			for (var i = 0; i < definitionIds.length; i++) {
				var cat = definitionIds[i],
					dfd = new Deferred();

				addedToQueryDfds.push(dfd);

				if (i !== 0) {
					var prevDfd = addedToQueryDfds[i - 1];
					prevDfd.then(lang.hitch(this, this._continueBuildQueryAndRequestData, dfd, cat));
				} else {
					this._continueBuildQueryAndRequestData(dfd, cat);
				}
			}

			addedToQueryDfds[addedToQueryDfds.length - 1].then(lang.hitch(this, function() {

				this._dataRequestInProgress = false;
			}));
		},

		_continueBuildQueryAndRequestData: function(dfd, cat) {

			var dataDefinitionIds = [],
				catSplitted = cat.split(this.idSeparator);

@@ -353,10 +379,11 @@ define([
				objQuery.interval = null;
			}

			this._once(this.getChannel('ADDED_TO_QUERY'), dfd.resolve);

			this._emitEvt('ADD_TO_QUERY', {
				query: objQuery
			});
		}
		}
	});
});
+14 −0
Original line number Diff line number Diff line
@@ -21,11 +21,13 @@ define([
			this.config = {
				filterEvents: {
					ADD_TO_QUERY: 'addToQuery',
					ADDED_TO_QUERY: 'addedToQuery',
					REFRESH: 'refresh',
					UPDATE_TARGET: 'updateTarget',
					QUERY_CHANNEL_SET: 'queryChannelSet'
				},
				filterActions: {
					ADDED_TO_QUERY: 'addedToQuery',
					SERIALIZED: 'serialized',
					REQUEST_FILTER: 'requestFilter',
					ADD_TO_QUERY: 'addToQuery',
@@ -79,6 +81,9 @@ define([
		_subscribeToFilter: function(queryChannel) {

			this.subscriptionsConfig.push({
				channel: this._buildChannel(queryChannel, this.actions.ADDED_TO_QUERY),
				callback: '_subAddedToQuery'
			},{
				channel: this._buildChannel(queryChannel, this.actions.SERIALIZED),
				callback: '_subFilterSerialized'
			},{ // TODO: REQUEST_FILTER parece lo mismo que SERIALIZE, hacer que todo vaya por SERIALIZE
@@ -97,6 +102,9 @@ define([
			this.publicationsConfig.push({
				event: 'ADD_TO_QUERY',
				channel: this._buildChannel(queryChannel, this.actions.ADD_TO_QUERY)
			},{
				event: 'ADDED_TO_QUERY',
				channel: this.getChannel('ADDED_TO_QUERY')
			},{
				event: 'REFRESH',
				channel: this._buildChannel(queryChannel, this.actions.REFRESH)
@@ -111,6 +119,11 @@ define([
			this._onEvt('QUERY_CHANNEL_SET', lang.hitch(this, this._onQueryChannelUpdated));
		},

		_subAddedToQuery: function(res) {

			this._emitEvt('ADDED_TO_QUERY', res);
		},

		_subFilterSerialized: function(res) {

			this._handleFilterParams(res.data);
@@ -146,6 +159,7 @@ define([
		_disconnectFromFilter: function(oldQueryChannel) {

			this._removeSubscriptions([
				this._buildChannel(queryChannel, this.actions.ADDED_TO_QUERY),
				this._buildChannel(oldQueryChannel, this.actions.SERIALIZED),
				this._buildChannel(oldQueryChannel, this.actions.REQUEST_FILTER)
			]);