Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
sukhwinder33445 committed Oct 6, 2023
1 parent 723d360 commit bdaa5a6
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 41 deletions.
42 changes: 42 additions & 0 deletions library/Notifications/Model/ObjectIdTag.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/* Icinga Notifications Web | (c) 2023 Icinga GmbH | GPLv2 */

namespace Icinga\Module\Notifications\Model;

use ipl\Orm\Behavior\Binary;
use ipl\Orm\Behaviors;
use ipl\Orm\Model;
use ipl\Orm\Relations;

class ObjectIdTag extends Model
{
public function getTableName(): string
{
return 'object_id_tag';
}

public function getKeyName(): array
{
return ['object_id', 'tag'];
}

public function getColumns(): array
{
return [
'object_id',
'tag',
'value'
];
}

public function createBehaviors(Behaviors $behaviors): void
{
$behaviors->add(new Binary(['object_id']));
}

public function createRelations(Relations $relations): void
{
$relations->belongsTo('object', Objects::class);
}
}
32 changes: 20 additions & 12 deletions library/Notifications/Model/Objects.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,19 @@ public function getColumns()
{
return [
'source_id',
'host',
'service',
'name',
'url'
];
}

public function getColumnDefinitions()
{
return [
'host' => t('Host Name'),
'service' => t('Service Name')
];
}

public function getSearchColumns()
{
return ['host', 'service'];
return ['tag', 'value'];
}

public function getDefaultSort()
{
return 'object.host';
return 'object.value';
}

public function createBehaviors(Behaviors $behaviors)
Expand All @@ -60,7 +50,25 @@ public function createRelations(Relations $relations)
$relations->hasMany('event', Event::class);
$relations->hasMany('incident', Incident::class);
$relations->belongsTo('source', Source::class);
$relations->hasMany('object_id_tag', ObjectIdTag::class);
$relations->hasMany('object_extra_tag', ObjectExtraTag::class)
->setJoinType('LEFT');
}

//TODO: Just a temporary solution to avoid changing code everywhere.
// This must be done with hooks, remove once hooks are available
public function getHostAndService(): array
{
$hostName = null;
$serviceName = null;
foreach ($this->object_id_tag as $id_tag) {
if ($id_tag->tag === 'host') {
$hostName = sprintf('host=%s', $id_tag->value);
} else {
$serviceName = sprintf('service=%s', $id_tag->value);
}
}

return [$hostName, $serviceName];
}
}
11 changes: 6 additions & 5 deletions library/Notifications/Widget/Detail/EventDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,14 @@ protected function createRelatedObject(): array
{
//TODO(sd): This is just placeholder. Add hook implementation instead
$relatedObj = Html::tag('ul', ['class' => ['item-list', 'action-list'], 'data-base-target' => '_next']);
$obj = new Link($this->event->object->host, $this->event->object->url, ['class' => 'subject']);
[$hostName, $serviceName] = $this->event->object->getHostAndService();
$obj = new Link($hostName, $this->event->object->url, ['class' => 'subject']);

if ($this->event->object->service) {
if ($serviceName) {
$obj = Html::sprintf(
t('%s on %s', '<service> on <host>'),
$obj->setContent($this->event->object->service),
Html::tag('span', ['class' => 'subject'], $this->event->object->host)
t('%s : %s'),
$obj->setContent($serviceName),
Html::tag('span', ['class' => 'subject'], $hostName)
);
}

Expand Down
11 changes: 6 additions & 5 deletions library/Notifications/Widget/Detail/IncidentDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,16 @@ protected function createRelatedObject()
{
//TODO(sd): Add hook implementation
$list = Html::tag('ul', ['class' => ['item-list', 'minimal', 'action-list'], 'data-base-target' => '_next']);
[$hostName, $serviceName] = $this->incident->object->getHostAndService();

if ($this->incident->object->service) {
if ($serviceName) {
$objectLink = Html::sprintf(
t('%s on %s', '<service> on <host>'),
new Link($this->incident->object->service, $this->incident->object->url, ['class' => 'subject']),
Html::tag('span', ['class' => 'subject'], $this->incident->object->host)
t('%s : %s'),
new Link($serviceName, $this->incident->object->url, ['class' => 'subject']),
Html::tag('span', ['class' => 'subject'], $hostName)
);
} else {
$objectLink = new Link($this->incident->object->host, $this->incident->object->url, ['class' => 'subject']);
$objectLink = new Link($hostName, $this->incident->object->url, ['class' => 'subject']);
}

$list->add(Html::tag(
Expand Down
18 changes: 8 additions & 10 deletions library/Notifications/Widget/ItemList/EventListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,19 @@ protected function assembleTitle(BaseHtmlElement $title): void
$title->addHtml(Html::tag('span', [], sprintf('#%d:', $this->item->incident->id)));
}

[$hostName, $serviceName] = $this->item->object->getHostAndService();

if (! $this->list->getNoSubjectLink()) {
$content = new Link(
$this->item->object->host,
Links::event($this->item->id),
['class' => 'subject']
);
$content = new Link($hostName, Links::event($this->item->id), ['class' => 'subject']);
} else {
$content = Html::tag('span', ['class' => 'subject'], $this->item->object->host);
$content = Html::tag('span', ['class' => 'subject'], $hostName);
}

if ($this->item->object->service) {
if ($serviceName) {
$content = Html::sprintf(
t('%s on %s', '<service> on <host>'),
$content->setContent($this->item->object->service),
Html::tag('span', ['class' => 'subject'], $this->item->object->host)
t('%s:%s'),
$content->setContent($serviceName),
Html::tag('span', ['class' => 'subject'], $hostName)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,20 @@ protected function assembleTitle(BaseHtmlElement $title): void
$this->getAttributes()
->set('data-action-item', true);

if ($event->object->service) {
[$hostName, $serviceName] = $event->object->getHostAndService();
if ($serviceName) {
$content = Html::sprintf(
t('%s on %s', '<service> on <host>'),
t('%s : %s'),
new Link(
$event->object->service,
$serviceName,
Links::event($this->item->event_id),
['class' => 'subject']
),
Html::tag('span', ['class' => 'subject'], $event->object->host)
Html::tag('span', ['class' => 'subject'], $hostName)
);
} else {
$content = new Link(
$event->object->host,
$hostName,
Links::event($this->item->event_id),
['class' => 'subject']
);
Expand Down
10 changes: 6 additions & 4 deletions library/Notifications/Widget/ItemList/IncidentListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ protected function assembleVisual(BaseHtmlElement $visual): void
protected function assembleTitle(BaseHtmlElement $title): void
{
$title->addHtml(Html::tag('span', [], sprintf('#%d:', $this->item->id)));
$subject = $this->item->object->service ?? $this->item->object->host;
[$hostName, $serviceName] = $this->item->object->getHostAndService();

$subject = $serviceName ?? $hostName;
if (! $this->list->getNoSubjectLink()) {
$content = new Link(
$subject,
Expand All @@ -63,11 +65,11 @@ protected function assembleTitle(BaseHtmlElement $title): void
);
}

if ($this->item->object->service) {
if ($serviceName) {
$content = Html::sprintf(
t('%s on %s', '<service> on <host>'),
t('%s : %s'),
$content,
Html::tag('span', ['class' => 'subject'], $this->item->object->host)
Html::tag('span', ['class' => 'subject'], $hostName)
);
}

Expand Down

0 comments on commit bdaa5a6

Please sign in to comment.