← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 306: Work in progress on report table in dashboard

 

------------------------------------------------------------
revno: 306
committer: Lars Helge Oeverland larshelge@xxxxxxxxx
branch nick: trunk
timestamp: Tue 2009-05-19 17:32:14 +0200
message:
  Work in progress on report table in dashboard
added:
  dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/action/RemoveReportTableAction.java
  dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/provider/ReportTableContentProvider.java
  dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/report_table.vm
  dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/AddReportTableToDashboardAction.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentials.java
  dhis-2/dhis-services/dhis-service-user-hibernate/src/main/java/org/hisp/dhis/user/UserCredentialsDeletionHandler.java
  dhis-2/dhis-services/dhis-service-user-hibernate/src/main/resources/org/hisp/dhis/user/hibernate/UserCredentials.hbm.xml
  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/org/hisp/dhis/dashboard/i18n_module.properties
  dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/resources/xwork.xml
  dhis-2/dhis-web/dhis-web-reporting/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties
  dhis-2/dhis-web/dhis-web-reporting/src/main/resources/xwork.xml
  dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/displayTableForm.vm
  dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/table.js
  dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/viewTableForm.vm

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentials.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentials.java	2009-03-06 13:07:11 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentials.java	2009-05-19 15:32:14 +0000
@@ -37,6 +37,7 @@
 import org.hisp.dhis.document.Document;
 import org.hisp.dhis.olap.OlapURL;
 import org.hisp.dhis.report.Report;
+import org.hisp.dhis.reporttable.ReportTable;
 
 /**
  * @author Nguyen Hong Duc
@@ -73,6 +74,8 @@
     private List<OlapURL> dashboardOlapUrls = new ArrayList<OlapURL>();
     
     private List<Document> dashboardDocuments = new ArrayList<Document>();
+    
+    private List<ReportTable> dashboardReportTables = new ArrayList<ReportTable>();
 
     // -------------------------------------------------------------------------
     // Logic
@@ -130,6 +133,19 @@
         }
     }
     
+    public void addReportTable( ReportTable reportTable )
+    {
+        if ( !dashboardReportTables.contains( reportTable ) )
+        {
+            dashboardReportTables.add( 0, reportTable );
+            
+            while ( dashboardReportTables.size() > MAX_DASHBOARD_ELEMENTS )
+            {
+                dashboardReportTables.remove( MAX_DASHBOARD_ELEMENTS );
+            }
+        }
+    }
+    
     // -------------------------------------------------------------------------
     // hashCode and equals
     // -------------------------------------------------------------------------
@@ -256,4 +272,14 @@
     {
         this.dashboardDocuments = dashboardDocuments;
     }
+
+    public List<ReportTable> getDashboardReportTables()
+    {
+        return dashboardReportTables;
+    }
+
+    public void setDashboardReportTables( List<ReportTable> dashboardReportTables )
+    {
+        this.dashboardReportTables = dashboardReportTables;
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-user-hibernate/src/main/java/org/hisp/dhis/user/UserCredentialsDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-user-hibernate/src/main/java/org/hisp/dhis/user/UserCredentialsDeletionHandler.java	2009-03-07 13:10:38 +0000
+++ dhis-2/dhis-services/dhis-service-user-hibernate/src/main/java/org/hisp/dhis/user/UserCredentialsDeletionHandler.java	2009-05-19 15:32:14 +0000
@@ -31,6 +31,7 @@
 import org.hisp.dhis.document.Document;
 import org.hisp.dhis.olap.OlapURL;
 import org.hisp.dhis.report.Report;
+import org.hisp.dhis.reporttable.ReportTable;
 import org.hisp.dhis.system.deletion.DeletionHandler;
 
 /**
@@ -108,6 +109,7 @@
         }
     }
     
+    @Override
     public void deleteDocument( Document document )
     {
         for ( UserCredentials credentials : userStore.getAllUserCredentials() )
@@ -118,4 +120,16 @@
             }
         }
     }
+    
+    @Override
+    public void deleteReportTable( ReportTable reportTable )
+    {
+        for ( UserCredentials credentials : userStore.getAllUserCredentials() )
+        {
+            if ( credentials.getDashboardReportTables().remove( reportTable ) )
+            {
+                userStore.updateUserCredentials( credentials );
+            }                
+        }
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-user-hibernate/src/main/resources/org/hisp/dhis/user/hibernate/UserCredentials.hbm.xml'
--- dhis-2/dhis-services/dhis-service-user-hibernate/src/main/resources/org/hisp/dhis/user/hibernate/UserCredentials.hbm.xml	2009-03-06 13:07:11 +0000
+++ dhis-2/dhis-services/dhis-service-user-hibernate/src/main/resources/org/hisp/dhis/user/hibernate/UserCredentials.hbm.xml	2009-05-19 15:32:14 +0000
@@ -59,5 +59,12 @@
         class="org.hisp.dhis.document.Document"/>
     </list>
     
+    <list name="dashboardReportTables" table="userrole_reporttables">
+      <key column="userid"/>
+      <list-index column="sort_order" base="0"/>
+      <many-to-many column="reporttableid"
+        class="org.hisp.dhis.reporttable.ReportTable"/>
+    </list>
+    
   </class>
 </hibernate-mapping>

=== added file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/action/RemoveReportTableAction.java'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/action/RemoveReportTableAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/action/RemoveReportTableAction.java	2009-05-19 15:32:14 +0000
@@ -0,0 +1,104 @@
+package org.hisp.dhis.dashboard.action;
+
+/*
+ * Copyright (c) 2004-2007, 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.reporttable.ReportTable;
+import org.hisp.dhis.reporttable.ReportTableService;
+import org.hisp.dhis.user.CurrentUserService;
+import org.hisp.dhis.user.User;
+import org.hisp.dhis.user.UserCredentials;
+import org.hisp.dhis.user.UserStore;
+
+import com.opensymphony.xwork.Action;
+
+/**
+ * @author Lars Helge Overland
+ * @version $Id$
+ */
+public class RemoveReportTableAction
+    implements Action
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private CurrentUserService currentUserService;
+
+    public void setCurrentUserService( CurrentUserService currentUserService )
+    {
+        this.currentUserService = currentUserService;
+    }
+
+    private UserStore userStore;
+
+    public void setUserStore( UserStore userStore )
+    {
+        this.userStore = userStore;
+    }
+
+    private ReportTableService reportTableService;
+
+    public void setReportTableService( ReportTableService reportTableService )
+    {
+        this.reportTableService = reportTableService;
+    }
+    
+    // -------------------------------------------------------------------------
+    // Input
+    // -------------------------------------------------------------------------
+
+    private Integer id;
+
+    public void setId( Integer id )
+    {
+        this.id = id;
+    }
+    
+    // -------------------------------------------------------------------------
+    // Action implementation
+    // -------------------------------------------------------------------------
+
+    public String execute()
+    {
+        User user = currentUserService.getCurrentUser();
+        
+        if ( user != null )
+        {
+            UserCredentials credentials = userStore.getUserCredentials( user );
+            
+            ReportTable table = reportTableService.getReportTable( id );
+            
+            if ( credentials.getDashboardReportTables().remove( table ) )
+            {
+                userStore.updateUserCredentials( credentials );
+            }            
+        }
+        
+        return SUCCESS;
+    }
+}

=== added file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/provider/ReportTableContentProvider.java'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/provider/ReportTableContentProvider.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/provider/ReportTableContentProvider.java	2009-05-19 15:32:14 +0000
@@ -0,0 +1,101 @@
+package org.hisp.dhis.dashboard.provider;
+
+/*
+ * Copyright (c) 2004-2007, 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 java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.hisp.dhis.reporttable.ReportTable;
+import org.hisp.dhis.reporttable.comparator.ReportTableComparator;
+import org.hisp.dhis.user.CurrentUserService;
+import org.hisp.dhis.user.User;
+import org.hisp.dhis.user.UserCredentials;
+import org.hisp.dhis.user.UserStore;
+
+/**
+ * @author Lars Helge Overland
+ * @version $Id$
+ */
+public class ReportTableContentProvider
+    implements ContentProvider
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private CurrentUserService currentUserService;
+
+    public void setCurrentUserService( CurrentUserService currentUserService )
+    {
+        this.currentUserService = currentUserService;
+    }
+    
+    private UserStore userStore;
+
+    public void setUserStore( UserStore userStore )
+    {
+        this.userStore = userStore;
+    }
+    
+    private String key;
+    
+    public void setKey( String key )
+    {
+        this.key = key;
+    }
+
+    // -------------------------------------------------------------------------
+    // ContentProvider implementation
+    // -------------------------------------------------------------------------
+
+    // -------------------------------------------------------------------------
+    // ContentProvider implementation
+    // -------------------------------------------------------------------------
+
+    public Map<String, Object> provide()
+    {
+        Map<String, Object> content = new HashMap<String, Object>();
+
+        User user = currentUserService.getCurrentUser();
+
+        if ( user != null )
+        {
+            UserCredentials credentials = userStore.getUserCredentials( user );
+            
+            List<ReportTable> reportTables = credentials.getDashboardReportTables();
+            
+            Collections.sort( reportTables, new ReportTableComparator() );
+            
+            content.put( key, reportTables );
+        }
+        
+        return content;
+    }
+}

=== 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	2009-03-07 13:10:38 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/resources/META-INF/dhis/beans.xml	2009-05-19 15:32:14 +0000
@@ -6,12 +6,6 @@
 
   <!-- Content providers -->
   
-  <bean id="rssHealthContentProvider" 
-    class="org.hisp.dhis.dashboard.provider.RssContentProvider">
-    <property name="url" value="http://health.yahoo.com/news/rss/health"/>
-    <property name="key" value="healthItems"/>
-  </bean>
-  
   <bean id="reportContentProvider" 
     class="org.hisp.dhis.dashboard.provider.ReportContentProvider">
     <property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService"/>
@@ -34,6 +28,13 @@
     <property name="key" value="dataMartExports"/>
   </bean>
   
+  <bean id="reportTableContentProvider"
+    class="org.hisp.dhis.dashboard.provider.ReportTableContentProvider">
+    <property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService"/>
+    <property name="userStore" ref="org.hisp.dhis.user.UserStore"/>
+    <property name="key" value="reportTables"/>
+  </bean>
+    
   <bean id="olapUrlContentProvider"
     class="org.hisp.dhis.dashboard.provider.OlapUrlContentProvider">
     <property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService"/>
@@ -41,6 +42,12 @@
     <property name="key" value="olapUrls"/>
   </bean>
     
+  <bean id="rssHealthContentProvider" 
+    class="org.hisp.dhis.dashboard.provider.RssContentProvider">
+    <property name="url" value="http://health.yahoo.com/news/rss/health"/>
+    <property name="key" value="healthItems"/>
+  </bean>
+  
   <!-- Manager -->
   
   <bean id="org.hisp.dhis.dashboard.manager.DashboardManager" 
@@ -61,6 +68,10 @@
           <ref local="dataMartExportContentProvider"/>
         </entry>
         <entry>
+          <key><value>report_table</value></key>
+          <ref local="reportTableContentProvider"/>
+        </entry>
+        <entry>
           <key><value>olap_url</value></key>
           <ref local="olapUrlContentProvider"/>
         </entry>
@@ -131,4 +142,12 @@
     <property name="documentService" ref="org.hisp.dhis.document.DocumentService"/>
   </bean>
   
+  <bean id="org.hisp.dhis.dashboard.action.RemoveReportTableAction"
+    class="org.hisp.dhis.dashboard.action.RemoveReportTableAction"
+    scope="prototype">
+    <property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService"/>
+    <property name="userStore" ref="org.hisp.dhis.user.UserStore"/>
+    <property name="reportTableService" ref="org.hisp.dhis.reporttable.ReportTableService"/>
+  </bean>
+  
 </beans>

=== modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/resources/org/hisp/dhis/dashboard/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/resources/org/hisp/dhis/dashboard/i18n_module.properties	2009-03-06 12:31:27 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/resources/org/hisp/dhis/dashboard/i18n_module.properties	2009-05-19 15:32:14 +0000
@@ -10,6 +10,7 @@
 report= Reports
 document= Documents
 data_mart_export= Data mart exports
+report_table= Report tables
 olap_url= OLAP URLs
 
 this_is_a_link_area = This is a link area

=== modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/resources/xwork.xml'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/resources/xwork.xml	2009-05-11 13:32:24 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/resources/xwork.xml	2009-05-19 15:32:14 +0000
@@ -46,5 +46,9 @@
       <result name="success" type="redirect">index.action</result>
     </action>
     
+    <action name="removeReportTable" class="org.hisp.dhis.dashboard.action.RemoveReportTableAction">
+      <result name="success" type="redirect">index.action</result>
+    </action>
+    
   </package>
 </xwork>

=== added file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/report_table.vm'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/report_table.vm	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/report_table.vm	2009-05-19 15:32:14 +0000
@@ -0,0 +1,17 @@
+
+<table class="contentProviderTable">
+    <tr>
+        <th colspan="2">$i18n.getString( "data_mart_export" )</th>
+    </tr>
+    #foreach ( $table in $reportTables )
+    <tr>
+        <td>
+            <a href="../dhis-web-reporting/getTableData.action?id=${table.id}" target="_blank">$table.name</a>
+        </td>       
+        <td style="width:16px">
+            <a href="javascript:window.location.href='removeReportTable.action?id=$table.id'" title="$i18n.getString( 'remove' )">
+            <img src="../images/close.png" alt="$i18n.getString( 'remove' )"></a>
+        </td>
+    </tr>
+    #end
+</table>
\ No newline at end of file

=== added file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/AddReportTableToDashboardAction.java'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/AddReportTableToDashboardAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/AddReportTableToDashboardAction.java	2009-05-19 15:32:14 +0000
@@ -0,0 +1,113 @@
+package org.hisp.dhis.reporting.tablecreator.action;
+
+/*
+ * Copyright (c) 2004-2007, 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.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hisp.dhis.reporttable.ReportTable;
+import org.hisp.dhis.reporttable.ReportTableService;
+import org.hisp.dhis.user.CurrentUserService;
+import org.hisp.dhis.user.User;
+import org.hisp.dhis.user.UserCredentials;
+import org.hisp.dhis.user.UserStore;
+
+import com.opensymphony.xwork.Action;
+
+/**
+ * @author Lars Helge Overland
+ * @version $Id$
+ */
+public class AddReportTableToDashboardAction
+    implements Action
+{
+    private static final Log log = LogFactory.getLog( AddReportTableToDashboardAction.class );
+    
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private CurrentUserService currentUserService;
+
+    public void setCurrentUserService( CurrentUserService currentUserService )
+    {
+        this.currentUserService = currentUserService;
+    }
+
+    private UserStore userStore;
+
+    public void setUserStore( UserStore userStore )
+    {
+        this.userStore = userStore;
+    }
+
+    private ReportTableService reportTableService;
+
+    public void setReportTableService( ReportTableService reportTableService )
+    {
+        this.reportTableService = reportTableService;
+    }
+
+    // -------------------------------------------------------------------------
+    // Input
+    // -------------------------------------------------------------------------
+
+    private Integer id;
+
+    public void setId( Integer id )
+    {
+        this.id = id;
+    }
+
+    // -------------------------------------------------------------------------
+    // Action implementation
+    // -------------------------------------------------------------------------
+
+    public String execute()
+    {
+        User user = currentUserService.getCurrentUser();
+        
+        if ( user != null )
+        {        
+            UserCredentials credentials = userStore.getUserCredentials( user );
+            
+            ReportTable reportTable = reportTableService.getReportTable( id );
+            
+            credentials.addReportTable( reportTable );
+            
+            userStore.updateUserCredentials( credentials );
+            
+            log.info( "Added report table '" + reportTable.getName() + "' to dashboard for user '" + credentials.getUsername() + "'" );
+        }
+        else
+        {
+            log.warn( "Could not add report to dashboard, no current user" );
+        }
+        
+        return SUCCESS;
+    }
+}

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/resources/META-INF/dhis/beans.xml	2009-05-18 20:04:49 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/resources/META-INF/dhis/beans.xml	2009-05-19 15:32:14 +0000
@@ -287,6 +287,17 @@
       ref="org.hisp.dhis.reporttable.ReportTableService"/>
   </bean>
   
+  <bean id="org.hisp.dhis.reporting.tablecreator.action.AddReportTableToDashboardAction"
+    class="org.hisp.dhis.reporting.tablecreator.action.AddReportTableToDashboardAction"
+    scope="prototype">
+    <property name="currentUserService"
+      ref="org.hisp.dhis.user.CurrentUserService"/>
+    <property name="userStore"
+      ref="org.hisp.dhis.user.UserStore"/>
+    <property name="reportTableService"
+      ref="org.hisp.dhis.reporttable.ReportTableService"/>
+  </bean>
+  
   <!-- ReportViewer -->
   
   <bean id="org.hisp.dhis.reporting.reportviewer.action.AddReportAction"

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties	2009-05-19 10:46:43 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties	2009-05-19 15:32:14 +0000
@@ -252,3 +252,4 @@
 move = Move
 column = Column
 click_and_drag = Click and drag
+confirm_add_report_table_to_dashboard = Are you sure you want to add this report table to dashboard?

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/resources/xwork.xml'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/resources/xwork.xml	2009-05-18 20:04:49 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/resources/xwork.xml	2009-05-19 15:32:14 +0000
@@ -245,6 +245,7 @@
     </action>
     
     <action name="getTableData" class="org.hisp.dhis.reporting.tablecreator.action.GetTableDataAction">
+      <result name="blank" type="velocity">/dhis-web-reporting/responseReportTableData.vm</result>
       <result name="success" type="velocity">/main.vm</result>
       <param name="page">/dhis-web-reporting/responseReportTableData.vm</param>
       <param name="menu">/dhis-web-reporting/menu.vm</param>
@@ -261,6 +262,11 @@
       <param name="onExceptionReturn">plainTextError</param>
     </action>
     
+    <action name="addReportTableToDashboard" class="org.hisp.dhis.reporting.tablecreator.action.AddReportTableToDashboardAction">
+      <result name="success" type="velocity-xml">/dhis-web-reporting/responseSuccess.vm</result>
+      <param name="onExceptionReturn">plainTextError</param>
+    </action>
+    
     <!-- PivotTable -->
     
     <action name="displayPivotTableForm" class="org.hisp.dhis.reporting.action.NoAction">

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/displayTableForm.vm'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/displayTableForm.vm	2009-05-19 10:46:43 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/displayTableForm.vm	2009-05-19 15:32:14 +0000
@@ -24,7 +24,7 @@
 	#foreach( $column in $columns )
 	<tr>
 		<td style="width:400px"><input type="text" id="$!encoder.htmlEncode( $column.name )" value="$!column.header" style="width:400px"/></td>
-		<td style="width:55px"><input type="checkbox" #if ( !$column.hidden )checked="checked"#end></td>
+		<td style="width:55px;text-align:center"><input type="checkbox" #if ( !$column.hidden )checked="checked"#end></td>
 		<td style="width:90px; color:#808080">$i18n.getString( "click_and_drag" )</td>
 	</tr>
 	#end

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/table.js'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/table.js	2009-05-18 20:04:49 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/table.js	2009-05-19 15:32:14 +0000
@@ -290,6 +290,21 @@
 }
 
 // -----------------------------------------------------------------------------
+// Dashboard
+// -----------------------------------------------------------------------------
+
+function addReportTableToDashboard( id )
+{
+    var dialog = window.confirm( i18n_confirm_add_report_table_to_dashboard );
+    
+    if ( dialog )
+    {
+        var request = new Request(); 
+        request.send( "addReportTableToDashboard.action?id=" + id );
+    }
+}
+
+// -----------------------------------------------------------------------------
 // Display
 // -----------------------------------------------------------------------------
 

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/viewTableForm.vm'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/viewTableForm.vm	2009-05-18 20:04:49 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/viewTableForm.vm	2009-05-19 15:32:14 +0000
@@ -15,8 +15,9 @@
                 <col width="20">
                 <col width="20">
                 <col width="20">
+                <col width="20">
 		        <tr>
-                    <td colspan="9" style="text-align:right">
+                    <td colspan="10" style="text-align:right">
                     	<input type="button" value="$i18n.getString( 'add_indicator_reporttable' )" style="width:250px" onclick="window.location.href='displayAddTableForm.action?mode=indicators'"><br>
                     	<input type="button" value="$i18n.getString( 'add_dataelement_reporttable' )" style="width:250px" onclick="window.location.href='displayAddTableForm.action?mode=dataelements'"><br>
                         <input type="button" value="$i18n.getString( 'add_dataelement_category_reporttable' )" style="width:250px" onclick="window.location.href='displayAddTableForm.action?mode=dataelements&category=true'"><br>
@@ -25,7 +26,7 @@
                 </tr>
 				<tr>
 					<th>$i18n.getString( "name" )</th>
-					<th colspan="8">$i18n.getString( "operations" )</th>
+					<th colspan="9">$i18n.getString( "operations" )</th>
 				</tr>
 				#set( $mark = false )
 				#foreach ( $table in $tables )
@@ -37,6 +38,7 @@
                     <td style="text-align:center"#alternate( $mark )><a href="generateTableDataWorkbook.action?id=$table.id" title="$i18n.getString( "export_to_excel" )"><img src="../images/excel.png" alt="$i18n.getString( "export_to_excel" )"></a></td>
                     <td style="text-align:center"#alternate( $mark )><a href="getTableData.action?id=$table.id" title="$i18n.getString( "export_to_html" )"><img src="../images/html.png" alt="$i18n.getString( "export_to_html" )"></a></td>
                     <td style="text-align:center"#alternate( $mark )><a href="getTableDataExport.action?id=$table.id&exportFormat=CSV" title="$i18n.getString( "export_to_csv" )"><img src="../images/csv.png" alt="$i18n.getString( "export_to_csv" )"></a></td>
+                    <td style="text-align:center"#alternate( $mark )><a href="javascript:addReportTableToDashboard( '$table.id' )" title="$i18n.getString( 'add_to_dashboard' )"><img src="../images/add_to_dashboard.png" alt="$i18n.getString( 'add_to_dashboard' )"></a></td>
                     <td style="text-align:center"#alternate( $mark )><a href="javascript:removeTable( $table.id, '$encoder.jsEncode( $table.name )' )" title="$i18n.getString( "remove" )"><img src="../images/delete.png" alt="$i18n.getString( "remove" )"></a></td>
 					<td style="text-align:center"#alternate( $mark )><a href="javascript:showTableDetails( $table.id )" title="$i18n.getString( "show_details" )"><img src="../images/information.png" alt="$i18n.getString( "show_details" )"></a></td>
 				</tr>
@@ -70,6 +72,7 @@
 </table>
 
 <script type="text/javascript">
+	var i18n_confirm_add_report_table_to_dashboard = '$encoder.jsEscape( $i18n.getString( "confirm_add_report_table_to_dashboard" ) , "'")';
     var i18n_confirm_delete = '$encoder.jsEscape( $i18n.getString( "confirm_delete_table" ) , "'")';
     var i18n_yes = '$encoder.jsEscape( $i18n.getString( "yes" ) , "'")';
     var i18n_no = '$encoder.jsEscape( $i18n.getString( "no" ) , "'")';



--
Trunk
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.