From c22a2c3ebc334fd7a891370e43a841d914893d47 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 14 Apr 2024 15:29:17 +0200 Subject: Merging upstream version 1.0.1. Signed-off-by: Daniel Baumann --- application/controllers/ReportsController.php | 95 +++++++++++++++++++-------- 1 file changed, 67 insertions(+), 28 deletions(-) (limited to 'application/controllers/ReportsController.php') 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 @@ 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); } -- cgit v1.2.3