99use Icinga \Module \Notifications \Model \IncidentHistory ;
1010use Icinga \Module \Notifications \Widget \IconBall ;
1111use ipl \Html \Attributes ;
12+ use ipl \Html \FormattedString ;
13+ use ipl \Html \Html ;
1214use ipl \Html \HtmlDocument ;
1315use ipl \Html \Text ;
16+ use ipl \Html \ValidHtml ;
1417use ipl \I18n \Translation ;
1518use ipl \Web \Common \ItemRenderer ;
1619use ipl \Web \Widget \Icon ;
@@ -24,8 +27,13 @@ class IncidentHistoryRenderer implements ItemRenderer
2427 public function assembleAttributes ($ item , Attributes $ attributes , string $ layout ): void
2528 {
2629 $ classes = ['incident-history ' ];
27- if ($ item ->type === 'notified ' && $ item ->notification_state === 'suppressed ' ) {
28- $ classes [] = 'notification-suppressed ' ;
30+ if ($ item ->type === 'notified ' ) {
31+ $ classes [] = 'notification-state ' ;
32+ if ($ item ->notification_state === 'suppressed ' ) {
33+ $ classes [] = 'suppressed ' ;
34+ } elseif ($ item ->notification_state === 'failed ' ) {
35+ $ classes [] = 'failed ' ;
36+ }
2937 }
3038
3139 $ attributes ->get ('class ' )->addValue ($ classes );
@@ -49,7 +57,7 @@ public function assembleTitle($item, HtmlDocument $title, string $layout): void
4957
5058 public function assembleCaption ($ item , HtmlDocument $ caption , string $ layout ): void
5159 {
52- $ caption ->addHtml (new Text ( $ this ->buildMessage ($ item) ));
60+ $ caption ->addHtml ($ this ->buildMessage ($ item ));
5361 }
5462
5563 public function assembleExtendedInfo ($ item , HtmlDocument $ info , string $ layout ): void
@@ -154,9 +162,9 @@ protected function getRoleIcon(IncidentHistory $item): string
154162 *
155163 * @param IncidentHistory $item
156164 *
157- * @return string
165+ * @return ValidHtml
158166 */
159- protected function buildMessage (IncidentHistory $ item ): string
167+ protected function buildMessage (IncidentHistory $ item ): ValidHtml
160168 {
161169 switch ($ item ->type ) {
162170 case 'opened ' :
@@ -212,11 +220,17 @@ protected function buildMessage(IncidentHistory $item): string
212220 $ item ->channel ->type
213221 );
214222 } else {
215- $ message = sprintf (
216- $ this ->translate ('Contact %s notified via %s (%s) ' ),
217- $ item ->contact ->full_name ,
218- $ item ->channel ->type ,
219- IncidentHistory::translateNotificationState ($ item ->notification_state )
223+ $ message = new FormattedString (
224+ $ this ->translate ('Contact %s notified via %s %s ' ),
225+ [
226+ $ item ->contact ->full_name ,
227+ $ item ->channel ->type ,
228+ Html::tag (
229+ 'span ' ,
230+ ['class ' => 'state-text ' ],
231+ sprintf ('(%s) ' , IncidentHistory::translateNotificationState ($ item ->notification_state ))
232+ )
233+ ]
220234 );
221235 }
222236
@@ -304,8 +318,12 @@ protected function buildMessage(IncidentHistory $item): string
304318 $ message = '' ;
305319 }
306320
307- if ($ item ->message ) {
308- $ message = $ message === '' ? $ item ->message : $ message . ': ' . $ item ->message ;
321+ $ messageFromDb = $ item ->message ? ': ' . $ item ->message : '' ;
322+
323+ if (is_string ($ message )) {
324+ $ message = new Text ($ message . $ messageFromDb );
325+ } else {
326+ $ message = new FormattedString ('%s %s ' , [$ message , $ messageFromDb ]);
309327 }
310328
311329 return $ message ;
0 commit comments