Skip to content

Commit

Permalink
Merge pull request #192 from Icinga/templates-modal
Browse files Browse the repository at this point in the history
Use modals for `creating` & `editing` templates
  • Loading branch information
yhabteab authored Jul 12, 2023
2 parents 2e7b96b + d9b0030 commit 971c7e9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
8 changes: 7 additions & 1 deletion application/controllers/TemplateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
use Icinga\Module\Reporting\Web\Controller;
use Icinga\Module\Reporting\Web\Forms\TemplateForm;
use Icinga\Module\Reporting\Web\Widget\Template;
use Icinga\Web\Notification;
use ipl\Stdlib\Filter;
use ipl\Web\Url;

class TemplateController extends Controller
{
Expand Down Expand Up @@ -59,11 +61,15 @@ public function editAction()
$template->settings = json_decode($template->settings, true);

$form = TemplateForm::fromTemplate($template)
->setAction((string) Url::fromRequest())
->on(TemplateForm::ON_SUCCESS, function () {
$this->redirectNow('reporting/templates');
Notification::success($this->translate('Updated template successfully'));

$this->redirectNow('__CLOSE__');
})
->handleRequest(ServerRequest::fromGlobals());

$this->setTitle($this->translate('Edit template'));
$this->addContent($form);
}

Expand Down
34 changes: 22 additions & 12 deletions application/controllers/TemplatesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Icinga\Module\Reporting\Web\Controller;
use Icinga\Module\Reporting\Web\Forms\TemplateForm;
use Icinga\Module\Reporting\Web\ReportsTimeframesAndTemplatesTabs;
use Icinga\Web\Notification;
use ipl\Html\Html;
use ipl\Web\Url;
use ipl\Web\Widget\ButtonLink;
Expand All @@ -30,7 +31,11 @@ public function indexAction()
$this->addControl(new ButtonLink(
$this->translate('New Template'),
Url::fromPath('reporting/templates/new'),
'plus'
'plus',
[
'data-icinga-modal' => true,
'data-no-icinga-ajax' => true
]
));
}

Expand All @@ -50,21 +55,21 @@ public function indexAction()

foreach ($templates as $template) {
if ($canManage) {
// Edit URL
$subjectUrl = Url::fromPath(
'reporting/template/edit',
['id' => $template->id]
$subjectLink = new Link(
$template->name,
Url::fromPath('reporting/template/edit', ['id' => $template->id]),
[
'data-icinga-modal' => true,
'data-no-icinga-ajax' => true
]
);
} else {
// Preview URL
$subjectUrl = Url::fromPath(
'reporting/template',
['id' => $template->id]
);
$subjectLink = new Link($template->name, Url::fromPath('reporting/template', ['id' => $template->id]));
}

$tableRows[] = Html::tag('tr', null, [
Html::tag('td', null, new Link($template->name, $subjectUrl)),
Html::tag('td', null, $subjectLink),
Html::tag('td', null, $template->author),
Html::tag('td', null, $template->ctime->format('Y-m-d H:i')),
Html::tag('td', null, $template->mtime->format('Y-m-d H:i'))
Expand Down Expand Up @@ -106,10 +111,15 @@ public function newAction()
$this->addTitleTab($this->translate('New Template'));

$form = (new TemplateForm())
->setAction((string) Url::fromRequest())
->on(TemplateForm::ON_SUCCESS, function () {
$this->redirectNow('reporting/templates');
Notification::success($this->translate('Created template successfully'));

$this->getResponse()->setHeader('X-Icinga-Container', 'modal-content', true);

$this->redirectNow('__CLOSE__');
})
->handleRequest(ServerRequest::fromGlobals());
->handleRequest($this->getServerRequest());

$this->addContent($form);
}
Expand Down

0 comments on commit 971c7e9

Please sign in to comment.