Skip to content

Commit b765153

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

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-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->switchToSingleColumnLayout();
116116
})
117117
->handleRequest($this->getServerRequest());
118118

application/controllers/ContactsController.php

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,26 @@
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;
19+
use ipl\Sql\Expression;
1620
use ipl\Stdlib\Filter;
1721
use ipl\Web\Compat\CompatController;
1822
use ipl\Web\Compat\SearchControls;
1923
use ipl\Web\Control\LimitControl;
2024
use ipl\Web\Control\SortControl;
2125
use ipl\Web\Filter\QueryString;
2226
use ipl\Web\Layout\MinimalItemLayout;
27+
use ipl\Web\Widget\ActionLink;
2328
use ipl\Web\Widget\ButtonLink;
2429

2530
class ContactsController extends CompatController
@@ -79,15 +84,36 @@ public function indexAction()
7984
$this->addControl($sortControl);
8085
$this->addControl($limitControl);
8186
$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);
87112

88113
$this->addContent(
89114
(new ObjectList($contacts, new ContactRenderer()))
90115
->setItemLayoutClass(MinimalItemLayout::class)
116+
->setEmptyStateMessage($emptyStateMessage)
91117
);
92118

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

0 commit comments

Comments
 (0)