Skip to content

Commit 2f52593

Browse files
committed
DashboardsController: Remove some superfluous control structures & keep all dashboard actions consistent
1 parent 5d3b9f3 commit 2f52593

File tree

1 file changed

+35
-42
lines changed

1 file changed

+35
-42
lines changed

application/controllers/DashboardsController.php

Lines changed: 35 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@ public function indexAction()
8888
*/
8989
public function homeAction()
9090
{
91-
$this->dashboard->load($this->params->getRequired('home'), $this->params->get('pane'));
91+
$home = $this->params->getRequired('home');
92+
$pane = $this->params->get('pane');
93+
94+
$this->dashboard->load($home, $pane);
9295

9396
$activeHome = $this->dashboard->getActiveHome();
9497
if (! $activeHome->getEntries()) {
@@ -190,10 +193,6 @@ public function editPaneAction()
190193

191194
$this->dashboard->load($home, $pane, true);
192195

193-
if (! $this->dashboard->getActiveHome()->hasEntry($pane)) {
194-
$this->httpNotFound(t('Pane "%s" not found'), $pane);
195-
}
196-
197196
$paneForm = new PaneForm($this->dashboard);
198197
$paneForm->on(PaneForm::ON_SUCCESS, function () use ($paneForm, $home) {
199198
if ($this->prevActive && $home !== $paneForm->getPopulatedValue('home')) {
@@ -219,10 +218,6 @@ public function removePaneAction()
219218

220219
$this->dashboard->load($home, $paneParam);
221220

222-
if (! $this->dashboard->getActiveHome()->hasEntry($paneParam)) {
223-
$this->httpNotFound(t('Pane "%s" not found'), $paneParam);
224-
}
225-
226221
$paneForm = new RemovePaneForm($this->dashboard);
227222
$paneForm->populate(['org_name' => $paneParam]);
228223
$paneForm->on(RemovePaneForm::ON_SUCCESS, function () {
@@ -242,8 +237,9 @@ public function removePaneAction()
242237
public function newDashletAction()
243238
{
244239
$home = $this->params->getRequired('home');
240+
$pane = $this->params->get('pane');
245241

246-
$this->dashboard->load($home, $this->params->get('pane'), true);
242+
$this->dashboard->load($home, $pane, true);
247243

248244
$dashletForm = new DashletForm($this->dashboard);
249245
$dashletForm->populate($this->getRequest()->getPost());
@@ -284,8 +280,18 @@ public function addToDashletAction()
284280

285281
public function editDashletAction()
286282
{
287-
$pane = $this->validateDashletParams();
288-
$dashlet = $pane->getEntry($this->params->get('dashlet'));
283+
$home = $this->params->getRequired('home');
284+
$pane = $this->params->getRequired('pane');
285+
$dashlet = $this->params->getRequired('dashlet');
286+
287+
$this->dashboard->load($home, $pane, true);
288+
289+
$pane = $this->dashboard->getActiveHome()->getActivePane();
290+
if (! $pane->hasEntry($dashlet)) {
291+
$this->httpNotFound(t('Dashlet "%s" not found'), $dashlet);
292+
}
293+
294+
$dashlet = $pane->getEntry($dashlet);
289295

290296
$dashletForm = (new DashletForm($this->dashboard))
291297
->on(DashletForm::ON_SUCCESS, function () {
@@ -295,8 +301,6 @@ public function editDashletAction()
295301
})
296302
->handleRequest($this->getServerRequest());
297303

298-
$dashletForm->getElement('submit')->setLabel(t('Update Dashlet'));
299-
300304
$dashletForm->load($dashlet);
301305

302306
$this->setTitle(t('Edit Dashlet'));
@@ -305,7 +309,16 @@ public function editDashletAction()
305309

306310
public function removeDashletAction()
307311
{
308-
$this->validateDashletParams();
312+
$home = $this->params->getRequired('home');
313+
$pane = $this->params->getRequired('pane');
314+
$dashlet = $this->params->getRequired('dashlet');
315+
316+
$this->dashboard->load($home, $pane);
317+
318+
$pane = $this->dashboard->getActiveHome()->getActivePane();
319+
if (! $pane->hasEntry($dashlet)) {
320+
$this->httpNotFound(t('Dashlet "%s" not found'), $dashlet);
321+
}
309322

310323
$removeForm = (new RemoveDashletForm($this->dashboard))
311324
->on(RemoveDashletForm::ON_SUCCESS, function () {
@@ -464,6 +477,13 @@ public function reorderWidgetsAction()
464477
*/
465478
public function setupDashboardAction()
466479
{
480+
$this->dashboard->load(DashboardHome::DEFAULT_HOME);
481+
482+
$setupForm = new SetupNewDashboardForm($this->dashboard);
483+
$setupForm->on(SetupNewDashboardForm::ON_SUCCESS, function () use ($setupForm) {
484+
$this->redirectNow($setupForm->getRedirectUrl());
485+
})->handleRequest($this->getServerRequest());
486+
467487
if (isset($this->getRequest()->getPost()['btn_next'])) {
468488
// Set compact view to prevent the controls from being
469489
// rendered in the modal view when redirecting
@@ -474,13 +494,6 @@ public function setupDashboardAction()
474494
$this->setTitle(t('Add Dashlet'));
475495
}
476496

477-
$this->dashboard->load();
478-
479-
$setupForm = new SetupNewDashboardForm($this->dashboard);
480-
$setupForm->on(SetupNewDashboardForm::ON_SUCCESS, function () use ($setupForm) {
481-
$this->redirectNow($setupForm->getRedirectUrl());
482-
})->handleRequest($this->getServerRequest());
483-
484497
$this->addContent($setupForm);
485498
}
486499

@@ -550,24 +563,4 @@ private function createTabs()
550563

551564
return $tabs;
552565
}
553-
554-
private function validateDashletParams()
555-
{
556-
$home = $this->params->getRequired('home');
557-
$pane = $this->params->getRequired('pane');
558-
$dashlet = $this->params->getRequired('dashlet');
559-
560-
$this->dashboard->load($home, $pane, true);
561-
562-
if (! $this->dashboard->getActiveHome()->hasEntry($pane)) {
563-
$this->httpNotFound(t('Pane "%s" not found'), $pane);
564-
}
565-
566-
$pane = $this->dashboard->getActiveHome()->getEntry($pane);
567-
if (! $pane->hasEntry($dashlet)) {
568-
$this->httpNotFound(t('Dashlet "%s" not found'), $dashlet);
569-
}
570-
571-
return $pane;
572-
}
573566
}

0 commit comments

Comments
 (0)