|
7 | 7 | use Icinga\Module\Notifications\Common\Database;
|
8 | 8 | use Icinga\Module\Notifications\Common\Links;
|
9 | 9 | use Icinga\Module\Notifications\Forms\ContactGroupForm;
|
| 10 | +use Icinga\Module\Notifications\Model\Contact; |
10 | 11 | use Icinga\Module\Notifications\Model\Contactgroup;
|
11 | 12 | use Icinga\Module\Notifications\View\ContactgroupRenderer;
|
12 | 13 | use Icinga\Module\Notifications\Web\Control\SearchBar\ObjectSuggestions;
|
13 | 14 | use Icinga\Module\Notifications\Widget\ItemList\ObjectList;
|
14 | 15 | use Icinga\Module\Notifications\Widget\MemberSuggestions;
|
15 | 16 | use Icinga\Web\Notification;
|
16 | 17 | use ipl\Html\Form;
|
17 |
| -use ipl\Html\Text; |
| 18 | +use ipl\Html\HtmlElement; |
| 19 | +use ipl\Html\TemplateString; |
18 | 20 | use ipl\Stdlib\Filter;
|
19 | 21 | use ipl\Web\Compat\CompatController;
|
20 | 22 | use ipl\Web\Compat\SearchControls;
|
21 | 23 | use ipl\Web\Control\LimitControl;
|
22 | 24 | use ipl\Web\Control\SortControl;
|
23 | 25 | use ipl\Web\Filter\QueryString;
|
24 | 26 | use ipl\Web\Layout\MinimalItemLayout;
|
| 27 | +use ipl\Web\Widget\ActionLink; |
25 | 28 | use ipl\Web\Widget\ButtonLink;
|
26 | 29 | use ipl\Web\Widget\Tabs;
|
27 | 30 |
|
@@ -78,18 +81,44 @@ public function indexAction(): void
|
78 | 81 | $this->addControl($sortControl);
|
79 | 82 | $this->addControl($limitControl);
|
80 | 83 | $this->addControl($searchBar);
|
81 |
| - $this->addContent( |
82 |
| - (new ButtonLink( |
83 |
| - Text::create(t('Add Contact Group')), |
84 |
| - Links::contactGroupsAdd()->with(['showCompact' => true, '_disableLayout' => 1]), |
85 |
| - 'plus', |
86 |
| - ['class' => 'add-new-component'] |
87 |
| - ))->openInModal() |
| 84 | + |
| 85 | + $addButton = new ButtonLink( |
| 86 | + t('Add Contact Group'), |
| 87 | + Links::contactGroupsAdd()->with(['showCompact' => true, '_disableLayout' => 1]), |
| 88 | + 'plus', |
| 89 | + ['class' => 'add-new-component'] |
88 | 90 | );
|
89 | 91 |
|
| 92 | + $emptyStateMessage = null; |
| 93 | + if (Contact::on(Database::get())->columns('1')->first() === null) { |
| 94 | + $addButton |
| 95 | + ->setDisabled() |
| 96 | + ->addAttributes(['title' => t('A contact is required to add a contact group')]); |
| 97 | + |
| 98 | + $emptyStateMessage = new HtmlElement( |
| 99 | + 'span', |
| 100 | + null, |
| 101 | + TemplateString::create( |
| 102 | + $this->translate( |
| 103 | + 'No contacts found. To add a new contact group, please {{#link}}add a Contact{{/link}} first.' |
| 104 | + ), |
| 105 | + ['link' => new ActionLink( |
| 106 | + null, |
| 107 | + Links::contactAdd(), |
| 108 | + attributes: ['data-base-target' => '_next'] |
| 109 | + )] |
| 110 | + ) |
| 111 | + ); |
| 112 | + } else { |
| 113 | + $addButton->openInModal(); |
| 114 | + } |
| 115 | + |
| 116 | + $this->addContent($addButton); |
| 117 | + |
90 | 118 | $this->addContent(
|
91 | 119 | (new ObjectList($groups, new ContactgroupRenderer()))
|
92 | 120 | ->setItemLayoutClass(MinimalItemLayout::class)
|
| 121 | + ->setEmptyStateMessage($emptyStateMessage) |
93 | 122 | );
|
94 | 123 |
|
95 | 124 | if (! $searchBar->hasBeenSubmitted() && $searchBar->hasBeenSent()) {
|
|
0 commit comments