From c082ad3d24da43f656a851fc759d8a6ab574323c Mon Sep 17 00:00:00 2001 From: Yonas Habteab Date: Wed, 13 Apr 2022 14:46:47 +0200 Subject: [PATCH] Regroup dashboard input elements --- application/forms/Dashboard/DashletForm.php | 40 ++++++++++---------- application/forms/Dashboard/HomePaneForm.php | 16 +++++--- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/application/forms/Dashboard/DashletForm.php b/application/forms/Dashboard/DashletForm.php index 60a257c7b..8ffc2763a 100644 --- a/application/forms/Dashboard/DashletForm.php +++ b/application/forms/Dashboard/DashletForm.php @@ -48,6 +48,24 @@ class DashletForm extends BaseDashboardForm $this->addElement('hidden', 'org_home', ['required' => false]); $this->addElement('hidden', 'org_dashlet', ['required' => false]); + $this->addElement('text', 'dashlet', [ + 'required' => true, + 'label' => t('Dashlet Title'), + 'placeholder' => t('Enter a dashlet title'), + 'description' => t('Enter a title for the dashlet.'), + ]); + + $this->addElement('textarea', 'url', [ + 'required' => true, + 'label' => t('Url'), + 'placeholder' => t('Enter dashlet url'), + 'description' => t( + 'Enter url to be loaded in the dashlet. You can paste the full URL, including filters.' + ), + ]); + + $this->addHtml(new HtmlElement('hr')); + $this->addElement('select', 'home', [ 'class' => 'autosubmit', 'required' => true, @@ -55,7 +73,7 @@ class DashletForm extends BaseDashboardForm 'value' => $populatedHome, 'multiOptions' => array_merge([self::CREATE_NEW_HOME => self::CREATE_NEW_HOME], $homes), 'label' => t('Select Home'), - 'descriptions' => t('Select a dashboard home you want to add the dashboard pane to.') + 'description' => t('Select a dashboard home you want to add the dashboard pane to.') ]); if (empty($homes) || $populatedHome === self::CREATE_NEW_HOME) { @@ -79,7 +97,7 @@ class DashletForm extends BaseDashboardForm 'class' => 'autosubmit', 'required' => true, 'disabled' => $disable ?: null, - 'value' => ! $disable ? $populatedPane : self::CREATE_NEW_PANE, // Cheat the browser complains + 'value' => ! $disable ? $populatedPane : self::CREATE_NEW_PANE, 'multiOptions' => array_merge([self::CREATE_NEW_PANE => self::CREATE_NEW_PANE], $panes), 'label' => t('Select Dashboard'), 'description' => t('Select a dashboard you want to add the dashlet to.'), @@ -94,24 +112,6 @@ class DashletForm extends BaseDashboardForm ]); } - $this->addHtml(new HtmlElement('hr')); - - $this->addElement('textarea', 'url', [ - 'required' => true, - 'label' => t('Url'), - 'placeholder' => t('Enter dashlet url'), - 'description' => t( - 'Enter url to be loaded in the dashlet. You can paste the full URL, including filters.' - ), - ]); - - $this->addElement('text', 'dashlet', [ - 'required' => true, - 'label' => t('Dashlet Title'), - 'placeholder' => t('Enter a dashlet title'), - 'description' => t('Enter a title for the dashlet.'), - ]); - $removeButton = null; if ($requestUrl->getPath() === Dashboard::BASE_ROUTE . '/edit-dashlet') { $targetUrl = (clone $requestUrl)->setPath(Dashboard::BASE_ROUTE . '/remove-dashlet'); diff --git a/application/forms/Dashboard/HomePaneForm.php b/application/forms/Dashboard/HomePaneForm.php index ff2cb296a..d17f909f4 100644 --- a/application/forms/Dashboard/HomePaneForm.php +++ b/application/forms/Dashboard/HomePaneForm.php @@ -30,7 +30,15 @@ class HomePaneForm extends BaseDashboardForm $titleDesc = t('Edit the title of this dashboard pane'); $buttonLabel = t('Update Pane'); $removeButtonLabel = t('Remove Pane'); + } + $this->addElement('text', 'title', [ + 'required' => true, + 'label' => t('Title'), + 'description' => $titleDesc + ]); + + if ($requestUrl->getPath() === Dashboard::BASE_ROUTE . '/edit-pane') { $removeTargetUrl = (clone $requestUrl)->setPath(Dashboard::BASE_ROUTE . '/remove-pane'); $homes = $this->dashboard->getEntryKeyTitleArr(); @@ -55,12 +63,6 @@ class HomePaneForm extends BaseDashboardForm } } - $this->addElement('text', 'title', [ - 'required' => true, - 'label' => t('Title'), - 'description' => $titleDesc - ]); - $formControls = $this->createFormControls(); $formControls->add([ $this->registerSubmitButton($buttonLabel), @@ -119,6 +121,8 @@ class HomePaneForm extends BaseDashboardForm try { $this->dashboard->manageEntry($currentHome); $currentHome->manageEntry($currentPane, $orgHome); + // We have to update all the dashlet ids too sha1(username + home + pane + dashlet) + $currentPane->manageEntry($currentPane->getEntries()); $conn->commitTransaction(); } catch (\Exception $err) {