dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #17503
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6987: (DV plugin) UserOrgunit, userOrgunitChildren options implemented.
Merge authors:
Jan Henrik Øverland (janhenrik-overland)
------------------------------------------------------------
revno: 6987 [merge]
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2012-05-19 14:20:07 +0300
message:
(DV plugin) UserOrgunit, userOrgunitChildren options implemented.
modified:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ChartPluginController.java
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/plugin/plugin.js
dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/plugin/index.html
dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/plugin/plugin.js
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ChartPluginController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ChartPluginController.java 2012-05-11 09:57:03 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ChartPluginController.java 2012-05-19 09:58:40 +0000
@@ -55,6 +55,7 @@
import org.hisp.dhis.period.Period;
import org.hisp.dhis.period.PeriodService;
import org.hisp.dhis.period.RelativePeriods;
+import org.hisp.dhis.user.CurrentUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
@@ -67,7 +68,7 @@
public class ChartPluginController
{
public static final String RESOURCE_PATH = "/chartValues";
-
+
@Autowired
private AggregatedDataValueService aggregatedDataValueService;
@@ -84,23 +85,26 @@
private OrganisationUnitService organisationUnitService;
@Autowired
+ private CurrentUserService currentUserService;
+
+ @Autowired
private I18nManager i18nManager;
@Autowired
private ContextUtils contextUtils;
@RequestMapping( method = RequestMethod.GET )
- public String getChartValues( @RequestParam(required=false) Set<String> indicatorIds,
- @RequestParam(required=false) Set<String> dataElementIds,
- @RequestParam Set<String> organisationUnitIds,
- @RequestParam(required=false) boolean orgUnitIsParent,
- RelativePeriods relativePeriods,
- Model model,
- HttpServletResponse response )
+ public String getChartValues( @RequestParam( required = false )
+ Set<String> indicatorIds, @RequestParam( required = false )
+ Set<String> dataElementIds, @RequestParam
+ Set<String> organisationUnitIds, @RequestParam( required = false )
+ boolean orgUnitIsParent, @RequestParam( required = false )
+ boolean userOrganisationUnit, @RequestParam( required = false )
+ boolean userOrganisationUnitChildren, RelativePeriods relativePeriods, Model model, HttpServletResponse response )
throws Exception
{
ChartPluginValue chartValue = new ChartPluginValue();
-
+
I18nFormat format = i18nManager.getI18nFormat();
// ---------------------------------------------------------------------
@@ -114,7 +118,7 @@
ContextUtils.conflictResponse( response, "No valid periods specified" );
return null;
}
-
+
for ( Period period : periods )
{
chartValue.getPeriods().add( period.getName() );
@@ -124,26 +128,45 @@
// Organisation units
// ---------------------------------------------------------------------
- List<OrganisationUnit> organisationUnits = organisationUnitService.getOrganisationUnitsByUid( organisationUnitIds );
-
+ List<OrganisationUnit> organisationUnits = new ArrayList<OrganisationUnit>();
+
+ if ( userOrganisationUnit || userOrganisationUnitChildren )
+ {
+ if ( userOrganisationUnit )
+ {
+ organisationUnits.add( currentUserService.getCurrentUser().getOrganisationUnit() );
+ }
+
+ if ( userOrganisationUnitChildren )
+ {
+ organisationUnits.addAll( new ArrayList<OrganisationUnit>( currentUserService.getCurrentUser()
+ .getOrganisationUnit().getChildren() ) );
+ }
+ }
+
+ else
+ {
+ organisationUnits = new ArrayList<OrganisationUnit>( organisationUnitService.getOrganisationUnitsByUid( organisationUnitIds ) );
+ }
+
if ( organisationUnits.isEmpty() )
{
ContextUtils.conflictResponse( response, "No valid organisation units specified" );
return null;
}
-
+
if ( orgUnitIsParent )
{
List<OrganisationUnit> childOrganisationUnits = new ArrayList<OrganisationUnit>();
-
+
for ( OrganisationUnit unit : organisationUnits )
{
childOrganisationUnits.addAll( unit.getChildren() );
}
-
+
organisationUnits = childOrganisationUnits;
}
-
+
for ( OrganisationUnit unit : organisationUnits )
{
chartValue.getOrgUnits().add( unit.getName() );
@@ -162,26 +185,25 @@
ContextUtils.conflictResponse( response, "No valid indicators specified" );
return null;
}
-
+
for ( Indicator indicator : indicators )
{
chartValue.getData().add( indicator.getDisplayShortName() );
}
-
- Collection<AggregatedIndicatorValue> indicatorValues = aggregatedDataValueService.getAggregatedIndicatorValues(
- getIdentifiers( Indicator.class, indicators ),
- getIdentifiers( Period.class, periods ),
- getIdentifiers( OrganisationUnit.class, organisationUnits ) );
+
+ Collection<AggregatedIndicatorValue> indicatorValues = aggregatedDataValueService
+ .getAggregatedIndicatorValues( getIdentifiers( Indicator.class, indicators ),
+ getIdentifiers( Period.class, periods ), getIdentifiers( OrganisationUnit.class, organisationUnits ) );
for ( AggregatedIndicatorValue value : indicatorValues )
{
String[] record = new String[4];
-
+
record[0] = String.valueOf( value.getValue() );
record[1] = indicatorService.getIndicator( value.getIndicatorId() ).getDisplayShortName();
record[2] = format.formatPeriod( periodService.getPeriod( value.getPeriodId() ) );
record[3] = organisationUnitService.getOrganisationUnit( value.getOrganisationUnitId() ).getName();
-
+
chartValue.getValues().add( record );
}
}
@@ -199,34 +221,33 @@
ContextUtils.conflictResponse( response, "No valid data elements specified" );
return null;
}
-
+
for ( DataElement element : dataElements )
{
chartValue.getData().add( element.getDisplayShortName() );
}
-
- Collection<AggregatedDataValue> dataValues = aggregatedDataValueService.getAggregatedDataValueTotals(
- getIdentifiers( DataElement.class, dataElements ),
- getIdentifiers( Period.class, periods ),
+
+ Collection<AggregatedDataValue> dataValues = aggregatedDataValueService.getAggregatedDataValueTotals(
+ getIdentifiers( DataElement.class, dataElements ), getIdentifiers( Period.class, periods ),
getIdentifiers( OrganisationUnit.class, organisationUnits ) );
for ( AggregatedDataValue value : dataValues )
{
String[] record = new String[4];
-
+
record[0] = String.valueOf( value.getValue() );
record[1] = dataElementService.getDataElement( value.getDataElementId() ).getDisplayShortName();
record[2] = format.formatPeriod( periodService.getPeriod( value.getPeriodId() ) );
record[3] = organisationUnitService.getOrganisationUnit( value.getOrganisationUnitId() ).getName();
-
- chartValue.getValues().add( record );
+
+ chartValue.getValues().add( record );
}
}
-
+
contextUtils.configureResponse( response, CONTENT_TYPE_JSON, CacheStrategy.RESPECT_SYSTEM_SETTING, null, false );
model.addAttribute( "model", chartValue );
-
+
return "chartValues";
}
}
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/plugin/plugin.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/plugin/plugin.js 2012-05-18 12:29:18 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/plugin/plugin.js 2012-05-19 11:11:26 +0000
@@ -688,10 +688,12 @@
trendLine: false,
hideLegend: false,
hideSubtitle: false,
+ userOrganisationUnit: false,
+ userOrganisationUnitChildren: false,
targetLineValue: null,
targetLineLabel: null,
baseLineValue: null,
- baseLineLabel: null,
+ baseLineLabel: null,
url: ''
};
@@ -731,6 +733,16 @@
conf.series = r.series.toLowerCase();
conf.category = r.category.toLowerCase();
conf.filter = r.filter.toLowerCase();
+ conf.showData = r.showData || false,
+ conf.trendLine = r.regression || false,
+ conf.hideLegend = r.hideLegend || false,
+ conf.hideSubtitle = r.hideSubtitle || false,
+ conf.userOrganisationUnit = r.userOrganisationUnit || false,
+ conf.userOrganisationUnitChildren = r.userOrganisationUnitChildren || false,
+ conf.targetLineValue = r.targetLineValue || null,
+ conf.targetLineLabel = r.targetLineLabel || null,
+ conf.baseLineValue = r.baseLineValue || null,
+ conf.baseLineLabel = r.baseLineLabel || null,
conf.legendPosition = conf.legendPosition || false;
if (r.indicators) {
@@ -761,6 +773,13 @@
baseUrl = Ext.String.urlAppend(baseUrl, item);
});
+ if (project.state.conf.userOrganisationUnit) {
+ baseUrl = Ext.String.urlAppend(baseUrl, 'userOrganisationUnit=true');
+ }
+ if (project.state.conf.userOrganisationUnitChildren) {
+ baseUrl = Ext.String.urlAppend(baseUrl, 'userOrganisationUnitChildren=true');
+ }
+
Ext.data.JsonP.request({
url: baseUrl,
disableCaching: false,
@@ -1243,4 +1262,4 @@
}
DHIS.getTable = DHIS.table.impl.render;
-DHIS.getUrl = DHIS.table.impl.getUrl;
\ No newline at end of file
+DHIS.getUrl = DHIS.table.impl.getUrl;
=== modified file 'dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/plugin/index.html'
--- dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/plugin/index.html 2012-05-18 12:29:18 +0000
+++ dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/plugin/index.html 2012-05-19 11:13:49 +0000
@@ -27,7 +27,7 @@
var url = '../../../'; // http://apps.dhis2.org/dev/
DHIS.getChart({
- uid: 'EbRN2VIbPdV',
+ uid: 'Y8iXMrjxDZ4',
el: 'chart1',
url: url
});
@@ -36,17 +36,19 @@
type: 'stackedcolumn',
indicators: ['Uvn6LCg7dVU'],
periods: 'last12Months',
- category: 'period',
- filter: 'organisationunit',
+ category: 'organisationunit',
+ filter: 'period',
organisationunits: ['ImspTQPwCqd'],
orgUnitIsParent: false,
showData: true,
trendLine: true,
hideLegend: false,
hideSubtitle: false,
+ userOrganisationUnit: false,
+ userOrganisationUnitChildren: true,
targetLineValue: 80,
targetLineLabel: null,
- baseLineValue: 20,
+ baseLineValue: null,
baseLineLabel: null,
el: 'chart2',
url: url
=== modified file 'dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/plugin/plugin.js'
--- dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/plugin/plugin.js 2012-05-18 12:29:18 +0000
+++ dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/plugin/plugin.js 2012-05-19 11:11:26 +0000
@@ -688,10 +688,12 @@
trendLine: false,
hideLegend: false,
hideSubtitle: false,
+ userOrganisationUnit: false,
+ userOrganisationUnitChildren: false,
targetLineValue: null,
targetLineLabel: null,
baseLineValue: null,
- baseLineLabel: null,
+ baseLineLabel: null,
url: ''
};
@@ -731,6 +733,16 @@
conf.series = r.series.toLowerCase();
conf.category = r.category.toLowerCase();
conf.filter = r.filter.toLowerCase();
+ conf.showData = r.showData || false,
+ conf.trendLine = r.regression || false,
+ conf.hideLegend = r.hideLegend || false,
+ conf.hideSubtitle = r.hideSubtitle || false,
+ conf.userOrganisationUnit = r.userOrganisationUnit || false,
+ conf.userOrganisationUnitChildren = r.userOrganisationUnitChildren || false,
+ conf.targetLineValue = r.targetLineValue || null,
+ conf.targetLineLabel = r.targetLineLabel || null,
+ conf.baseLineValue = r.baseLineValue || null,
+ conf.baseLineLabel = r.baseLineLabel || null,
conf.legendPosition = conf.legendPosition || false;
if (r.indicators) {
@@ -761,6 +773,13 @@
baseUrl = Ext.String.urlAppend(baseUrl, item);
});
+ if (project.state.conf.userOrganisationUnit) {
+ baseUrl = Ext.String.urlAppend(baseUrl, 'userOrganisationUnit=true');
+ }
+ if (project.state.conf.userOrganisationUnitChildren) {
+ baseUrl = Ext.String.urlAppend(baseUrl, 'userOrganisationUnitChildren=true');
+ }
+
Ext.data.JsonP.request({
url: baseUrl,
disableCaching: false,
@@ -1243,4 +1262,4 @@
}
DHIS.getTable = DHIS.table.impl.render;
-DHIS.getUrl = DHIS.table.impl.getUrl;
\ No newline at end of file
+DHIS.getUrl = DHIS.table.impl.getUrl;