Skip to content

Commit

Permalink
[FIXED JENKINS-20144] Added option to force column width for
Browse files Browse the repository at this point in the history
"Build description" and "Project description" columns
  • Loading branch information
fredg02 committed Nov 6, 2013
1 parent 9d38ff2 commit 89f67d0
Show file tree
Hide file tree
Showing 13 changed files with 143 additions and 18 deletions.
Expand Up @@ -33,10 +33,27 @@

public class BuildDescriptionColumn extends ListViewColumn {

private int columnWidth;
private boolean isForceWidth;


@DataBoundConstructor
public BuildDescriptionColumn() {
public BuildDescriptionColumn(int columnWidth, boolean isForceWidth) {
super();
this.columnWidth = columnWidth;
this.isForceWidth = isForceWidth;
}

public BuildDescriptionColumn() {
this(80, false);
}

public int getColumnWidth() {
return columnWidth;
}

public boolean isForceWidth() {
return isForceWidth;
}

public String getBuildDescription(@SuppressWarnings("rawtypes") Job job) {
Expand All @@ -59,5 +76,10 @@ public String getDisplayName() {
return Messages.BuildDescriptionColumn_DisplayName();
}

@Override
public String getHelpFile() {
return "/plugin/extra-columns/help-buildDescription-column.html";
}

}
}
16 changes: 14 additions & 2 deletions src/main/java/jenkins/plugins/extracolumns/DescriptionColumn.java
Expand Up @@ -36,20 +36,24 @@ public class DescriptionColumn extends ListViewColumn {
private boolean displayName;
private boolean trim;
private int displayLength; //numbers of lines to display
private int columnWidth;
private boolean isForceWidth;

private final static String SEPARATOR = "<br/>";
private final static String SEPARATORS_REGEX = "(?i)<br\\s*/>|<br>";

@DataBoundConstructor
public DescriptionColumn(boolean displayName, boolean trim, int displayLength) {
public DescriptionColumn(boolean displayName, boolean trim, int displayLength, int columnWidth, boolean isForceWidth) {
super();
this.displayName = displayName;
this.trim = trim;
this.displayLength = displayLength;
this.columnWidth = columnWidth;
this.isForceWidth = isForceWidth;
}

public DescriptionColumn() {
this(false, false, 1);
this(false, false, 1, 80, false);
}

public boolean isDisplayName() {
Expand All @@ -64,6 +68,14 @@ public int getDisplayLength() {
return displayLength;
}

public int getColumnWidth() {
return columnWidth;
}

public boolean isForceWidth() {
return isForceWidth;
}

public String getToolTip(@SuppressWarnings("rawtypes") AbstractItem job) {
return formatDescription(job, false);
}
Expand Down
Expand Up @@ -25,7 +25,8 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core">
<j:set var="buildDesc" value="${it.getBuildDescription(job)}"/>
<td>
<j:set var="widthAttribute" value="width: ${it.getColumnWidth()}px;word-wrap: break-word;white-space:normal;"/>
<td style="${it.isForceWidth() ? widthAttribute : null}">
<j:out value="${buildDesc!=null ? app.markupFormatter.translate(buildDesc) : ''}" />
</td>
</j:jelly>
Expand Up @@ -27,6 +27,15 @@
xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form"
xmlns:i="jelly:fmt" xmlns:p="/lib/hudson/project">
<f:block>
<p>${%This column shows the build description of the last build.}</p>
<table>
<tr>
<td colspan="3">${%This column shows the build description of the last build.}</td>
</tr>
<f:optionalBlock field="isForceWidth" title="${%Force column width}" inline="true">
<f:entry title="${%Column width}">
<f:textbox field="columnWidth" default="80" />
</f:entry>
</f:optionalBlock>
</table>
</f:block>
</j:jelly>
Expand Up @@ -21,3 +21,5 @@
# THE SOFTWARE.

This\ column\ shows\ the\ build\ description\ of\ the\ last\ build.=Diese Spalte zeigt die Buildbeschreibung des letzten Builds an.
Force\ column\ width=Spaltenbreite festlegen
Column\ width=Spaltenbreite
Expand Up @@ -27,11 +27,12 @@
<j:set var="desc" value="${it.getDescription(job)}"/>
<j:set var="tooltipdesc" value="${it.getToolTip(job)}"/>
<j:set var="relativeDisplayName" value="${job.getRelativeDisplayNameFrom(currentView.owner.itemGroup)}"/>
<j:set var="widthAttribute" value="width: ${it.getColumnWidth()}px;word-wrap: break-word;white-space:normal;"/>
<td>
<j:if test="${it.isDisplayName()}">
<a href="${jobBaseUrl}${job.shortUrl}" class='model-link inside'>${relativeDisplayName != null ? relativeDisplayName : job.displayName}</a><br/>
</j:if>
<div tooltip="${tooltipdesc}">
<div tooltip="${tooltipdesc}" style="${it.isForceWidth() ? widthAttribute : null}">
<j:out value="${app.markupFormatter.translate(desc)}"/>
</div>
</td>
Expand Down
Expand Up @@ -27,12 +27,25 @@
xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form"
xmlns:i="jelly:fmt" xmlns:p="/lib/hudson/project">
<f:block>
<p>${%This column shows the project description.}</p>
<f:checkbox field="displayName" title="${%DescriptionColumn.DisplayName}" />
<f:optionalBlock field="trim" title="${%DescriptionColumn.Trim}" inline="true">
<f:entry title="${%DescriptionColumn.DisplayLength}">
<f:textbox field="displayLength" default="1" />
</f:entry>
</f:optionalBlock>
<table>
<tr>
<td colspan="3">${%This column shows the project description.}</td>
</tr>
<tr>
<td colspan="3">
<f:checkbox field="displayName" title="${%DescriptionColumn.DisplayName}" />
</td>
</tr>
<f:optionalBlock field="trim" title="${%DescriptionColumn.Trim}" inline="true">
<f:entry title="${%DescriptionColumn.DisplayLength}">
<f:textbox field="displayLength" default="1" />
</f:entry>
</f:optionalBlock>
<f:optionalBlock field="isForceWidth" title="${%Force column width}" inline="true">
<f:entry title="${%Column width}">
<f:textbox field="columnWidth" default="80" />
</f:entry>
</f:optionalBlock>
</table>
</f:block>
</j:jelly>
Expand Up @@ -25,4 +25,6 @@
DescriptionColumn.DisplayName=Projektnamen anzeigen
DescriptionColumn.Trim=Beschreibung begrenzen
DescriptionColumn.DisplayLength=Zeilenanzahl
This\ column\ shows\ the\ project\ description.=Diese Spalte zeigt die Projektbeschreibung an.
This\ column\ shows\ the\ project\ description.=Diese Spalte zeigt die Projektbeschreibung an.
Force\ column\ width=Spaltenbreite festlegen
Column\ width=Spaltenbreite
29 changes: 29 additions & 0 deletions src/main/webapp/help-buildDescription-column.html
@@ -0,0 +1,29 @@
<!--
The MIT License
Copyright (c) 2013, Frederic Gurr
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->

<div>
This column shows the build description of the last build.<br/>
<br/>
To force a specific column width in pixel (px) check the "Force column width" checkbox and set the desired width.<br/>
</div>
30 changes: 30 additions & 0 deletions src/main/webapp/help-buildDescription-column_de.html
@@ -0,0 +1,30 @@
<!--
The MIT License
Copyright (c) 2011, Axel Haustant
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->

<div>
<p>Diese Spalte zeigt die Buildbeschreibung des letzten Builds an.<br/>
<br/>
Die Option "Spaltenbreite festlegen" erlaubt die Spaltenbreite in Pixel (px) festzulegen.
</p>
</div>
2 changes: 2 additions & 0 deletions src/main/webapp/help-description-column.html
Expand Up @@ -30,4 +30,6 @@
It's possible to trim the description to a fixed number of lines by checking "Trim description".
In this case, you should set the desired amount of lines to display.<br/>
The trimming is done on the <code>&lt;br/&gt;</code> tags.<br/>
To force a specific column width in pixel (px) check the "Force column width" checkbox and set the desired
width.<br/>
</div>
2 changes: 2 additions & 0 deletions src/main/webapp/help-description-column_de.html
Expand Up @@ -29,5 +29,7 @@
<br/>
Mit der Option "Beschreibung begrenzen" kann die Beschreibung auf eine bestimmte Anzahl von Zeilen beschr&auml;nkt werden.<br/>
Die Einschr&auml;nkung erfolgt anhand der <code>&lt;br/&gt;</code> Tags.
<br/>
Die Option "Spaltenbreite festlegen" erlaubt die Spaltenbreite in Pixel (px) festzulegen.
</p>
</div>
Expand Up @@ -86,7 +86,7 @@ public void setUp() {

@Test
public void formatWithoutTrimming() throws IOException {
DescriptionColumn plugin = new DescriptionColumn(false, false, 2);
DescriptionColumn plugin = new DescriptionColumn(false, false, 2, 80, false);
job.setDescription(SIMPLE_DESCRIPTION);
String result = plugin.getDescription(job);
assertEquals(SIMPLE_DESCRIPTION, result);
Expand All @@ -97,21 +97,21 @@ public void formatWithoutTrimming() throws IOException {

@Test
public void formatWithTrimming() throws IOException {
DescriptionColumn plugin = new DescriptionColumn(false, true, 2);
DescriptionColumn plugin = new DescriptionColumn(false, true, 2, 80, false);
job.setDescription(SIMPLE_DESCRIPTION);
String result = plugin.getDescription(job);
assertEquals(SIMPLE_DESCRIPTION, result);
job.setDescription(MULTILINE_DESCRIPTION);
result = plugin.getDescription(job);
assertEquals("Just a test<br/>Another Line", result);
plugin = new DescriptionColumn(false, true, 7);
plugin = new DescriptionColumn(false, true, 7, 80, false);
result = plugin.getDescription(job);
assertEquals("Just a test<br/>Another Line<br/>One <b>more</b> line<br/>Last line", result);
}

@Test
public void displayName() throws IOException {
DescriptionColumn plugin = new DescriptionColumn(true, false, 2);
DescriptionColumn plugin = new DescriptionColumn(true, false, 2, 80, false);
job.setDescription(SIMPLE_DESCRIPTION);
String result = plugin.getDescription(job);
assertEquals("Just a test", result);
Expand Down

1 comment on commit 89f67d0

@oleg-nenashev
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I'll test the changes and report results

Please sign in to comment.