← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7159: Dashboard, loading number of charts automatically dependening on viewport size

 

------------------------------------------------------------
revno: 7159
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2012-06-03 18:26:12 +0200
message:
  Dashboard, loading number of charts automatically dependening on viewport size
added:
  dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/action/InitAction.java
  dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/dashboard.vm
modified:
  dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/action/ProvideContentAction.java
  dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/resources/struts.xml
  dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/javascript/dropdown.js
  dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/mainForm.vm


--
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-commons/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml	2012-04-12 12:39:47 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml	2012-06-03 16:26:12 +0000
@@ -45,6 +45,7 @@
       <set>
         <value>page</value>
         <value>menu</value>
+		<value>hideMenu</value>
         <value>offline</value>
       </set>
     </property>

=== added file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/action/InitAction.java'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/action/InitAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/action/InitAction.java	2012-06-03 16:26:12 +0000
@@ -0,0 +1,47 @@
+package org.hisp.dhis.dashboard.action;
+
+import org.hisp.dhis.interpretation.InterpretationService;
+import org.hisp.dhis.message.MessageService;
+
+import com.opensymphony.xwork2.Action;
+
+public class InitAction
+    implements Action
+{
+    private MessageService messageService;
+
+    public void setMessageService( MessageService messageService )
+    {
+        this.messageService = messageService;
+    }
+    
+    private InterpretationService interpretationService;
+
+    public void setInterpretationService( InterpretationService interpretationService )
+    {
+        this.interpretationService = interpretationService;
+    }
+
+    private long messageCount;
+
+    public long getMessageCount()
+    {
+        return messageCount;
+    }
+    
+    private long interpretationCount;
+
+    public long getInterpretationCount()
+    {
+        return interpretationCount;
+    }
+
+    public String execute()
+    {
+        messageCount = messageService.getUnreadMessageConversationCount();
+        
+        interpretationCount = interpretationService.getNewInterpretationCount();
+        
+        return SUCCESS;
+    }
+}

=== modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/action/ProvideContentAction.java'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/action/ProvideContentAction.java	2012-05-29 21:23:47 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/action/ProvideContentAction.java	2012-06-03 16:26:12 +0000
@@ -27,9 +27,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import static org.hisp.dhis.user.UserSettingService.DEFAULT_CHARTS_IN_DASHBOARD;
-import static org.hisp.dhis.user.UserSettingService.KEY_CHARTS_IN_DASHBOARD;
-
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -40,9 +37,6 @@
 import org.hisp.dhis.chart.ChartService;
 import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
 import org.hisp.dhis.dashboard.DashboardManager;
-import org.hisp.dhis.interpretation.InterpretationService;
-import org.hisp.dhis.message.MessageService;
-import org.hisp.dhis.user.UserSettingService;
 
 import com.opensymphony.xwork2.Action;
 import com.opensymphony.xwork2.ActionContext;
@@ -72,25 +66,15 @@
         this.chartService = chartService;
     }
 
-    private UserSettingService userSettingService;
-
-    public void setUserSettingService( UserSettingService userSettingService )
-    {
-        this.userSettingService = userSettingService;
-    }
-
-    private MessageService messageService;
-
-    public void setMessageService( MessageService messageService )
-    {
-        this.messageService = messageService;
-    }
-    
-    private InterpretationService interpretationService;
-
-    public void setInterpretationService( InterpretationService interpretationService )
-    {
-        this.interpretationService = interpretationService;
+    // -------------------------------------------------------------------------
+    // Input
+    // -------------------------------------------------------------------------
+
+    private Integer noCharts;
+
+    public void setNoCharts( Integer noCharts )
+    {
+        this.noCharts = noCharts;
     }
 
     // -------------------------------------------------------------------------
@@ -118,20 +102,6 @@
         return chartAreas;
     }
 
-    private long messageCount;
-
-    public long getMessageCount()
-    {
-        return messageCount;
-    }
-    
-    private long interpretationCount;
-
-    public long getInterpretationCount()
-    {
-        return interpretationCount;
-    }
-
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
@@ -148,9 +118,9 @@
 
         Collections.sort( charts, IdentifiableObjectNameComparator.INSTANCE );
 
-        int chartsInDashboardCount = (Integer) userSettingService.getUserSetting( KEY_CHARTS_IN_DASHBOARD, DEFAULT_CHARTS_IN_DASHBOARD );
+        noCharts = noCharts == null ? 6 : noCharts;
 
-        for ( int i = 1; i <= chartsInDashboardCount; i++ )
+        for ( int i = 1; i <= noCharts; i++ )
         {
             Object id = content.get( DashboardManager.CHART_AREA_PREFIX + i );
 
@@ -164,10 +134,6 @@
             chartAreas.add( chart );
         }
 
-        messageCount = messageService.getUnreadMessageConversationCount();
-        
-        interpretationCount = interpretationService.getNewInterpretationCount();
-
         return SUCCESS;
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/resources/META-INF/dhis/beans.xml	2012-05-29 21:23:47 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/resources/META-INF/dhis/beans.xml	2012-06-03 16:26:12 +0000
@@ -5,13 +5,16 @@
 
   <!-- Dashboard -->
 
+  <bean id="org.hisp.dhis.dashboard.action.InitAction" class="org.hisp.dhis.dashboard.action.InitAction"
+	scope="prototype">
+    <property name="messageService" ref="org.hisp.dhis.message.MessageService" />
+	<property name="interpretationService" ref="org.hisp.dhis.interpretation.InterpretationService" />	
+  </bean>
+
   <bean id="org.hisp.dhis.dashboard.action.ProvideContentAction" class="org.hisp.dhis.dashboard.action.ProvideContentAction"
     scope="prototype">
     <property name="manager" ref="org.hisp.dhis.dashboard.DashboardManager" />
-    <property name="userSettingService" ref="org.hisp.dhis.user.UserSettingService" />
     <property name="chartService" ref="org.hisp.dhis.chart.ChartService" />
-    <property name="messageService" ref="org.hisp.dhis.message.MessageService" />
-	<property name="interpretationService" ref="org.hisp.dhis.interpretation.InterpretationService" />
   </bean>
 
   <bean id="org.hisp.dhis.dashboard.action.SetAreaItemAction" class="org.hisp.dhis.dashboard.action.SetAreaItemAction"

=== modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/resources/struts.xml	2012-05-29 12:04:07 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/resources/struts.xml	2012-06-03 16:26:12 +0000
@@ -10,7 +10,7 @@
 
     <!--  Dashboard -->
 
-    <action name="index" class="org.hisp.dhis.dashboard.action.ProvideContentAction">
+    <action name="index" class="org.hisp.dhis.dashboard.action.InitAction">
       <result name="success" type="velocity">/main.vm</result>
       <param name="page">/dhis-web-dashboard-integration/mainForm.vm</param>
       <param name="menu">/dhis-web-dashboard-integration/menu.vm</param>
@@ -18,6 +18,10 @@
       <param name="javascripts">javascript/dropdown.js</param>
     </action>
 
+    <action name="provideContent" class="org.hisp.dhis.dashboard.action.ProvideContentAction">
+      <result name="success" type="velocity">/dhis-web-dashboard-integration/dashboard.vm</result>
+    </action>
+
     <action name="setAreaItem" class="org.hisp.dhis.dashboard.action.SetAreaItemAction">
       <result name="success" type="velocity-xml">/dhis-web-dashboard-integration/responseSuccess.vm</result>
       <param name="onExceptionReturn">plainTextError</param>

=== added file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/dashboard.vm'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/dashboard.vm	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/dashboard.vm	2012-06-03 16:26:12 +0000
@@ -0,0 +1,90 @@
+
+#macro ( linkDropDownButtonDiv $dropDownId $areaDivId )
+<div class="buttonArea">
+    <a href="javascript:showDropDown( '${dropDownId}' )">$i18n.getString( "insert" )</a>
+    <a href="javascript:hideDropDown()">$i18n.getString( "close" )</a>
+    <a href="javascript:clearArea( '${areaDivId}' )">$i18n.getString( "clear" )</a>
+</div>
+#end
+
+#macro ( chartDropDownButtonDiv $dropDownId $areaDivId $chart )
+<div class="buttonArea">
+    <a href="javascript:showDropDown( '${dropDownId}' )">$i18n.getString( "insert" )</a>
+    <a href="javascript:hideDropDown()">$i18n.getString( "close" )</a>
+    <a href="javascript:clearArea( '${areaDivId}' )">$i18n.getString( "clear" )</a>
+    #if( $chart )
+    <a href="javascript:explore( '${chart.uid}' )">$i18n.getString( "explore" )</a>
+    #end
+</div>
+#end
+
+#macro ( linkDropDownListDiv $divId $listId $page )
+<div id="$divId" class="linkArea">
+    <div id="$listId" class="menuDropDownArea">
+        <ul class="menuDropDownBox">
+        #foreach( $provider in $providerNames )
+            <li class="menuDropDownItem" onclick="setAreaItem( '$divId', '$provider' )">$i18n.getString( "$provider" )&nbsp;</li>
+        #end
+        </ul>
+    </div>
+    #if ( $page )
+        #parse( "/dhis-web-dashboard-integration/${page}.vm" )
+    #else
+        <div class="labelText">$i18n.getString( 'this_is_a_link_area' )</div>
+    #end
+</div>
+#end
+
+#macro ( chartDropDownListDiv $divId $listId $chart )
+<div id="$divId" class="chartArea">
+    <div id="$listId" class="menuDropDownArea">
+        <ul class="menuDropDownBox">
+        #foreach( $availableChart in $charts )
+            <li class="menuDropDownItem" onclick="setAreaItem( '${divId}', '${availableChart.id}' )">${availableChart.name}&nbsp;</li>
+        #end
+        </ul>
+    </div>
+    #if ( $chart )
+        <img style="cursor:pointer" src="../api/charts/${chart.uid}/data?width=310&height=310" onclick="viewChart( '../api/charts/${chart.uid}/data' )">
+    #else
+        <div class="labelText">$i18n.getString( 'this_is_a_chart_area' )</div>
+    #end
+</div>
+#end
+
+<table cellspacing="0" cellpadding="0" style="width:960px">
+<tr>
+    <td style="width:305px">        
+        #linkDropDownButtonDiv( "dropDownA" "areaA" )
+        #linkDropDownListDiv( "areaA" "dropDownA" $areaA )
+
+        #linkDropDownButtonDiv( "dropDownB" "areaB" )
+        #linkDropDownListDiv( "areaB" "dropDownB" $areaB )
+
+        #linkDropDownButtonDiv( "dropDownC" "areaC" )
+        #linkDropDownListDiv( "areaC" "dropDownC" $areaC )      
+    </td>
+	<td>
+
+<table>
+
+#set( $sizeHalf = $chartAreas.size() / 2 )
+
+#foreach( $chart in $chartAreas )
+#set( $count0 = $velocityCount - 1 )
+#set( $count1 = $velocityCount )
+#set( $startHr = ($count0 % $sizeHalf) == 0 )
+#set( $endHr =  ($count0 % $sizeHalf) == ($sizeHalf - 1) )
+
+#if( $startHr )<tr> #end
+	<td style="width:305px; padding-left: 10px;">
+		#chartDropDownButtonDiv( "chartDropDown${count1}" "chartArea${count1}" $chart )
+		#chartDropDownListDiv( "chartArea${count1}" "chartDropDown${count1}" $chart )
+	</td>
+#end
+#if( $endHr )</tr> #end
+</table>
+
+	</td>
+</tr>
+</table>

=== modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/javascript/dropdown.js'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/javascript/dropdown.js	2012-05-05 19:13:56 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/javascript/dropdown.js	2012-06-03 16:26:12 +0000
@@ -1,3 +1,20 @@
+
+$( document ).ready( function()
+{
+	var viewportWidth = parseInt( $( window ).width() );
+	var linkWidth = parseInt( 355 );
+	var chartWidth = parseInt( 325 );
+	
+	if ( viewportWidth == undefined )
+	{
+		viewportWidth = parseInt( 1366 );
+	}
+	
+	var noCharts = 2 * Math.floor( ( viewportWidth - linkWidth ) / chartWidth ); 
+		
+	$( "#contentDiv" ).load( "provideContent.action?noCharts=" + noCharts + "&_dc=" + getRandomNumber() );
+} );
+
 function setAreaItem( area, item )
 {
     $.get( "setAreaItem.action", {

=== modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/mainForm.vm'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/mainForm.vm	2012-05-29 21:23:47 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/mainForm.vm	2012-06-03 16:26:12 +0000
@@ -1,99 +1,11 @@
 
-#macro ( linkDropDownButtonDiv $dropDownId $areaDivId )
-<div class="buttonArea">
-    <a href="javascript:showDropDown( '${dropDownId}' )">$i18n.getString( "insert" )</a>
-    <a href="javascript:hideDropDown()">$i18n.getString( "close" )</a>
-    <a href="javascript:clearArea( '${areaDivId}' )">$i18n.getString( "clear" )</a>
-</div>
-#end
-
-#macro ( chartDropDownButtonDiv $dropDownId $areaDivId $chart )
-<div class="buttonArea">
-    <a href="javascript:showDropDown( '${dropDownId}' )">$i18n.getString( "insert" )</a>
-    <a href="javascript:hideDropDown()">$i18n.getString( "close" )</a>
-    <a href="javascript:clearArea( '${areaDivId}' )">$i18n.getString( "clear" )</a>
-    #if( $chart )
-    <a href="javascript:explore( '${chart.uid}' )">$i18n.getString( "explore" )</a>
-    #end
-</div>
-#end
-
-#macro ( linkDropDownListDiv $divId $listId $page )
-<div id="$divId" class="linkArea">
-    <div id="$listId" class="menuDropDownArea">
-        <ul class="menuDropDownBox">
-        #foreach( $provider in $providerNames )
-            <li class="menuDropDownItem" onclick="setAreaItem( '$divId', '$provider' )">$i18n.getString( "$provider" )&nbsp;</li>
-        #end
-        </ul>
-    </div>
-    #if ( $page )
-        #parse( "/dhis-web-dashboard-integration/${page}.vm" )
-    #else
-        <div class="labelText">$i18n.getString( 'this_is_a_link_area' )</div>
-    #end
-</div>
-#end
-
-#macro ( chartDropDownListDiv $divId $listId $chart )
-<div id="$divId" class="chartArea">
-    <div id="$listId" class="menuDropDownArea">
-        <ul class="menuDropDownBox">
-        #foreach( $availableChart in $charts )
-            <li class="menuDropDownItem" onclick="setAreaItem( '${divId}', '${availableChart.id}' )">${availableChart.name}&nbsp;</li>
-        #end
-        </ul>
-    </div>
-    #if ( $chart )
-        <img style="cursor:pointer" src="../api/charts/${chart.uid}/data?width=310&height=310" onclick="viewChart( '../api/charts/${chart.uid}/data' )">
-    #else
-        <div class="labelText">$i18n.getString( 'this_is_a_chart_area' )</div>
-    #end
-</div>
-#end
-
 <h3>$i18n.getString( "dashboard" ) #openHelp( "dashboards_setup" )
 &#8226; <a href="showSendFeedback.action">$i18n.getString( "write_feedback" )</a>
 #if( $messageCount > 0 )&#8226; <a href="message.action">$messageCount #if( $messageCount > 1 )$i18n.getString( "unread_messages" )#else$i18n.getString( "unread_message" )#end</a> #end
 #if( $interpretationCount > 0 )&#8226; <a href="interpretation.action">$interpretationCount #if( $interpretationCount > 1 )$i18n.getString( "new_interpretations" )#else$i18n.getString( "new_interpretation" )#end</a> #end
 </h3>
 
-<table cellspacing="0" cellpadding="0" style="width:960px">
-<tr>
-    <td style="width:305px">        
-        #linkDropDownButtonDiv( "dropDownA" "areaA" )
-        #linkDropDownListDiv( "areaA" "dropDownA" $areaA )
-
-        #linkDropDownButtonDiv( "dropDownB" "areaB" )
-        #linkDropDownListDiv( "areaB" "dropDownB" $areaB )
-
-        #linkDropDownButtonDiv( "dropDownC" "areaC" )
-        #linkDropDownListDiv( "areaC" "dropDownC" $areaC )      
-    </td>
-	<td>
-
-<table>
-
-#set( $sizeHalf = $chartAreas.size() / 2 )
-
-#foreach( $chart in $chartAreas )
-#set( $count0 = $velocityCount - 1 )
-#set( $count1 = $velocityCount )
-#set( $startHr = ($count0 % $sizeHalf) == 0 )
-#set( $endHr =  ($count0 % $sizeHalf) == ($sizeHalf - 1) )
-
-#if( $startHr )<tr> #end
-	<td style="width:305px; padding-left: 10px;">
-		#chartDropDownButtonDiv( "chartDropDown${count1}" "chartArea${count1}" $chart )
-		#chartDropDownListDiv( "chartArea${count1}" "chartDropDown${count1}" $chart )
-	</td>
-#end
-#if( $endHr )</tr> #end
-</table>
-
-	</td>
-</tr>
-</table>
+<div id="contentDiv"></div>
 
 <div id="chartView" style="display:none; padding:0; margin:0;">
 	<img id="chartImage" src="" style="padding: 10px;"></img>