Fix PSR compliance of code

refs #4192
This commit is contained in:
Jannis Moßhammer 2013-08-07 18:10:39 +02:00
parent 2a2966fc56
commit 6e68826da6
6 changed files with 91 additions and 67 deletions

View File

@ -8,7 +8,6 @@ use Icinga\Config\Config as IcingaConfig;
use Icinga\Form\Dashboard\AddUrlForm; use Icinga\Form\Dashboard\AddUrlForm;
use Icinga\Exception\ConfigurationError; use Icinga\Exception\ConfigurationError;
/** /**
* Handle creation, removal and displaying of dashboards, panes and components * Handle creation, removal and displaying of dashboards, panes and components
* *
@ -100,12 +99,14 @@ class DashboardController extends ActionController
$dashboard->activate($dashboardName); $dashboard->activate($dashboardName);
} }
$this->view->tabs = $dashboard->getTabs(); $this->view->tabs = $dashboard->getTabs();
$this->view->tabs->add('Add', array( $this->view->tabs->add(
'Add',
array(
'title' => 'Add Url', 'title' => 'Add Url',
'iconCls' => 'plus', 'iconCls' => 'plus',
'url' => Url::fromPath('dashboard/addurl') 'url' => Url::fromPath('dashboard/addurl')
)); )
);
$this->view->dashboard = $dashboard; $this->view->dashboard = $dashboard;
} }
} }

View File

@ -25,18 +25,24 @@ class AddUrlForm extends Form
private function addPaneSelectionBox(Dashboard $dashboard) private function addPaneSelectionBox(Dashboard $dashboard)
{ {
$selectPane = new Zend_Form_Element_Select('pane', array( $selectPane = new Zend_Form_Element_Select(
'pane',
array(
'label' => 'Dashboard', 'label' => 'Dashboard',
'required' => true, 'required' => true,
'style' => 'display:inline-block', 'style' => 'display:inline-block',
'multiOptions' => $dashboard->getPaneKeyTitleArray() 'multiOptions' => $dashboard->getPaneKeyTitleArray()
)); )
);
$newDashboardBtn = new Zend_Form_Element_Submit('create_new_pane', array( $newDashboardBtn = new Zend_Form_Element_Submit(
'create_new_pane',
array(
'label' => '+', 'label' => '+',
'required' => false, 'required' => false,
'style' => 'display:inline-block' 'style' => 'display:inline-block'
)); )
);
$newDashboardBtn->removeDecorator('DtDdWrapper'); $newDashboardBtn->removeDecorator('DtDdWrapper');
$selectPane->removeDecorator('DtDdWrapper'); $selectPane->removeDecorator('DtDdWrapper');
@ -54,23 +60,32 @@ class AddUrlForm extends Form
*/ */
private function addNewPaneTextField() private function addNewPaneTextField()
{ {
$txtCreatePane = new Zend_Form_Element_Text('pane', array( $txtCreatePane = new Zend_Form_Element_Text(
'pane',
array(
'label' => 'New dashboard title', 'label' => 'New dashboard title',
'required' => true, 'required' => true,
'style' => 'display:inline-block' 'style' => 'display:inline-block'
)); )
);
// Marks this field as a new pane (and prevents the checkbox being displayed when validation errors occur) // Marks this field as a new pane (and prevents the checkbox being displayed when validation errors occur)
$markAsNewPane = new Zend_Form_Element_Hidden('create_new_pane', array( $markAsNewPane = new Zend_Form_Element_Hidden(
'create_new_pane',
array(
'required' => true, 'required' => true,
'value' => 1 'value' => 1
)); )
);
$cancelDashboardBtn = new Zend_Form_Element_Submit('use_existing_dashboard', array( $cancelDashboardBtn = new Zend_Form_Element_Submit(
'use_existing_dashboard',
array(
'label' => 'X', 'label' => 'X',
'required' => false, 'required' => false,
'style' => 'display:inline-block' 'style' => 'display:inline-block'
)); )
);
$cancelDashboardBtn->removeDecorator('DtDdWrapper'); $cancelDashboardBtn->removeDecorator('DtDdWrapper');
$txtCreatePane->removeDecorator('DtDdWrapper'); $txtCreatePane->removeDecorator('DtDdWrapper');
@ -89,10 +104,14 @@ class AddUrlForm extends Form
{ {
$dashboard = new Dashboard(); $dashboard = new Dashboard();
$dashboard->readConfig(IcingaConfig::app('dashboard/dashboard')); $dashboard->readConfig(IcingaConfig::app('dashboard/dashboard'));
$this->addElement('text', 'url', array( $this->addElement(
'text',
'url',
array(
'label' => 'Url', 'label' => 'Url',
'required' => true, 'required' => true,
)); )
);
$elems = $dashboard->getPaneKeyTitleArray(); $elems = $dashboard->getPaneKeyTitleArray();
if (empty($elems) || // show textfield instead of combobox when no pane is available if (empty($elems) || // show textfield instead of combobox when no pane is available
@ -104,11 +123,14 @@ class AddUrlForm extends Form
$this->addPaneSelectionBox($dashboard); $this->addPaneSelectionBox($dashboard);
} }
$this->addElement('text', 'component', array( $this->addElement(
'text',
'component',
array(
'label' => 'Title', 'label' => 'Title',
'required' => true, 'required' => true,
)); )
);
$this->setSubmitLabel("Add to dashboard"); $this->setSubmitLabel("Add to dashboard");
} }
} }

View File

@ -75,11 +75,14 @@ class Dashboard implements Widget
$this->tabs = new Tabs(); $this->tabs = new Tabs();
foreach ($this->panes as $key => $pane) { foreach ($this->panes as $key => $pane) {
$this->tabs->add($key, array( $this->tabs->add(
$key,
array(
'title' => $pane->getTitle(), 'title' => $pane->getTitle(),
'url' => clone($url), 'url' => clone($url),
'urlParams' => array($this->tabParam => $key) 'urlParams' => array($this->tabParam => $key)
)); )
);
} }
} }
return $this->tabs; return $this->tabs;
@ -113,7 +116,7 @@ class Dashboard implements Widget
} }
if (!@file_put_contents($file, $iniString)) { if (!@file_put_contents($file, $iniString)) {
$error = error_get_last(); $error = error_get_last();
if ($error == NULL) { if ($error == null) {
$error = 'Unknown error'; $error = 'Unknown error';
} else { } else {
$error = $error['message']; $error = $error['message'];
@ -340,4 +343,3 @@ class Dashboard implements Widget
} }
} }
} }

View File

@ -103,10 +103,7 @@ class Pane implements Widget
if ($this->hasComponent($title)) { if ($this->hasComponent($title)) {
return $this->components[$title]; return $this->components[$title];
} }
throw new ProgrammingError(sprintf( throw new ProgrammingError(sprintf('Trying to access invalid component: %s', $title));
'Trying to access invalid component: %s',
$title
));
} }
/** /**
@ -148,7 +145,8 @@ class Pane implements Widget
/** /**
* Add a component to this pane, optionally creating it if $component is a string * Add a component to this pane, optionally creating it if $component is a string
* *
* @param string|Component $component The component object or title (if a new component will be created) * @param string|Component $component The component object or title
* (if a new component will be created)
* @param string|null $url An Url to be used when component is a string * @param string|null $url An Url to be used when component is a string
* *
* @return Pane $this * @return Pane $this
@ -173,8 +171,7 @@ class Pane implements Widget
*/ */
public function toIni() public function toIni()
{ {
if (empty($this->components)) if (empty($this->components)) {
{
return ''; return '';
} }
$ini = '['.$this->getName().']'.PHP_EOL. $ini = '['.$this->getName().']'.PHP_EOL.

View File

@ -185,10 +185,13 @@ class Tab implements Widget
$class = $this->active ? ' class="active"' : ''; $class = $this->active ? ' class="active"' : '';
$caption = $this->title; $caption = $this->title;
if ($this->icon !== null) { if ($this->icon !== null) {
$caption = $view->img($this->icon, array( $caption = $view->img(
$this->icon,
array(
'width' => 16, 'width' => 16,
'height' => 16 'height' => 16
)) . ' ' . $caption; )
) . ' ' . $caption;
} elseif ($this->iconCls !== null) { } elseif ($this->iconCls !== null) {
$caption = '<i class="icon-'.$this->iconCls.'"></i> ' . $caption; $caption = '<i class="icon-'.$this->iconCls.'"></i> ' . $caption;
} }
@ -205,5 +208,4 @@ class Tab implements Widget
return '<li '.$class.'>'.$tab.'</li>'.PHP_EOL; return '<li '.$class.'>'.$tab.'</li>'.PHP_EOL;
} }
} }