← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12057: Dashboard, put in place a max limit (40) for number of items

 

------------------------------------------------------------
revno: 12057
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2013-09-12 10:13:03 +0200
message:
  Dashboard, put in place a max limit (40) for number of items
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardService.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/impl/DefaultDashboardService.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DashboardController.java
  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/Dashboard.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java	2013-09-09 12:45:37 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java	2013-09-12 08:13:03 +0000
@@ -49,6 +49,8 @@
 public class Dashboard
     extends BaseIdentifiableObject
 {
+    public static final int MAX_ITEMS = 40;
+    
     private List<DashboardItem> items = new ArrayList<DashboardItem>();
 
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardService.java	2013-09-04 15:50:41 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardService.java	2013-09-12 08:13:03 +0000
@@ -45,7 +45,7 @@
     
     DashboardSearchResult search( String query, Set<String> maxTypes );
     
-    void addItemContent( String dashboardUid, String type, String contentUid );
+    boolean addItemContent( String dashboardUid, String type, String contentUid );
     
     void mergeDashboard( Dashboard dashboard );
     

=== 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	2013-09-04 15:50:41 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/impl/DefaultDashboardService.java	2013-09-12 08:13:03 +0000
@@ -111,10 +111,15 @@
     }
 
     @Override
-    public void addItemContent( String dashboardUid, String type, String contentUid )
+    public boolean addItemContent( String dashboardUid, String type, String contentUid )
     {
         Dashboard dashboard = getDashboard( dashboardUid );               
         
+        if ( dashboard == null )
+        {
+            return false;
+        }
+        
         if ( TYPE_CHART.equals( type ) )
         {
             DashboardItem item = new DashboardItem();
@@ -164,8 +169,15 @@
                 dashboard.getItems().add( 0, item );
             }
         }
+
+        if ( dashboard.getItemCount() > Dashboard.MAX_ITEMS )
+        {
+            return false;
+        }
         
         updateDashboard( dashboard );
+        
+        return true;
     }
     
     public void mergeDashboard( Dashboard dashboard )

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DashboardController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DashboardController.java	2013-09-11 13:46:35 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DashboardController.java	2013-09-12 08:13:03 +0000
@@ -53,6 +53,8 @@
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.ResponseStatus;
 
+import static org.hisp.dhis.dashboard.Dashboard.MAX_ITEMS;
+
 /**
  * @author Lars Helge Overland
  */
@@ -155,9 +157,16 @@
     public void postJsonItemContent( HttpServletResponse response, HttpServletRequest request, 
         @PathVariable String dashboardUid, @RequestParam String type, @RequestParam( "id" ) String contentUid ) throws Exception
     {
-        dashboardService.addItemContent( dashboardUid, type, contentUid );
+        boolean result = dashboardService.addItemContent( dashboardUid, type, contentUid );
         
-        ContextUtils.okResponse( response, "Dashboard item added" );
+        if ( !result )
+        {
+            ContextUtils.conflictResponse( response, "Max number of dashboard items reached: " + MAX_ITEMS );
+        }
+        else
+        {
+            ContextUtils.okResponse( response, "Dashboard item added" );
+        }
     }
     
     @RequestMapping( value = "/{dashboardUid}/items/{itemUid}/position/{position}", method = RequestMethod.POST )

=== 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	2013-09-10 07:40:25 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/javascript/dashboard.js	2013-09-12 08:13:03 +0000
@@ -7,6 +7,7 @@
 dhis2.db.currentShareType;
 dhis2.db.currentShareId;
 dhis2.db.currentMaxType = [];
+dhis2.db.maxItems = 40;
 
 // TODO remove position from template
 // TODO support table as link and embedded
@@ -467,6 +468,9 @@
 	    	},
 	    	success: function() {
 	    		dhis2.db.renderDashboard( dhis2.db.current );
+	    	},
+	    	error: function( xhr ) {
+	    		setHeaderDelayMessage( xhr.responseText );
 	    	}
 	    } );
 	}