Skip to content

Paginating history entries #1049

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/org/opensolaris/opengrok/history/History.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ public List<HistoryEntry> getHistoryEntries() {
return entries;
}

/**
* Get the list of log entries, most recent first.
* With parameters
* @param limit max number of entries
* @param offset starting position
*
* @return The list of entries in this history
*/
public List<HistoryEntry> getHistoryEntries(int limit, int offset) {
offset = offset < 0 ? 0 : offset;
limit = offset + limit > entries.size() ? limit = entries.size() - offset : limit;
return entries.subList(offset, offset + limit);
}

/**
* Check if at least one history entry has a file list.
*
Expand Down
4 changes: 2 additions & 2 deletions src/org/opensolaris/opengrok/web/PageConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

/*
* Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
* Portions copyright (c) 2011 Jens Elkner.
*/
package org.opensolaris.opengrok.web;
Expand Down Expand Up @@ -416,7 +416,7 @@ public int getIntParam(String name, int defaultValue) {
}
return ret;
}

/**
* Get the <b>start</b> index for a search result to return by looking up
* the {@code start} request parameter.
Expand Down
6 changes: 3 additions & 3 deletions web/default/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ a.scope { /* scope */ color: dodgerblue; font-weight: bold; pa
#results {
}

#results p { /* pagetitle and slider */
#results p, #revisions p { /* pagetitle and slider */
padding: 0.1em;
}

Expand Down Expand Up @@ -795,14 +795,14 @@ a.scope { /* scope */ color: dodgerblue; font-weight: bold; pa
padding-left: 1ex;
}

#results .sel { /* slider item for the shown search result page */
#results .sel, #revisions .sel { /* slider item for the shown search result page */
background-color: #a3b8cb;
border: 1px #333366 solid;
padding: .5em;
margin: 1px;
}

#results .more { /* slider item for the n-th search result page */
#results .more, #revisions .more { /* slider item for the n-th search result page */
border: 1px #bba solid;
padding: .3em;
margin: 1px;
Expand Down
120 changes: 101 additions & 19 deletions web/history.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ information: Portions Copyright [yyyy] [name of copyright owner]

CDDL HEADER END

Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.

Portions Copyright 2011 Jens Elkner.

Expand Down Expand Up @@ -87,10 +87,73 @@ document.domReady.push(function() {domReadyHistory();});
}
</style>
<![endif]-->
<%
// We have a lots of results to show: create a slider for
String slider = "";
int thispage; // number of items to display on the current page
int start = cfg.getSearchStart();
int max = cfg.getSearchMaxItems();
int totalHits = hist.getHistoryEntries().size();
if (max < totalHits) {
StringBuilder buf = new StringBuilder(4096);
thispage = (start + max) < totalHits ? max : totalHits - start;
int labelStart = 1;
int sstart = start - max * (start / max % 10 + 1) ;
if (sstart < 0) {
sstart = 0;
labelStart = 1;
} else {
labelStart = sstart / max + 1;
}
int label = labelStart;
int labelEnd = label + 11;
for (int i = sstart; i < totalHits && label <= labelEnd; i+= max) {
if (i <= start && start < i + max) {
buf.append("<span class=\"sel\">").append(label).append("</span>");
} else {
buf.append("<a class=\"more\" href=\"?n=").append(max)
.append("&amp;start=").append(i);
// append revision parameters
if (cfg.getIntParam("r1", -1) != -1) {
buf.append("&amp;r1=").append(cfg.getIntParam("r1", -1));
}
if (cfg.getIntParam("r2", -1) != -1) {
buf.append("&amp;r2=").append(cfg.getIntParam("r2", -1));
}
buf.append("\">");
if (label == labelStart && label != 1) {
buf.append("&lt;&lt");
} else if (label == labelEnd && i < totalHits) {
buf.append("&gt;&gt;");
} else {
buf.append(label);
}
buf.append("</a>");
}
label++;
}
slider = buf.toString();
} else {
// set the max index to max or last
thispage = totalHits - start;
}

int revision2 = cfg.getIntParam("r2", -1) < 0 ? 0 : cfg.getIntParam("r2", -1);
int revision1 = cfg.getIntParam("r1", -1) < revision2 ? revision2 + 1 : cfg.getIntParam("r1", -1);
revision2 = revision2 >= hist.getHistoryEntries().size() ? hist.getHistoryEntries().size() - 1 : revision2;


%>

<form action="<%= context + Prefix.DIFF_P + uriEncodedName %>">
<table class="src" id="revisions">
<caption>History log of <a href="<%= context + Prefix.XREF_P
+ uriEncodedName %>"><%= path %></a></caption>
+ uriEncodedName %>"><%= path %></a>
(Results <b> <%= start + 1 %> - <%= thispage + start
%></b> of <b><%= totalHits %></b>)
<p class="slider"><%= slider %></p>
</caption>

<thead>
<tr>
<th>Revision <%
Expand All @@ -104,7 +167,14 @@ document.domReady.push(function() {domReadyHistory();});
%></th><%
if (!cfg.isDir()) {
%>
<th><input type="submit" value=" Compare "/></th><%
<th><input type="submit" value=" Compare "/>
<% if (hist.getHistoryEntries().size() > revision1 && revision1 >= 0) { %>
<input type="hidden" name="r1" value="<%= path + '@' + hist.getHistoryEntries().get(revision1).getRevision() %>" />
<% } %>
<% if (hist.getHistoryEntries().size() > revision2 && revision2 >= 0) { %>
<input type="hidden" name="r2" value="<%= path + '@' + hist.getHistoryEntries().get(revision2).getRevision() %>" />
<% } %>
</th><%
}
%>
<th>Date</th>
Expand All @@ -122,9 +192,9 @@ document.domReady.push(function() {domReadyHistory();});
</tr>
</thead>
<tbody>
<%
<%
int count=0;
for (HistoryEntry entry : hist.getHistoryEntries()) {
for (HistoryEntry entry : hist.getHistoryEntries(max, start)) {
String rev = entry.getRevision();
if (rev == null || rev.length() == 0) {
rev = "";
Expand Down Expand Up @@ -157,20 +227,32 @@ document.domReady.push(function() {domReadyHistory();});
title="link to revision line">#</a>
<a href="<%= context + Prefix.XREF_P + rp + "?r=" + Util.URIEncode(rev) %>"><%=
rev %></a></td>
<td>
<input type="radio"<%
if (count == 0 ) {
%> disabled="disabled"<%
} else if (count == 1) {
%> checked="checked"<%
}
%> name="r1" value="<%= path %>@<%= rev%>"/>
<input type="radio"
name="r2"<%
if (count == 0) {
%> checked="checked"<%
}
%> value="<%= path %>@<%= rev %>"/></td><%
<td><%
String url;
if (count + start > revision1 || (count + start > revision2 && count + start <= revision1 - 1)) {
// revision1 enabled
url = context + Prefix.HIST_L + uriEncodedName + "?n=" + max + "&start=" + start +"&r1="+(start + count) +"&r2="+revision2;
%><input type="radio" onclick="javascript: window.location.assign('<%= url %>');"/><%
} else if (count + start == revision1 ) {
// revision1 selected
%><input type="radio" checked/><%
} else if( count + start <= revision2 ) {
// revision1 disabled
%><input type="radio" disabled/><%
}

if( count + start < revision2 || (count + start > revision2 && count + start <= revision1 - 1) ) {
// revision2 enabled
url = context + Prefix.HIST_L + uriEncodedName + "?n=" + max + "&start=" + start +"&r1="+revision1 +"&r2="+(start + count);
%><input type="radio" onclick="javascript: window.location.assign('<%= url %>');"/><%
} else if( count + start == revision2 ) {
// revision2 selected
%><input type="radio" checked/><%
} else if (count + start >= revision1 ) {
// revision2 disabled
%><input type="radio" disabled/><%
}
%></td><%
} else {
striked = true;
%>
Expand Down
6 changes: 3 additions & 3 deletions web/offwhite/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ a.scope { /* scope */ color: dodgerblue; font-weight: bold; pa
#results {
}

#results p { /* pagetitle and slider */
#results p, #revisions p { /* pagetitle and slider */
padding: 0.5em;
}

Expand Down Expand Up @@ -782,14 +782,14 @@ a.scope { /* scope */ color: dodgerblue; font-weight: bold; pa
font-weight: bold;
}

#results .sel { /* slider item for the shown search result page */
#results .sel, #revisions .sel { /* slider item for the shown search result page */
background-color: #d6d6c0;
border: 1px #998 solid;
padding: .5em;
margin: 1px;
}

#results .more { /* slider item for the n-th search result page */
#results .more, #revisions .more { /* slider item for the n-th search result page */
border: 1px #bba solid;
padding: .3em;
margin: 1px;
Expand Down
6 changes: 3 additions & 3 deletions web/polished/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ a.scope { /* scope */ color: dodgerblue; font-weight: bold; pa
padding: 1ex 0;
}

#results p { /* pagetitle and slider */
#results p, #revisions p { /* pagetitle and slider */
padding: 0.5em;
}

Expand Down Expand Up @@ -851,14 +851,14 @@ a.scope { /* scope */ color: dodgerblue; font-weight: bold; pa
font-weight: bold;
}

#results .sel { /* slider item for the shown search result page */
#results .sel, #revisions .sel { /* slider item for the shown search result page */
background-color: #a3b8cb;
border: 1px solid #333366;
padding: .5em;
margin: 1px;
}

#results .more { /* slider item for the n-th search result page */
#results .more, #revisions .more { /* slider item for the n-th search result page */
border: 1px #ccc solid;
padding: .3em;
margin: 1px;
Expand Down