summaryrefslogtreecommitdiffstats
path: root/application/controllers/TemplatesController.php
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 13:29:16 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 13:29:16 +0000
commit8a985929ed84cdb458a13c66b25f84e41133b24f (patch)
tree102a3d6e3cb731c6d23263095d0098f99572626d /application/controllers/TemplatesController.php
parentAdding upstream version 0.10.0. (diff)
downloadicingaweb2-module-reporting-8a985929ed84cdb458a13c66b25f84e41133b24f.tar.xz
icingaweb2-module-reporting-8a985929ed84cdb458a13c66b25f84e41133b24f.zip
Adding upstream version 1.0.1.upstream/1.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'application/controllers/TemplatesController.php')
-rw-r--r--application/controllers/TemplatesController.php75
1 files changed, 40 insertions, 35 deletions
diff --git a/application/controllers/TemplatesController.php b/application/controllers/TemplatesController.php
index 91a82b1..99a5dcb 100644
--- a/application/controllers/TemplatesController.php
+++ b/application/controllers/TemplatesController.php
@@ -1,22 +1,22 @@
<?php
+
// Icinga Reporting | (c) 2019 Icinga GmbH | GPLv2
namespace Icinga\Module\Reporting\Controllers;
-use GuzzleHttp\Psr7\ServerRequest;
use Icinga\Module\Reporting\Database;
+use Icinga\Module\Reporting\Model;
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\Sql\Select;
use ipl\Web\Url;
use ipl\Web\Widget\ButtonLink;
use ipl\Web\Widget\Link;
class TemplatesController extends Controller
{
- use Database;
use ReportsTimeframesAndTemplatesTabs;
public function indexAction()
@@ -26,38 +26,40 @@ class TemplatesController extends Controller
$canManage = $this->hasPermission('reporting/templates');
if ($canManage) {
- $this->addControl(new ButtonLink(
- $this->translate('New Template'),
- Url::fromPath('reporting/templates/new'),
- 'plus'
- ));
+ $this->addControl(
+ (new ButtonLink(
+ $this->translate('New Template'),
+ Url::fromPath('reporting/templates/new'),
+ 'plus'
+ ))->openInModal()
+ );
}
- $select = (new Select())
- ->from('template')
- ->columns(['id', 'name', 'author', 'ctime', 'mtime'])
- ->orderBy('mtime', SORT_DESC);
-
- foreach ($this->getDb()->select($select) as $template) {
- if ($canManage) {
- // Edit URL
- $subjectUrl = Url::fromPath(
- 'reporting/template/edit',
- ['id' => $template->id]
- );
- } else {
- // Preview URL
- $subjectUrl = Url::fromPath(
- 'reporting/template',
- ['id' => $template->id]
- );
- }
+ $templates = Model\Template::on(Database::get());
+
+ $sortControl = $this->createSortControl(
+ $templates,
+ [
+ 'name' => $this->translate('Name'),
+ 'author' => $this->translate('Author'),
+ 'ctime' => $this->translate('Created At'),
+ 'mtime' => $this->translate('Modified At')
+ ]
+ );
+ $this->addControl($sortControl);
+
+ $tableRows = [];
+
+ /** @var Model\Template $template */
+ foreach ($templates as $template) {
+ // Preview URL
+ $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, date('Y-m-d H:i', $template->ctime / 1000)),
- Html::tag('td', null, date('Y-m-d H:i', $template->mtime / 1000))
+ Html::tag('td', null, $template->ctime->format('Y-m-d H:i')),
+ Html::tag('td', null, $template->mtime->format('Y-m-d H:i'))
]);
}
@@ -93,13 +95,16 @@ class TemplatesController extends Controller
public function newAction()
{
$this->assertPermission('reporting/templates');
- $this->addTitleTab('New Template');
-
- $form = new TemplateForm();
+ $this->addTitleTab($this->translate('New Template'));
- $form->handleRequest(ServerRequest::fromGlobals());
+ $form = (new TemplateForm())
+ ->setAction((string) Url::fromRequest())
+ ->on(TemplateForm::ON_SUCCESS, function () {
+ Notification::success($this->translate('Created template successfully'));
- $this->redirectForm($form, 'reporting/templates');
+ $this->closeModalAndRefreshRelatedView(Url::fromPath('reporting/templates'));
+ })
+ ->handleRequest($this->getServerRequest());
$this->addContent($form);
}