Skip to content

Commit 247b983

Browse files
authored
Merge pull request #65 from jenkinsci/messages-view
Add a new detail view that shows info and error messages
2 parents 632fc0e + ef7d988 commit 247b983

File tree

5 files changed

+161
-2
lines changed

5 files changed

+161
-2
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package io.jenkins.plugins.bootstrap5;
2+
3+
import java.util.ArrayList;
4+
import java.util.Collection;
5+
import java.util.Collections;
6+
import java.util.List;
7+
8+
import hudson.model.ModelObject;
9+
import hudson.model.Run;
10+
11+
/**
12+
* A view model to visualize logging messages and errors of a build step.
13+
*
14+
* @author Ullrich Hafner
15+
*/
16+
@SuppressWarnings("PMD.DataClass")
17+
public class MessagesViewModel implements ModelObject {
18+
private final Run<?, ?> owner;
19+
private final List<String> errorMessages;
20+
private final List<String> infoMessages;
21+
private final String displayName;
22+
23+
/**
24+
* Creates a new {@link MessagesViewModel} with info messages only.
25+
*
26+
* @param owner
27+
* current build as owner of this view
28+
* @param displayName
29+
* display name of the step
30+
* @param infoMessages
31+
* all info messages that should be shown (should not be empty)
32+
*/
33+
public MessagesViewModel(final Run<?, ?> owner, final String displayName,
34+
final List<String> infoMessages) {
35+
this(owner, displayName, infoMessages, Collections.emptyList());
36+
}
37+
38+
/**
39+
* Creates a new {@link MessagesViewModel} with error and info messages.
40+
*
41+
* @param owner
42+
* current build as owner of this view
43+
* @param displayName
44+
* display name of the step
45+
* @param infoMessages
46+
* all info messages that should be shown (should not be empty)
47+
* @param errorMessages
48+
* all error messages that should be shown (might be empty)
49+
*/
50+
public MessagesViewModel(final Run<?, ?> owner, final String displayName,
51+
final List<String> infoMessages, final List<String> errorMessages) {
52+
this.owner = owner;
53+
this.errorMessages = asImmutableList(errorMessages);
54+
this.infoMessages = asImmutableList(infoMessages);
55+
56+
this.displayName = displayName + " - " + Messages.Messages_View_Name();
57+
}
58+
59+
private List<String> asImmutableList(final List<String> elements) {
60+
return Collections.unmodifiableList(new ArrayList<>(elements));
61+
}
62+
63+
/**
64+
* Returns the build as owner of this view model.
65+
*
66+
* @return the owner
67+
*/
68+
public final Run<?, ?> getOwner() {
69+
return owner;
70+
}
71+
72+
@Override
73+
public String getDisplayName() {
74+
return displayName;
75+
}
76+
77+
/**
78+
* Returns the information messages of the step.
79+
*
80+
* @return the information messages
81+
*/
82+
@SuppressWarnings("unused") // Called by jelly view
83+
public Collection<String> getInfoMessages() {
84+
return infoMessages;
85+
}
86+
87+
/**
88+
* Returns the error messages of the step.
89+
*
90+
* @return the error messages
91+
*/
92+
@SuppressWarnings("unused") // Called by jelly view
93+
public Collection<String> getErrorMessages() {
94+
return errorMessages;
95+
}
96+
}
97+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Messages.View.Name=Messages
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?jelly escape-by-default='true'?>
2+
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:bs="/bootstrap5">
3+
4+
<st:header name="Content-Type" value="text/html;charset=UTF-8"/>
5+
6+
<bs:page it="${it}">
7+
8+
<j:if test="${size(errors) > 0}">
9+
<div class="row py-3">
10+
<div class="col">
11+
<bs:card title="${%Error Messages}" fontAwesomeIcon="exclamation-triangle">
12+
13+
<pre>
14+
<samp id="errors" class="log-output">
15+
<j:forEach var="message" items="${it.errorMessages}">
16+
<div>
17+
${message}
18+
</div>
19+
</j:forEach>
20+
</samp>
21+
</pre>
22+
23+
</bs:card>
24+
</div>
25+
</div>
26+
</j:if>
27+
28+
<div class="row py-3">
29+
<div class="col">
30+
31+
<bs:card title="${%Information Messages}" fontAwesomeIcon="info-circle">
32+
33+
<pre>
34+
<samp id="info" class="log-output">
35+
<j:forEach var="message" items="${it.infoMessages}">
36+
<div>
37+
${message}
38+
</div>
39+
</j:forEach>
40+
</samp>
41+
</pre>
42+
</bs:card>
43+
44+
</div>
45+
</div>
46+
47+
</bs:page>
48+
49+
</j:jelly>

src/main/webapp/css/jenkins-style.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ pre {
2626
color: var(--text-color);
2727
}
2828

29+
.log-output {
30+
font-size: var(--font-size-sm);
31+
}
32+
33+
.info-page-decorator {
34+
fill: #b4b4b4;
35+
height: 16px;
36+
width: 16px;
37+
vertical-align: text-bottom;
38+
margin-left: 0.2em;
39+
}
40+
2941
/* ------------------------------------------------------------------------------------------------------------------- */
3042
/* Bootstrap Carousel */
3143
/* ------------------------------------------------------------------------------------------------------------------- */

0 commit comments

Comments
 (0)