Merge pull request #3748 from Icinga/feature/sortable-announcements-page-3414
Sortable announcements page
This commit is contained in:
commit
0be1053197
|
@ -27,10 +27,26 @@ class AnnouncementsController extends Controller
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$repo = new AnnouncementIniRepository();
|
$announcements = (new AnnouncementIniRepository())
|
||||||
$this->view->announcements = $repo
|
->select([
|
||||||
->select(array('id', 'author', 'message', 'start', 'end'))
|
'id',
|
||||||
->order('start', 'DESC');
|
'author',
|
||||||
|
'message',
|
||||||
|
'start',
|
||||||
|
'end'
|
||||||
|
]);
|
||||||
|
|
||||||
|
$sortAndFilterColumns = [
|
||||||
|
'author' => $this->translate('Author'),
|
||||||
|
'message' => $this->translate('Message'),
|
||||||
|
'start' => $this->translate('Start'),
|
||||||
|
'end' => $this->translate('End')
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->setupSortControl($sortAndFilterColumns, $announcements, ['start' => 'desc']);
|
||||||
|
$this->setupFilterControl($announcements, $sortAndFilterColumns, ['message']);
|
||||||
|
|
||||||
|
$this->view->announcements = $announcements->fetchAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -13,6 +13,21 @@ use Icinga\Forms\RepositoryForm;
|
||||||
*/
|
*/
|
||||||
class AnnouncementForm extends RepositoryForm
|
class AnnouncementForm extends RepositoryForm
|
||||||
{
|
{
|
||||||
|
protected function fetchEntry()
|
||||||
|
{
|
||||||
|
$entry = parent::fetchEntry();
|
||||||
|
if ($entry !== false) {
|
||||||
|
if ($entry->start !== null) {
|
||||||
|
$entry->start = (new DateTime())->setTimestamp($entry->start);
|
||||||
|
}
|
||||||
|
if ($entry->end !== null) {
|
||||||
|
$entry->end = (new DateTime())->setTimestamp($entry->end);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $entry;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,6 +1,12 @@
|
||||||
<?php if (! $compact): ?>
|
<?php if (! $this->compact): ?>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<?= $tabs ?>
|
<?= $this->tabs ?>
|
||||||
|
<?= $this->paginator ?>
|
||||||
|
<div class="sort-controls-container">
|
||||||
|
<?= $this->limiter ?>
|
||||||
|
<?= $this->sortBox ?>
|
||||||
|
</div>
|
||||||
|
<?= $this->filterEditor ?>
|
||||||
</div>
|
</div>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
|
@ -17,7 +23,7 @@
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
} ?>
|
} ?>
|
||||||
<?php if (! $announcements->hasResult()): ?>
|
<?php if (empty($this->announcements)): ?>
|
||||||
<p><?= $this->translate('No announcements found.') ?></p>
|
<p><?= $this->translate('No announcements found.') ?></p>
|
||||||
</div>
|
</div>
|
||||||
<?php return; endif ?>
|
<?php return; endif ?>
|
||||||
|
@ -32,7 +38,7 @@
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<?php foreach ($announcements as $announcement): /** @var object $announcement */ ?>
|
<?php foreach ($this->announcements as $announcement): /** @var object $announcement */ ?>
|
||||||
<?php if ($this->hasPermission('admin')): ?>
|
<?php if ($this->hasPermission('admin')): ?>
|
||||||
<tr href="<?= $this->href('announcements/update', array('id' => $announcement->id)) ?>">
|
<tr href="<?= $this->href('announcements/update', array('id' => $announcement->id)) ?>">
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
|
@ -40,8 +46,8 @@
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
<td><?= $this->escape($announcement->author) ?></td>
|
<td><?= $this->escape($announcement->author) ?></td>
|
||||||
<td><?= $this->ellipsis($this->escape($announcement->message), 100) ?></td>
|
<td><?= $this->ellipsis($this->escape($announcement->message), 100) ?></td>
|
||||||
<td><?= $this->formatDateTime($announcement->start->getTimestamp()) ?></td>
|
<td><?= $this->formatDateTime($announcement->start) ?></td>
|
||||||
<td><?= $this->formatDateTime($announcement->end->getTimestamp()) ?></td>
|
<td><?= $this->formatDateTime($announcement->end) ?></td>
|
||||||
<?php if ($this->hasPermission('admin')): ?>
|
<?php if ($this->hasPermission('admin')): ?>
|
||||||
<td class="icon-col"><?= $this->qlink(
|
<td class="icon-col"><?= $this->qlink(
|
||||||
null,
|
null,
|
||||||
|
|
|
@ -365,13 +365,11 @@ class SimpleQuery implements QueryInterface, Queryable, Iterator
|
||||||
}
|
}
|
||||||
|
|
||||||
$column = $this->order[$orderIndex][0];
|
$column = $this->order[$orderIndex][0];
|
||||||
if (array_key_exists($column, $this->flippedColumns)) {
|
if (array_key_exists($column, $this->flippedColumns) && is_string($this->flippedColumns[$column])) {
|
||||||
$column = $this->flippedColumns[$column];
|
$column = $this->flippedColumns[$column];
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: throw Exception if column is missing
|
$result = strcmp(strtolower($a->$column), strtolower($b->$column));
|
||||||
//$res = strnatcmp(strtolower($a->$column), strtolower($b->$column));
|
|
||||||
$result = @strcmp(strtolower($a->$column), strtolower($b->$column));
|
|
||||||
if ($result === 0) {
|
if ($result === 0) {
|
||||||
return $this->compare($a, $b, ++$orderIndex);
|
return $this->compare($a, $b, ++$orderIndex);
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,25 +30,6 @@ class AnnouncementIniRepository extends IniRepository
|
||||||
'end' => 'timestamp'
|
'end' => 'timestamp'
|
||||||
));
|
));
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a DateTime from a timestamp
|
|
||||||
*
|
|
||||||
* @param string $timestamp
|
|
||||||
*
|
|
||||||
* @return DateTime|null
|
|
||||||
*/
|
|
||||||
protected function retrieveTimestamp($timestamp)
|
|
||||||
{
|
|
||||||
if ($timestamp !== null) {
|
|
||||||
$dateTime = new DateTime();
|
|
||||||
$dateTime->setTimestamp($timestamp);
|
|
||||||
|
|
||||||
return $dateTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a DateTime's timestamp
|
* Get a DateTime's timestamp
|
||||||
*
|
*
|
||||||
|
@ -157,7 +138,7 @@ class AnnouncementIniRepository extends IniRepository
|
||||||
$refresh = null;
|
$refresh = null;
|
||||||
|
|
||||||
foreach ($query as $row) {
|
foreach ($query as $row) {
|
||||||
$min = min($row->start->getTimestamp(), $row->end->getTimestamp());
|
$min = min($row->start, $row->end);
|
||||||
|
|
||||||
if ($refresh === null) {
|
if ($refresh === null) {
|
||||||
$refresh = $min;
|
$refresh = $min;
|
||||||
|
|
Loading…
Reference in New Issue