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 [] = 'notified ' ;
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,12 +220,16 @@ protected function buildMessage(IncidentHistory $item): string
212220 $ item ->channel ->type
213221 );
214222 } else {
215- $ message = sprintf (
223+ $ message = new FormattedString (
216224 $ this ->translate ('Contact %s notified via %s (%s) ' ),
217- $ item ->contact ->full_name ,
225+ [ $ item ->contact ->full_name ,
218226 $ item ->channel ->type ,
219- IncidentHistory::translateNotificationState ($ item ->notification_state )
220- );
227+ Html::tag (
228+ 'span ' ,
229+ ['class ' => 'state-text ' ],
230+ IncidentHistory::translateNotificationState ($ item ->notification_state )
231+ )
232+ ]);
221233 }
222234
223235 break ;
@@ -304,8 +316,12 @@ protected function buildMessage(IncidentHistory $item): string
304316 $ message = '' ;
305317 }
306318
307- if ($ item ->message ) {
308- $ message = $ message === '' ? $ item ->message : $ message . ': ' . $ item ->message ;
319+ $ messageFromDb = $ item ->message ? ': ' . $ item ->message : '' ;
320+
321+ if (is_string ($ message )) {
322+ $ message = new Text ($ message . $ messageFromDb );
323+ } else {
324+ $ message = new FormattedString ('%s %s ' , [$ message , $ messageFromDb ]);
309325 }
310326
311327 return $ message ;
0 commit comments