Skip to content

Commit

Permalink
Merge pull request #91 from Icinga/perf-refactor
Browse files Browse the repository at this point in the history
Various small improvements and normalization
  • Loading branch information
martialblog authored Oct 4, 2024
2 parents 5d5644b + 727db95 commit 81c0783
Show file tree
Hide file tree
Showing 18 changed files with 165 additions and 109 deletions.
2 changes: 0 additions & 2 deletions application/controllers/EditController.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ public function indexAction()
$view = $c->loadByName($name);
}

$view->setFormat($c::FORMAT_YAML);

$this->view->form = $form = new EditForm();
$form->setViewConfig($c);
$form->setViews($view);
Expand Down
48 changes: 24 additions & 24 deletions application/forms/EditForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function getRedirectUrl()
*/
public function onRequest()
{
$values = array();
$values = [];
$values['name'] = $this->view->getName();
$values['config'] = $this->view->getText();

Expand All @@ -124,70 +124,70 @@ public function createElements(array $formData)
$this->addElement(
'text',
'name',
array(
'label' => $this->translate('File name'),
[
'label' => $this->translate('File name'),
'required' => true
)
]
);
$this->addElement(
'textarea',
'config',
array(
'label' => $this->translate('YAML Config'),
'class' => 'code-editor codemirror',
'decorators' => array(
array('Label', array('tag'=>'div', 'separator' => '')),
array('HtmlTag', array('tag' => 'div')),
[
'label' => $this->translate('YAML Config'),
'class' => 'code-editor codemirror',
'decorators' => [
['Label', ['tag' => 'div', 'separator' => '']],
['HtmlTag', ['tag' => 'div']],
'ViewHelper'
),
],
'data-codemirror-mode' => 'yaml'
)
]
);

$this->addElement(
'submit',
'btn_submit_save_session',
array(
[
'ignore' => true,
'label' => $this->translate('Save for the current Session'),
'decorators' => array('ViewHelper')
)
'decorators' => ['ViewHelper']
]
);

$this->addElement(
'submit',
'btn_submit_save_file',
array(
[
'ignore' => true,
'label' => $this->translate('Save to config file'),
'decorators' => array('ViewHelper')
)
'decorators' => ['ViewHelper']
]
);

if ($this->view->hasBeenLoadedFromSession()) {
$this->addElement(
'submit',
'btn_submit_cancel',
array(
[
'ignore' => true,
'label' => $this->translate('Cancel editing'),
'class' => 'btn-cancel',
'decorators' => array('ViewHelper')
)
'decorators' => ['ViewHelper']
]
);
}

if ($this->view->hasBeenLoaded()) {
$this->addElement(
'submit',
'btn_submit_delete',
array(
[
'ignore' => true,
'label' => $this->translate('Delete config'),
'class' => 'btn-remove',
'onclick' => 'return confirm("' . $this->translate('Confirm deletion') . '")',
'decorators' => array('ViewHelper')
)
'decorators' => ['ViewHelper']
]
);
}
}
Expand Down
12 changes: 2 additions & 10 deletions application/views/helpers/Badges.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,13 @@
/* Icinga Web 2 Top Level View | (c) 2017 Icinga Development Team | GPLv2+ */

use Icinga\Module\Toplevelview\Tree\TLVStatus;
use Icinga\Module\Toplevelview\Util\Str;

class Zend_View_Helper_Badges extends Zend_View_Helper_Abstract
{
/** @var \Icinga\Web\View */
public $view;

protected function prettyTitle($identifier)
{
$s = '';
foreach (preg_split('/[\.\-_\s]+/', $identifier) as $p) {
$s .= ' ' . ucfirst($p);
}
return trim($s);
}

/**
* badges renders a TLVNode's TLVStatus into HTML.
* A badge represents the number of status of a given node
Expand All @@ -35,7 +27,7 @@ public function badges(TLVStatus $status, $problemsOnly = true, $showTotal = fal
}
if ($value !== null && $value > 0) {
$values = true;
$title = $value . ' ' . $this->prettyTitle($key);
$title = $value . ' ' . Str::prettyTitle($key);
$class = 'tlv-status-tile ' . str_replace('_', ' ', $key);
$htm .= sprintf(
'<div class="badge status-badge %s" title="%s">%s</div>',
Expand Down
8 changes: 4 additions & 4 deletions application/views/helpers/Breadcrumb.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ public function breadcrumb($breadcrumb, $config_name)
$htm .= '<li>' . $this->view->qlink(
Str::limit($crumb->getTitle()),
'toplevelview/show/tree',
array(
'name' => $config_name,
'id' => $crumb->getFullId()
)
[
'name' => $config_name,
'id' => $crumb->getFullId()
]
) . '</li>';
}
$htm .= '</ul>';
Expand Down
10 changes: 5 additions & 5 deletions application/views/helpers/Tiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function tiles(TLVTreeNode $node, $levels = 2, $classes = array())
} else {
$statusClass = 'tlv-status-tile';
}
$statusClasses = array($statusClass, $status->getOverall());
$statusClasses = [$statusClass, $status->getOverall()];

$htm .= sprintf(
'<div class="tlv-tile %s" title="%s" data-base-target="_next">' . "\n",
Expand All @@ -34,13 +34,13 @@ public function tiles(TLVTreeNode $node, $levels = 2, $classes = array())
$htm .= $this->view->qlink(
$title . $badges,
'toplevelview/show/tree',
array(
[
'name' => $node->getRoot()->getViewName(),
'id' => $node->getFullId()
),
array(
],
[
'class' => 'tlv-tile-title'
),
],
false
);

Expand Down
16 changes: 8 additions & 8 deletions application/views/helpers/Tree.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@ public function tree(TLVTreeNode $node, $classes = array(), $level = 0)
$icon = 'services';
$url = Url::fromPath(
'icingadb/servicegroup',
array(
[
'name' => $node->get('servicegroup'),
'sort' => 'service.state.severity desc'
)
]
);
} elseif ($type === 'hostgroup') {
$icon = 'cubes';
$url = Url::fromPath(
'icingadb/services',
array(
[
'hostgroup.name' => $node->get('hostgroup'),
'sort' => 'service.state.severity desc'
)
]
);

if (($h = $status->getMeta('hosts_unhandled')) > 0) {
Expand All @@ -68,21 +68,21 @@ public function tree(TLVTreeNode $node, $classes = array(), $level = 0)
$htmExtra .= ' ' . $this->view->qlink(
$hostTitle,
'icingadb/hosts',
array(
[
'hostgroup.name' => $node->get('hostgroup'),
'sort' => 'service.state.severity desc'
),
],
null,
false
);
} else {
$icon = null;
$url = Url::fromPath(
'toplevelview/show/tree',
array(
[
'name' => $node->getRoot()->getViewName(),
'id' => $node->getFullId()
)
]
);
}

Expand Down
8 changes: 4 additions & 4 deletions application/views/scripts/index/index.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ if (! $this->compact): ?>
<?= $this->qlink(
$this->translate('Add'),
'toplevelview/edit/add',
array(),
array(
[],
[
'class' => 'action-link',
'icon' => 'plus',
)
]
) ?>
<?php endif; ?>
</div>
Expand All @@ -21,7 +21,7 @@ if (! $this->compact): ?>
<div class="tlv-overview-tiles">
<?php
foreach ($views as $name => $view):
$url = $this->url('toplevelview/show', array('name' => $name));
$url = $this->url('toplevelview/show', ['name' => $name]);
?>
<a href="<?= $url ?>" class="tlv-overview-tile">
<div class="tlv-title"><?= $view->getMeta('name') ?></div>
Expand Down
30 changes: 15 additions & 15 deletions application/views/scripts/show/actions.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,49 @@
echo $this->qlink(
$this->translate('Source'),
'toplevelview/show/source',
array('name' => $view->getName()),
array(
['name' => $view->getName()],
[
'class' => 'action-link',
'icon' => 'doc-text',
'data-base-target' => '_next'
)
]
);

echo $this->qlink(
$this->translate('Fullscreen'),
'toplevelview/show',
array(
[
'name' => $view->getName(),
'view' => 'compact',
'showFullscreen' => true
),
array(
'class' => 'action-link',
'icon' => 'resize-full',
],
[
'class' => 'action-link',
'icon' => 'resize-full',
'target' => '_blank'
)
]
);

if ($this->hasPermission('toplevelview/edit')) {
echo $this->qlink(
$this->translate('Edit'),
'toplevelview/edit',
array('name' => $view->getName()),
array(
['name' => $view->getName()],
[
'class' => 'action-link',
'icon' => 'edit',
'data-base-target' => '_next'
)
]
);
echo $this->qlink(
$this->translate('Clone'),
'toplevelview/edit/clone',
array('name' => $view->getName()),
array(
['name' => $view->getName()],
[
'class' => 'action-link',
'icon' => 'rewind',
'data-base-target' => '_next'
)
]
);
}
}
Expand Down
4 changes: 1 addition & 3 deletions application/views/scripts/show/index.phtml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?php
use Icinga\Module\Toplevelview\Util\Str;

/** @var \Icinga\Web\View $this */
/** @var \Icinga\Module\Toplevelview\ViewConfig $view */
/** @var \Icinga\Module\Toplevelview\Tree\TLVTree $tree */

$tree = $view->getTree();
if (! $this->compact):
Expand Down
4 changes: 1 addition & 3 deletions application/views/scripts/show/tree.phtml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?php
use Icinga\Module\Toplevelview\Util\Str;

/** @var \Icinga\Module\Toplevelview\ViewConfig $view */
/** @var \Icinga\Module\Toplevelview\Tree\TLVTreeNode $node */
/** @var \Icinga\Module\Toplevelview\Tree\TLVTree $tree */

$tree = $view->getTree();

Expand Down
1 change: 0 additions & 1 deletion application/views/scripts/text/index.phtml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php
/** @var \Icinga\Module\Toplevelview\ViewConfig $view */
if (! $this->compact):
?>
<div class="controls separated">
Expand Down
11 changes: 0 additions & 11 deletions library/Toplevelview/Model/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,17 +200,6 @@ public function getTextChecksum(): string
return $this->textChecksum;
}

/**
* setFormat sets the format for this View
* @param string $format Format for this view (e.g. 'yml')
* @return $this
*/
public function setFormat($format)
{
$this->format = $format;
return $this;
}

/**
* getFormat returns the View's format
*/
Expand Down
Loading

0 comments on commit 81c0783

Please sign in to comment.