← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16294: Added paging function for options of an option-set.

 

------------------------------------------------------------
revno: 16294
committer: Tran Chau<tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2014-08-03 14:05:52 +0700
message:
   Added paging function for options of an option-set.
added:
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/option/GetOptionListAction.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionStore.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/DefaultOptionService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/hibernate/HibernateOptionStore.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/struts.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/javascript/optionSet.js
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/option.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-api/src/main/java/org/hisp/dhis/option/OptionService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionService.java	2014-07-29 07:52:47 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionService.java	2014-08-03 07:05:52 +0000
@@ -79,4 +79,6 @@
     Option getOptionByCode( String code );
     
     Option getOptionValueByName( OptionSet optionSet, String name );
+    
+    Collection<Option> getOptionValues( OptionSet optionSet, String option, Integer min, Integer max );
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionStore.java	2014-07-29 07:52:47 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionStore.java	2014-08-03 07:05:52 +0000
@@ -28,6 +28,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.util.Collection;
 import java.util.List;
 
 import org.hisp.dhis.common.GenericIdentifiableObjectStore;
@@ -42,5 +43,7 @@
     List<Option> getOptions( int optionSetId, String key, Integer max  );
    
     Option getOptionValueByName( OptionSet optionSet, String name );
+
+    Collection<Option> getOptionValues( OptionSet optionSet, String option, Integer min, Integer max );
 }
 

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/DefaultOptionService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/DefaultOptionService.java	2014-07-29 07:52:47 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/DefaultOptionService.java	2014-08-03 07:05:52 +0000
@@ -182,4 +182,9 @@
     {
         return i18n( i18nService, optionStore.getOptionValueByName( optionSet, name ) );
     }
+    
+    public Collection<Option> getOptionValues( OptionSet optionSet, String option, Integer min, Integer max )
+    {
+        return i18n( i18nService, optionStore.getOptionValues( optionSet, option, min, max ) );
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/hibernate/HibernateOptionStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/hibernate/HibernateOptionStore.java	2014-07-29 07:52:47 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/hibernate/HibernateOptionStore.java	2014-08-03 07:05:52 +0000
@@ -28,6 +28,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.util.Collection;
 import java.util.List;
 
 import org.hibernate.Query;
@@ -67,18 +68,42 @@
         {
             query.setMaxResults( max );
         }
-        
+
         return query.list();
     }
-    
+
     public Option getOptionValueByName( OptionSet optionSet, String name )
     {
         String hql = "select option from OptionSet as optionset join optionset.options as option where optionset = :optionSet and lower(option.name) = :name";
-        
+
         Query query = getQuery( hql );
         query.setEntity( "optionSet", optionSet );
         query.setString( "name", name );
-        
+
         return (Option) query.uniqueResult();
     }
+
+    @SuppressWarnings( "unchecked" )
+    public Collection<Option> getOptionValues( OptionSet optionSet, String option, Integer min, Integer max )
+    {
+        String hql = "select option from OptionSet as optionset join optionset.options as option where optionset = :optionSet ";
+
+        if ( option != null )
+        {
+            hql += " and lower(option.name) like ('%" + option + "%') ";
+        }
+
+        Query query = getQuery( hql );
+        query.setEntity( "optionSet", optionSet );
+
+        if ( min != null && max != null )
+        {
+            query.setFirstResult( min );
+            query.setMaxResults( max );
+        }
+        
+        hql += " order by index(option)";
+
+        return query.list();
+    }
 }

=== added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/option/GetOptionListAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/option/GetOptionListAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/option/GetOptionListAction.java	2014-08-03 07:05:52 +0000
@@ -0,0 +1,110 @@
+/*
+ * Copyright (c) 2004-2014, 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.
+ */
+
+package org.hisp.dhis.dataadmin.action.option;
+
+import java.util.Collection;
+
+import org.hisp.dhis.option.Option;
+import org.hisp.dhis.option.OptionService;
+import org.hisp.dhis.option.OptionSet;
+import org.hisp.dhis.paging.ActionPagingSupport;
+
+/**
+ * @author Chau Thu Tran
+ *
+ * @version $ GetOptionListAction.java Aug 3, 2014 10:33:16 AM $
+ */
+public class GetOptionListAction
+    extends ActionPagingSupport<Option>
+{
+    // -------------------------------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------------------------------
+
+    private OptionService optionService;
+
+    public void setOptionService( OptionService optionService )
+    {
+        this.optionService = optionService;
+    }
+
+    // -------------------------------------------------------------------------------------------------
+    // Input
+    // -------------------------------------------------------------------------------------------------
+
+    private Integer optionSetId;
+
+    public void setOptionSetId( Integer optionSetId )
+    {
+        this.optionSetId = optionSetId;
+    }
+
+    public Integer getOptionSetId()
+    {
+        return optionSetId;
+    }
+
+    private String key;
+
+    public void setKey( String key )
+    {
+        this.key = key;
+    }
+
+    private OptionSet optionSet;
+
+    public OptionSet getOptionSet()
+    {
+        return optionSet;
+    }
+
+    private Collection<Option> options;
+
+    public Collection<Option> getOptions()
+    {
+        return options;
+    }
+
+    // -------------------------------------------------------------------------------------------------
+    // Action implementation
+    // -------------------------------------------------------------------------------------------------
+
+    @Override
+    public String execute()
+        throws Exception
+    {
+        optionSet = optionService.getOptionSet( optionSetId );
+       
+        this.paging = createPaging( optionSet.getOptions().size() );
+
+        options = optionService.getOptionValues( optionSet, key, paging.getStartPos(), paging.getPageSize() );
+
+        return SUCCESS;
+    }
+}

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/META-INF/dhis/beans.xml	2014-07-31 14:17:58 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/META-INF/dhis/beans.xml	2014-08-03 07:05:52 +0000
@@ -416,4 +416,10 @@
     <property name="optionService" ref="org.hisp.dhis.option.OptionService" />
   </bean>
 
+  <bean id="org.hisp.dhis.dataadmin.action.option.GetOptionListAction"
+    class="org.hisp.dhis.dataadmin.action.option.GetOptionListAction"
+    scope="prototype">
+    <property name="optionService" ref="org.hisp.dhis.option.OptionService" />
+  </bean>
+
 </beans>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/struts.xml	2014-07-31 14:17:58 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/struts.xml	2014-08-03 07:05:52 +0000
@@ -647,7 +647,7 @@
 	<!-- Option -->
 
 	<action name="option"
-		class="org.hisp.dhis.dataadmin.action.option.GetOptionSetAction">
+		class="org.hisp.dhis.dataadmin.action.option.GetOptionListAction">
 		<result name="success" type="velocity">/main.vm</result>
 		<param name="page">/dhis-web-maintenance-dataadmin/option.vm</param>
 		<param name="menu">/dhis-web-maintenance-dataadmin/menu.vm</param>
@@ -706,10 +706,10 @@
 		<param name="anyAuthorities">F_OPTIONSET_PUBLIC_ADD, F_OPTIONSET_PRIVATE_ADD</param>
 	</action>
 
-	<action name="sortOptions"
-		class="org.hisp.dhis.dataadmin.action.option.SortOptionsAction">
+	<action name="getOptionList"
+		class="org.hisp.dhis.dataadmin.action.option.GetOptionListAction">
 		<result name="success" type="redirect">option.action?id=${optionSetId}</result>
-		<param name="anyAuthorities">F_OPTIONSET_PUBLIC_ADD, F_OPTIONSET_PRIVATE_ADD</param>
+		<param name="anyAuthorities">F_OPTIONSET_MANAGEMENT</param>
 	</action>
 	
   </package>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/javascript/optionSet.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/javascript/optionSet.js	2014-07-29 07:52:47 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/javascript/optionSet.js	2014-08-03 07:05:52 +0000
@@ -17,7 +17,7 @@
 }
 
 function showOptionList( context ) {
-  location.href = 'option.action?id=' + context.id;
+  location.href = 'option.action?optionSetId=' + context.id;
 }
 
 // -----------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/option.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/option.vm	2014-07-29 07:52:47 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/option.vm	2014-08-03 07:05:52 +0000
@@ -1,6 +1,4 @@
 
-#sharingDialog()
-
 <script type="text/javascript">
 	jQuery(document).ready(function() {
 	
@@ -31,7 +29,15 @@
 				<col>          
 				<col width="120"> 
 				<tr>
-					<td>#filterDiv( "option" )</td>
+					<td>
+						<form onsubmit="submitFilter()" method="GET" action="option.action" id="filterKeyForm">
+							<input type="text" class="filterInput" placeholder="$i18n.getString('filter_by_name')" name="key" id="key">
+							<input type="hidden" id="optionSetId" name="optionSetId" value="$optionSet.id" />
+							<input type="hidden" value="" name="curKey" id="curKey">
+							<input type="submit" class="filterButton" value="Filter" id="filterButton">
+							<input type="button" class="filterButton" onclick="javascript:setFieldValue('key');byId('filterKeyForm').submit();" value="$i18n.getString('clear')">
+						</form>
+					</td>
 					<td colspan="3" style="text-align:right">
 						<input type="button" value="$i18n.getString( "add_new" )" onclick="window.location.href='showAddOptionForm.action?id=$optionSet.id'" style="width:150px"><br>
 						<input type="button" value="$i18n.getString( "sort_options" )" onclick="window.location.href='sortOptionsForm.action?id=$optionSet.id'" style="width:150px"><br>
@@ -47,7 +53,7 @@
       </tr>
       </thead>
       <tbody id="list">
-      #foreach( $option in $optionSet.options )
+      #foreach( $option in $options )
       <tr id="tr${option.id}">
         <td data-id="$!option.id" data-uid="$!option.uid" data-type="Option" data-name="$encoder.htmlEncode( $!option.displayName )"
           data-can-manage="$security.canManage( $option )"