← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16119: Impl support for event charts in dashboard

 

------------------------------------------------------------
revno: 16119
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2014-07-13 20:46:24 +0200
message:
  Impl support for event charts in dashboard
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardItem.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardSearchResult.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/impl/DefaultDashboardService.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/dashboard/hibernate/DashboardItem.hbm.xml
  dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/javascript/dashboard.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-api/src/main/java/org/hisp/dhis/dashboard/DashboardItem.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardItem.java	2014-06-07 14:26:31 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardItem.java	2014-07-13 18:46:24 +0000
@@ -34,12 +34,14 @@
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+
 import org.hisp.dhis.chart.Chart;
 import org.hisp.dhis.common.BaseIdentifiableObject;
 import org.hisp.dhis.common.DxfNamespaces;
 import org.hisp.dhis.common.IdentifiableObject;
 import org.hisp.dhis.common.view.DetailedView;
 import org.hisp.dhis.document.Document;
+import org.hisp.dhis.eventchart.EventChart;
 import org.hisp.dhis.mapping.Map;
 import org.hisp.dhis.report.Report;
 import org.hisp.dhis.reporttable.ReportTable;
@@ -61,7 +63,8 @@
 {
     public static final int MAX_CONTENT = 8;
 
-    public static final String TYPE_CHART = "chart";
+    public static final String TYPE_CHART = "chart"; //TODO use enum
+    public static final String TYPE_EVENT_CHART = "eventChart"; //TODO use enum
     public static final String TYPE_MAP = "map";
     public static final String TYPE_REPORT_TABLE = "reportTable";
     public static final String TYPE_USERS = "users";
@@ -72,10 +75,12 @@
 
     private Chart chart;
 
+    private EventChart eventChart;
+
     private Map map;
 
     private ReportTable reportTable;
-
+    
     private List<User> users = new ArrayList<User>();
 
     private List<ReportTable> reportTables = new ArrayList<ReportTable>();
@@ -112,6 +117,10 @@
         {
             return TYPE_CHART;
         }
+        else if ( eventChart != null )
+        {
+            return TYPE_EVENT_CHART;
+        }
         else if ( map != null )
         {
             return TYPE_MAP;
@@ -154,6 +163,10 @@
         {
             return chart;
         }
+        else if ( eventChart != null )
+        {
+            return eventChart;
+        }
         else if ( map != null )
         {
             return map;
@@ -198,6 +211,7 @@
     {
         int count = 0;
         count += chart != null ? 1 : 0;
+        count += eventChart != null ? 1 : 0;
         count += map != null ? 1 : 0;
         count += reportTable != null ? 1 : 0;
         count += users.size();
@@ -273,6 +287,20 @@
     @JsonView( { DetailedView.class } )
     @JsonSerialize( as = BaseIdentifiableObject.class )
     @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+    public EventChart getEventChart()
+    {
+        return eventChart;
+    }
+    
+    public void setEventChart( EventChart eventChart )
+    {
+        this.eventChart = eventChart;
+    }
+    
+    @JsonProperty
+    @JsonView( { DetailedView.class } )
+    @JsonSerialize( as = BaseIdentifiableObject.class )
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
     public Map getMap()
     {
         return map;

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardSearchResult.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardSearchResult.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardSearchResult.java	2014-07-13 18:46:24 +0000
@@ -35,6 +35,7 @@
 import org.hisp.dhis.common.BaseIdentifiableObject;
 import org.hisp.dhis.common.DxfNamespaces;
 import org.hisp.dhis.document.Document;
+import org.hisp.dhis.eventchart.EventChart;
 import org.hisp.dhis.mapping.Map;
 import org.hisp.dhis.report.Report;
 import org.hisp.dhis.reporttable.ReportTable;
@@ -53,6 +54,8 @@
     
     private List<Chart> charts = new ArrayList<Chart>();
     
+    private List<EventChart> eventCharts = new ArrayList<EventChart>();
+    
     private List<Map> maps = new ArrayList<Map>();
 
     private List<ReportTable> reportTables = new ArrayList<ReportTable>();
@@ -79,6 +82,7 @@
         int results = 0;
         results += users.size();
         results += charts.size();
+        results += eventCharts.size();
         results += maps.size();
         results += reportTables.size();
         results += reports.size();
@@ -97,6 +101,12 @@
     {
         return charts.size();
     }
+    
+    @JsonProperty
+    private int getEventChartCount()
+    {
+        return eventCharts.size();
+    }
 
     @JsonProperty
     public int getMapCount()
@@ -154,6 +164,20 @@
         this.charts = charts;
     }
 
+    @JsonProperty( value = "eventCharts" )
+    @JsonSerialize( contentAs = BaseIdentifiableObject.class )
+    @JacksonXmlElementWrapper( localName = "eventCharts", namespace = DxfNamespaces.DXF_2_0)
+    @JacksonXmlProperty( localName = "eventChart", namespace = DxfNamespaces.DXF_2_0)
+    public List<EventChart> getEventCharts()
+    {
+        return eventCharts;
+    }
+    
+    public void setEventCharts( List<EventChart> eventCharts )
+    {
+        this.eventCharts = eventCharts;
+    }
+    
     @JsonProperty( value = "maps" )
     @JsonSerialize( contentAs = BaseIdentifiableObject.class )
     @JacksonXmlElementWrapper( localName = "maps", namespace = DxfNamespaces.DXF_2_0)

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/impl/DefaultDashboardService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/impl/DefaultDashboardService.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/impl/DefaultDashboardService.java	2014-07-13 18:46:24 +0000
@@ -30,6 +30,7 @@
 
 import static org.hisp.dhis.common.IdentifiableObjectUtils.getUids;
 import static org.hisp.dhis.dashboard.DashboardItem.TYPE_CHART;
+import static org.hisp.dhis.dashboard.DashboardItem.TYPE_EVENT_CHART;
 import static org.hisp.dhis.dashboard.DashboardItem.TYPE_MAP;
 import static org.hisp.dhis.dashboard.DashboardItem.TYPE_MESSAGES;
 import static org.hisp.dhis.dashboard.DashboardItem.TYPE_REPORTS;
@@ -51,6 +52,7 @@
 import org.hisp.dhis.dashboard.DashboardSearchResult;
 import org.hisp.dhis.dashboard.DashboardService;
 import org.hisp.dhis.document.Document;
+import org.hisp.dhis.eventchart.EventChart;
 import org.hisp.dhis.mapping.Map;
 import org.hisp.dhis.report.Report;
 import org.hisp.dhis.reporttable.ReportTable;
@@ -104,6 +106,7 @@
 
         result.setUsers( objectManager.getBetweenByName( User.class, query, 0, getMax( TYPE_USERS, maxTypes ) ) );
         result.setCharts( objectManager.getBetweenByName( Chart.class, query, 0, getMax( TYPE_CHART, maxTypes ) ) );
+        result.setEventCharts( objectManager.getBetweenByName( EventChart.class, query, 0, getMax( TYPE_EVENT_CHART, maxTypes ) ) );
         result.setMaps( objectManager.getBetweenByName( Map.class, query, 0, getMax( TYPE_MAP, maxTypes ) ) );
         result.setReportTables( objectManager.getBetweenByName( ReportTable.class, query, 0, getMax( TYPE_REPORT_TABLE, maxTypes ) ) );
         result.setReports( objectManager.getBetweenByName( Report.class, query, 0, getMax( TYPE_REPORTS, maxTypes ) ) );
@@ -128,6 +131,12 @@
             item.setChart( objectManager.get( Chart.class, contentUid ) );
             dashboard.getItems().add( 0, item );
         }
+        else if ( TYPE_EVENT_CHART.equals( type ) )
+        {
+            DashboardItem item = new DashboardItem();
+            item.setEventChart( objectManager.get( EventChart.class, contentUid ) );
+            dashboard.getItems().add( 0, item );
+        }
         else if ( TYPE_MAP.equals( type ) )
         {
             DashboardItem item = new DashboardItem();
@@ -203,6 +212,11 @@
             item.setChart( objectManager.get( Chart.class, item.getChart().getUid() ) );
         }
 
+        if ( item.getEventChart() != null )
+        {
+            item.setEventChart( objectManager.get( EventChart.class, item.getEventChart().getUid() ) );
+        }
+        
         if ( item.getMap() != null )
         {
             item.setMap( objectManager.get( Map.class, item.getMap().getUid() ) );

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/dashboard/hibernate/DashboardItem.hbm.xml'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/dashboard/hibernate/DashboardItem.hbm.xml	2014-03-07 10:59:18 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/dashboard/hibernate/DashboardItem.hbm.xml	2014-07-13 18:46:24 +0000
@@ -17,6 +17,8 @@
 
     <many-to-one name="chart" class="org.hisp.dhis.chart.Chart" column="chartid" foreign-key="fk_dashboarditem_chartid" />
     
+    <many-to-one name="eventChart" class="org.hisp.dhis.eventchart.EventChart" column="eventchartid" foreign-key="fk_dashboarditem_eventchartid" />
+    
     <many-to-one name="map" class="org.hisp.dhis.mapping.Map" column="mapid" foreign-key="fk_dashboarditem_mapid" />
     
     <many-to-one name="reportTable" class="org.hisp.dhis.reporttable.ReportTable" foreign-key="fk_dashboarditem_reporttableid" />

=== modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/javascript/dashboard.js'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/javascript/dashboard.js	2014-06-17 15:58:51 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/javascript/dashboard.js	2014-07-13 18:46:24 +0000
@@ -78,13 +78,18 @@
 	           "<a href='javascript:dhis2.db.viewImage( \"../api/charts/${id}/data?width=820&height=550\", \"${name}\" )'>${i18n_view}</a>" +
 	           "<a href='javascript:dhis2.db.viewShareForm( \"${id}\", \"chart\", \"${name}\" )'>${i18n_share}</a></div>" +
 	           "<img src='../api/charts/${id}/data?width=405&height=294' onclick='dhis2.db.exploreChart( \"${id}\" )' title='${i18n_click}'></div></li>",
-	           
+
+   	eventChartItem: "<li id='liDrop-${itemId}' class='liDropItem'><div class='dropItem' id='drop-${itemId}' data-item='${itemId}'></div></li>" +
+   	           "<li id='li-${itemId}' class='liItem'><div class='item' id='${itemId}'><div class='itemHeader'><a href='javascript:dhis2.db.removeItem( \"${itemId}\" )'>${i18n_remove}</a>" +
+   	           "<a href='javascript:dhis2.db.viewImage( \"../api/eventCharts/${id}/data?width=820&height=550\", \"${name}\" )'>${i18n_view}</a></div>" +
+   	           "<img src='../api/eventCharts/${id}/data?width=405&height=294' onclick='dhis2.db.exploreEventChart( \"${id}\" )' title='${i18n_click}'></div></li>",
+
 	mapItem: "<li id='liDrop-${itemId}' class='liDropItem'><div class='dropItem' id='drop-${itemId}' data-item='${itemId}'></div></li>" +
 	         "<li id='li-${itemId}' class='liItem'><div class='item' id='${itemId}'><div class='itemHeader'><a href='javascript:dhis2.db.removeItem( \"${itemId}\" )'>${i18n_remove}</a>" +
 	         "<a href='javascript:dhis2.db.viewImage( \"../api/maps/${id}/data?width=820&height=550\", \"${name}\" )'>${i18n_view}</a>" +
 	         "<a href='javascript:dhis2.db.viewShareForm( \"${id}\", \"map\", \"${name}\" )'>${i18n_share}</a></div>" +
 		     "<img src='../api/maps/${id}/data?width=405&height=294' onclick='dhis2.db.exploreMap( \"${id}\" )' title='${i18n_click}'></div></li>",
-		     
+
 	reportTableItem: "<li id='liDrop-${itemId}' class='liDropItem'><div class='dropItem' id='drop-${itemId}' data-item='${itemId}'></div></li>" +
                "<li id='li-${itemId}' class='liItem'><div class='item' id='${itemId}'><div class='itemHeader'><a href='javascript:dhis2.db.removeItem( \"${itemId}\" )'>${i18n_remove}</a>" +
                "<a href='javascript:dhis2.db.viewReportDialog( \"../api/reportTables/${id}/data.html\", \"${name}\" )'>${i18n_view}</a>" +
@@ -391,6 +396,11 @@
 					$d.append( $.tmpl( dhis2.db.tmpl.chartItem, { "itemId": dashboardItem.id, "id": dashboardItem.chart.id, "name": dashboardItem.chart.name,
 						"i18n_remove": i18n_remove, "i18n_view": i18n_view_full_size, "i18n_share": i18n_share_interpretation, "i18n_click": i18n_click_to_explore_drag_to_new_position } ) )
 				}
+				if ( "eventChart" == dashboardItem.type )
+				{
+					$d.append( $.tmpl( dhis2.db.tmpl.eventChartItem, { "itemId": dashboardItem.id, "id": dashboardItem.eventChart.id, "name": dashboardItem.eventChart.name,
+						"i18n_remove": i18n_remove, "i18n_view": i18n_view_full_size, "i18n_share": i18n_share_interpretation, "i18n_click": i18n_click_to_explore_drag_to_new_position } ) )
+				}
 				else if ( "map" == dashboardItem.type )
 				{
 					$d.append( $.tmpl( dhis2.db.tmpl.mapItem, { "itemId": dashboardItem.id, "id": dashboardItem.map.id, "name": dashboardItem.map.name,
@@ -483,7 +493,8 @@
 		}		
 		
 		html += 
-			"<li><a href='" + baseUrl + content.id + urlSuffix + "'>" + content.name + "</a><a class='removeItemLink' href='javascript:dhis2.db.removeItemContent( \"" + itemId + "\", \"" + content.id + "\" )' title='" + i18n_remove + "'>" + 
+			"<li><a href='" + baseUrl + content.id + urlSuffix + "'>" + content.name + "</a>" +
+			"<a class='removeItemLink' href='javascript:dhis2.db.removeItemContent( \"" + itemId + "\", \"" + content.id + "\" )' title='" + i18n_remove + "'>" + 
 			"<img src='../images/hide.png'></a></li>";
 	} );
 	
@@ -574,6 +585,11 @@
 	window.location.href = "../dhis-web-visualizer/app/index.html?id=" + uid;
 }
 
+dhis2.db.exploreEventChart = function( uid )
+{
+	window.location.href = "../dhis-web-event-visualizer/app/index.html?id=" + uid;
+}
+
 dhis2.db.exploreMap = function( uid )
 {
 	window.location.href = "../dhis-web-mapping/app/index.html?id=" + uid;
@@ -687,6 +703,17 @@
 				$h.append( $.tmpl( dhis2.db.tmpl.hitItem, { "canManage": canManage, "link": "../dhis-web-visualizer/app/index.html?id=" + o.id, "img": "chart_small", "name": o.name, "type": "chart", "id": o.id, "i18n_add": i18n_add } ) );
 			}
 		}
+
+		if ( data.eventChartCount > 0 )
+		{
+			$h.append( $.tmpl( dhis2.db.tmpl.hitHeader, { "title": "Event charts", "type": "eventChart", "i18n_see_more_hits": i18n_see_more_hits, "i18n_see_fewer_hits": i18n_see_fewer_hits } ) );
+			
+			for ( var i in data.eventCharts )
+			{
+				var o = data.eventCharts[i];
+				$h.append( $.tmpl( dhis2.db.tmpl.hitItem, { "canManage": canManage, "link": "../dhis-web-event-visualizer/app/index.html?id=" + o.id, "img": "chart_small", "name": o.name, "type": "eventChart", "id": o.id, "i18n_add": i18n_add } ) );
+			}
+		}
 		
 		if ( data.mapCount > 0 )
 		{