Skip to content

Commit d7616a6

Browse files
committed
Merge pull request #1049 from tulinkry/paginator
Paginating history entries
2 parents 3b86bfe + d3427c1 commit d7616a6

File tree

6 files changed

+126
-30
lines changed

6 files changed

+126
-30
lines changed

src/org/opensolaris/opengrok/history/History.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,20 @@ public List<HistoryEntry> getHistoryEntries() {
7171
return entries;
7272
}
7373

74+
/**
75+
* Get the list of log entries, most recent first.
76+
* With parameters
77+
* @param limit max number of entries
78+
* @param offset starting position
79+
*
80+
* @return The list of entries in this history
81+
*/
82+
public List<HistoryEntry> getHistoryEntries(int limit, int offset) {
83+
offset = offset < 0 ? 0 : offset;
84+
limit = offset + limit > entries.size() ? limit = entries.size() - offset : limit;
85+
return entries.subList(offset, offset + limit);
86+
}
87+
7488
/**
7589
* Check if at least one history entry has a file list.
7690
*

src/org/opensolaris/opengrok/web/PageConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
2222
* Portions copyright (c) 2011 Jens Elkner.
2323
*/
2424
package org.opensolaris.opengrok.web;
@@ -416,7 +416,7 @@ public int getIntParam(String name, int defaultValue) {
416416
}
417417
return ret;
418418
}
419-
419+
420420
/**
421421
* Get the <b>start</b> index for a search result to return by looking up
422422
* the {@code start} request parameter.

web/default/style.css

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ a.scope { /* scope */ color: dodgerblue; font-weight: bold; pa
745745
#results {
746746
}
747747

748-
#results p { /* pagetitle and slider */
748+
#results p, #revisions p { /* pagetitle and slider */
749749
padding: 0.1em;
750750
}
751751

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

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

805-
#results .more { /* slider item for the n-th search result page */
805+
#results .more, #revisions .more { /* slider item for the n-th search result page */
806806
border: 1px #bba solid;
807807
padding: .3em;
808808
margin: 1px;

web/history.jsp

Lines changed: 101 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ information: Portions Copyright [yyyy] [name of copyright owner]
1818
1919
CDDL HEADER END
2020
21-
Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
21+
Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
2222
2323
Portions Copyright 2011 Jens Elkner.
2424
@@ -87,10 +87,73 @@ document.domReady.push(function() {domReadyHistory();});
8787
}
8888
</style>
8989
<![endif]-->
90+
<%
91+
// We have a lots of results to show: create a slider for
92+
String slider = "";
93+
int thispage; // number of items to display on the current page
94+
int start = cfg.getSearchStart();
95+
int max = cfg.getSearchMaxItems();
96+
int totalHits = hist.getHistoryEntries().size();
97+
if (max < totalHits) {
98+
StringBuilder buf = new StringBuilder(4096);
99+
thispage = (start + max) < totalHits ? max : totalHits - start;
100+
int labelStart = 1;
101+
int sstart = start - max * (start / max % 10 + 1) ;
102+
if (sstart < 0) {
103+
sstart = 0;
104+
labelStart = 1;
105+
} else {
106+
labelStart = sstart / max + 1;
107+
}
108+
int label = labelStart;
109+
int labelEnd = label + 11;
110+
for (int i = sstart; i < totalHits && label <= labelEnd; i+= max) {
111+
if (i <= start && start < i + max) {
112+
buf.append("<span class=\"sel\">").append(label).append("</span>");
113+
} else {
114+
buf.append("<a class=\"more\" href=\"?n=").append(max)
115+
.append("&amp;start=").append(i);
116+
// append revision parameters
117+
if (cfg.getIntParam("r1", -1) != -1) {
118+
buf.append("&amp;r1=").append(cfg.getIntParam("r1", -1));
119+
}
120+
if (cfg.getIntParam("r2", -1) != -1) {
121+
buf.append("&amp;r2=").append(cfg.getIntParam("r2", -1));
122+
}
123+
buf.append("\">");
124+
if (label == labelStart && label != 1) {
125+
buf.append("&lt;&lt");
126+
} else if (label == labelEnd && i < totalHits) {
127+
buf.append("&gt;&gt;");
128+
} else {
129+
buf.append(label);
130+
}
131+
buf.append("</a>");
132+
}
133+
label++;
134+
}
135+
slider = buf.toString();
136+
} else {
137+
// set the max index to max or last
138+
thispage = totalHits - start;
139+
}
140+
141+
int revision2 = cfg.getIntParam("r2", -1) < 0 ? 0 : cfg.getIntParam("r2", -1);
142+
int revision1 = cfg.getIntParam("r1", -1) < revision2 ? revision2 + 1 : cfg.getIntParam("r1", -1);
143+
revision2 = revision2 >= hist.getHistoryEntries().size() ? hist.getHistoryEntries().size() - 1 : revision2;
144+
145+
146+
%>
147+
90148
<form action="<%= context + Prefix.DIFF_P + uriEncodedName %>">
91149
<table class="src" id="revisions">
92150
<caption>History log of <a href="<%= context + Prefix.XREF_P
93-
+ uriEncodedName %>"><%= path %></a></caption>
151+
+ uriEncodedName %>"><%= path %></a>
152+
(Results <b> <%= start + 1 %> - <%= thispage + start
153+
%></b> of <b><%= totalHits %></b>)
154+
<p class="slider"><%= slider %></p>
155+
</caption>
156+
94157
<thead>
95158
<tr>
96159
<th>Revision <%
@@ -104,7 +167,14 @@ document.domReady.push(function() {domReadyHistory();});
104167
%></th><%
105168
if (!cfg.isDir()) {
106169
%>
107-
<th><input type="submit" value=" Compare "/></th><%
170+
<th><input type="submit" value=" Compare "/>
171+
<% if (hist.getHistoryEntries().size() > revision1 && revision1 >= 0) { %>
172+
<input type="hidden" name="r1" value="<%= path + '@' + hist.getHistoryEntries().get(revision1).getRevision() %>" />
173+
<% } %>
174+
<% if (hist.getHistoryEntries().size() > revision2 && revision2 >= 0) { %>
175+
<input type="hidden" name="r2" value="<%= path + '@' + hist.getHistoryEntries().get(revision2).getRevision() %>" />
176+
<% } %>
177+
</th><%
108178
}
109179
%>
110180
<th>Date</th>
@@ -122,9 +192,9 @@ document.domReady.push(function() {domReadyHistory();});
122192
</tr>
123193
</thead>
124194
<tbody>
125-
<%
195+
<%
126196
int count=0;
127-
for (HistoryEntry entry : hist.getHistoryEntries()) {
197+
for (HistoryEntry entry : hist.getHistoryEntries(max, start)) {
128198
String rev = entry.getRevision();
129199
if (rev == null || rev.length() == 0) {
130200
rev = "";
@@ -157,20 +227,32 @@ document.domReady.push(function() {domReadyHistory();});
157227
title="link to revision line">#</a>
158228
<a href="<%= context + Prefix.XREF_P + rp + "?r=" + Util.URIEncode(rev) %>"><%=
159229
rev %></a></td>
160-
<td>
161-
<input type="radio"<%
162-
if (count == 0 ) {
163-
%> disabled="disabled"<%
164-
} else if (count == 1) {
165-
%> checked="checked"<%
166-
}
167-
%> name="r1" value="<%= path %>@<%= rev%>"/>
168-
<input type="radio"
169-
name="r2"<%
170-
if (count == 0) {
171-
%> checked="checked"<%
172-
}
173-
%> value="<%= path %>@<%= rev %>"/></td><%
230+
<td><%
231+
String url;
232+
if (count + start > revision1 || (count + start > revision2 && count + start <= revision1 - 1)) {
233+
// revision1 enabled
234+
url = context + Prefix.HIST_L + uriEncodedName + "?n=" + max + "&start=" + start +"&r1="+(start + count) +"&r2="+revision2;
235+
%><input type="radio" onclick="javascript: window.location.assign('<%= url %>');"/><%
236+
} else if (count + start == revision1 ) {
237+
// revision1 selected
238+
%><input type="radio" checked/><%
239+
} else if( count + start <= revision2 ) {
240+
// revision1 disabled
241+
%><input type="radio" disabled/><%
242+
}
243+
244+
if( count + start < revision2 || (count + start > revision2 && count + start <= revision1 - 1) ) {
245+
// revision2 enabled
246+
url = context + Prefix.HIST_L + uriEncodedName + "?n=" + max + "&start=" + start +"&r1="+revision1 +"&r2="+(start + count);
247+
%><input type="radio" onclick="javascript: window.location.assign('<%= url %>');"/><%
248+
} else if( count + start == revision2 ) {
249+
// revision2 selected
250+
%><input type="radio" checked/><%
251+
} else if (count + start >= revision1 ) {
252+
// revision2 disabled
253+
%><input type="radio" disabled/><%
254+
}
255+
%></td><%
174256
} else {
175257
striked = true;
176258
%>

web/offwhite/style.css

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ a.scope { /* scope */ color: dodgerblue; font-weight: bold; pa
746746
#results {
747747
}
748748

749-
#results p { /* pagetitle and slider */
749+
#results p, #revisions p { /* pagetitle and slider */
750750
padding: 0.5em;
751751
}
752752

@@ -782,14 +782,14 @@ a.scope { /* scope */ color: dodgerblue; font-weight: bold; pa
782782
font-weight: bold;
783783
}
784784

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

792-
#results .more { /* slider item for the n-th search result page */
792+
#results .more, #revisions .more { /* slider item for the n-th search result page */
793793
border: 1px #bba solid;
794794
padding: .3em;
795795
margin: 1px;

web/polished/style.css

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ a.scope { /* scope */ color: dodgerblue; font-weight: bold; pa
805805
padding: 1ex 0;
806806
}
807807

808-
#results p { /* pagetitle and slider */
808+
#results p, #revisions p { /* pagetitle and slider */
809809
padding: 0.5em;
810810
}
811811

@@ -851,14 +851,14 @@ a.scope { /* scope */ color: dodgerblue; font-weight: bold; pa
851851
font-weight: bold;
852852
}
853853

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

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

0 commit comments

Comments
 (0)