← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3718: implemented filtering for user/usergroup (ajax)

 

------------------------------------------------------------
revno: 3718
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2011-05-24 09:52:35 +0200
message:
  implemented filtering for user/usergroup (ajax)
modified:
  dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetUserGroupsAction.java
  dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetUsersAction.java


--
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/java/org/hisp/dhis/commons/action/GetUserGroupsAction.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetUserGroupsAction.java	2011-05-23 13:05:25 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetUserGroupsAction.java	2011-05-24 07:52:35 +0000
@@ -30,8 +30,10 @@
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.ListIterator;
 
 import org.hisp.dhis.paging.ActionPagingSupport;
+import org.hisp.dhis.user.User;
 import org.hisp.dhis.user.UserGroup;
 import org.hisp.dhis.user.UserGroupService;
 import org.hisp.dhis.user.comparator.UserGroupComparator;
@@ -57,6 +59,13 @@
     // Input & Output
     // -------------------------------------------------------------------------
 
+    private String key;
+
+    public void setKey( String key )
+    {
+        this.key = key;
+    }
+
     private List<UserGroup> userGroups;
 
     public List<UserGroup> getUserGroups()
@@ -67,13 +76,18 @@
     // -------------------------------------------------------------------------
     // Action Implementation
     // -------------------------------------------------------------------------
-    
+
     @Override
     public String execute()
         throws Exception
     {
         userGroups = new ArrayList<UserGroup>( userGroupService.getAllUserGroups() );
 
+        if ( key != null )
+        {
+            filterByKey( key, true );
+        }
+
         Collections.sort( userGroups, new UserGroupComparator() );
 
         if ( usePaging )
@@ -85,4 +99,25 @@
 
         return SUCCESS;
     }
+
+    private void filterByKey( String key, boolean ignoreCase )
+    {
+        ListIterator<UserGroup> iterator = userGroups.listIterator();
+
+        if ( ignoreCase )
+        {
+            key = key.toLowerCase();
+        }
+
+        while ( iterator.hasNext() )
+        {
+            UserGroup userGroup = iterator.next();
+            String name = ignoreCase ? userGroup.getName().toLowerCase() : userGroup.getName();
+
+            if ( name.indexOf( key ) == -1 )
+            {
+                iterator.remove();
+            }
+        }
+    }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetUsersAction.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetUsersAction.java	2011-05-23 13:05:25 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetUsersAction.java	2011-05-24 07:52:35 +0000
@@ -31,6 +31,7 @@
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
+import java.util.ListIterator;
 
 import org.hisp.dhis.paging.ActionPagingSupport;
 import org.hisp.dhis.user.User;
@@ -90,7 +91,7 @@
     // -------------------------------------------------------------------------
     // Action Implementation
     // -------------------------------------------------------------------------
-    
+
     @Override
     public String execute()
         throws Exception
@@ -105,6 +106,11 @@
             }
         }
 
+        if ( key != null )
+        {
+            filterByKey( key, true );
+        }
+
         Collections.sort( users, new UserComparator() );
 
         if ( usePaging )
@@ -116,4 +122,25 @@
 
         return SUCCESS;
     }
+
+    private void filterByKey( String key, boolean ignoreCase )
+    {
+        ListIterator<User> iterator = users.listIterator();
+
+        if ( ignoreCase )
+        {
+            key = key.toLowerCase();
+        }
+
+        while ( iterator.hasNext() )
+        {
+            User user = iterator.next();
+            String name = ignoreCase ? user.getName().toLowerCase() : user.getName();
+
+            if ( name.indexOf( key ) == -1 )
+            {
+                iterator.remove();
+            }
+        }
+    }
 }