Skip to content

Commit

Permalink
ContactListItem: Add icon for webhook
Browse files Browse the repository at this point in the history
  • Loading branch information
raviks789 committed Jun 20, 2024
1 parent ba627b4 commit eb16dfd
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion application/controllers/ContactsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function init()
public function indexAction()
{
$contacts = Contact::on($this->db)
->withColumns('has_email');
->withColumns(['has_email', 'has_webhook']);

$limitControl = $this->createLimitControl();
$paginationControl = $this->createPaginationControl($contacts);
Expand Down
4 changes: 4 additions & 0 deletions library/Notifications/Common/Icons.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,8 @@ private function __construct()
public const RULE_MATCHED = 'filter';

public const UNDEFINED = 'notdef';

public const EMAIL = 'at';

public const WEBHOOK = 'link';
}
10 changes: 6 additions & 4 deletions library/Notifications/Model/Behavior/HasAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function setQuery(Query $query)
public function rewriteColumn($column, ?string $relation = null)
{
if ($this->isSelectableColumn($column)) {
$type = 'email';
$type = $column === 'has_email' ? 'email' : 'webhook';

$subQueryRelation = $relation !== null ? $relation . '.contact.contact_address' : 'contact.contact_address';

Expand All @@ -53,15 +53,17 @@ public function rewriteColumn($column, ?string $relation = null)

public function isSelectableColumn(string $name): bool
{
return $name === 'has_email';
return $name === 'has_email' || $name === 'has_webhook';
}

public function rewriteColumnDefinition(ColumnDefinition $def, string $relation): void
{
$name = $def->getName();

if ($this->isSelectableColumn($name)) {
$def->setLabel(t('Has Email Address'));
$def->setLabel(
$name === 'has_email' ? t('Has Email Address') : t('Has Webhook')
);
}
}

Expand All @@ -70,7 +72,7 @@ public function rewriteCondition(Filter\Condition $condition, $relation = null)
$column = substr($condition->getColumn(), strlen($relation));

if ($this->isSelectableColumn($column)) {
$type = 'email';
$type = $column === 'has_email' ? 'email' : 'webhook';

$subQuery = $this->query->createSubQuery(new ContactAddress(), $relation)
->limit(1)
Expand Down
7 changes: 6 additions & 1 deletion library/Notifications/Widget/ItemList/ContactListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Icinga\Module\Notifications\Widget\ItemList;

use Icinga\Module\Notifications\Common\Icons;
use Icinga\Module\Notifications\Model\Contact;
use ipl\Html\Attributes;
use ipl\Html\BaseHtmlElement;
Expand Down Expand Up @@ -45,7 +46,11 @@ protected function assembleFooter(BaseHtmlElement $footer): void
$contactIcons = new HtmlElement('div', Attributes::create(['class' => 'contact-icons']));

if (isset($this->item->has_email) && $this->item->has_email) {
$contactIcons->addHtml(new Icon('at'));
$contactIcons->addHtml(new Icon(Icons::EMAIL));
}

if (isset($this->item->has_webhook) && $this->item->has_webhook) {
$contactIcons->addHtml(new Icon(Icons::WEBHOOK));
}

$footer->addHtml($contactIcons);
Expand Down

0 comments on commit eb16dfd

Please sign in to comment.