summaryrefslogtreecommitdiffstats
path: root/application/controllers/TimeframesController.php
diff options
context:
space:
mode:
Diffstat (limited to 'application/controllers/TimeframesController.php')
-rw-r--r--application/controllers/TimeframesController.php61
1 files changed, 39 insertions, 22 deletions
diff --git a/application/controllers/TimeframesController.php b/application/controllers/TimeframesController.php
index 505d8d9..f38c661 100644
--- a/application/controllers/TimeframesController.php
+++ b/application/controllers/TimeframesController.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\TimeframeForm;
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 TimeframesController extends Controller
{
- use Database;
use ReportsTimeframesAndTemplatesTabs;
public function indexAction()
@@ -26,42 +26,56 @@ class TimeframesController extends Controller
$canManage = $this->hasPermission('reporting/timeframes');
if ($canManage) {
- $this->addControl(new ButtonLink(
- $this->translate('New Timeframe'),
- Url::fromPath('reporting/timeframes/new'),
- 'plus'
- ));
+ $this->addControl(
+ (new ButtonLink(
+ $this->translate('New Timeframe'),
+ Url::fromPath('reporting/timeframes/new'),
+ 'plus'
+ ))->openInModal()
+ );
}
$tableRows = [];
- $select = (new Select())
- ->from('timeframe t')
- ->columns('*');
+ $timeframes = Model\Timeframe::on(Database::get());
+
+ $sortControl = $this->createSortControl(
+ $timeframes,
+ [
+ 'name' => $this->translate('Name'),
+ 'ctime' => $this->translate('Created At'),
+ 'mtime' => $this->translate('Modified At')
+ ]
+ );
- foreach ($this->getDb()->select($select) as $timeframe) {
+ $this->addControl($sortControl);
+
+ foreach ($timeframes as $timeframe) {
$subject = $timeframe->name;
if ($canManage) {
- $subject = new Link($timeframe->name, Url::fromPath(
- 'reporting/timeframe/edit',
- ['id' => $timeframe->id]
- ));
+ $subject = new Link(
+ $timeframe->name,
+ Url::fromPath('reporting/timeframe/edit', ['id' => $timeframe->id])
+ );
}
$tableRows[] = Html::tag('tr', null, [
Html::tag('td', null, $subject),
Html::tag('td', null, $timeframe->start),
Html::tag('td', null, $timeframe->end),
- Html::tag('td', null, date('Y-m-d H:i', $timeframe->ctime / 1000)),
- Html::tag('td', null, date('Y-m-d H:i', $timeframe->mtime / 1000))
+ Html::tag('td', null, $timeframe->ctime->format('Y-m-d H:i')),
+ Html::tag('td', null, $timeframe->mtime->format('Y-m-d H:i'))
]);
}
if (! empty($tableRows)) {
$table = Html::tag(
'table',
- ['class' => 'common-table table-row-selectable', 'data-base-target' => '_next'],
+ [
+ 'class' => 'common-table table-row-selectable',
+ 'data-base-target' => '_next'
+ ],
[
Html::tag(
'thead',
@@ -93,10 +107,13 @@ class TimeframesController extends Controller
$this->assertPermission('reporting/timeframes');
$this->addTitleTab($this->translate('New Timeframe'));
- $form = new TimeframeForm();
- $form->handleRequest(ServerRequest::fromGlobals());
+ $form = (new TimeframeForm())
+ ->setAction((string) Url::fromRequest())
+ ->on(TimeframeForm::ON_SUCCESS, function () {
+ Notification::success($this->translate('Created timeframe successfully'));
- $this->redirectForm($form, 'reporting/timeframes');
+ $this->closeModalAndRefreshRelatedView(Url::fromPath('reporting/timeframes'));
+ })->handleRequest($this->getServerRequest());
$this->addContent($form);
}