You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@continuum.apache.org by ct...@apache.org on 2009/04/02 05:26:02 UTC

svn commit: r761152 - in /continuum/trunk/continuum-webapp/src/main: java/org/apache/maven/continuum/web/action/ProjectGroupAction.java webapp/WEB-INF/jsp/projectGroupMembers.jsp

Author: ctan
Date: Thu Apr  2 03:26:01 2009
New Revision: 761152

URL: http://svn.apache.org/viewvc?rev=761152&view=rev
Log:
[CONTINUUM-2156] fix sorting of username in Members tab 

merge -r 761150:761151 from 1.3.x branch



Modified:
    continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/ProjectGroupAction.java
    continuum/trunk/continuum-webapp/src/main/webapp/WEB-INF/jsp/projectGroupMembers.jsp

Modified: continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/ProjectGroupAction.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/ProjectGroupAction.java?rev=761152&r1=761151&r2=761152&view=diff
==============================================================================
--- continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/ProjectGroupAction.java (original)
+++ continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/ProjectGroupAction.java Thu Apr  2 03:26:01 2009
@@ -22,12 +22,14 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.commons.collections.ComparatorUtils;
 import org.apache.continuum.buildmanager.BuildManagerException;
 import org.apache.continuum.buildmanager.BuildsManager;
 import org.apache.continuum.model.project.ProjectScmRoot;
@@ -113,6 +115,9 @@
     private String filterProperty;
 
     private String filterKey;
+    
+    //Default order is by username
+    private String sorterProperty = "username";
 
     private boolean ascending = true;
 
@@ -700,9 +705,13 @@
             logger.error( "Can't get the users list", e );
         }
 
-        if ( !StringUtils.isEmpty( filterKey ) )
+        if ( StringUtils.isNotBlank( filterKey ) )
         {
-            users = findUsers( users, filterProperty, filterKey, ascending );
+            users = findUsers( users, filterProperty, filterKey );
+        }
+        if ( StringUtils.isNotBlank( sorterProperty ) )
+        {
+            sortUsers( users, sorterProperty, ascending );
         }
 
         projectGroupUsers = new ArrayList();
@@ -747,7 +756,7 @@
         }
     }
 
-    private List<User> findUsers( List<User> users, String searchProperty, String searchKey, boolean orderAscending )
+    private List<User> findUsers( List<User> users, String searchProperty, String searchKey)
     {
         List<User> userList = new ArrayList<User>();
         for ( User user : users )
@@ -789,6 +798,37 @@
 
         return userList;
     }
+    
+    private void sortUsers( List<User> userList, final String sorterProperty, final boolean orderAscending )
+    {
+        Collections.sort( userList, new Comparator<User>()
+        {
+            public int compare( User o1, User o2 )
+            {
+                String value1, value2;
+                if ( "fullName".equals( sorterProperty ) )
+                {
+                    value1 = o1.getFullName();
+                    value2 = o2.getFullName();
+                }
+                else if ( "email".equals( sorterProperty ) )
+                {
+                    value1 = o1.getEmail();
+                    value2 = o2.getEmail();
+                }
+                else
+                {
+                    value1 = o1.getUsername();
+                    value2 = o2.getUsername();
+                }
+                if ( orderAscending )
+                {
+                    return ComparatorUtils.nullLowComparator( null ).compare( value1, value2 );
+                }
+                return ComparatorUtils.nullLowComparator( null ).compare( value2, value1 );
+            }
+        } );
+    }
 
     public int getProjectGroupId()
     {
@@ -1047,4 +1087,14 @@
             return false;
         }
     }
+    
+    public String getSorterProperty()
+    {
+        return sorterProperty;
+    }
+
+    public void setSorterProperty( String sorterProperty )
+    {
+        this.sorterProperty = sorterProperty;
+    }
 }

Modified: continuum/trunk/continuum-webapp/src/main/webapp/WEB-INF/jsp/projectGroupMembers.jsp
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-webapp/src/main/webapp/WEB-INF/jsp/projectGroupMembers.jsp?rev=761152&r1=761151&r2=761152&view=diff
==============================================================================
--- continuum/trunk/continuum-webapp/src/main/webapp/WEB-INF/jsp/projectGroupMembers.jsp (original)
+++ continuum/trunk/continuum-webapp/src/main/webapp/WEB-INF/jsp/projectGroupMembers.jsp Thu Apr  2 03:26:01 2009
@@ -149,10 +149,11 @@
             <s:else>
               <s:a href="javascript:document.forms['sortlist'].submit()"><img src="<s:url value='/images/icon_sortup.gif' includeParams="none"/>" title="<s:text name='sort.ascending'/>" border="0"></s:a> <s:text name="user.username.label"/>
             </s:else>
-            <s:hidden name="ascending">${!ascending}</s:hidden>
+            <s:hidden name="ascending" value="%{!ascending}"/>
             <s:hidden name="projectGroupId" />
-            <s:hidden name="filterProperty" />
-            <s:hidden name="filterKey" />
+            <s:hidden name="sorterProperty" value="username"/>
+            <s:hidden name="filterKey" value="%{filterKey}"/>
+            <s:hidden name="filterProperty" value="%{filterProperty}"/>
           </s:form>
         </th>   
         <th><s:text name="user.fullName.label"/></th>