[icinga-checkins] icinga.org: icinga-web/next: Search in admin user- / group dialog

git at icinga.org git at icinga.org
Tue Apr 2 14:00:57 CEST 2013


Module: icinga-web
Branch: next
Commit: cdadfecff2435049e0e748d5a52847a5b56bc4b9
URL:    https://git.icinga.org/?p=icinga-web.git;a=commit;h=cdadfecff2435049e0e748d5a52847a5b56bc4b9

Author: Marius Hein <marius.hein at netways.de>
Date:   Tue Apr  2 13:25:35 2013 +0200

Search in admin user- / group dialog

Add search text box in user dialog

refs #3909

---

 .../DataProvider/UserProviderAction.class.php      |   16 ++++--
 app/modules/AppKit/lib/js/admin/UserManager.js     |   23 +++++++-
 app/modules/AppKit/models/UserAdminModel.class.php |   56 ++++++++++++++++++-
 .../AppKit/validate/DataProvider/UserProvider.xml  |    6 ++-
 4 files changed, 88 insertions(+), 13 deletions(-)

diff --git a/app/modules/AppKit/actions/DataProvider/UserProviderAction.class.php b/app/modules/AppKit/actions/DataProvider/UserProviderAction.class.php
index 641eae9..c1687f5 100644
--- a/app/modules/AppKit/actions/DataProvider/UserProviderAction.class.php
+++ b/app/modules/AppKit/actions/DataProvider/UserProviderAction.class.php
@@ -98,14 +98,23 @@ class AppKit_DataProvider_UserProviderAction extends AppKitBaseAction {
     }
 
     public function executeRead(AgaviRequestDataHolder $rd) {
+
+        /** @var $useradmin AppKit_UserAdminModel */
         $useradmin = $this->getContext()->getModel('UserAdmin', 'AppKit');
+
         $userId = $rd->getParameter('userId',false);
         $disabled = $rd->getParameter('hideDisabled',false) == "false";
         $start = $rd->getParameter('start',false);
         $limit = $rd->getParameter('limit',false);
         $sort = $rd->getParameter('sort',false);
         $asc = ($rd->getParameter('dir','ASC') == 'ASC');
+        $query = $rd->getParameter('query');
+
+        if ($query) {
+            $useradmin->setQuery($query);
+        }
 
+        $result = null;
         if($sort) {
             if(array_key_exists($sort, self::$sortArray))
                 $sort = self::$sortArray[$sort];
@@ -113,10 +122,6 @@ class AppKit_DataProvider_UserProviderAction extends AppKitBaseAction {
                 $sort = false;
         }
 
-
-
-        $result;
-
         // return a single user when an id is provided
         if ($userId !== false) {
             $user = $useradmin->getUserById($userId);
@@ -130,8 +135,7 @@ class AppKit_DataProvider_UserProviderAction extends AppKitBaseAction {
             $this->setAttribute("user", $result);
 
         } else {    //return list of all users if no id is provided
-            $users;
-
+            $users = null;
             if ($start === false || $limit === false) {
                 $users = $useradmin->getUsersCollection($disabled);
             } else {
diff --git a/app/modules/AppKit/lib/js/admin/UserManager.js b/app/modules/AppKit/lib/js/admin/UserManager.js
index 5af1736..3cd249a 100644
--- a/app/modules/AppKit/lib/js/admin/UserManager.js
+++ b/app/modules/AppKit/lib/js/admin/UserManager.js
@@ -42,7 +42,8 @@ Ext.ns("AppKit.Admin");
                 remoteSort: true,
 
                 baseParams: {
-                    hideDisabled: false
+                    hideDisabled: false,
+                    query: null
                 },
                 proxy: new Ext.data.HttpProxy({
                     api: {
@@ -140,8 +141,24 @@ Ext.ns("AppKit.Admin");
                             Ext.getCmp('progressbar-field').setValue();
                         }
 
-                    }, '->',
-                    {
+                    }, ' ', {
+                            xtype: "textfield",
+                            name: "query",
+                            emptyText: _('Search user'),
+                            enableKeyEvents: true,
+                            validationDelay: 300,
+                            allowBlank: true,
+                            listeners: {
+                                focus: function(field) {
+                                    field.selectText();
+                                },
+                                valid: function(field) {
+                                    var searchVal = field.getValue();
+                                    userGridCmp.getStore().setBaseParam('query', searchVal);
+                                    userGridCmp.getBottomToolbar().doRefresh();
+                                }
+                            }
+                    }, '->', {
                         xtype: 'button',
                         enableToggle: true,
                         text: _('Hide disabled'),
diff --git a/app/modules/AppKit/models/UserAdminModel.class.php b/app/modules/AppKit/models/UserAdminModel.class.php
index c43d2a4..17911bc 100644
--- a/app/modules/AppKit/models/UserAdminModel.class.php
+++ b/app/modules/AppKit/models/UserAdminModel.class.php
@@ -29,13 +29,21 @@
  *
  */
 class AppKit_UserAdminModel extends AppKitBaseModel {
-
     private static $editableAttributes = array(
             'user_name', 'user_lastname', 'user_firstname',
             'user_email', 'user_disabled', 'user_authsrc','user_authkey'
                                          );
 
     /**
+     * Query for users
+     *
+     * Human readable query to restrict users
+     *
+     * @var string
+     */
+    private $query;
+
+    /**
      * Creates a collection of NsmUser objects and returns it
      * @param boolean $disabled
      * @return Doctrine_Collection
@@ -46,11 +54,27 @@ class AppKit_UserAdminModel extends AppKitBaseModel {
     }
 
     /**
+     * Apply user restriction to doctrine query
+     * @param Doctrine_Query $query
+     */
+    private function applyQueryToDoctrineQuery(Doctrine_Query $query) {
+        if ($this->getQuery()) {
+            $queryVal = '%'. $this->getQuery(). '%';
+            $queryParams = array($queryVal, $queryVal, $queryVal, $queryVal);
+            $query->andWhere(
+                '(user_name LIKE ? OR user_firstname LIKE ?'
+                    . ' OR user_lastname LIKE ? OR user_email LIKE ?)',
+                $queryParams
+            );
+        }
+    }
+
+    /**
      * Creates a collection NsmUser objects within the range $start and $limit and optionally
      * sorts it by param $sort
      * @param boolean $disabled
-     * @param numeric $start
-     * @param numeric $limit
+     * @param integer $start
+     * @param integer $limit
      * @param string $sort
      * @param boolean $asc
      *
@@ -71,6 +95,8 @@ class AppKit_UserAdminModel extends AppKitBaseModel {
             $query->andWhere('user_disabled=?', array(0));
         }
 
+        $this->applyQueryToDoctrineQuery($query);
+
         return $query->execute();
     }
 
@@ -102,6 +128,8 @@ class AppKit_UserAdminModel extends AppKitBaseModel {
             $query->andWhere('user_disabled=?', array(0));
         }
 
+        $this->applyQueryToDoctrineQuery($query);
+
         return $query;
     }
 
@@ -266,4 +294,26 @@ class AppKit_UserAdminModel extends AppKitBaseModel {
             throw($e);
         }
     }
+
+    /**
+     * Setter for query
+     * @param string $query
+     */
+    public function setQuery($query)
+    {
+        $this->query = $query;
+    }
+
+    /**
+     * Getter for query
+     * @return string
+     */
+    public function getQuery()
+    {
+        if (strlen($this->query) >= 3) {
+            return $this->query;
+        }
+
+        return null;
+    }
 }
diff --git a/app/modules/AppKit/validate/DataProvider/UserProvider.xml b/app/modules/AppKit/validate/DataProvider/UserProvider.xml
index 32036c5..d87ca08 100644
--- a/app/modules/AppKit/validate/DataProvider/UserProvider.xml
+++ b/app/modules/AppKit/validate/DataProvider/UserProvider.xml
@@ -13,10 +13,14 @@
                     <error>Validation of 'userId' failed</error>
                 </errors>
             </validator>
+
             <validator class="string" name="hideDisabled" required="false">
                 <argument>hideDisabled</argument>
             </validator>
-            
+
+            <validator class="string" name="query" required="false">
+                <argument>query</argument>
+            </validator>
             
             <!--  Paging properties -->
             <validator class="number" name="start" required="false">





More information about the icinga-checkins mailing list