Skip to content

Commit 81c0783

Browse files
authored
Merge pull request #91 from Icinga/perf-refactor
Various small improvements and normalization
2 parents 5d5644b + 727db95 commit 81c0783

File tree

18 files changed

+165
-109
lines changed

18 files changed

+165
-109
lines changed

application/controllers/EditController.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ public function indexAction()
7474
$view = $c->loadByName($name);
7575
}
7676

77-
$view->setFormat($c::FORMAT_YAML);
78-
7977
$this->view->form = $form = new EditForm();
8078
$form->setViewConfig($c);
8179
$form->setViews($view);

application/forms/EditForm.php

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function getRedirectUrl()
9999
*/
100100
public function onRequest()
101101
{
102-
$values = array();
102+
$values = [];
103103
$values['name'] = $this->view->getName();
104104
$values['config'] = $this->view->getText();
105105

@@ -124,70 +124,70 @@ public function createElements(array $formData)
124124
$this->addElement(
125125
'text',
126126
'name',
127-
array(
128-
'label' => $this->translate('File name'),
127+
[
128+
'label' => $this->translate('File name'),
129129
'required' => true
130-
)
130+
]
131131
);
132132
$this->addElement(
133133
'textarea',
134134
'config',
135-
array(
136-
'label' => $this->translate('YAML Config'),
137-
'class' => 'code-editor codemirror',
138-
'decorators' => array(
139-
array('Label', array('tag'=>'div', 'separator' => '')),
140-
array('HtmlTag', array('tag' => 'div')),
135+
[
136+
'label' => $this->translate('YAML Config'),
137+
'class' => 'code-editor codemirror',
138+
'decorators' => [
139+
['Label', ['tag' => 'div', 'separator' => '']],
140+
['HtmlTag', ['tag' => 'div']],
141141
'ViewHelper'
142-
),
142+
],
143143
'data-codemirror-mode' => 'yaml'
144-
)
144+
]
145145
);
146146

147147
$this->addElement(
148148
'submit',
149149
'btn_submit_save_session',
150-
array(
150+
[
151151
'ignore' => true,
152152
'label' => $this->translate('Save for the current Session'),
153-
'decorators' => array('ViewHelper')
154-
)
153+
'decorators' => ['ViewHelper']
154+
]
155155
);
156156

157157
$this->addElement(
158158
'submit',
159159
'btn_submit_save_file',
160-
array(
160+
[
161161
'ignore' => true,
162162
'label' => $this->translate('Save to config file'),
163-
'decorators' => array('ViewHelper')
164-
)
163+
'decorators' => ['ViewHelper']
164+
]
165165
);
166166

167167
if ($this->view->hasBeenLoadedFromSession()) {
168168
$this->addElement(
169169
'submit',
170170
'btn_submit_cancel',
171-
array(
171+
[
172172
'ignore' => true,
173173
'label' => $this->translate('Cancel editing'),
174174
'class' => 'btn-cancel',
175-
'decorators' => array('ViewHelper')
176-
)
175+
'decorators' => ['ViewHelper']
176+
]
177177
);
178178
}
179179

180180
if ($this->view->hasBeenLoaded()) {
181181
$this->addElement(
182182
'submit',
183183
'btn_submit_delete',
184-
array(
184+
[
185185
'ignore' => true,
186186
'label' => $this->translate('Delete config'),
187187
'class' => 'btn-remove',
188188
'onclick' => 'return confirm("' . $this->translate('Confirm deletion') . '")',
189-
'decorators' => array('ViewHelper')
190-
)
189+
'decorators' => ['ViewHelper']
190+
]
191191
);
192192
}
193193
}

application/views/helpers/Badges.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,13 @@
22
/* Icinga Web 2 Top Level View | (c) 2017 Icinga Development Team | GPLv2+ */
33

44
use Icinga\Module\Toplevelview\Tree\TLVStatus;
5+
use Icinga\Module\Toplevelview\Util\Str;
56

67
class Zend_View_Helper_Badges extends Zend_View_Helper_Abstract
78
{
89
/** @var \Icinga\Web\View */
910
public $view;
1011

11-
protected function prettyTitle($identifier)
12-
{
13-
$s = '';
14-
foreach (preg_split('/[\.\-_\s]+/', $identifier) as $p) {
15-
$s .= ' ' . ucfirst($p);
16-
}
17-
return trim($s);
18-
}
19-
2012
/**
2113
* badges renders a TLVNode's TLVStatus into HTML.
2214
* A badge represents the number of status of a given node
@@ -35,7 +27,7 @@ public function badges(TLVStatus $status, $problemsOnly = true, $showTotal = fal
3527
}
3628
if ($value !== null && $value > 0) {
3729
$values = true;
38-
$title = $value . ' ' . $this->prettyTitle($key);
30+
$title = $value . ' ' . Str::prettyTitle($key);
3931
$class = 'tlv-status-tile ' . str_replace('_', ' ', $key);
4032
$htm .= sprintf(
4133
'<div class="badge status-badge %s" title="%s">%s</div>',

application/views/helpers/Breadcrumb.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ public function breadcrumb($breadcrumb, $config_name)
2323
$htm .= '<li>' . $this->view->qlink(
2424
Str::limit($crumb->getTitle()),
2525
'toplevelview/show/tree',
26-
array(
27-
'name' => $config_name,
28-
'id' => $crumb->getFullId()
29-
)
26+
[
27+
'name' => $config_name,
28+
'id' => $crumb->getFullId()
29+
]
3030
) . '</li>';
3131
}
3232
$htm .= '</ul>';

application/views/helpers/Tiles.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function tiles(TLVTreeNode $node, $levels = 2, $classes = array())
2222
} else {
2323
$statusClass = 'tlv-status-tile';
2424
}
25-
$statusClasses = array($statusClass, $status->getOverall());
25+
$statusClasses = [$statusClass, $status->getOverall()];
2626

2727
$htm .= sprintf(
2828
'<div class="tlv-tile %s" title="%s" data-base-target="_next">' . "\n",
@@ -34,13 +34,13 @@ public function tiles(TLVTreeNode $node, $levels = 2, $classes = array())
3434
$htm .= $this->view->qlink(
3535
$title . $badges,
3636
'toplevelview/show/tree',
37-
array(
37+
[
3838
'name' => $node->getRoot()->getViewName(),
3939
'id' => $node->getFullId()
40-
),
41-
array(
40+
],
41+
[
4242
'class' => 'tlv-tile-title'
43-
),
43+
],
4444
false
4545
);
4646

application/views/helpers/Tree.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,19 @@ public function tree(TLVTreeNode $node, $classes = array(), $level = 0)
4141
$icon = 'services';
4242
$url = Url::fromPath(
4343
'icingadb/servicegroup',
44-
array(
44+
[
4545
'name' => $node->get('servicegroup'),
4646
'sort' => 'service.state.severity desc'
47-
)
47+
]
4848
);
4949
} elseif ($type === 'hostgroup') {
5050
$icon = 'cubes';
5151
$url = Url::fromPath(
5252
'icingadb/services',
53-
array(
53+
[
5454
'hostgroup.name' => $node->get('hostgroup'),
5555
'sort' => 'service.state.severity desc'
56-
)
56+
]
5757
);
5858

5959
if (($h = $status->getMeta('hosts_unhandled')) > 0) {
@@ -68,21 +68,21 @@ public function tree(TLVTreeNode $node, $classes = array(), $level = 0)
6868
$htmExtra .= ' ' . $this->view->qlink(
6969
$hostTitle,
7070
'icingadb/hosts',
71-
array(
71+
[
7272
'hostgroup.name' => $node->get('hostgroup'),
7373
'sort' => 'service.state.severity desc'
74-
),
74+
],
7575
null,
7676
false
7777
);
7878
} else {
7979
$icon = null;
8080
$url = Url::fromPath(
8181
'toplevelview/show/tree',
82-
array(
82+
[
8383
'name' => $node->getRoot()->getViewName(),
8484
'id' => $node->getFullId()
85-
)
85+
]
8686
);
8787
}
8888

application/views/scripts/index/index.phtml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ if (! $this->compact): ?>
77
<?= $this->qlink(
88
$this->translate('Add'),
99
'toplevelview/edit/add',
10-
array(),
11-
array(
10+
[],
11+
[
1212
'class' => 'action-link',
1313
'icon' => 'plus',
14-
)
14+
]
1515
) ?>
1616
<?php endif; ?>
1717
</div>
@@ -21,7 +21,7 @@ if (! $this->compact): ?>
2121
<div class="tlv-overview-tiles">
2222
<?php
2323
foreach ($views as $name => $view):
24-
$url = $this->url('toplevelview/show', array('name' => $name));
24+
$url = $this->url('toplevelview/show', ['name' => $name]);
2525
?>
2626
<a href="<?= $url ?>" class="tlv-overview-tile">
2727
<div class="tlv-title"><?= $view->getMeta('name') ?></div>

application/views/scripts/show/actions.phtml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,49 +7,49 @@
77
echo $this->qlink(
88
$this->translate('Source'),
99
'toplevelview/show/source',
10-
array('name' => $view->getName()),
11-
array(
10+
['name' => $view->getName()],
11+
[
1212
'class' => 'action-link',
1313
'icon' => 'doc-text',
1414
'data-base-target' => '_next'
15-
)
15+
]
1616
);
1717

1818
echo $this->qlink(
1919
$this->translate('Fullscreen'),
2020
'toplevelview/show',
21-
array(
21+
[
2222
'name' => $view->getName(),
2323
'view' => 'compact',
2424
'showFullscreen' => true
25-
),
26-
array(
27-
'class' => 'action-link',
28-
'icon' => 'resize-full',
25+
],
26+
[
27+
'class' => 'action-link',
28+
'icon' => 'resize-full',
2929
'target' => '_blank'
30-
)
30+
]
3131
);
3232

3333
if ($this->hasPermission('toplevelview/edit')) {
3434
echo $this->qlink(
3535
$this->translate('Edit'),
3636
'toplevelview/edit',
37-
array('name' => $view->getName()),
38-
array(
37+
['name' => $view->getName()],
38+
[
3939
'class' => 'action-link',
4040
'icon' => 'edit',
4141
'data-base-target' => '_next'
42-
)
42+
]
4343
);
4444
echo $this->qlink(
4545
$this->translate('Clone'),
4646
'toplevelview/edit/clone',
47-
array('name' => $view->getName()),
48-
array(
47+
['name' => $view->getName()],
48+
[
4949
'class' => 'action-link',
5050
'icon' => 'rewind',
5151
'data-base-target' => '_next'
52-
)
52+
]
5353
);
5454
}
5555
}

application/views/scripts/show/index.phtml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
<?php
2-
use Icinga\Module\Toplevelview\Util\Str;
3-
4-
/** @var \Icinga\Web\View $this */
52
/** @var \Icinga\Module\Toplevelview\ViewConfig $view */
3+
/** @var \Icinga\Module\Toplevelview\Tree\TLVTree $tree */
64

75
$tree = $view->getTree();
86
if (! $this->compact):

application/views/scripts/show/tree.phtml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
<?php
2-
use Icinga\Module\Toplevelview\Util\Str;
3-
42
/** @var \Icinga\Module\Toplevelview\ViewConfig $view */
5-
/** @var \Icinga\Module\Toplevelview\Tree\TLVTreeNode $node */
3+
/** @var \Icinga\Module\Toplevelview\Tree\TLVTree $tree */
64

75
$tree = $view->getTree();
86

application/views/scripts/text/index.phtml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php
2-
/** @var \Icinga\Module\Toplevelview\ViewConfig $view */
32
if (! $this->compact):
43
?>
54
<div class="controls separated">

library/Toplevelview/Model/View.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -200,17 +200,6 @@ public function getTextChecksum(): string
200200
return $this->textChecksum;
201201
}
202202

203-
/**
204-
* setFormat sets the format for this View
205-
* @param string $format Format for this view (e.g. 'yml')
206-
* @return $this
207-
*/
208-
public function setFormat($format)
209-
{
210-
$this->format = $format;
211-
return $this;
212-
}
213-
214203
/**
215204
* getFormat returns the View's format
216205
*/

0 commit comments

Comments
 (0)