Skip to content

Commit 71bba87

Browse files
committed
Web/Dashboard: Keep all error messages consistent & add some class docblocks
1 parent 2f52593 commit 71bba87

File tree

7 files changed

+33
-21
lines changed

7 files changed

+33
-21
lines changed

library/Icinga/Web/Dashboard/Common/DashboardEntries.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public function rewindEntries()
109109
public function unsetEntry(BaseDashboard $dashboard)
110110
{
111111
if (! $this->hasEntry($dashboard->getName())) {
112-
throw new ProgrammingError('Trying to unset an invalid Dashboard entry: "%s"', $dashboard->getName());
112+
throw new ProgrammingError('Trying to unset an invalid Dashboard entry: "%s"', $dashboard->getTitle());
113113
}
114114

115115
unset($this->dashboards[strtolower($dashboard->getName())]);

library/Icinga/Web/Dashboard/Common/DashboardManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function loadDashboardEntries(string $name = null)
100100
public function activateHome(DashboardHome $home): self
101101
{
102102
if (! $this->hasEntry($home->getName())) {
103-
throw new ProgrammingError('Trying to activate Dashboard Home "%s" that does not exist.', $home->getName());
103+
throw new ProgrammingError('Trying to activate Dashboard Home "%s" that does not exist.', $home->getTitle());
104104
}
105105

106106
$activeHome = $this->getActiveHome();

library/Icinga/Web/Dashboard/Common/DashboardUserManager.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Icinga\Util\DBUtils;
1111
use ipl\Stdlib\Filter;
1212

13-
// TODO: Remove this completely as soon as we have introduced a daemon in Icinga Web 2.
1413
trait DashboardUserManager
1514
{
1615
/** @var User */

library/Icinga/Web/Dashboard/Dashboard.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,7 @@ protected function assemble()
173173
. ' You will always be able to edit them afterwards.'
174174
);
175175
$this->addHtml(HtmlElement::create('p', null, $message));
176-
} elseif (! $activeHome->hasEntries()) {
177-
$this->addHtml(HtmlElement::create('h1', null, t('No dashboard added to this dashboard home.')));
178-
} else {
176+
} elseif ($activeHome->hasEntries()) {
179177
$activePane = $activeHome->getActivePane();
180178

181179
if (! $activePane->hasEntries()) {
@@ -185,6 +183,8 @@ protected function assemble()
185183
$this->addHtml($dashlet->getHtml());
186184
}
187185
}
186+
} else {
187+
$this->addHtml(HtmlElement::create('h1', null, t('No dashboard added to this dashboard home.')));
188188
}
189189
}
190190
}

library/Icinga/Web/Dashboard/DashboardHome.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,16 @@
1414
use Icinga\Web\Dashboard\Common\Sortable;
1515
use Icinga\Util\DBUtils;
1616
use Icinga\Web\Dashboard\Common\WidgetState;
17+
use Icinga\Web\Navigation\NavigationItem;
1718
use ipl\Stdlib\Filter;
1819

1920
use function ipl\Stdlib\get_php_type;
2021

22+
/**
23+
* A Dashboard Home groups various Dashboard Panes and provides the ability
24+
* to load Panes from different entry point of view. Dashboard Homes are
25+
* rendered as child of {@see NavigationItem}s of the main dashboard menu.
26+
*/
2127
class DashboardHome extends BaseDashboard implements DashboardEntry, Sortable
2228
{
2329
use DashboardEntries;
@@ -108,15 +114,15 @@ public function getType(): string
108114
public function activatePane(Pane $pane): self
109115
{
110116
if (! $this->hasEntry($pane->getName())) {
111-
throw new ProgrammingError('Trying to activate Dashboard Pane "%s" that does not exist.', $pane->getName());
117+
throw new ProgrammingError('Trying to activate Dashboard Pane "%s" that does not exist.', $pane->getTitle());
112118
}
113119

114120
$active = $this->getActivePane();
115121
if ($active && $active->getName() !== $pane->getName()) {
116122
$active->setActive(false);
117123
}
118124

119-
$pane->setActive(true);
125+
$pane->setActive();
120126

121127
return $this;
122128
}
@@ -250,6 +256,8 @@ public function manageEntry($entryOrEntries, BaseDashboard $origin = null, bool
250256
'id = ?' => $origin->getEntry($pane->getName())->getUuid(),
251257
'home_id = ?' => $origin->getUuid()
252258
];
259+
260+
$this->addEntry($pane);
253261
}
254262

255263
$conn->update(Pane::TABLE, [
@@ -262,9 +270,10 @@ public function manageEntry($entryOrEntries, BaseDashboard $origin = null, bool
262270
// Failed to move the pane! Should have already been handled by the caller,
263271
// though I think it's better that we raise an exception here!!
264272
throw new AlreadyExistsException(
265-
'Dashboard Pane "%s" could not be managed. Dashboard Home "%s" has Pane with the same name!',
266-
$pane->getTitle(),
267-
$this->getTitle()
273+
'Failed to successfully manage the Dashboard Pane. Dashboard Home "%s" has already' .
274+
' a Pane called "%s"!',
275+
$this->getTitle(),
276+
$pane->getTitle()
268277
);
269278
}
270279

library/Icinga/Web/Dashboard/Dashlet.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313
use ipl\Web\Widget\Link;
1414

1515
/**
16-
* A dashboard pane dashlet
17-
*
18-
* This is the new element being used for the Dashlets view
16+
* A Dashlet/View is basically an Url which is being visualized
17+
* into a single View by Icinga Web 2
1918
*/
2019
class Dashlet extends BaseDashboard
2120
{
@@ -91,7 +90,7 @@ public function getUrl(): ?Url
9190
}
9291

9392
/**
94-
* Set the dashlets URL
93+
* Set the URL of this dashlet
9594
*
9695
* @param string|Url $url The url to use, either as an Url object or as a path
9796
*
@@ -191,7 +190,7 @@ public function isModuleDashlet(): bool
191190
}
192191

193192
/**
194-
* Set whether this dashlet widget is provided by a module
193+
* Set whether this dashlet is provided by a module
195194
*
196195
* @param bool $moduleDashlet
197196
*

library/Icinga/Web/Dashboard/Pane.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
use function ipl\Stdlib\get_php_type;
2121

2222
/**
23-
* A pane, displaying different Dashboard dashlets
23+
* A Pane or Dashboard Pane organizes various Dashlets/Views into a single panel
24+
* and can be accessed via the tabs rendered on the upper navigation bar of Icinga Web 2.
2425
*/
2526
class Pane extends BaseDashboard implements DashboardEntry, Sortable
2627
{
@@ -100,6 +101,7 @@ public function loadDashboardEntries(string $name = null)
100101
$dashlets = Model\Dashlet::on(DBUtils::getConn())
101102
->utilize(self::TABLE)
102103
->with('icingaweb_module_dashlet');
104+
103105
$dashlets->filter(Filter::equal('dashboard_id', $this->getUuid()));
104106

105107
// TODO(yh): Qualify those columns properly??
@@ -166,7 +168,8 @@ public function manageEntry($entryOrEntries, BaseDashboard $origin = null, bool
166168

167169
if (! $this->getHome()) {
168170
throw new \LogicException(
169-
'Dashlets cannot be managed. Please make sure to set the current dashboard home beforehand.'
171+
'Dashlet(s) cannot be managed without a valid Dashboard Home. Please make sure to set' .
172+
' the current dashboard home beforehand.'
170173
);
171174
}
172175

@@ -231,6 +234,8 @@ public function manageEntry($entryOrEntries, BaseDashboard $origin = null, bool
231234
'id = ?' => $origin->getEntry($dashlet->getName())->getUuid(),
232235
'dashboard_id = ?' => $origin->getUuid()
233236
];
237+
238+
$this->addEntry($dashlet);
234239
}
235240

236241
$conn->update(Dashlet::TABLE, [
@@ -246,9 +251,9 @@ public function manageEntry($entryOrEntries, BaseDashboard $origin = null, bool
246251
// Failed to move the pane! Should have already been handled by the caller,
247252
// though I think it's better that we raise an exception here!!
248253
throw new AlreadyExistsException(
249-
'Dashlet "%s" could not be managed. Dashboard Pane "%s" has a Dashlet with the same name!',
250-
$dashlet->getTitle(),
251-
$this->getTitle()
254+
'Failed to successfully manage the Dashlet. Dashboard Pane "%s" has already a Dashlet called "%s"!',
255+
$this->getTitle(),
256+
$dashlet->getTitle()
252257
);
253258
}
254259

0 commit comments

Comments
 (0)