Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move source icon in incident detail to the header #181

Merged
merged 4 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion application/controllers/EventController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function indexAction(): void
$id = $this->params->getRequired('id');

$query = Event::on(Database::get())
->with(['object', 'object.source', 'incident', 'incident.object'])
->with(['object', 'object.source', 'incident', 'incident.object', 'incident.object.source'])
->withColumns(['object.id_tags', 'incident.object.id_tags'])
->filter(Filter::equal('event.id', $id));

Expand Down
2 changes: 1 addition & 1 deletion application/controllers/IncidentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function indexAction(): void
$this->addTitleTab(t('Incidents'));

$incidents = Incident::on(Database::get())
->with('object')
->with(['object', 'object.source'])
->withColumns('object.id_tags');

$limitControl = $this->createLimitControl();
Expand Down
1 change: 0 additions & 1 deletion library/Notifications/Widget/Detail/IncidentDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ protected function createHistory()
new IncidentHistoryList(
$this->incident->incident_history
->with([
'incident.object.source',
'contact',
'rule',
'rule_escalation',
Expand Down
raviks789 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
use Icinga\Module\Notifications\Model\Event;
use Icinga\Module\Notifications\Model\IncidentHistory;
use Icinga\Module\Notifications\Widget\IconBall;
use Icinga\Module\Notifications\Widget\SourceIcon;
use ipl\Html\BaseHtmlElement;
use ipl\Web\Common\BaseListItem;
use ipl\Web\Widget\Icon;
use ipl\Web\Widget\TimeAgo;

/**
* Event item of an event list. Represents one database row.
* Incident history item of an incident history list. Represents one database row.
*/
class IncidentHistoryListItem extends BaseListItem
{
Expand Down Expand Up @@ -50,11 +49,6 @@ protected function assembleHeader(BaseHtmlElement $header): void
}

$header->addHtml($this->createCaption());
if ($this->item->type === 'opened' || $this->item->type === 'incident_severity_changed') {
$header->add(
(new SourceIcon(SourceIcon::SIZE_BIG))->addHtml($this->item->incident->object->source->getIcon())
);
}

$header->add(new TimeAgo($this->item->time->getTimestamp()));
}
Expand Down
29 changes: 20 additions & 9 deletions library/Notifications/Widget/ItemList/IncidentListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,27 @@
use Icinga\Module\Notifications\Common\Links;
use Icinga\Module\Notifications\Model\Incident;
use Icinga\Module\Notifications\Model\Objects;
use Icinga\Module\Notifications\Model\Source;
use Icinga\Module\Notifications\Widget\SourceIcon;
use ipl\Html\Attributes;
use ipl\Html\BaseHtmlElement;
use ipl\Html\FormattedString;
use ipl\Html\Html;
use ipl\Html\HtmlElement;
use ipl\I18n\Translation;
use ipl\Web\Common\BaseListItem;
use ipl\Web\Widget\Icon;
use ipl\Web\Widget\Link;
use ipl\Web\Widget\TimeAgo;
use ipl\Web\Widget\TimeSince;

/**
* Event item of an event list. Represents one database row.
* Incident item of an incident list. Represents one database row.
*/
class IncidentListItem extends BaseListItem
{
use Translation;

/** @var Incident The associated list item */
protected $item;

Expand Down Expand Up @@ -73,19 +81,22 @@ protected function assembleTitle(BaseHtmlElement $title): void
protected function assembleHeader(BaseHtmlElement $header): void
{
$header->add($this->createTitle());
$meta = new HtmlElement('span', Attributes::create(['class' => 'meta']));

/** @var Source $source */
$source = $this->item->object->source;
$meta->addHtml((new SourceIcon(SourceIcon::SIZE_BIG))->addHtml($source->getIcon()));

if ($this->item->recovered_at !== null) {
$header->add(Html::tag(
'span',
['class' => 'meta'],
[
'closed ',
new TimeAgo($this->item->recovered_at->getTimestamp())
]
$meta->addHtml(FormattedString::create(
$this->translate('closed %s', '(incident) ... <relative time>'),
new TimeAgo($this->item->recovered_at->getTimestamp())
));
} else {
$header->add(new TimeSince($this->item->started_at->getTimestamp()));
$meta->addHtml(new TimeSince($this->item->started_at->getTimestamp()));
}

$header->addHtml($meta);
}

protected function getSeverityIcon(): string
Expand Down
8 changes: 8 additions & 0 deletions public/css/common.less
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,11 @@
.full-width .add-new-component {
margin: 0 0 1em 1em;
}

.event-list .list-item,
.incident-list .list-item {
.meta .source-icon {
margin-left: auto;
margin-right: 0.5em;
}
}
Loading