[icinga-checkins] icinga.org: icingaweb2/feature/add-to-dashboard-4537: Dashboard: Introduce user flag widget

git at icinga.org git at icinga.org
Tue Nov 11 15:39:31 CET 2014


Module: icingaweb2
Branch: feature/add-to-dashboard-4537
Commit: 56dd0474645b639f85f05430e1f5cf4928576ecb
URL:    https://git.icinga.org/?p=icingaweb2.git;a=commit;h=56dd0474645b639f85f05430e1f5cf4928576ecb

Author: Marius Hein <marius.hein at netways.de>
Date:   Tue Nov 11 15:38:51 2014 +0100

Dashboard: Introduce user flag widget

Fix: Do not render disabled components.

refs #4537

---

 library/Icinga/Web/Widget/Dashboard.php            |   31 +++++++++++-----
 library/Icinga/Web/Widget/Dashboard/Component.php  |    2 +-
 library/Icinga/Web/Widget/Dashboard/Pane.php       |   10 ++++--
 library/Icinga/Web/Widget/Dashboard/UserWidget.php |   37 ++++++++++++++++++++
 4 files changed, 69 insertions(+), 11 deletions(-)

diff --git a/library/Icinga/Web/Widget/Dashboard.php b/library/Icinga/Web/Widget/Dashboard.php
index 0fdb61d..866dfe3 100644
--- a/library/Icinga/Web/Widget/Dashboard.php
+++ b/library/Icinga/Web/Widget/Dashboard.php
@@ -85,8 +85,7 @@ class Dashboard extends AbstractWidget
      */
     private function loadUserDashboards()
     {
-        $configFile = '/var/lib/icingaweb/' . $this->user->getUsername() . '/dashboard.ini';
-        $config = Config::fromIni($configFile);
+        $config = Config::fromIni($this->getConfigFile());
         if (! count($config)) {
             return false;
         }
@@ -96,6 +95,7 @@ class Dashboard extends AbstractWidget
             if (strpos($key, '.') === false) {
                 $panes[$key] = new Pane($key);
                 $panes[$key]->setTitle($part->title);
+                $panes[$key]->setUserWidget();
 
             } else {
                 list($paneName, $componentName) = explode('.', $key, 2);
@@ -114,15 +114,22 @@ class Dashboard extends AbstractWidget
             } else {
                 continue;
             }
-            $pane->addComponent(
-                new DashboardComponent(
-                    $componentData->title,
-                    $componentData->url,
-                    $pane
-                )
+            $component = new DashboardComponent(
+                $componentData->title,
+                $componentData->url,
+                $pane
             );
+
+            if ((bool) $componentData->get('disabled', false) === true) {
+                $component->setDisabled(true);
+            }
+
+            $component->setUserWidget();
+            $pane->addComponent($component);
         }
+
         $this->mergePanes($panes);
+
         return true;
     }
 
@@ -323,4 +330,12 @@ class Dashboard extends AbstractWidget
     {
         return $this->user;
     }
+
+    public function getConfigFile()
+    {
+        if ($this->user === null) {
+            return '';
+        }
+        return '/var/lib/icingaweb/' . $this->user->getUsername() . '/dashboard.ini';
+    }
 }
diff --git a/library/Icinga/Web/Widget/Dashboard/Component.php b/library/Icinga/Web/Widget/Dashboard/Component.php
index 6edf140..0017ce9 100644
--- a/library/Icinga/Web/Widget/Dashboard/Component.php
+++ b/library/Icinga/Web/Widget/Dashboard/Component.php
@@ -17,7 +17,7 @@ use Icinga\Exception\IcingaException;
  * This is the element displaying a specific view in icinga2web
  *
  */
-class Component extends AbstractWidget
+class Component extends UserWidget
 {
     /**
      * The url of this Component
diff --git a/library/Icinga/Web/Widget/Dashboard/Pane.php b/library/Icinga/Web/Widget/Dashboard/Pane.php
index 3b0e97c..0407341 100644
--- a/library/Icinga/Web/Widget/Dashboard/Pane.php
+++ b/library/Icinga/Web/Widget/Dashboard/Pane.php
@@ -12,7 +12,7 @@ use Icinga\Exception\ConfigurationError;
 /**
  * A pane, displaying different Dashboard components
  */
-class Pane extends AbstractWidget
+class Pane extends UserWidget
 {
     /**
      * The name of this pane, as defined in the ini file
@@ -168,7 +168,13 @@ class Pane extends AbstractWidget
      */
     public function render()
     {
-        return implode("\n", $this->components) . "\n";
+        $components = array_filter(
+            $this->components,
+            function ($e) {
+                return ! $e->getDisabled();
+            }
+        );
+        return implode("\n", $components) . "\n";
     }
 
     /**
diff --git a/library/Icinga/Web/Widget/Dashboard/UserWidget.php b/library/Icinga/Web/Widget/Dashboard/UserWidget.php
new file mode 100644
index 0000000..0b17196
--- /dev/null
+++ b/library/Icinga/Web/Widget/Dashboard/UserWidget.php
@@ -0,0 +1,37 @@
+<?php
+// {{{ICINGA_LICENSE_HEADER}}}
+// {{{ICINGA_LICENSE_HEADER}}}
+
+namespace Icinga\Web\Widget\Dashboard;
+
+use Icinga\Web\Widget\AbstractWidget;
+
+abstract class UserWidget extends AbstractWidget
+{
+    /**
+     * Flag if widget is created by an user
+     *
+     * @var bool
+     */
+    protected $userWidget = false;
+
+    /**
+     * Set the user widget flag
+     *
+     * @param boolean $userWidget
+     */
+    public function setUserWidget($userWidget = true)
+    {
+        $this->userWidget = (bool) $userWidget;
+    }
+
+    /**
+     * Getter for user widget flag
+     *
+     * @return boolean
+     */
+    public function isUserWidget()
+    {
+        return $this->userWidget;
+    }
+}



More information about the icinga-checkins mailing list