[icinga-checkins] icinga.org: icingaweb2/feature/add-to-dashboard-4537: Dashboard/Component: Add remove link

git at icinga.org git at icinga.org
Tue Nov 11 16:35:58 CET 2014


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

Author: Marius Hein <marius.hein at netways.de>
Date:   Tue Nov 11 16:35:35 2014 +0100

Dashboard/Component: Add remove link

refs #4537

---

 application/controllers/DashboardController.php   |    6 ++++
 library/Icinga/Web/Widget/Dashboard/Component.php |   35 +++++----------------
 library/Icinga/Web/Widget/Dashboard/Pane.php      |    8 ++++-
 3 files changed, 20 insertions(+), 29 deletions(-)

diff --git a/application/controllers/DashboardController.php b/application/controllers/DashboardController.php
index 9023fb2..c8fe7d8 100644
--- a/application/controllers/DashboardController.php
+++ b/application/controllers/DashboardController.php
@@ -63,6 +63,12 @@ class DashboardController extends ActionController
                 $this->view->title = $dashboard->getActivePane()->getTitle() . ' :: Dashboard';
                 $this->view->tabs = $dashboard->getTabs();
 
+                if ($this->hasParam('remove')) {
+                    $dashboard->getActivePane()->removeComponent($this->getParam('remove'));
+                    $dashboard->write();
+                    $this->redirectNow(URL::fromRequest()->remove('remove'));
+                }
+
                 /* Temporarily removed
                 $this->view->tabs->add(
                     'Add',
diff --git a/library/Icinga/Web/Widget/Dashboard/Component.php b/library/Icinga/Web/Widget/Dashboard/Component.php
index 46b49eb..693f60b 100644
--- a/library/Icinga/Web/Widget/Dashboard/Component.php
+++ b/library/Icinga/Web/Widget/Dashboard/Component.php
@@ -53,7 +53,7 @@ class Component extends UserWidget
     private $template =<<<'EOD'
 
     <div class="container" data-icinga-url="{URL}">
-        <h1>{REMOVE}<a href="{FULL_URL}" data-base-target="col1">{TITLE}</a></h1>
+        <h1><a href="{FULL_URL}" data-base-target="col1">{TITLE}</a> ({REMOVE})</h1>
         <noscript>
             <iframe src="{IFRAME_URL}" style="height:100%; width:99%" frameborder="no"></iframe>
         </noscript>
@@ -179,7 +179,6 @@ EOD;
             '{URL}',
             '{IFRAME_URL}',
             '{FULL_URL}',
-            '{REMOVE_BTN}',
             '{TITLE}',
             '{REMOVE}'
         );
@@ -188,9 +187,8 @@ EOD;
             $url,
             $iframeUrl,
             $url->getUrlWithout(array('view', 'limit')),
-            $this->getRemoveForm($view),
             $view->escape($this->getTitle()),
-            $this->getRemoveForm()
+            $this->getRemoveLink()
         );
 
         return str_replace($searchTokens, $replaceTokens, $this->template);
@@ -201,32 +199,13 @@ EOD;
      *
      * @return string                       The html representation of the form
      */
-    protected function getRemoveForm()
+    protected function getRemoveLink()
     {
-        // TODO: temporarily disabled, should point to a form asking for confirmal
-        return '';
-        $removeUrl = Url::fromPath(
-            '/dashboard/removecomponent',
-            array(
-                'pane' => $this->pane->getName(),
-                'component' => $this->getTitle()
-            )
+        return sprintf(
+            '<a data-base-target="main" href="%s">%s</a>',
+            Url::fromRequest(array('remove' => $this->getTitle())),
+            t('Remove')
         );
-        $form = new Form();
-        $form->setMethod('POST');
-        $form->setAttrib('class', 'inline');
-        $form->setAction($removeUrl);
-        $form->addElement(
-            new Zend_Form_Element_Button(
-                'remove_pane_btn',
-                array(
-                    'class'=> 'link-like pull-right',
-                    'type' => 'submit',
-                    'label' => 'x'
-                )
-            )
-        );
-        return $form;
     }
 
     /**
diff --git a/library/Icinga/Web/Widget/Dashboard/Pane.php b/library/Icinga/Web/Widget/Dashboard/Pane.php
index 8119eaf..26cd46e 100644
--- a/library/Icinga/Web/Widget/Dashboard/Pane.php
+++ b/library/Icinga/Web/Widget/Dashboard/Pane.php
@@ -130,7 +130,13 @@ class Pane extends UserWidget
     public function removeComponent($title)
     {
         if ($this->hasComponent($title)) {
-            unset($this->components[$title]);
+            $component = $this->getComponent($title);
+            if ($component->isUserWidget() === true) {
+                unset($this->components[$title]);
+            } else {
+                $component->setUserWidget();
+                $component->setDisabled(true);
+            }
         }
         return $this;
     }



More information about the icinga-checkins mailing list