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

Recupera datos en listados de visor de series

Renombra estructura y usa métodos de acceso para simplificar la gestión
de los datos.

Optimiza la construcción de estructuras internas, procesando una sola
vez y obteniendo contenido desde las mismas, en lugar de reprocesar
datos de entrada.
parent 2b7c6a6c
Loading
Loading
Loading
Loading
+27 −6
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ define([
				pathSeparator: '.',
				_timeseriesDefinitionList: [],
				_timeseriesStationList: [],
				_timeseriesDefinitionIndexByPath: {},
				_timeseriesDefinitionIndexByParameterPath: {},
				_timeseriesStationIndexByPath: {},
				// TODO renombrar, esqueleto de 'seriesData'
				_emptySeriesData: {
@@ -99,7 +99,8 @@ define([
					this._timeseriesStationIndexByPath[itemPath] = this._timeseriesStationList.length - 1;
				} else {
					this._timeseriesDefinitionList.push(item);
					this._timeseriesDefinitionIndexByPath[itemPath] = this._timeseriesDefinitionList.length - 1;
					this._timeseriesDefinitionIndexByParameterPath[itemPath] = this._timeseriesDefinitionList.length -
						1;
				}
			}
		},
@@ -109,9 +110,29 @@ define([
			return !this._timeseriesDefinitionList || this._timeseriesDefinitionList.length === 0;
		},

		_getTimeseriesDefinitionList: function() {
		_getTimeseriesHierarchicalList: function() {

			return this._timeseriesDefinitionList;
			return this._timeseriesDefinitionList.concat(this._timeseriesStationList);
		},

		_getParsedStation: function(/*string?*/ stationPath) {

			if (stationPath && stationPath.length) {
				var index = this._timeseriesStationIndexByPath[stationPath];
				return this._timeseriesStationList[index]; // object
			}

			return this._timeseriesStationList; // array
		},

		_getParsedDataDefinition: function(/*string?*/ parameterPath) {

			if (parameterPath && parameterPath.length) {
				var index = this._timeseriesDefinitionIndexByParameterPath[parameterPath];
				return this._timeseriesDefinitionList[index]; // object
			}

			return this._timeseriesDefinitionList; // array
		},

		_generateChartsDefinitionDataFromTimeseriesInternalStructures: function() {
@@ -127,7 +148,7 @@ define([
		// TODO renombrar
		_insertItemInDataChart: function(path) {

			var itemIndex = this._timeseriesDefinitionIndexByPath[path];
			var itemIndex = this._timeseriesDefinitionIndexByParameterPath[path];

			if (itemIndex === undefined) {
				return false;
@@ -250,7 +271,7 @@ define([

			this._timeseriesDefinitionList = [];
			this._timeseriesStationList = [];
			this._timeseriesDefinitionIndexByPath = {};
			this._timeseriesDefinitionIndexByParameterPath = {};
			this._timeseriesStationIndexByPath = {};
		}
	});
+6 −3
Original line number Diff line number Diff line
@@ -465,13 +465,16 @@ define([
			}

			if (_activeBrowserPopupCopy !== obj.data[this.idProperty]) {
				this._activeBrowserPopup = obj.data[this.idProperty];
				this._itemAvailable(obj); // TODO refactorizar en _TimeSeriesDataManagement

				// TODO no hace falta pedir mientras la petición inicial siga trayendo todos los datos
				/*this._activeBrowserPopup = obj.data[this.idProperty];

				this._emitEvt('GET', {
					target: this.target,
					requesterId: this.getOwnChannel(),
					id: obj.data[this.idProperty]
				});
				});*/
			}
		},

+28 −13
Original line number Diff line number Diff line
@@ -80,6 +80,7 @@ define([
				currentEmbeddedContentKey = this._getCurrentContentKey();

			this._prepareDataToInject(data.features);

			if (currentEmbeddedContentKey === embeddedListKey) {
				this._injectDataToList();
			} else {
@@ -95,12 +96,26 @@ define([

		_itemAvailable: function(response) {

			this._parseData(response.data.properties);
			this._publish(this.browserPopup.getChannel('SHOW'));

			var browserPopupData = [],
				itemProps = response.data.properties;

			var stationPath = itemProps.site.path,
				stationParsedData = this._getParsedStation(stationPath);

			this._publish(this.browserPopup.getChannel("SHOW"));
			browserPopupData.push(stationParsedData);

			for (var i = 0; i < itemProps.measurements.length; i++) {
				var measurement = itemProps.measurements[i],
					parameterPath = measurement.parameter.path,
					dataDefinitionParsedData = this._getParsedDataDefinition(parameterPath);

				browserPopupData.push(dataDefinitionParsedData);
			}

			this._emitEvt('INJECT_DATA', {
				data: this._getTimeseriesDefinitionList(),
				data: browserPopupData,
				target: this.browserPopupTarget
			});
		},
@@ -125,20 +140,11 @@ define([
		_injectDataToList: function() {

			this._emitEvt('INJECT_DATA', {
				data: lang.clone(this._getTimeseriesDefinitionList()),
				data: this._getTimeseriesHierarchicalList(),
				target: this.browserTarget
			});
		},

		_getMapData: function() {

			this._emitEvt('ADD_TO_QUERY', {
				query: {
					returnFields: this._mapReturnFields
				}
			});
		},

		_prepareTimeSeriesData: function(argument) {

			if (this._showChartIsValid()) {
@@ -153,6 +159,15 @@ define([
			}
		},

		_getMapData: function() {

			this._emitEvt('ADD_TO_QUERY', {
				query: {
					returnFields: this._mapReturnFields
				}
			});
		},

		_getListData: function() {

			this._emitEvt('ADD_TO_QUERY', {