Commit 77c7be69 authored by Pedro Eduardo Trujillo's avatar Pedro Eduardo Trujillo
Browse files

Elimina extensiones de vista para consultas a capa

Elimina las extensiones de vista que ya no son necesarias.

Adapta vistas que usaban la funcionalidad, siguiendo el ejemplo de la
vista de atlas.

Aplica traducción a título de resultado de consulta.
parent 05e4a477
Loading
Loading
Loading
Loading
+0 −356
Original line number Diff line number Diff line
define([
	"dojo/_base/declare"
	, "dojo/_base/lang"
	, "dojo/aspect"

	, "templates/AtlasPrimaryList"
	, "templates/AtlasSecondaryList"
	, "templates/AtlasRedpromarSecondaryList"
	, "templates/TrackingPrimaryList"
	, "templates/TrackingSecondaryList"
	, "templates/SpeciesDistributionPrimaryList"
	, "templates/SpeciesDistributionCitation"
], function(
	declare
	, lang
	, aspect

	, AtlasPrimaryList
	, AtlasSecondaryList
	, AtlasRedpromarSecondaryList
	, TrackingPrimaryList
	, TrackingSecondaryList
	, SpeciesDistributionPrimaryList
	, SpeciesDistributionCitation
) {

	return declare(null, {
		//	summary:
		//		Extensión para las vistas con mapa que desean hacer consultas sobre el mismo.
		//	description:
		//		Escucha los clicks del mapa y la información (sobre ese punto) de las capas presentes.
		//		Muestra la información en un popup.


		constructor: function(args) {

			this.config = {
				queryOnMapEvents: {
					HIDE_LAYERS_INFO: "hideLayersInfo",
					ADD_INFO_DATA: "addInfoData",
					ADD_NEW_TEMPLATES: "addNewTemplates",
					SHOW_LAYERS_INFO: "showLayersInfo",
					SET_MAP_QUERYABLE_CURSOR: "setMapQueryableCursor"
				},
				queryOnMapActions: {
					HIDE_LAYERS_INFO: "hideLayersInfo",
					ADD_INFO_DATA: "addInfoData",
					ADD_NEW_TEMPLATES: "addNewTemplates",
					SHOW_LAYERS_INFO: "showLayersInfo"
				},

				layerIdSeparator: "_",
				layerIdPrefix: "layer-",
				layerThemeSeparator: "-",
				typeGroupProperty: "dataType",
				parentTemplateSuffix: "Parent",
				childrenTemplateSuffix: "Children",

				_queryableLayersLoaded: 0,
				_layersWaiting: 0,

				_templatesByTypeGroup: {
					//	Podemos sobreescribir las plantillas genéricas de las capas
					//	de atlas especificando el nombre de la capa completo
					//"el-batimetriaIslasParent": AtlasPrimaryList",
					//"el-batimetriaIslasChildren": AtlasBathymetry",

					"defaultParent": AtlasPrimaryList,
					"defaultChildren": AtlasSecondaryList,

					"trackingParent": TrackingPrimaryList,
					"trackingChildren": TrackingSecondaryList,

					"taxonDistributionParent": SpeciesDistributionPrimaryList,
					"taxonDistributionChildren": {
						"ci": SpeciesDistributionCitation,
						"at": TrackingSecondaryList
					},

					"sd-full_sighting_taxon_yearChildren": AtlasRedpromarSecondaryList,
					"sd-exotic-species-sightingChildren": AtlasRedpromarSecondaryList
				}
			};

			lang.mixin(this, this.config);

			aspect.before(this, "_mixEventsAndActions", lang.hitch(this, this._mixQueryOnMapEventsAndActions));
			aspect.before(this, "_setOwnCallbacksForEvents",
				lang.hitch(this, this._setQueryOnMapOwnCallbacksForEvents));

			aspect.after(this, "_defineSubscriptions", lang.hitch(this, this._defineQueryOnMapSubscriptions));
			aspect.after(this, "_definePublications", lang.hitch(this, this._defineQueryOnMapPublications));
		},

		_mixQueryOnMapEventsAndActions: function() {

			lang.mixin(this.events, this.queryOnMapEvents);
			lang.mixin(this.actions, this.queryOnMapActions);

			delete this.queryOnMapEvents;
			delete this.queryOnMapActions;
		},

		_defineQueryOnMapSubscriptions: function() {

			var getMapChannel = this.map ?
				lang.hitch(this.map, this.map.getChannel) :
				this.getMapChannel;

			var options = {
				predicate: lang.hitch(this, this._chkLayerIsQueryable)
			};

			this.subscriptionsConfig.push({
				channel : getMapChannel("MAP_CLICKED"),
				callback: "_subMapClickedQueryOnMap"
			},{
				channel: getMapChannel("LAYER_ADDED_CONFIRMED"),
				callback: "_subLayerAddedQueryOnMap",
				options: options
			},{
				channel: getMapChannel("LAYER_REMOVED_CONFIRMED"),
				callback: "_subLayerRemovedQueryOnMap",
				options: options
			},{
				channel: getMapChannel("LAYER_QUERYING"),
				callback: "_subLayerQueryingQueryOnMap"
			},{
				channel: getMapChannel("LAYER_INFO"),
				callback: "_subLayerInfoQueryOnMap"
			});
		},

		_defineQueryOnMapPublications: function() {

			var getMapChannel = this.map ?
				lang.hitch(this.map, this.map.getChannel) :
				this.getMapChannel;

			this.publicationsConfig.push({
				event: 'HIDE_LAYERS_INFO',
				channel: this.getChannel("HIDE_LAYERS_INFO")
			},{
				event: 'ADD_INFO_DATA',
				channel: this.getChannel("ADD_INFO_DATA")
			},{
				event: 'ADD_NEW_TEMPLATES',
				channel: this.getChannel("ADD_NEW_TEMPLATES")
			},{
				event: 'SHOW_LAYERS_INFO',
				channel: this.getChannel("SHOW_LAYERS_INFO")
			},{
				event: 'SET_MAP_QUERYABLE_CURSOR',
				channel: getMapChannel("SET_QUERYABLE_CURSOR")
			});
		},

		_setQueryOnMapOwnCallbacksForEvents: function() {

			this.on([this.events.HIDE, this.events.ANCESTOR_HIDE],
				lang.hitch(this, this.emit, this.events.HIDE_LAYERS_INFO));
		},

		_chkLayerIsQueryable: function(res) {

			return !!res.queryable;
		},

		_subMapClickedQueryOnMap: function(response) {

			this._emitEvt('HIDE_LAYERS_INFO');

			if (this._queryableLayersLoaded) {
				this._emitEvt('LOADING', {
					global: true
				});
			}
		},

		_subLayerAddedQueryOnMap: function(res) {

			this._queryableLayersLoaded++;

			this._emitEvt('SET_MAP_QUERYABLE_CURSOR', {enable: true});

			var layerId = res.layerId,
				layerName = this._getLayerName(layerId);

			var parentTemplateDefinition = this._getTemplateForLayer(layerName, this.parentTemplateSuffix),
				childrenTemplateDefinition = this._getTemplateForLayer(layerName, this.childrenTemplateSuffix);

			this._emitEvt('ADD_NEW_TEMPLATES', {
				typeGroup: layerName,
				parentTemplate: parentTemplateDefinition,
				childrenTemplate: childrenTemplateDefinition
			});
		},

		_getLayerName: function(layerId) {

			var layerIdSplit = layerId.split(this.layerIdSeparator + this.layerIdPrefix);

			if (layerIdSplit.length > 1) {
				return layerIdSplit[0];
			}

			return layerId.split(this.layerIdSeparator)[0];
		},

		_getTemplateForLayer: function(layerName, suffix) {

			var specificTemplate = this._templatesByTypeGroup[layerName + suffix],
				typeGroup = layerName.split(this.layerThemeSeparator)[0],
				genericTemplate = this._templatesByTypeGroup[typeGroup + suffix] ||
					this._templatesByTypeGroup['default' + suffix],

				templateDefinition = specificTemplate ? specificTemplate : genericTemplate;

			if (!templateDefinition) {
				console.error('Layer templates definition is wrong, default template was not found.');
			}

			return templateDefinition;
		},

		_subLayerRemovedQueryOnMap: function(res) {

			this._queryableLayersLoaded--;
			if (!this._queryableLayersLoaded) {
				this._emitEvt('SET_MAP_QUERYABLE_CURSOR', {enable: false});
			}
		},

		_subLayerQueryingQueryOnMap: function(res) {

			this._layersWaiting++;
			clearTimeout(this._showInfoTimeoutHandler);
		},

		_subLayerInfoQueryOnMap: function(res) {

			this._layersWaiting--;

			this._processLayerInfo(res);
		},

		_processLayerInfo: function(res) {

			var layerId = res.layerId,
				layerLabel = res.layerLabel,
				layerInfo = res.info,
				isGeoJson = !!(layerInfo && layerInfo.features),
				hasFeatures = !!(isGeoJson && layerInfo.features.length),
				hasValidInfo = !!((!isGeoJson && layerInfo) || hasFeatures);

			if (hasValidInfo) {
				this._hadValidInfo = true;
				if (layerInfo instanceof Array) {
					for (var i = 0; i < layerInfo.length; i++) {
						this._loadInfo(layerId, layerLabel, layerInfo[i]);
					}
				} else {
					this._loadInfo(layerId, layerLabel, layerInfo);
				}
			}

			if (!this._layersWaiting) {
				this._showInfoTimeoutHandler = setTimeout(
					lang.hitch(this, this._showWhenNoLayersWaiting, this._hadValidInfo), 0);
			}
		},

		_loadInfo: function(layerId, layerLabel, layerInfo) {

			var infoData = this._getDataForAddInfo(layerId, layerLabel, layerInfo),
				typeGroup = this._getLayerName(layerId);

			infoData[this.typeGroupProperty] = typeGroup;

			this._emitEvt('ADD_INFO_DATA', infoData);
		},

		_showWhenNoLayersWaiting: function(hasValidInfo) {

			this._emitEvt('LOADED');

			if (hasValidInfo) {
				this._emitEvt('SHOW_LAYERS_INFO');
			} else {
				this._emitEvt('COMMUNICATION', {
					description: this.i18n.noLayerInfo
				});
			}

			this._hadValidInfo = false;
		},

		_getDataForAddInfo: function(layerId, layerLabel, data) {

			var layerIdPrefix = this._getLayerName(layerId),
				method;

			if (layerIdPrefix === "tracking") {
				method = '_getTrackingSpecificData';
			} else if (layerIdPrefix === "taxonDistribution") {
				method = '_getTaxonDistributionSpecificData';
			} else if (layerIdPrefix.indexOf(this.layerThemeSeparator) !== -1) {
				method = '_getThemeSpecificData';
			} else {
				method = '_showErrorOnGettingSpecificData';
			}
			return this[method](layerIdPrefix, layerLabel, data);
		},

		_getTrackingSpecificData: function(layerIdPrefix, layerLabel, data) {

			return {
				parent: lang.getObject("properties.element", false, data.features[0]),
				parentName: "name",
				children: data.features
			};
		},

		_getTaxonDistributionSpecificData: function(layerIdPrefix, layerLabel, data) {

			return {
				parent: data,
				parentName: function(parentData) {

					return "<i>" + parentData.scientificName + "</i> " + parentData.authorship;
				},
				children: data.citations.concat(data.animalTrackings)
			};
		},

		_getThemeSpecificData: function(layerIdPrefix, layerLabel, data) {

			return {
				parent: {
					name: layerLabel,
					id: layerIdPrefix
				},
				parentName: "name",
				children: data.features
			};
		},

		_showErrorOnGettingSpecificData: function(layerIdPrefix, layerLabel, data) {

			console.error('Received data with unknown type', layerIdPrefix, layerLabel, data);

			return {};
		}

	});
});
+0 −140
Original line number Diff line number Diff line
define([
	"app/designs/primaryAndSecondaryContent/main/HierarchicalLists"
	, "dojo/_base/declare"
	, "dojo/_base/lang"
	, "dojo/aspect"
	, "redmic/modules/base/_ShowInPopup"
], function(
	HierarchicalLists
	, declare
	, lang
	, aspect
	, _ShowInPopup
) {

	return declare(null, {
		//	summary:
		//		Extensión para las vistas con mapa que hacen consultas sobre el mismo y quieren mostrar
		//		el resultado de dicha consulta en un popup.
		//	description:
		//		Escucha los resultados de la consulta y los manda al popup propio para mostrarlos.


		constructor: function(args) {

			this.config = {
				showInPopupResultsFromQueryOnMapEvents: {
					HIDE_LAYERS_INFO_POPUP: "hideLayersInfoPopup",
					ADD_INFO_DATA_POPUP: "addInfoDataPopup",
					ADD_NEW_TEMPLATES_POPUP: "addNewTemplatesPopup",
					SHOW_LAYERS_INFO_POPUP: "showLayersInfoPopup"
				},
				showInPopupResultsFromQueryOnMapActions: {
					HIDE_LAYERS_INFO: "hideLayersInfo",
					ADD_INFO_DATA: "addInfoData",
					ADD_NEW_TEMPLATES: "addNewTemplates",
					SHOW_LAYERS_INFO: "showLayersInfo"
				},
				channelsToListen: []
			};

			lang.mixin(this, this.config);

			aspect.before(this, "_mixEventsAndActions", lang.hitch(this,
				this._mixShowInPopupResultsFromQueryOnMapEventsAndActions));
			aspect.after(this, "_beforeInitialize", lang.hitch(this, this._initializeShowInPopupResultsFromQueryOnMap));
			aspect.after(this, "_defineSubscriptions", lang.hitch(this,
				this._defineShowInPopupResultsFromQueryOnMapSubscriptions));
			aspect.after(this, "_definePublications", lang.hitch(this,
				this._defineShowInPopupResultsFromQueryOnMapPublications));
		},

		_mixShowInPopupResultsFromQueryOnMapEventsAndActions: function() {

			lang.mixin(this.events, this.showInPopupResultsFromQueryOnMapEvents);
			lang.mixin(this.actions, this.showInPopupResultsFromQueryOnMapActions);

			delete this.showInPopupResultsFromQueryOnMapEvents;
			delete this.showInPopupResultsFromQueryOnMapActions;
		},

		_initializeShowInPopupResultsFromQueryOnMap: function() {

			this.layersInfo = new declare(HierarchicalLists).extend(_ShowInPopup)({
				parentChannel: this.getChannel(),
				typeGroupProperty: this.typeGroupProperty,
				primaryTitle: this.i18n.presentElements,
				primaryListButtons: this.primaryListButtons,
				secondaryListButtons: this.secondaryListButtons,
				width: 5,
				height: "md"
			});
		},

		_defineShowInPopupResultsFromQueryOnMapSubscriptions: function() {

			this._doSubscriptionsAtChannel(this.getChannel());

			for (var i = 0; i < this.channelsToListen.length; i++) {
				this._doSubscriptionsAtChannel(this.channelsToListen[i]);
			}
		},

		_doSubscriptionsAtChannel: function(channel) {

			this.subscriptionsConfig.push({
				channel : this._buildChannel(channel, this.actions.HIDE_LAYERS_INFO),
				callback: "_subHideLayersInfo"
			},{
				channel : this._buildChannel(channel, this.actions.SHOW_LAYERS_INFO),
				callback: "_subShowLayersInfo"
			},{
				channel : this._buildChannel(channel, this.actions.ADD_INFO_DATA),
				callback: "_subAddInfoData"
			},{
				channel : this._buildChannel(channel, this.actions.ADD_NEW_TEMPLATES),
				callback: "_subAddNewTemplates"
			});
		},

		_defineShowInPopupResultsFromQueryOnMapPublications: function() {

			this.publicationsConfig.push({
				event: 'HIDE_LAYERS_INFO_POPUP',
				channel: this.layersInfo.getChannel("HIDE")
			},{
				event: 'HIDE_LAYERS_INFO_POPUP',
				channel: this.layersInfo.getChannel("CLEAR")
			},{
				event: 'ADD_INFO_DATA_POPUP',
				channel: this.layersInfo.getChannel("NEW_DATA")
			},{
				event: 'ADD_NEW_TEMPLATES_POPUP',
				channel: this.layersInfo.getChannel("ADD_NEW_TEMPLATES")
			},{
				event: 'SHOW_LAYERS_INFO_POPUP',
				channel: this.layersInfo.getChannel("SHOW")
			});
		},

		_subHideLayersInfo: function(response) {

			this._emitEvt('HIDE_LAYERS_INFO_POPUP');
		},

		_subShowLayersInfo: function() {

			this._emitEvt('SHOW_LAYERS_INFO_POPUP');
		},

		_subAddInfoData: function(req) {

			this._emitEvt('ADD_INFO_DATA_POPUP', req);
		},

		_subAddNewTemplates: function(req) {

			this._emitEvt('ADD_NEW_TEMPLATES_POPUP', req);
		}
	});
});
+19 −7
Original line number Diff line number Diff line
define([
	"app/base/views/extensions/_LocalSelectionView"
	, "app/base/views/extensions/_ShowInPopupResultsFromQueryOnMap"
	, "app/base/views/extensions/_QueryOnMap"
	, "app/designs/base/_Main"
	, "app/designs/mapWithSideContent/Controller"
	, "app/designs/mapWithSideContent/layout/MapAndContent"
@@ -20,12 +18,12 @@ define([
	, "redmic/modules/browser/_GeoJsonParser"
	, "redmic/modules/browser/ListImpl"
	, "redmic/modules/atlas/Atlas"
	, "redmic/modules/base/_ShowInPopup"
	, "redmic/modules/mapQuery/QueryOnMap"
	, "redmic/modules/search/TextImpl"
	, "templates/CitationList"
], function(
	_LocalSelectionView
	, _ShowInPopupResultsFromQueryOnMap
	, _QueryOnMap
	, _Main
	, Controller
	, Layout
@@ -44,9 +42,12 @@ define([
	, _GeoJsonParser
	, ListImpl
	, Atlas
	, _ShowInPopup
	, QueryOnMap
	, TextImpl
	, TemplateList
) {

	return declare([Layout, Controller, _Main, _Store, _Filter, _LocalSelectionView], {
		//	summary:
		//		Vista base para todas las vistas de geográfica.
@@ -228,10 +229,21 @@ define([

		_createAtlas: function() {

			this.atlas = new declare([Atlas, _QueryOnMap, _ShowInPopupResultsFromQueryOnMap])({
			var getMapChannel = lang.hitch(this.map, this.map.getChannel);

			this.atlas = new Atlas({
				parentChannel: this.getChannel(),
				perms: this.perms,
				getMapChannel: lang.hitch(this.map, this.map.getChannel)
				getMapChannel: getMapChannel
			});

			var QueryOnMapPopup = declare(QueryOnMap).extend(_ShowInPopup);
			this._queryOnMap = new QueryOnMapPopup({
				parentChannel: this.getChannel(),
				getMapChannel: getMapChannel,
				title: this.i18n.layersQueryResults,
				width: 5,
				height: "md"
			});

			var cp = new ContentPane({
+17 −6
Original line number Diff line number Diff line
@@ -2,8 +2,6 @@ define([
	"app/base/views/extensions/_CompositeInTooltipFromIconKeypad"
	, "app/base/views/extensions/_EditionView"
	, "app/base/views/extensions/_LocalSelectionView"
	, "app/base/views/extensions/_ShowInPopupResultsFromQueryOnMap"
	, "app/base/views/extensions/_QueryOnMap"
	, "app/designs/base/_Main"
	, "app/designs/mapWithSideContent/Controller"
	, "app/designs/mapWithSideContent/layout/MapAndContentAndTopbar"
@@ -30,11 +28,13 @@ define([
	, "redmic/modules/browser/bars/Total"
	, "redmic/modules/layout/dataDisplayer/DataDisplayer"
	, "redmic/modules/atlas/Atlas"
	, "redmic/modules/base/_ShowInPopup"
	, "redmic/modules/map/layer/GeoJsonLayerImpl"
	, "redmic/modules/map/layer/_Editable"
	, "redmic/modules/map/layer/_RadiusOnSelect"
	, "redmic/modules/map/layer/_Selectable"
	, "redmic/modules/map/layer/_SelectOnClick"
	, "redmic/modules/mapQuery/QueryOnMap"
	, "redmic/modules/search/TextImpl"
	, "redmic/view/effects/Animation"
	, "templates/CitationPopup"
@@ -43,8 +43,6 @@ define([
	_CompositeInTooltipFromIconKeypad
	, _EditionView
	, _LocalSelectionView
	, _ShowInPopupResultsFromQueryOnMap
	, _QueryOnMap
	, _Main
	, Controller
	, Layout
@@ -71,11 +69,13 @@ define([
	, Total
	, DataDisplayer
	, Atlas
	, _ShowInPopup
	, GeoJsonLayerImpl
	, _Editable
	, _RadiusOnSelect
	, _Selectable
	, _SelectOnClick
	, QueryOnMap
	, TextImpl
	, Animation
	, TemplatePopup
@@ -389,10 +389,21 @@ define([

		_createAtlas: function() {

			this.atlas = new declare([Atlas, _QueryOnMap, _ShowInPopupResultsFromQueryOnMap])({
			var getMapChannel = lang.hitch(this.map, this.map.getChannel);

			this.atlas = new Atlas({
				parentChannel: this.getChannel(),
				perms: this.perms,
				getMapChannel: lang.hitch(this.map, this.map.getChannel)
				getMapChannel: getMapChannel
			});

			var QueryOnMapPopup = declare(QueryOnMap).extend(_ShowInPopup);
			this._queryOnMap = new QueryOnMapPopup({
				parentChannel: this.getChannel(),
				getMapChannel: getMapChannel,
				title: this.i18n.layersQueryResults,
				width: 5,
				height: "md"
			});

			var cp = new ContentPane({
+18 −6
Original line number Diff line number Diff line
define([
	'alertify/alertify.min'
	, "app/base/views/extensions/_ShowInPopupResultsFromQueryOnMap"
	, "app/base/views/extensions/_QueryOnMap"
	, "app/designs/base/_Main"
	, "app/designs/mapWithSideContent/Controller"
	, "app/designs/mapWithSideContent/layout/MapAndContentAndTopbar"
@@ -20,13 +18,13 @@ define([
	, "redmic/modules/base/_Store"
	, "redmic/modules/components/ProgressSlider/ProgressSlider"
	, "redmic/modules/atlas/Atlas"
	, "redmic/modules/base/_ShowInPopup"
	, "redmic/modules/map/layer/_AddFilter"
	, "redmic/modules/map/layer/_PublishInfo"
	, "redmic/modules/map/layer/TrackingLayerImpl"
	, "redmic/modules/mapQuery/QueryOnMap"
], function(
	alertify
	, _ShowInPopupResultsFromQueryOnMap
	, _QueryOnMap
	, _Main
	, Controller
	, Layout
@@ -45,12 +43,14 @@ define([
	, _Store
	, ProgressSlider
	, Atlas
	, _ShowInPopup
	, _AddFilter
	, _PublishInfo
	, TrackingLayerImpl
	, QueryOnMap
) {

	return declare([Layout, Controller, _Main, _Store, _QueryOnMap, _ShowInPopupResultsFromQueryOnMap], {
	return declare([Layout, Controller, _Main, _Store], {
		//	summary:
		//		Vista de Tracking.
		//	description:
@@ -150,10 +150,22 @@ define([
				}
			});

			var getMapChannel = lang.hitch(this.map, this.map.getChannel);

			this.atlas = new Atlas({
				parentChannel: this.getChannel(),
				perms: this.perms,
				getMapChannel: lang.hitch(this.map, this.map.getChannel)
				getMapChannel: getMapChannel
			});

			var QueryOnMapPopup = declare(QueryOnMap).extend(_ShowInPopup);
			this._queryOnMap = new QueryOnMapPopup({
				parentChannel: this.getChannel(),
				getMapChannel: getMapChannel,
				typeGroupProperty: this.typeGroupProperty,
				title: this.i18n.layersQueryResults,
				width: 5,
				height: "md"
			});
		},

Loading