Skip to content

Commit 15afc4c

Browse files
ContactsController: Show add channel link if no channel exists
- ChannelsContoller: Closing the container is sufficient.
1 parent b2df1bd commit 15afc4c

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

application/controllers/ChannelsController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public function addAction()
112112
$form->getValue('name')
113113
)
114114
);
115-
$this->redirectNow(Links::channels());
115+
$this->redirectNow('__CLOSE__');
116116
})
117117
->handleRequest($this->getServerRequest());
118118

application/controllers/ContactsController.php

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@
55
namespace Icinga\Module\Notifications\Controllers;
66

77
use Icinga\Module\Notifications\Common\Links;
8+
use Icinga\Module\Notifications\Model\Channel;
89
use Icinga\Module\Notifications\View\ContactRenderer;
910
use Icinga\Module\Notifications\Web\Control\SearchBar\ObjectSuggestions;
1011
use Icinga\Module\Notifications\Common\Database;
1112
use Icinga\Module\Notifications\Model\Contact;
1213
use Icinga\Module\Notifications\Web\Form\ContactForm;
1314
use Icinga\Module\Notifications\Widget\ItemList\ObjectList;
1415
use Icinga\Web\Notification;
16+
use ipl\Html\HtmlElement;
17+
use ipl\Html\TemplateString;
1518
use ipl\Sql\Connection;
1619
use ipl\Stdlib\Filter;
1720
use ipl\Web\Compat\CompatController;
@@ -20,6 +23,7 @@
2023
use ipl\Web\Control\SortControl;
2124
use ipl\Web\Filter\QueryString;
2225
use ipl\Web\Layout\MinimalItemLayout;
26+
use ipl\Web\Widget\ActionLink;
2327
use ipl\Web\Widget\ButtonLink;
2428

2529
class ContactsController extends CompatController
@@ -79,15 +83,43 @@ public function indexAction()
7983
$this->addControl($sortControl);
8084
$this->addControl($limitControl);
8185
$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-
);
86+
87+
$addButton = (new ButtonLink(
88+
t('Add Contact'),
89+
Links::contactAdd(),
90+
'plus',
91+
['class' => 'add-new-component']
92+
))->setBaseTarget('_next');
93+
94+
$emptyStateMessage = null;
95+
if (! Channel::on($this->db)->columns('1')->first() !== null) {
96+
$addButton
97+
->setDisabled()
98+
->addAttributes(['title' => t('A channel is required to add a contact')]);
99+
100+
$emptyStateMessage = new HtmlElement(
101+
'span',
102+
null,
103+
TemplateString::create(
104+
$this->translate(
105+
'No contacts found. To add a new contact, please {{#link}}configure a Channel{{/link}} first.'
106+
.' A default channel is required for the contact.'
107+
),
108+
['link' => new ActionLink(
109+
null,
110+
Links::channelAdd(),
111+
attributes: ['data-base-target' => '_next']
112+
)]
113+
)
114+
);
115+
}
116+
117+
$this->addContent($addButton);
87118

88119
$this->addContent(
89120
(new ObjectList($contacts, new ContactRenderer()))
90121
->setItemLayoutClass(MinimalItemLayout::class)
122+
->setEmptyStateMessage($emptyStateMessage)
91123
);
92124

93125
if (! $searchBar->hasBeenSubmitted() && $searchBar->hasBeenSent()) {

0 commit comments

Comments
 (0)