[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: f9d409c4d78a7cb7edf3f371a319fb044faeaf78
URL:    https://git.icinga.org/?p=icinga-web.git;a=commit;h=f9d409c4d78a7cb7edf3f371a319fb044faeaf78

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

Search in admin user- / group dialog

Add search text box for group dialog to simply
lookup for specific groups.

fixes #3909

---

 .../DataProvider/GroupProviderAction.class.php     |    8 +++
 app/modules/AppKit/lib/js/admin/RoleManager.js     |    3 +-
 app/modules/AppKit/lib/js/admin/UserManager.js     |    4 +-
 .../lib/js/admin/components/RoleListingGrid.js     |   20 ++++++++-
 app/modules/AppKit/models/RoleAdminModel.class.php |   48 ++++++++++++++++++--
 .../AppKit/validate/DataProvider/GroupProvider.xml |    6 ++-
 6 files changed, 80 insertions(+), 9 deletions(-)

diff --git a/app/modules/AppKit/actions/DataProvider/GroupProviderAction.class.php b/app/modules/AppKit/actions/DataProvider/GroupProviderAction.class.php
index 6aeaca6..a03047c 100644
--- a/app/modules/AppKit/actions/DataProvider/GroupProviderAction.class.php
+++ b/app/modules/AppKit/actions/DataProvider/GroupProviderAction.class.php
@@ -104,6 +104,8 @@ class AppKit_DataProvider_GroupProviderAction extends AppKitBaseAction {
     }
     
     public function executeRead(AgaviRequestDataHolder $rd) {
+
+        /** @var $roleadmin AppKit_RoleAdminModel */
         $roleadmin = $this->getContext()->getModel('RoleAdmin', 'AppKit');
         $groupId = $rd->getParameter('groupId',false);
         $disabled = $rd->getParameter('hideDisabled',false) == "false";
@@ -113,6 +115,12 @@ class AppKit_DataProvider_GroupProviderAction extends AppKitBaseAction {
         $asc = ($rd->getParameter('dir','ASC') == 'ASC');
         $oldBehaviour = $rd->getParameter('oldBehaviour', false);
         $user = $this->getContext()->getUser();
+        $query = $rd->getParameter('query');
+
+        if ($query) {
+            $roleadmin->setQuery($query);
+        }
+
         $groups = null;
         
         // Return roles the user belongs to
diff --git a/app/modules/AppKit/lib/js/admin/RoleManager.js b/app/modules/AppKit/lib/js/admin/RoleManager.js
index a09264c..a80ba83 100644
--- a/app/modules/AppKit/lib/js/admin/RoleManager.js
+++ b/app/modules/AppKit/lib/js/admin/RoleManager.js
@@ -36,7 +36,8 @@ AppKit.Admin.RoleManager = Ext.extend(Ext.Container, {
 
             baseParams: {
                 hideDisabled: false,
-        oldBehaviour : 0
+                oldBehaviour : 0,
+                query: ''
             },
             proxy: new Ext.data.HttpProxy({
                 api: {
diff --git a/app/modules/AppKit/lib/js/admin/UserManager.js b/app/modules/AppKit/lib/js/admin/UserManager.js
index 3cd249a..6ef1680 100644
--- a/app/modules/AppKit/lib/js/admin/UserManager.js
+++ b/app/modules/AppKit/lib/js/admin/UserManager.js
@@ -43,7 +43,7 @@ Ext.ns("AppKit.Admin");
 
                 baseParams: {
                     hideDisabled: false,
-                    query: null
+                    query: ''
                 },
                 proxy: new Ext.data.HttpProxy({
                     api: {
@@ -144,7 +144,7 @@ Ext.ns("AppKit.Admin");
                     }, ' ', {
                             xtype: "textfield",
                             name: "query",
-                            emptyText: _('Search user'),
+                            emptyText: _('Type to search'),
                             enableKeyEvents: true,
                             validationDelay: 300,
                             allowBlank: true,
diff --git a/app/modules/AppKit/lib/js/admin/components/RoleListingGrid.js b/app/modules/AppKit/lib/js/admin/components/RoleListingGrid.js
index dbb4f5d..316a341 100644
--- a/app/modules/AppKit/lib/js/admin/components/RoleListingGrid.js
+++ b/app/modules/AppKit/lib/js/admin/components/RoleListingGrid.js
@@ -125,7 +125,25 @@ AppKit.Admin.Components.RoleListingGrid = Ext.extend(Ext.grid.GridPanel,{
                 Ext.getCmp('progressbar-field').setValue();
             }
 
-        },'->',{
+        }, ' ', {
+            xtype: "textfield",
+            name: "query",
+            emptyText: _('Type to search'),
+            enableKeyEvents: true,
+            validationDelay: 300,
+            allowBlank: true,
+            listeners: {
+                focus: function(field) {
+                    field.selectText();
+                },
+                valid: function(field) {
+                    var searchVal = field.getValue();
+                    var store = field.ownerCt.ownerCt.store;
+                    store.setBaseParam('query', searchVal);
+                    store.reload();
+                }
+            }
+        }, '->',{
             xtype:'button',
             enableToggle:true,
             text: _('Hide disabled'),
diff --git a/app/modules/AppKit/models/RoleAdminModel.class.php b/app/modules/AppKit/models/RoleAdminModel.class.php
index 71a09bf..4269ec0 100644
--- a/app/modules/AppKit/models/RoleAdminModel.class.php
+++ b/app/modules/AppKit/models/RoleAdminModel.class.php
@@ -34,8 +34,22 @@ class AppKit_RoleAdminModel extends AppKitBaseModel {
                                          );
 
     /**
-     *
-     * @param boolean $disabled
+     * Human query to restrict groups
+     * @var string
+     */
+    private $query;
+
+    private function applyQueryToDoctrineQuery(Doctrine_Query $query) {
+        if ($this->getQuery()) {
+            $searchQuery = '%'. $this->getQuery(). '%';
+            $searchParams = array($searchQuery, $searchQuery);
+            $query->andWhere('(role_name LIKE ? OR role_description LIKE ?)', $searchParams);
+        }
+    }
+
+    /**
+     * Returns query for roles
+     * @param bool|int $disabled
      * @return Doctrine_Query
      * @author Marius Hein
      */
@@ -48,6 +62,8 @@ class AppKit_RoleAdminModel extends AppKitBaseModel {
             $roles->andWhere('role_disabled = 0');
         }
 
+        $this->applyQueryToDoctrineQuery($roles);
+
         return $roles;
     }
 
@@ -66,8 +82,8 @@ class AppKit_RoleAdminModel extends AppKitBaseModel {
      * Creates a collection of NsmRole 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
      * @param boolean $own
@@ -94,6 +110,8 @@ class AppKit_RoleAdminModel extends AppKitBaseModel {
             $query->innerJoin('r.NsmUser u WITH user_id=?', $this->getContext()->getUser()->getNsmUser()->user_id);
         }
 
+        $this->applyQueryToDoctrineQuery($query);
+
         return $query->execute();
     }
 
@@ -208,4 +226,26 @@ class AppKit_RoleAdminModel extends AppKitBaseModel {
             $child->save();
         }
     }
+
+    /**
+     * Setter for a group query
+     * @param string $query
+     */
+    public function setQuery($query)
+    {
+        $this->query = $query;
+    }
+
+    /**
+     * Getter for group query
+     * @return string
+     */
+    public function getQuery()
+    {
+        if (strlen($this->query) >= 3) {
+            return $this->query;
+        }
+
+        return null;
+    }
 }
diff --git a/app/modules/AppKit/validate/DataProvider/GroupProvider.xml b/app/modules/AppKit/validate/DataProvider/GroupProvider.xml
index 9e3233f..e1ed92b 100644
--- a/app/modules/AppKit/validate/DataProvider/GroupProvider.xml
+++ b/app/modules/AppKit/validate/DataProvider/GroupProvider.xml
@@ -17,7 +17,11 @@
             <validator class="string" name="hideDisabled" required="false">
                 <argument>hideDisabled</argument>
             </validator>
-            
+
+            <validator class="string" name="query" required="false">
+                <argument>query</argument>
+            </validator>
+
             <validator class="string" name="oldBehaviour" required="false">
                 <argument>oldBehaviour</argument>
             </validator>





More information about the icinga-checkins mailing list