Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
JENKINS-21411 Shift (Prev/Next) for diff results for slaves
  • Loading branch information
Stefan Brausch committed Feb 6, 2014
1 parent 049e1c6 commit ba5576f
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 21 deletions.
Expand Up @@ -12,13 +12,20 @@
import hudson.plugins.jobConfigHistory.SideBySideView.Line;
import hudson.security.AccessControlled;
import hudson.util.MultipartFormDataParser;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.SortedMap;
import java.util.Map.Entry;

import javax.servlet.ServletException;

import jenkins.model.Jenkins;

import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;

Expand Down Expand Up @@ -167,6 +174,56 @@ public final String getOperation(int timestampNumber) {
return getHistoryDao().getRevisions(this.slave)
.get(getTimestamp(timestampNumber)).getOperation();
}

/**
* Used in the Difference jelly only. Returns the next timestamp of
* the next entry of the two Files A and B. timestampNumber decides which
* file exactly.
*
* @param timestampNumber
* 1 for File A, 2 for File B
* @return the timestamp of the next entry as String.
*/
public final String getNextTimestamp(int timestampNumber) {
checkConfigurePermission();
final String timestamp = this.getRequestParameter("timestamp" + timestampNumber);
final SortedMap<String, HistoryDescr> revisions = getHistoryDao().getRevisions(this.slave);
final Iterator<Entry<String, HistoryDescr>> itr = revisions.entrySet().iterator();
while (itr.hasNext()) {
if (itr.next().getValue().getTimestamp().equals((String) timestamp) && itr.hasNext()) {
return itr.next().getValue().getTimestamp();
}
}
//no next entry found
return timestamp;
}

/**
* Used in the Difference jelly only. Returns the previous timestamp of
* the next entry of the two Files A and B. timestampNumber decides which
* file exactly.
*
* @param timestampNumber
* 1 for File A, 2 for File B
* @return the timestamp of the preious entry as String.
*/
public final String getPrevTimestamp(int timestampNumber) {
checkConfigurePermission();
final String timestamp = this.getRequestParameter("timestamp" + timestampNumber);
final SortedMap<String, HistoryDescr> revisions = getHistoryDao().getRevisions(this.slave);
final Iterator<Entry<String, HistoryDescr>> itr = revisions.entrySet().iterator();
String prevTimestamp = timestamp;
while (itr.hasNext()) {
final String checkTimestamp = itr.next().getValue().getTimestamp();
if (checkTimestamp.equals((String) timestamp)) {
return prevTimestamp;
} else {
prevTimestamp = checkTimestamp;
}
}
//no previous entry found
return timestamp;
}

/**
* Returns {@link JobConfigHistoryBaseAction#getConfigXml(String)} as
Expand Down Expand Up @@ -207,6 +264,22 @@ public final void doDiffFiles(StaplerRequest req, StaplerResponse rsp)
+ "&timestamp2=" + parser.get("timestamp2"));
}


/**
* Action when 'Prev' or 'Next' button in showDiffFiles.jelly is pressed.
* Forwards to the previous or next diff.
* @param req StaplerRequest created by pressing the button
* @param rsp Outgoing StaplerResponse
* @throws IOException If XML file can't be read
*/
public final void doDiffFilesPrevNext(StaplerRequest req, StaplerResponse rsp)
throws IOException {
final String timestamp1 = req.getParameter("timestamp1");
final String timestamp2 = req.getParameter("timestamp2");
rsp.sendRedirect("showDiffFiles?timestamp1=" + timestamp1
+ "&timestamp2=" + timestamp2);
}

/**
* Takes the two timestamp request parameters and returns the diff between the corresponding
Expand Down
@@ -1,5 +1,5 @@
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt">
<l:layout title="Slave Configuration History" css="/plugin/jobConfigHistory/diff_highlight.css">
<l:layout title="Job Configuration History" css="/plugin/jobConfigHistory/diff_highlight.css">
<st:include it="${it.slave.toComputer()}" page="sidepanel.jelly" />
<l:main-panel>
<h1>${%Slave Configuration Difference}</h1>
Expand All @@ -13,24 +13,32 @@
</j:when>
<j:otherwise>
<div>
<j:choose>
<j:when test="${it.getLines().size() == 0}">
<p>${%No lines changed}</p>
</j:when>
<j:otherwise>
<table style="width:100%;">
<thead>
<tr>
<td colspan="2"> <font size="3"> File A </font></td>
<td colspan="2"> <font size="3"> File B </font></td>
</tr>
<tr>
<td colspan="2"> ${it.getTimestamp(1)}; ${it.getOperation(1)}; <a href="${rootURL}/user/${it.getUser(1)}">${it.getUser(1)}</a> </td>
<td colspan="2"> ${it.getTimestamp(2)}; ${it.getOperation(2)}; <a href="${rootURL}/user/${it.getUser(2)}">${it.getUser(2)}</a> </td>
</tr>
</thead>
<j:set var="prev1" value="${it.getPrevTimestamp(1)}"/>
<j:set var="prev2" value="${it.getPrevTimestamp(2)}"/>
<j:set var="next1" value="${it.getNextTimestamp(1)}"/>
<j:set var="next2" value="${it.getNextTimestamp(2)}"/>
<table style="width:100%;">
<thead>
<tr>
<td colspan="2"> <font size="3"> File A </font></td>
<td colspan="2"> <font size="3"> File B </font></td>
</tr>
<tr>
<td colspan="2"> ${it.getTimestamp(1)}; ${it.getOperation(1)}; <a href="${rootURL}/user/${it.getUser(1)}">${it.getUser(1)}</a> </td>
<td colspan="2"> ${it.getTimestamp(2)}; ${it.getOperation(2)}; <a href="${rootURL}/user/${it.getUser(2)}">${it.getUser(2)}</a> </td>
</tr>
</thead>
<tbody style="outline: 1pt solid #B2B2B2;">
<j:forEach items="${it.getLines()}" var="line">
<j:choose>
<j:when test="${it.getLines().size() == 0}">
<tr>
<td colspan="4">
<p>${%No lines changed}</p>
</td>
</tr>
</j:when>
<j:otherwise>
<j:forEach items="${it.getLines()}" var="line">
<tr>
<j:choose>
<j:when test="${line.skipping}">
Expand All @@ -48,8 +56,31 @@
</j:choose>
</tr>
</j:forEach>
</tbody>

</j:otherwise>
</j:choose>
</tbody>
</table>
<div align="right">
<table>
<tr>
<td>
<j:if test="${prev1 != prev2}">
<f:form method="post" action="diffFilesPrevNext?timestamp1=${prev1}&amp;timestamp2=${prev2}" name="prevEntry" >
<f:submit value="&lt; ${%Prev}" />
</f:form>
</j:if>
</td>
<td>
<j:if test="${next1 != next2}">
<f:form method="post" action="diffFilesPrevNext?timestamp1=${next1}&amp;timestamp2=${next2}" name="nextEntry" >
<f:submit value="${%Next} &gt;" />
</f:form>
</j:if>
</td>
</tr>
</table>
</div>
<div align="right">
<table>
<tr>
Expand All @@ -66,8 +97,6 @@
</tr>
</table>
</div>
</j:otherwise>
</j:choose>
</div>
</j:otherwise>
</j:choose>
Expand Down

0 comments on commit ba5576f

Please sign in to comment.