* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
*/
-class Form extends AbstractWidget
+class Form
{
protected $form;
protected $properties = array(
@@ -74,7 +71,7 @@ class Form extends AbstractWidget
$this->form = new $class($this->options);
}
- public function renderAsHtml()
+ public function render()
{
return (string) $this->form;
}
diff --git a/library/Icinga/Web/Widget/Tab.php b/library/Icinga/Web/Widget/Tab.php
index a8ea47f68..501e358de 100644
--- a/library/Icinga/Web/Widget/Tab.php
+++ b/library/Icinga/Web/Widget/Tab.php
@@ -1,8 +1,5 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
*/
-class Tab extends AbstractWidget
+class Tab implements Widget
{
/**
* Whether this tab is currently active
*
* @var bool
*/
- protected $active = false;
+ private $active = false;
/**
* Default values for widget properties
*
* @var array
*/
- protected $properties = array(
- 'name' => null,
- 'title' => '',
- 'url' => null,
- 'urlParams' => array(),
- 'icon' => null,
- );
+ private $name = null;
+
+ private $title = '';
+ private $url = null;
+ private $urlParams = array();
+ private $icon = null;
+
+
+ /**
+ * @param mixed $icon
+ */
+ public function setIcon($icon)
+ {
+ $this->icon = $icon;
+ }
+
+ /**
+ * @return mixed
+ */
+ public function getIcon()
+ {
+ return $this->icon;
+ }
+
+ /**
+ * @param mixed $name
+ */
+ public function setName($name)
+ {
+ $this->name = $name;
+ }
+
+ /**
+ * @return mixed
+ */
+ public function getName()
+ {
+ return $this->name;
+ }
+
+ /**
+ * @param mixed $title
+ */
+ public function setTitle($title)
+ {
+ $this->title = $title;
+ }
+
+ /**
+ * @return mixed
+ */
+ public function getTitle()
+ {
+ return $this->title;
+ }
+
+ /**
+ * @param mixed $url
+ */
+ public function setUrl($url)
+ {
+ $this->url = $url;
+ }
+
+ /**
+ * @return mixed
+ */
+ public function getUrl()
+ {
+ return $this->url;
+ }
+
+ public function __construct(array $properties = array())
+ {
+ foreach ($properties as $name=>$value) {
+ $setter = 'set'.ucfirst($name);
+ if (method_exists($this, $setter)) {
+ $this->$setter($value);
+ }
+ }
+
+ }
/**
* Health check at initialization time
@@ -56,9 +128,7 @@ class Tab extends AbstractWidget
protected function init()
{
if ($this->name === null) {
- throw new ProgrammingError(
- 'Cannot create a nameless tab'
- );
+ throw new ProgrammingError('Cannot create a nameless tab');
}
}
@@ -93,16 +163,15 @@ class Tab extends AbstractWidget
*
* @return string
*/
- public function renderAsHtml()
+ public function render(\Zend_View_Abstract $view)
{
- $view = $this->view();
$class = $this->isActive() ? ' class="active"' : '';
$caption = $this->title;
if ($this->icon !== null) {
$caption = $view->img($this->icon, array(
- 'width' => 16,
- 'height' => 16
- )) . ' ' . $caption;
+ 'width' => 16,
+ 'height' => 16
+ )) . ' ' . $caption;
}
if ($this->url !== null) {
$tab = $view->qlink(
@@ -114,6 +183,8 @@ class Tab extends AbstractWidget
} else {
$tab = $caption;
}
+
return "$tab\n";
}
+
}
diff --git a/library/Icinga/Web/Widget/Tabs.php b/library/Icinga/Web/Widget/Tabs.php
index 8e9c3483d..af3fa1f21 100644
--- a/library/Icinga/Web/Widget/Tabs.php
+++ b/library/Icinga/Web/Widget/Tabs.php
@@ -1,12 +1,10 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
*/
-class Tabs extends AbstractWidget implements Countable
+class Tabs implements Countable, Widget
{
/**
* This is where single tabs added to this container will be stored
*
* @var array
*/
- protected $tabs = array();
+ private $tabs = array();
/**
* The name of the currently activated tab
*
* @var string
*/
- protected $active;
+ private $active;
/**
* Class name(s) going to be assigned to the <ul> element
*
* @var string
*/
- protected $tab_class = 'nav-tabs';
+ private $tab_class = 'nav-tabs';
- protected $specialActions = false;
+ private $specialActions = false;
/**
* Activate the tab with the given name
@@ -188,48 +186,46 @@ class Tabs extends AbstractWidget implements Countable
*
* @return string
*/
- public function renderAsHtml()
+ public function render(\Zend_View_Abstract $view)
{
- $view = $this->view();
-
if (empty($this->tabs)) {
return '';
}
$html = '' . "\n";
foreach ($this->tabs as $tab) {
- $html .= $tab;
+ $html .= $tab->render($view);
}
$special = array();
- $special[] = $this->view()->qlink(
- $this->view()->img('img/classic/application-pdf.png') . ' PDF',
+ $special[] = $view->qlink(
+ $view->img('img/classic/application-pdf.png') . ' PDF',
Url::fromRequest(),
array('filetype' => 'pdf'),
array('target' => '_blank', 'quote' => false)
);
- $special[] = $this->view()->qlink(
- $this->view()->img('img/classic/application-csv.png') . ' CSV',
+ $special[] = $view->qlink(
+ $view->img('img/classic/application-csv.png') . ' CSV',
Url::fromRequest(),
array('format' => 'csv'),
array('target' => '_blank', 'quote' => false)
);
- $special[] = $this->view()->qlink(
- $this->view()->img('img/classic/application-json.png') . ' JSON',
+ $special[] = $view->qlink(
+ $view->img('img/classic/application-json.png') . ' JSON',
Url::fromRequest(),
array('format' => 'json', 'quote' => false),
array('target' => '_blank', 'quote' => false)
);
- $special[] = $this->view()->qlink(
- $this->view()->img('img/classic/basket.png') . ' URL Basket',
+ $special[] = $view->qlink(
+ $view->img('img/classic/basket.png') . ' URL Basket',
Url::fromPath('basket/add'),
array('url' => Url::fromRequest()->getRelativeUrl()),
array('quote' => false)
);
- $special[] = $this->view()->qlink(
- $this->view()->img('img/classic/dashboard.png') . ' Dashboard',
+ $special[] = $view->qlink(
+ $view->img('img/classic/dashboard.png') . ' Dashboard',
Url::fromPath('dashboard/addurl'),
array('url' => Url::fromRequest()->getRelativeUrl()),
array('quote' => false)
@@ -255,6 +251,7 @@ class Tabs extends AbstractWidget implements Countable
return $html;
}
+
public function count()
{
return count($this->tabs);
diff --git a/library/Icinga/Web/Widget/Widget.php b/library/Icinga/Web/Widget/Widget.php
new file mode 100644
index 000000000..70c570d92
--- /dev/null
+++ b/library/Icinga/Web/Widget/Widget.php
@@ -0,0 +1,18 @@
+widget('tabs');
+ $tabs = new Tabs();
$tabs->add('services', array(
'title' => 'All services',
'icon' => 'img/classic/service.png',
diff --git a/modules/monitoring/application/controllers/ShowController.php b/modules/monitoring/application/controllers/ShowController.php
index ac08efc07..975da9c6d 100644
--- a/modules/monitoring/application/controllers/ShowController.php
+++ b/modules/monitoring/application/controllers/ShowController.php
@@ -33,6 +33,7 @@ use Icinga\Web\Hook;
use Monitoring\Object\Host;
use Monitoring\Object\Service;
use Icinga\Application\Benchmark;
+use Icinga\Web\Widget\Tabs;
/**
* Class Monitoring_ShowController
*
@@ -425,7 +426,7 @@ class Monitoring_ShowController extends ModuleActionController
protected function createTabs()
{
$object = $this->view->object;
- $tabs = $this->widget('tabs');
+ $tabs = new Tabs();
if (!$this->view->host) {
return $tabs;
}
diff --git a/modules/monitoring/application/controllers/SummaryController.php b/modules/monitoring/application/controllers/SummaryController.php
index e9eb6d952..ead0c22ec 100644
--- a/modules/monitoring/application/controllers/SummaryController.php
+++ b/modules/monitoring/application/controllers/SummaryController.php
@@ -2,6 +2,7 @@
use Icinga\Web\ModuleActionController;
use Icinga\Backend;
+use Icinga\Web\Widget\Tabs;
class Monitoring_SummaryController extends ModuleActionController
{
@@ -18,7 +19,7 @@ class Monitoring_SummaryController extends ModuleActionController
protected function getTabs()
{
- $tabs = $this->widget('tabs');
+ $tabs = new Tabs();
$tabs->add('hostgroup', array(
'title' => 'Hostgroups',
'url' => 'monitoring/summary/group',
diff --git a/modules/monitoring/application/views/scripts/list/contactgroups.phtml b/modules/monitoring/application/views/scripts/list/contactgroups.phtml
index a4841c008..77bef0553 100644
--- a/modules/monitoring/application/views/scripts/list/contactgroups.phtml
+++ b/modules/monitoring/application/views/scripts/list/contactgroups.phtml
@@ -1,4 +1,5 @@
-= $this->tabs ?>
+= $this->tabs->render($this); ?>
+
= $this->escape(print_r($this->contactgroups->fetchAll(), 1)) ?>
diff --git a/modules/monitoring/application/views/scripts/list/contacts.phtml b/modules/monitoring/application/views/scripts/list/contacts.phtml
index bacc8f878..2a2930443 100644
--- a/modules/monitoring/application/views/scripts/list/contacts.phtml
+++ b/modules/monitoring/application/views/scripts/list/contacts.phtml
@@ -1,4 +1,5 @@
-= $this->tabs ?>
+= $this->tabs->render($this); ?>
+
= $this->escape(print_r($this->contacts->fetchAll(), 1)) ?>
diff --git a/modules/monitoring/application/views/scripts/list/downtimes.phtml b/modules/monitoring/application/views/scripts/list/downtimes.phtml
index 1decf5052..ca28045bf 100644
--- a/modules/monitoring/application/views/scripts/list/downtimes.phtml
+++ b/modules/monitoring/application/views/scripts/list/downtimes.phtml
@@ -1,4 +1,4 @@
-= $this->tabs ?>
+= $this->tabs->render($this); ?>
tabs ?>
+= $this->tabs->render($this); ?>
+
= $this->escape(print_r($this->hostgroups->fetchAll(), 1)) ?>
diff --git a/modules/monitoring/application/views/scripts/list/hosts.phtml b/modules/monitoring/application/views/scripts/list/hosts.phtml
index 51f06990e..adc6aa477 100644
--- a/modules/monitoring/application/views/scripts/list/hosts.phtml
+++ b/modules/monitoring/application/views/scripts/list/hosts.phtml
@@ -1,4 +1,4 @@
-= $this->tabs ?>
+= $this->tabs->render($this); ?>
hosts->paginate();
diff --git a/modules/monitoring/application/views/scripts/list/servicegroups.phtml b/modules/monitoring/application/views/scripts/list/servicegroups.phtml
index 926a6dd33..952e5dd9d 100644
--- a/modules/monitoring/application/views/scripts/list/servicegroups.phtml
+++ b/modules/monitoring/application/views/scripts/list/servicegroups.phtml
@@ -1,4 +1,5 @@
-= $this->tabs ?>
+= $this->tabs->render($this); ?>
+
= $this->escape(print_r($this->servicegroups->fetchAll(), 1)) ?>
diff --git a/modules/monitoring/application/views/scripts/list/services.phtml b/modules/monitoring/application/views/scripts/list/services.phtml
index 19f5f4152..2fb224e75 100644
--- a/modules/monitoring/application/views/scripts/list/services.phtml
+++ b/modules/monitoring/application/views/scripts/list/services.phtml
@@ -1,4 +1,4 @@
-= $this->tabs ?>
+= $this->tabs->render($this); ?>
paginate();
diff --git a/modules/monitoring/application/views/scripts/show/header.phtml b/modules/monitoring/application/views/scripts/show/header.phtml
index dd49b266a..89c643e93 100644
--- a/modules/monitoring/application/views/scripts/show/header.phtml
+++ b/modules/monitoring/application/views/scripts/show/header.phtml
@@ -13,7 +13,8 @@ if ($this->tabs->getActiveName() === 'history') {
}
if (!$this->compact) {
- echo $this->tabs;
+ echo $this->tabs->render($this);
+
}
?>
diff --git a/test/php/library/Icinga/Web/Hook/Configuration/ConfigurationTabBuilderTest.php b/test/php/library/Icinga/Web/Hook/Configuration/ConfigurationTabBuilderTest.php
index 8dc207391..20b5b44e4 100644
--- a/test/php/library/Icinga/Web/Hook/Configuration/ConfigurationTabBuilderTest.php
+++ b/test/php/library/Icinga/Web/Hook/Configuration/ConfigurationTabBuilderTest.php
@@ -6,7 +6,7 @@ require_once '../../library/Icinga/Web/Hook/Configuration/ConfigurationTabInterf
require_once '../../library/Icinga/Web/Hook/Configuration/ConfigurationTab.php';
require_once '../../library/Icinga/Web/Hook/Configuration/ConfigurationTabBuilder.php';
require_once '../../library/Icinga/Web/Hook.php';
-require_once '../../library/Icinga/Web/Widget/AbstractWidget.php';
+require_once '../../library/Icinga/Web/Widget/Widget.php';
require_once '../../library/Icinga/Web/Widget/Tabs.php';
require_once '../../library/Icinga/Web/Widget/Tab.php';
require_once '../../library/Icinga/Exception/ProgrammingError.php';
diff --git a/test/php/library/Icinga/Web/Widget/AbstractWidgetTest.php b/test/php/library/Icinga/Web/Widget/AbstractWidgetTest.php
deleted file mode 100644
index 28a249f27..000000000
--- a/test/php/library/Icinga/Web/Widget/AbstractWidgetTest.php
+++ /dev/null
@@ -1,113 +0,0 @@
- true,
- 'test2' => false
- );
-
- public function renderAsHtml()
- {
- return "ok123123";
- }
-}
-
-class TestWidget2 extends AbstractWidget
-{
- protected function init()
- {
- $this->view();
- }
-
- public function getView()
- {
- return $this->view();
- }
-
- public function renderAsHtml()
- {
- return "ok123123";
- }
-
-}
-
-class AbstractWidgetTest extends \PHPUnit_Framework_TestCase
-{
- public function testAbstractImplementation1()
- {
- $widget = new TestWidget(
- array(
- 'test1' => false,
- 'test2' => true
- )
- );
-
- $this->assertTrue($widget->test2);
- $this->assertFalse($widget->test1);
-
- $this->assertEquals('ok123123', (string)$widget);
- $this->assertEquals('ok123123', $widget->renderAsHtml());
- }
-
- /**
- * @expectedException Icinga\Exception\ProgrammingError
- * @expectedExceptionMessage Trying to set invalid "test3" property in Tests\Icinga\Web\Widget\TestWidget. Allowed are: test1, test2
- */
- public function testSetFail1()
- {
- $widget = new TestWidget();
- $widget->test3 = true;
- }
-
- /**
- * @expectedException Icinga\Exception\ProgrammingError
- * @expectedExceptionMessage Trying to set invalid "unknown" property in Tests\Icinga\Web\Widget\TestWidget2. Allowed are: none
- */
- public function testSetFail2()
- {
- $widget = new TestWidget2();
- $widget->unknown = true;
- }
-
- /**
- * @expectedException Icinga\Exception\ProgrammingError
- * @expectedExceptionMessage Trying to get invalid "test3" property for Tests\Icinga\Web\Widget\TestWidget
- */
- public function testGetFail()
- {
- $widget = new TestWidget();
- $target = $widget->test3;
- }
-
- public function testView1()
- {
- $widget = new TestWidget2();
- $view = $widget->getView();
- $this->assertInstanceOf('Zend_View', $view);
- }
-}
\ No newline at end of file
diff --git a/test/php/library/Icinga/Web/WidgetTest.php b/test/php/library/Icinga/Web/WidgetTest.php
deleted file mode 100644
index 1f8bbd54e..000000000
--- a/test/php/library/Icinga/Web/WidgetTest.php
+++ /dev/null
@@ -1,31 +0,0 @@
-create('tab', array('name' => 'TEST'));
-
- $this->assertInstanceOf('Icinga\Web\Widget\Tab', $widget);
- }
-
- /**
- * @expectedException Icinga\Exception\ProgrammingError
- * @expectedExceptionMessage There is no such widget: DOES_NOT_EXIST
- */
- public function testFail1()
- {
- $widgetCreator = new Widget();
- $widget = $widgetCreator->create('DOES_NOT_EXIST');
- }
-}
\ No newline at end of file