=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapLegendSet.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapLegendSet.java 2010-08-30 13:58:52 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapLegendSet.java 2010-09-09 19:19:51 +0000 @@ -30,6 +30,7 @@ import java.util.HashSet; import java.util.Set; +import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.indicator.Indicator; /** @@ -55,13 +56,15 @@ private Set mapLegends = new HashSet(); private Set indicators = new HashSet(); + + private Set dataElements = new HashSet(); public MapLegendSet() { } public MapLegendSet( String name, String type, int method, int classes, String colorLow, String colorHigh, - Set mapLegends, Set indicators ) + Set mapLegends, Set indicators, Set dataElements ) { this.name = name; this.type = type; @@ -71,6 +74,7 @@ this.colorHigh = colorHigh; this.mapLegends = mapLegends; this.indicators = indicators; + this.dataElements = dataElements; } // ------------------------------------------------------------------------- @@ -199,4 +203,14 @@ { this.indicators = indicators; } + + public Set getDataElements() + { + return dataElements; + } + + public void setDataElements( Set dataElements ) + { + this.dataElements = dataElements; + } } \ No newline at end of file === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingService.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingService.java 2010-09-01 09:02:32 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingService.java 2010-09-09 19:19:51 +0000 @@ -380,6 +380,8 @@ Collection getMapLegendSetsByType( String type ); MapLegendSet getMapLegendSetByIndicator( int indicatorId ); + + MapLegendSet getMapLegendSetByDataElement( int dataElementId ); Collection getAllMapLegendSets(); === modified file 'dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java' --- dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java 2010-09-01 09:02:32 +0000 +++ dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java 2010-09-09 19:19:51 +0000 @@ -660,6 +660,8 @@ MapLegendSet mapLegendSet = getMapLegendSetByName( name ); Set indicators = new HashSet(); + + Set dataElements = new HashSet(); if ( mapLegendSet != null ) { @@ -670,12 +672,13 @@ mapLegendSet.setColorHigh( colorHigh ); mapLegendSet.setMapLegends( mapLegends ); mapLegendSet.setIndicators( indicators ); + mapLegendSet.setDataElements( dataElements ); this.mappingStore.updateMapLegendSet( mapLegendSet ); } else { - mapLegendSet = new MapLegendSet( name, type, method, classes, colorLow, colorHigh, mapLegends, indicators ); + mapLegendSet = new MapLegendSet( name, type, method, classes, colorLow, colorHigh, mapLegends, indicators, dataElements ); this.mappingStore.addMapLegendSet( mapLegendSet ); } @@ -718,6 +721,23 @@ return null; } + public MapLegendSet getMapLegendSetByDataElement( int dataElementId ) + { + DataElement dataElement = dataElementService.getDataElement( dataElementId ); + + Collection mapLegendSets = mappingStore.getAllMapLegendSets(); + + for ( MapLegendSet mapLegendSet : mapLegendSets ) + { + if ( mapLegendSet.getDataElements().contains( dataElement ) ) + { + return mapLegendSet; + } + } + + return null; + } + public Collection getAllMapLegendSets() { return mappingStore.getAllMapLegendSets(); === modified file 'dhis-2/dhis-services/dhis-service-mapping/src/main/resources/org/hisp/dhis/mapping/hibernate/MapLegendSet.hbm.xml' --- dhis-2/dhis-services/dhis-service-mapping/src/main/resources/org/hisp/dhis/mapping/hibernate/MapLegendSet.hbm.xml 2010-04-07 10:19:08 +0000 +++ dhis-2/dhis-services/dhis-service-mapping/src/main/resources/org/hisp/dhis/mapping/hibernate/MapLegendSet.hbm.xml 2010-09-09 19:19:51 +0000 @@ -34,6 +34,12 @@ + + + + + === added file 'dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/AssignDataElementsToMapLegendSetAction.java' --- dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/AssignDataElementsToMapLegendSetAction.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/AssignDataElementsToMapLegendSetAction.java 2010-09-09 19:19:51 +0000 @@ -0,0 +1,76 @@ +package org.hisp.dhis.mapping.action; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +import org.hisp.dhis.dataelement.DataElement; +import org.hisp.dhis.dataelement.DataElementService; +import org.hisp.dhis.indicator.Indicator; +import org.hisp.dhis.indicator.IndicatorService; +import org.hisp.dhis.mapping.MapLegendSet; +import org.hisp.dhis.mapping.MappingService; + +import com.opensymphony.xwork2.Action; + +public class AssignDataElementsToMapLegendSetAction + implements Action +{ + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + private MappingService mappingService; + + public void setMappingService( MappingService mappingService ) + { + this.mappingService = mappingService; + } + + private DataElementService dataElementService; + + public void setDataElementService( DataElementService dataElementService ) + { + this.dataElementService = dataElementService; + } + + // ------------------------------------------------------------------------- + // Input + // ------------------------------------------------------------------------- + + private Integer id; + + public void setId( Integer id ) + { + this.id = id; + } + + private Collection dataElements; + + public void setDataElements( Collection dataElements ) + { + this.dataElements = dataElements; + } + + // ------------------------------------------------------------------------- + // Action implementation + // ------------------------------------------------------------------------- + + public String execute() + { + MapLegendSet mapLegendSet = mappingService.getMapLegendSet( id ); + + Set dataElementSet = new HashSet(); + + for ( String dataElement : dataElements ) + { + dataElementSet.add( dataElementService.getDataElement( Integer.parseInt( dataElement ) ) ); + } + + mapLegendSet.setDataElements( dataElementSet ); + + mappingService.updateMapLegendSet( mapLegendSet ); + + return SUCCESS; + } +} === added file 'dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetMapLegendSetByDataElementAction.java' --- dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetMapLegendSetByDataElementAction.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetMapLegendSetByDataElementAction.java 2010-09-09 19:19:51 +0000 @@ -0,0 +1,86 @@ +package org.hisp.dhis.mapping.action; + +/* + * Copyright (c) 2004-2010, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import org.hisp.dhis.mapping.MapLegendSet; +import org.hisp.dhis.mapping.MappingService; + +import com.opensymphony.xwork2.Action; + +/** + * @author Lars Helge Overland + * @version $Id$ + */ +public class GetMapLegendSetByDataElementAction + implements Action +{ + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + private MappingService mappingService; + + public void setMappingService( MappingService mappingService ) + { + this.mappingService = mappingService; + } + + // ------------------------------------------------------------------------- + // Input + // ------------------------------------------------------------------------- + + private int dataElementId; + + public void setDataElementId( int dataElementId ) + { + this.dataElementId = dataElementId; + } + + // ------------------------------------------------------------------------- + // Input + // ------------------------------------------------------------------------- + + private MapLegendSet object; + + public MapLegendSet getObject() + { + return object; + } + + // ------------------------------------------------------------------------- + // Action implementation + // ------------------------------------------------------------------------- + + public String execute() + throws Exception + { + object = mappingService.getMapLegendSetByDataElement( dataElementId ); + + return SUCCESS; + } +} === modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-web/dhis-web-mapping/src/main/resources/META-INF/dhis/beans.xml 2010-08-31 10:40:24 +0000 +++ dhis-2/dhis-web/dhis-web-mapping/src/main/resources/META-INF/dhis/beans.xml 2010-09-09 19:19:51 +0000 @@ -210,6 +210,12 @@ scope="prototype"> + + + + + + + + + + + + /dhis-web-mapping/jsonMapLegendSet.vm + + /dhis-web-mapping/jsonminMapLegendSets.vm - - - /dhis-web-mapping/jsonMapLegendSetIndicators.vm - - /dhis-web-mapping/void.vm + + /dhis-web-mapping/void.vm + + + '+i18n_legend_set+'' }, + new Ext.form.ComboBox({ + id: 'predefinedmaplegendsetdataelement_cb', + isFormField: true, + hideLabel: true, + typeAhead: true, + editable: false, + valueField: 'id', + displayField: 'name', + mode: 'remote', + forceSelection: true, + triggerAction: 'all', + emptyText: emptytext, + selectOnFocus: true, + width: combo_width, + minListWidth: combo_width, + store: predefinedMapLegendSetStore, + listeners:{ + 'select': { + fn: function() { + var lsid = Ext.getCmp('predefinedmaplegendsetdataelement_cb').getValue(); + + Ext.Ajax.request({ + url: path_mapping + 'getMapLegendSet' + type, + method: 'POST', + params: {id: lsid}, + success: function(r) { + var dataElements = Ext.util.JSON.decode(r.responseText).mapLegendSet[0].dataElements; + var dataElementString = ''; + + for (var i = 0; i < dataElements.length; i++) { + dataElementString += dataElements[i]; + if (i < dataElements.length-1) { + dataElementString += ','; + } + } + + Ext.getCmp('predefinedmaplegendsetdataelement_ms').setValue(dataElementString); + }, + failure: function() { + alert( i18n_status , i18n_error_while_saving_data ); + } + }); + } + } + } + }), + { html: '
'+i18n_dataelement+'
' }, + new Ext.ux.Multiselect({id:'predefinedmaplegendsetdataelement_ms',isFormField:true,hideLabel:true,dataFields:['id','name','shortName'],valueField:'id',displayField:'shortName',width:multiselect_width,height:getMultiSelectHeight(),store:predefinedMapLegendSetDataElementStore}), + { + xtype: 'button', + id: 'assignpredefinedmaplegendsetdataelement_b', + text: i18n_assign_to_dataelement, + cls: 'window-button', + handler: function() { + var ls = Ext.getCmp('predefinedmaplegendsetdataelement_cb').getValue(); + var lsrw = Ext.getCmp('predefinedmaplegendsetdataelement_cb').getRawValue(); + var lims = Ext.getCmp('predefinedmaplegendsetdataelement_ms').getValue(); + + if (!ls) { + Ext.message.msg(false, i18n_please_select_a_legend_set); + return; + } + + if (!lims) { + Ext.message.msg(false, i18n_please_select_at_least_one_indicator); + return; + } + + var array = new Array(); + array = lims.split(','); + var params = '?dataElements=' + array[0]; + + if (array.length > 1) { + for (var i = 1; i < array.length; i++) { + array[i] = '&dataElements=' + array[i]; + params += array[i]; + } + } + + Ext.Ajax.request({ + url: path_mapping + 'assignDataElementsToMapLegendSet.action' + params, + method: 'POST', + params: {id: ls}, + success: function(r) { + Ext.message.msg(true, i18n_legend_set+' ' + lsrw + ' ' + i18n_was_updated); + Ext.getCmp('predefinedmaplegendsetdataelement_cb').getStore().load(); + }, + failure: function() { + alert( 'Error: assignDataElementsToMapLegendSet' ); + } + }); + } + } + ] + }); var predefinedMapLegendSetWindow = new Ext.Window({ id: 'predefinedmaplegendset_w', title: ''+i18n_predefined_legend_sets+'', layout: 'fit', closeAction: 'hide', - width: 441, + width: 592, items: [ { @@ -1140,6 +1242,9 @@ else if (tab.id == 'predefinedmaplegendset4') { w.setHeight(getMultiSelectHeight() + 180); } + else if (tab.id == 'predefinedmaplegendset5') { + w.setHeight(getMultiSelectHeight() + 180); + } } }, items: @@ -1176,7 +1281,14 @@ title: ''+i18n_assign_to_indicator+'', id: 'predefinedmaplegendset4', items: [ - assignPredefinedMapLegendSetPanel + assignPredefinedMapLegendSetIndicatorPanel + ] + }, + { + title: ''+i18n_assign_to_dataelement+'', + id: 'predefinedmaplegendset5', + items: [ + assignPredefinedMapLegendSetDataElementPanel ] } ] === modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/resources/mapfish/widgets/geostat/Choropleth.js' --- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/resources/mapfish/widgets/geostat/Choropleth.js 2010-09-06 10:17:56 +0000 +++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/resources/mapfish/widgets/geostat/Choropleth.js 2010-09-09 19:19:51 +0000 @@ -854,7 +854,35 @@ if (Ext.getCmp('mapview_cb').getValue()) { Ext.getCmp('mapview_cb').clearValue(); } - choropleth.classify(false, true); + + var deId = Ext.getCmp('dataelement_cb').getValue(); + + Ext.Ajax.request({ + url: path_mapping + 'getMapLegendSetByDataElement' + type, + method: 'POST', + params: {dataElementId: deId}, + success: function(r) { + var mapLegendSet = Ext.util.JSON.decode(r.responseText).mapLegendSet[0]; + if (mapLegendSet.id) { + LEGEND[thematicMap].type = map_legend_type_predefined; + Ext.getCmp('maplegendtype_cb').setValue(map_legend_type_predefined); + Ext.getCmp('maplegendset_cb').showField(); + Ext.getCmp('maplegendset_cb').setValue(mapLegendSet.id); + Ext.getCmp('method_cb').hideField(); + Ext.getCmp('numClasses_cb').hideField(); + Ext.getCmp('colorA_cf').hideField(); + Ext.getCmp('colorB_cf').hideField(); + + choropleth.applyPredefinedLegend(); + } + + choropleth.classify(false, true); + }, + failure: function() + { + alert( i18n_status , i18n_error_while_retrieving_data ); + } + }); } } } === modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/resources/mapfish/widgets/geostat/Symbol.js' --- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/resources/mapfish/widgets/geostat/Symbol.js 2010-09-04 06:08:10 +0000 +++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/resources/mapfish/widgets/geostat/Symbol.js 2010-09-09 19:19:51 +0000 @@ -851,7 +851,35 @@ if (Ext.getCmp('mapview_cb2').getValue()) { Ext.getCmp('mapview_cb2').clearValue(); } - proportionalSymbol.classify(false, true); + + var deId = Ext.getCmp('dataelement_cb2').getValue(); + + Ext.Ajax.request({ + url: path_mapping + 'getMapLegendSetByDataElement' + type, + method: 'POST', + params: {dataElementId: deId}, + success: function(r) { + var mapLegendSet = Ext.util.JSON.decode(r.responseText).mapLegendSet[0]; + if (mapLegendSet.id) { + LEGEND[thematicMap2].type = map_legend_type_predefined; + Ext.getCmp('maplegendtype_cb2').setValue(map_legend_type_predefined); + Ext.getCmp('maplegendset_cb2').showField(); + Ext.getCmp('maplegendset_cb2').setValue(mapLegendSet.id); + Ext.getCmp('method_cb2').hideField(); + Ext.getCmp('numClasses_cb2').hideField(); + Ext.getCmp('colorA_cf2').hideField(); + Ext.getCmp('colorB_cf2').hideField(); + + proportionalSymbol.applyPredefinedLegend(); + } + + proportionalSymbol.classify(false, true); + }, + failure: function() + { + alert( i18n_status , i18n_error_while_retrieving_data ); + } + }); } } }