77use Icinga \Module \Notifications \Common \Database ;
88use Icinga \Module \Notifications \Common \Links ;
99use Icinga \Module \Notifications \Forms \ContactGroupForm ;
10+ use Icinga \Module \Notifications \Model \Channel ;
11+ use Icinga \Module \Notifications \Model \Contact ;
1012use Icinga \Module \Notifications \Model \Contactgroup ;
1113use Icinga \Module \Notifications \View \ContactgroupRenderer ;
1214use Icinga \Module \Notifications \Web \Control \SearchBar \ObjectSuggestions ;
1315use Icinga \Module \Notifications \Widget \ItemList \ObjectList ;
1416use Icinga \Module \Notifications \Widget \MemberSuggestions ;
1517use Icinga \Web \Notification ;
1618use ipl \Html \Form ;
17- use ipl \Html \Text ;
19+ use ipl \Html \HtmlString ;
20+ use ipl \Html \TemplateString ;
1821use ipl \Stdlib \Filter ;
1922use ipl \Web \Compat \CompatController ;
2023use ipl \Web \Compat \SearchControls ;
2124use ipl \Web \Control \LimitControl ;
2225use ipl \Web \Control \SortControl ;
2326use ipl \Web \Filter \QueryString ;
2427use ipl \Web \Layout \MinimalItemLayout ;
28+ use ipl \Web \Widget \ActionLink ;
2529use ipl \Web \Widget \ButtonLink ;
2630use ipl \Web \Widget \Tabs ;
2731
@@ -46,8 +50,8 @@ public function indexAction(): void
4650 $ sortControl = $ this ->createSortControl (
4751 $ groups ,
4852 [
49- 'name ' => t ('Group Name ' ),
50- 'changed_at ' => t ('Changed At ' )
53+ 'name ' => $ this -> translate ('Group Name ' ),
54+ 'changed_at ' => $ this -> translate ('Changed At ' )
5155 ]
5256 );
5357
@@ -78,25 +82,54 @@ public function indexAction(): void
7882 $ this ->addControl ($ sortControl );
7983 $ this ->addControl ($ limitControl );
8084 $ 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 ()
85+
86+ $ addButton = new ButtonLink (
87+ $ this ->translate ('Add Contact Group ' ),
88+ Links::contactGroupsAdd ()->with (['showCompact ' => true , '_disableLayout ' => 1 ]),
89+ 'plus ' ,
90+ ['class ' => 'add-new-component ' ]
8891 );
8992
93+ $ emptyStateMessage = null ;
94+ if (Contact::on (Database::get ())->columns ('1 ' )->limit (1 )->first () === null ) {
95+ if (Channel::on (Database::get ())->columns ('1 ' )->limit (1 )->first () === null ) {
96+ $ addButton ->disable ($ this ->translate ('A channel is required to add a contact group ' ));
97+
98+ $ emptyStateMessage = TemplateString::create (
99+ // translators: %1$s will be replaced by a line break
100+ 'No contact groups found.%1$sTo add new contact group, please {{#link}}configure a Channel{{/link}} '
101+ . ' first.%1$sOnce done, you should proceed by creating your first contact. ' ,
102+ ['link ' => (new ActionLink (null , Links::channelAdd ()))->setBaseTarget ('_next ' )],
103+ [HtmlString::create ('<br> ' )]
104+ );
105+ } else {
106+ $ emptyStateMessage = TemplateString::create (
107+ $ this ->translate (
108+ 'No contact groups found. Do not forget to also '
109+ . ' {{#link}}create your first contact!{{/link}} '
110+ ),
111+ ['link ' => (new ActionLink (null , Links::contactAdd ()))->setBaseTarget ('_next ' )]
112+ );
113+
114+ $ addButton ->openInModal ();
115+ }
116+ } else {
117+ $ addButton ->openInModal ();
118+ }
119+
120+ $ this ->addContent ($ addButton );
121+
90122 $ this ->addContent (
91123 (new ObjectList ($ groups , new ContactgroupRenderer ()))
92124 ->setItemLayoutClass (MinimalItemLayout::class)
125+ ->setEmptyStateMessage ($ emptyStateMessage )
93126 );
94127
95128 if (! $ searchBar ->hasBeenSubmitted () && $ searchBar ->hasBeenSent ()) {
96129 $ this ->sendMultipartUpdate ();
97130 }
98131
99- $ this ->setTitle (t ('Contact Groups ' ));
132+ $ this ->setTitle ($ this -> translate ('Contact Groups ' ));
100133 $ this ->getTabs ()->activate ('contact-groups ' );
101134 }
102135
@@ -118,15 +151,15 @@ public function addAction(): void
118151 ->on (Form::ON_SUCCESS , function (ContactGroupForm $ form ) {
119152 $ groupIdentifier = $ form ->addGroup ();
120153
121- Notification::success (t ('New contact group has been successfully added ' ));
154+ Notification::success ($ this -> translate ('New contact group has been successfully added ' ));
122155 $ this ->sendExtraUpdates (['#col1 ' ]);
123156 $ this ->getResponse ()->setHeader ('X-Icinga-Container ' , 'col2 ' );
124157 $ this ->redirectNow (Links::contactGroup ($ groupIdentifier ));
125158 })
126159 ->handleRequest ($ this ->getServerRequest ());
127160
128161 $ this ->addContent ($ form );
129- $ this ->setTitle (t ('Add Contact Group ' ));
162+ $ this ->setTitle ($ this -> translate ('Add Contact Group ' ));
130163 }
131164
132165 public function completeAction (): void
@@ -163,19 +196,19 @@ public function getTabs(): Tabs
163196 {
164197 return parent ::getTabs ()
165198 ->add ('schedules ' , [
166- 'label ' => t ('Schedules ' ),
199+ 'label ' => $ this -> translate ('Schedules ' ),
167200 'url ' => Links::schedules (),
168201 'baseTarget ' => '_main '
169202 ])->add ('event-rules ' , [
170- 'label ' => t ('Event Rules ' ),
203+ 'label ' => $ this -> translate ('Event Rules ' ),
171204 'url ' => Links::eventRules (),
172205 'baseTarget ' => '_main '
173206 ])->add ('contacts ' , [
174- 'label ' => t ('Contacts ' ),
207+ 'label ' => $ this -> translate ('Contacts ' ),
175208 'url ' => Links::contacts (),
176209 'baseTarget ' => '_main '
177210 ])->add ('contact-groups ' , [
178- 'label ' => t ('Contact Groups ' ),
211+ 'label ' => $ this -> translate ('Contact Groups ' ),
179212 'url ' => Links::contactGroups (),
180213 'baseTarget ' => '_main '
181214 ]);
0 commit comments