|
5 | 5 | namespace Icinga\Module\Notifications\Controllers; |
6 | 6 |
|
7 | 7 | use Icinga\Module\Notifications\Common\Links; |
| 8 | +use Icinga\Module\Notifications\Model\Channel; |
8 | 9 | use Icinga\Module\Notifications\View\ContactRenderer; |
9 | 10 | use Icinga\Module\Notifications\Web\Control\SearchBar\ObjectSuggestions; |
10 | 11 | use Icinga\Module\Notifications\Common\Database; |
11 | 12 | use Icinga\Module\Notifications\Model\Contact; |
12 | 13 | use Icinga\Module\Notifications\Web\Form\ContactForm; |
13 | 14 | use Icinga\Module\Notifications\Widget\ItemList\ObjectList; |
14 | 15 | use Icinga\Web\Notification; |
| 16 | +use ipl\Html\HtmlElement; |
| 17 | +use ipl\Html\TemplateString; |
15 | 18 | use ipl\Sql\Connection; |
| 19 | +use ipl\Sql\Expression; |
16 | 20 | use ipl\Stdlib\Filter; |
17 | 21 | use ipl\Web\Compat\CompatController; |
18 | 22 | use ipl\Web\Compat\SearchControls; |
19 | 23 | use ipl\Web\Control\LimitControl; |
20 | 24 | use ipl\Web\Control\SortControl; |
21 | 25 | use ipl\Web\Filter\QueryString; |
22 | 26 | use ipl\Web\Layout\MinimalItemLayout; |
| 27 | +use ipl\Web\Widget\ActionLink; |
23 | 28 | use ipl\Web\Widget\ButtonLink; |
24 | 29 |
|
25 | 30 | class ContactsController extends CompatController |
@@ -79,15 +84,36 @@ public function indexAction() |
79 | 84 | $this->addControl($sortControl); |
80 | 85 | $this->addControl($limitControl); |
81 | 86 | $this->addControl($searchBar); |
82 | | - $this->addContent( |
83 | | - (new ButtonLink(t('Add Contact'), Links::contactAdd(), 'plus')) |
84 | | - ->setBaseTarget('_next') |
85 | | - ->addAttributes(['class' => 'add-new-component']) |
86 | | - ); |
| 87 | + |
| 88 | + $addButton = (new ButtonLink( |
| 89 | + t('Add Contact'), |
| 90 | + Links::contactAdd(), |
| 91 | + 'plus', |
| 92 | + ['class' => 'add-new-component'] |
| 93 | + ))->setBaseTarget('_next'); |
| 94 | + |
| 95 | + $emptyStateMessage = null; |
| 96 | + if (Channel::on($this->db)->columns([new Expression('1')])->first() === null) { |
| 97 | + $addButton->disable(t('A channel is required to add a contact')); |
| 98 | + |
| 99 | + $emptyStateMessage = new HtmlElement( |
| 100 | + 'span', |
| 101 | + null, |
| 102 | + TemplateString::create( |
| 103 | + $this->translate( |
| 104 | + 'No contacts found. To add a new contact, please {{#link}}configure a Channel{{/link}} first.' |
| 105 | + ), |
| 106 | + ['link' => new ActionLink(null, Links::channelAdd(), attributes: ['data-base-target' => '_next'])] |
| 107 | + ) |
| 108 | + ); |
| 109 | + } |
| 110 | + |
| 111 | + $this->addContent($addButton); |
87 | 112 |
|
88 | 113 | $this->addContent( |
89 | 114 | (new ObjectList($contacts, new ContactRenderer())) |
90 | 115 | ->setItemLayoutClass(MinimalItemLayout::class) |
| 116 | + ->setEmptyStateMessage($emptyStateMessage) |
91 | 117 | ); |
92 | 118 |
|
93 | 119 | if (! $searchBar->hasBeenSubmitted() && $searchBar->hasBeenSent()) { |
|
0 commit comments