diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:29:17 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:29:17 +0000 |
commit | c22a2c3ebc334fd7a891370e43a841d914893d47 (patch) | |
tree | 8a2c06166a1025a97cad914e1ce9da2bc78d646c /application/controllers/ReportsController.php | |
parent | Releasing progress-linux version 0.10.0-2~progress7.99u1. (diff) | |
download | icingaweb2-module-reporting-c22a2c3ebc334fd7a891370e43a841d914893d47.tar.xz icingaweb2-module-reporting-c22a2c3ebc334fd7a891370e43a841d914893d47.zip |
Merging upstream version 1.0.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'application/controllers/ReportsController.php')
-rw-r--r-- | application/controllers/ReportsController.php | 95 |
1 files changed, 67 insertions, 28 deletions
diff --git a/application/controllers/ReportsController.php b/application/controllers/ReportsController.php index 7971897..f6aeedd 100644 --- a/application/controllers/ReportsController.php +++ b/application/controllers/ReportsController.php @@ -1,23 +1,23 @@ <?php + // Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2 namespace Icinga\Module\Reporting\Controllers; -use GuzzleHttp\Psr7\ServerRequest; +use Icinga\Module\Icingadb\ProvidedHook\Reporting\HostSlaReport; +use Icinga\Module\Icingadb\ProvidedHook\Reporting\ServiceSlaReport; use Icinga\Module\Reporting\Database; +use Icinga\Module\Reporting\Model\Report; use Icinga\Module\Reporting\Web\Controller; use Icinga\Module\Reporting\Web\Forms\ReportForm; 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\Icon; -use ipl\Web\Widget\Link; class ReportsController extends Controller { - use Database; use ReportsTimeframesAndTemplatesTabs; public function indexAction() @@ -25,36 +25,42 @@ class ReportsController extends Controller $this->createTabs()->activate('reports'); if ($this->hasPermission('reporting/reports')) { - $this->addControl(new ButtonLink( - $this->translate('New Report'), - Url::fromPath('reporting/reports/new'), - 'plus' - )); + $this->addControl( + (new ButtonLink( + $this->translate('New Report'), + Url::fromPath('reporting/reports/new'), + 'plus' + ))->openInModal() + ); } $tableRows = []; - $select = (new Select()) - ->from('report r') - ->columns(['r.*', 'timeframe' => 't.name']) - ->join('timeframe t', 'r.timeframe_id = t.id') - ->orderBy('r.mtime', SORT_DESC); + $reports = Report::on(Database::get()) + ->withColumns(['report.timeframe.name']); + + $sortControl = $this->createSortControl( + $reports, + [ + 'name' => $this->translate('Name'), + 'author' => $this->translate('Author'), + 'ctime' => $this->translate('Created At'), + 'mtime' => $this->translate('Modified At') + ] + ); + + $this->addControl($sortControl); - foreach ($this->getDb()->select($select) as $report) { + /** @var Report $report */ + foreach ($reports as $report) { $url = Url::fromPath('reporting/report', ['id' => $report->id])->getAbsoluteUrl('&'); $tableRows[] = Html::tag('tr', ['href' => $url], [ Html::tag('td', null, $report->name), Html::tag('td', null, $report->author), - Html::tag('td', null, $report->timeframe), - Html::tag('td', null, date('Y-m-d H:i', $report->ctime / 1000)), - Html::tag('td', null, date('Y-m-d H:i', $report->mtime / 1000)), - Html::tag('td', ['class' => 'icon-col'], [ - new Link( - new Icon('edit'), - Url::fromPath('reporting/report/edit', ['id' => $report->id]) - ) - ]) + Html::tag('td', null, $report->timeframe->name), + Html::tag('td', null, $report->ctime->format('Y-m-d H:i')), + Html::tag('td', null, $report->mtime->format('Y-m-d H:i')), ]); } @@ -94,10 +100,43 @@ class ReportsController extends Controller $this->assertPermission('reporting/reports'); $this->addTitleTab($this->translate('New Report')); - $form = new ReportForm(); - $form->handleRequest(ServerRequest::fromGlobals()); + switch ($this->params->shift('report')) { + case 'host': + $class = HostSlaReport::class; + break; + case 'service': + $class = ServiceSlaReport::class; + break; + default: + $class = null; + break; + } + + $form = (new ReportForm()) + ->setAction((string) Url::fromRequest()) + ->setRenderCreateAndShowButton($class !== null) + ->populate([ + 'filter' => $this->params->shift('filter'), + 'reportlet' => $class + ]) + ->on(ReportForm::ON_SUCCESS, function (ReportForm $form) { + Notification::success($this->translate('Created report successfully')); - $this->redirectForm($form, 'reporting/reports'); + $pressedButton = $form->getPressedSubmitElement(); + if ($pressedButton && $pressedButton->getName() !== 'create_show') { + $this->closeModalAndRefreshRelatedView(Url::fromPath('reporting/reports')); + } else { + $this->redirectNow( + Url::fromPath( + sprintf( + 'reporting/reports#!%s', + Url::fromPath('reporting/report', ['id' => $form->getId()])->getAbsoluteUrl() + ) + ) + ); + } + }) + ->handleRequest($this->getServerRequest()); $this->addContent($form); } |