[icinga-checkins] icinga.org: icingaweb2/master: FilterEditor: add compact search render support

git at icinga.org git at icinga.org
Sun Nov 16 00:38:42 CET 2014


Module: icingaweb2
Branch: master
Commit: ac483a0fe61e7ab6e8ab8ce05c0bc815964e7dbe
URL:    https://git.icinga.org/?p=icingaweb2.git;a=commit;h=ac483a0fe61e7ab6e8ab8ce05c0bc815964e7dbe

Author: Thomas Gelf <thomas at gelf.net>
Date:   Sat Nov 15 23:11:55 2014 +0100

FilterEditor: add compact search render support

We show the search box and a filter preview while not modifying the
filter

---

 library/Icinga/Web/Widget/FilterEditor.php |   38 ++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/library/Icinga/Web/Widget/FilterEditor.php b/library/Icinga/Web/Widget/FilterEditor.php
index bc82f89..7f86a9d 100644
--- a/library/Icinga/Web/Widget/FilterEditor.php
+++ b/library/Icinga/Web/Widget/FilterEditor.php
@@ -284,8 +284,38 @@ class FilterEditor extends AbstractWidget
         }
     }
 
+    public function renderSearch()
+    {
+        $html = ' <form method="post" class="inline" action="'
+              . $this->url()
+              . '"><input type="text" name="q" style="width: 8em" class="search" value="" placeholder="'
+              . t('Search...')
+              . '" /></form>';
+
+        if  ($this->filter->isEmpty()) {
+            $title = t('Filter this list');
+        } else {
+            $title = t('Modify this filter');
+            if (! $this->filter->isEmpty()) {
+                $title .= ': ' . $this->filter;
+            }
+        }
+        return $html
+            . '<a href="'
+            . $this->url()->with('modifyFilter', true)
+            . '" title="'
+            . $title
+            . '">'
+            . '<i class="icon-filter"></i>'
+            . '</a>';
+    }
+
     public function render()
     {
+        if (! $this->url()->getParam('modifyFilter')) {
+            return $this->renderSearch() . $this->shorten($this->filter, 50);
+        }
+
         return '<h3>'
               . t('Modify this filter')
               . '</h3>'
@@ -298,6 +328,14 @@ class FilterEditor extends AbstractWidget
               . '</form>';
     }
 
+    protected function shorten($string, $length)
+    {
+        if (strlen($string) > $length) {
+            return substr($string, 0, $length) . '...';
+        }
+        return $string;
+    }
+
     public function __toString()
     {
         try {



More information about the icinga-checkins mailing list