mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-09-25 18:59:04 +02:00
Merge some related classes
This commit is contained in:
parent
1429d4aa65
commit
49b37ea522
@ -10,13 +10,13 @@ use Icinga\Forms\Dashboard\HomePaneForm;
|
||||
use Icinga\Forms\Dashboard\NewHomePaneForm;
|
||||
use Icinga\Forms\Dashboard\RemoveDashletForm;
|
||||
use Icinga\Forms\Dashboard\RemoveHomePaneForm;
|
||||
use Icinga\Forms\Dashboard\SetupNewDashboardForm;
|
||||
use Icinga\Forms\Dashboard\WelcomeForm;
|
||||
use Icinga\Util\Json;
|
||||
use Icinga\Web\Dashboard\Dashboard;
|
||||
use Icinga\Web\Dashboard\DashboardHome;
|
||||
use Icinga\Web\Dashboard\Pane;
|
||||
use Icinga\Web\Dashboard\Settings;
|
||||
use Icinga\Web\Dashboard\Setup\SetupNewDashboard;
|
||||
use Icinga\Web\Notification;
|
||||
use Icinga\Web\Widget\Tabextension\DashboardSettings;
|
||||
use ipl\Web\Compat\CompatController;
|
||||
@ -395,8 +395,8 @@ class DashboardsController extends CompatController
|
||||
$this->setTitle(t('Add Dashlet'));
|
||||
}
|
||||
|
||||
$setupForm = new SetupNewDashboard($this->dashboard);
|
||||
$setupForm->on(SetupNewDashboard::ON_SUCCESS, function () use ($setupForm) {
|
||||
$setupForm = new SetupNewDashboardForm($this->dashboard);
|
||||
$setupForm->on(SetupNewDashboardForm::ON_SUCCESS, function () use ($setupForm) {
|
||||
$this->redirectNow($setupForm->getRedirectUrl());
|
||||
})->handleRequest(ServerRequest::fromGlobals());
|
||||
|
||||
|
@ -14,21 +14,34 @@ use Icinga\Web\Dashboard\Pane;
|
||||
use ipl\Html\HtmlElement;
|
||||
use ipl\Web\Url;
|
||||
|
||||
class DashletForm extends BaseSetupDashboard
|
||||
class DashletForm extends SetupNewDashboardForm
|
||||
{
|
||||
protected function assembleNextPage()
|
||||
protected function init()
|
||||
{
|
||||
if (! $this->getPopulatedValue('btn_next')) {
|
||||
parent::init();
|
||||
|
||||
$this->setAction((string) Url::fromRequest());
|
||||
}
|
||||
|
||||
public function load(BaseDashboard $dashboard)
|
||||
{
|
||||
$home = Url::fromRequest()->getParam('home');
|
||||
/** @var Dashlet $dashboard */
|
||||
$this->populate(array(
|
||||
'org_home' => $home,
|
||||
'org_pane' => $dashboard->getPane()->getName(),
|
||||
'org_dashlet' => $dashboard->getName(),
|
||||
'dashlet' => $dashboard->getTitle(),
|
||||
'url' => $dashboard->getUrl()->getRelativeUrl()
|
||||
));
|
||||
}
|
||||
|
||||
protected function assembleNextPageDashboardPart()
|
||||
{
|
||||
if (! $this->isUpdatingADashlet() && ! $this->getPopulatedValue('btn_next')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->dumpArbitaryDashlets();
|
||||
$this->assembleNexPageDashletPart();
|
||||
}
|
||||
|
||||
protected function assemble()
|
||||
{
|
||||
if ($this->isUpdatingADashlet() || $this->getPopulatedValue('btn_next')) {
|
||||
$requestUrl = Url::fromRequest();
|
||||
|
||||
$homes = $this->dashboard->getEntryKeyTitleArr();
|
||||
@ -110,9 +123,15 @@ class DashletForm extends BaseSetupDashboard
|
||||
'description' => t('Enter a title for the new dashboard.'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
protected function assemble()
|
||||
{
|
||||
if ($this->isUpdatingADashlet() || $this->getPopulatedValue('btn_next')) {
|
||||
$this->assembleNextPage();
|
||||
|
||||
if ($this->isUpdatingADashlet()) {
|
||||
$targetUrl = (clone $requestUrl)->setPath(Dashboard::BASE_ROUTE . '/remove-dashlet');
|
||||
$targetUrl = (clone Url::fromRequest())->setPath(Dashboard::BASE_ROUTE . '/remove-dashlet');
|
||||
$removeButton = $this->createRemoveButton($targetUrl, t('Remove Dashlet'));
|
||||
|
||||
$formControls = $this->createFormControls();
|
||||
@ -124,8 +143,6 @@ class DashletForm extends BaseSetupDashboard
|
||||
|
||||
$this->addHtml($formControls);
|
||||
} else {
|
||||
$this->assembleNextPage();
|
||||
|
||||
$formControls = $this->createFormControls();
|
||||
$formControls->add([
|
||||
$this->registerSubmitButton(t('Add to Dashboard')),
|
||||
@ -315,17 +332,4 @@ class DashletForm extends BaseSetupDashboard
|
||||
Notification::success(sprintf(t('Updated dashlet "%s" successfully'), $currentDashlet->getTitle()));
|
||||
}
|
||||
}
|
||||
|
||||
public function load(BaseDashboard $dashboard)
|
||||
{
|
||||
$home = Url::fromRequest()->getParam('home');
|
||||
/** @var Dashlet $dashboard */
|
||||
$this->populate(array(
|
||||
'org_home' => $home,
|
||||
'org_pane' => $dashboard->getPane()->getName(),
|
||||
'org_dashlet' => $dashboard->getName(),
|
||||
'dashlet' => $dashboard->getTitle(),
|
||||
'url' => $dashboard->getUrl()->getRelativeUrl()
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -3,15 +3,18 @@
|
||||
namespace Icinga\Forms\Dashboard;
|
||||
|
||||
use Icinga\Web\Dashboard\Dashboard;
|
||||
use Icinga\Web\Dashboard\DashboardHome;
|
||||
use Icinga\Web\Dashboard\Dashlet;
|
||||
use Icinga\Web\Dashboard\ItemList\DashletListMultiSelect;
|
||||
use Icinga\Web\Dashboard\ItemList\EmptyDashlet;
|
||||
use Icinga\Web\Dashboard\Pane;
|
||||
use Icinga\Web\Notification;
|
||||
use ipl\Html\HtmlElement;
|
||||
use ipl\Html\ValidHtml;
|
||||
use ipl\Web\Url;
|
||||
use ipl\Web\Widget\Icon;
|
||||
|
||||
abstract class BaseSetupDashboard extends BaseDashboardForm
|
||||
class SetupNewDashboardForm extends BaseDashboardForm
|
||||
{
|
||||
const DATA_TOGGLE_ELEMENT = 'dashlets-list-info';
|
||||
|
||||
@ -31,6 +34,9 @@ abstract class BaseSetupDashboard extends BaseDashboardForm
|
||||
if (empty(self::$moduleDashlets)) {
|
||||
self::$moduleDashlets = Dashboard::getModuleDashlets();
|
||||
}
|
||||
|
||||
$this->setRedirectUrl((string) Url::fromPath(Dashboard::BASE_ROUTE));
|
||||
$this->setAction($this->getRedirectUrl() . '/setup-dashboard');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -91,7 +97,7 @@ abstract class BaseSetupDashboard extends BaseDashboardForm
|
||||
*/
|
||||
protected function assembleNextPage()
|
||||
{
|
||||
if (! $this->getPopulatedValue('btn_next')) {
|
||||
if (! $this->isUpdatingADashlet() && ! $this->getPopulatedValue('btn_next')) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -245,6 +251,47 @@ abstract class BaseSetupDashboard extends BaseDashboardForm
|
||||
$this->addHtml($formControls);
|
||||
}
|
||||
|
||||
protected function onSuccess()
|
||||
{
|
||||
if ($this->getPopulatedValue('submit')) {
|
||||
$conn = Dashboard::getConn();
|
||||
$pane = new Pane($this->getPopulatedValue('pane'));
|
||||
$home = $this->dashboard->getEntry(DashboardHome::DEFAULT_HOME);
|
||||
|
||||
$conn->beginTransaction();
|
||||
|
||||
try {
|
||||
$this->dashboard->manageEntry($home);
|
||||
$home->manageEntry($pane);
|
||||
|
||||
$this->dumpArbitaryDashlets(false);
|
||||
|
||||
if (($name = $this->getPopulatedValue('dashlet')) && ($url = $this->getPopulatedValue('url'))) {
|
||||
if ($this->duplicateCustomDashlet) {
|
||||
Notification::error(sprintf(
|
||||
t('Failed to create new dahlets. Dashlet "%s" exists within the selected one'),
|
||||
$name
|
||||
));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$dashlet = new Dashlet($name, $url, $pane);
|
||||
$pane->manageEntry($dashlet);
|
||||
}
|
||||
|
||||
$pane->manageEntry(self::$moduleDashlets);
|
||||
|
||||
$conn->commitTransaction();
|
||||
} catch (\Exception $err) {
|
||||
$conn->rollBackTransaction();
|
||||
throw $err;
|
||||
}
|
||||
|
||||
Notification::success(t('Added new dashlet(s) successfully'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create form list controls (can be collapsible if you want)
|
||||
*
|
@ -1,70 +0,0 @@
|
||||
<?php
|
||||
|
||||
/* Icinga Web 2 | (c) 2022 Icinga GmbH | GPLv2+ */
|
||||
|
||||
namespace Icinga\Web\Dashboard\Setup;
|
||||
|
||||
use Icinga\Forms\Dashboard\BaseDashboardForm;
|
||||
use Icinga\Forms\Dashboard\BaseSetupDashboard;
|
||||
use Icinga\Web\Dashboard\Dashboard;
|
||||
use Icinga\Web\Dashboard\DashboardHome;
|
||||
use Icinga\Web\Dashboard\Dashlet;
|
||||
use Icinga\Web\Dashboard\Pane;
|
||||
use Icinga\Web\Notification;
|
||||
use Icinga\Web\Dashboard\ItemList\DashletListMultiSelect;
|
||||
use ipl\Html\HtmlElement;
|
||||
use ipl\Html\ValidHtml;
|
||||
use ipl\Web\Url;
|
||||
use ipl\Web\Widget\Icon;
|
||||
|
||||
class SetupNewDashboard extends BaseSetupDashboard
|
||||
{
|
||||
protected function init()
|
||||
{
|
||||
parent::init();
|
||||
|
||||
$this->setRedirectUrl((string) Url::fromPath(Dashboard::BASE_ROUTE));
|
||||
$this->setAction($this->getRedirectUrl() . '/setup-dashboard');
|
||||
}
|
||||
|
||||
protected function onSuccess()
|
||||
{
|
||||
if ($this->getPopulatedValue('submit')) {
|
||||
$conn = Dashboard::getConn();
|
||||
$pane = new Pane($this->getPopulatedValue('pane'));
|
||||
$home = $this->dashboard->getEntry(DashboardHome::DEFAULT_HOME);
|
||||
|
||||
$conn->beginTransaction();
|
||||
|
||||
try {
|
||||
$this->dashboard->manageEntry($home);
|
||||
$home->manageEntry($pane);
|
||||
|
||||
$this->dumpArbitaryDashlets(false);
|
||||
|
||||
if (($name = $this->getPopulatedValue('dashlet')) && ($url = $this->getPopulatedValue('url'))) {
|
||||
if ($this->duplicateCustomDashlet) {
|
||||
Notification::error(sprintf(
|
||||
t('Failed to create new dahlets. Dashlet "%s" exists within the selected one'),
|
||||
$name
|
||||
));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$dashlet = new Dashlet($name, $url, $pane);
|
||||
$pane->manageEntry($dashlet);
|
||||
}
|
||||
|
||||
$pane->manageEntry(self::$moduleDashlets);
|
||||
|
||||
$conn->commitTransaction();
|
||||
} catch (\Exception $err) {
|
||||
$conn->rollBackTransaction();
|
||||
throw $err;
|
||||
}
|
||||
|
||||
Notification::success(t('Added new dashlet(s) successfully'));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user