summaryrefslogtreecommitdiffstats
path: root/application/controllers/ReportsController.php
diff options
context:
space:
mode:
Diffstat (limited to 'application/controllers/ReportsController.php')
-rw-r--r--application/controllers/ReportsController.php95
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);
}