Skip to content

Commit 2f97488

Browse files
committed
Search result background color for odd rows fix
fixes #2082
1 parent a04e70f commit 2f97488

File tree

2 files changed

+31
-18
lines changed

2 files changed

+31
-18
lines changed

src/org/opensolaris/opengrok/search/Results.java

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

2020
/*
21-
* Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
2222
* Portions Copyright 2011 Jens Elkner.
2323
* Portions Copyright (c) 2017-2018, Chris Fraire <[email protected]>.
2424
*/
@@ -171,6 +171,8 @@ public static void prettyPrint(Writer out, SearchHelper sh, int start,
171171

172172
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
173173

174+
boolean evenRow = true;
175+
out.write("<tbody class=\"search-result\">");
174176
for (Map.Entry<String, ArrayList<Integer>> entry :
175177
createMap(sh.searcher, sh.hits, start, end).entrySet()) {
176178
String parent = entry.getKey();
@@ -190,8 +192,7 @@ public static void prettyPrint(Writer out, SearchHelper sh, int start,
190192
&& (messages = Util.messagesToJson(p,
191193
RuntimeEnvironment.MESSAGES_MAIN_PAGE_TAG
192194
)).size() > 0) {
193-
out.write(" <a ");
194-
out.write("href=\"" + xrefPrefix + "/" + p.getName() + "\">");
195+
out.write(" <a href=\"" + xrefPrefix + "/" + p.getName() + "\">");
195196
out.write("<span class=\"important-note important-note-rounded\" data-messages='" + messages + "'>!</span>");
196197
out.write("</a>");
197198
}
@@ -205,26 +206,19 @@ public static void prettyPrint(Writer out, SearchHelper sh, int start,
205206
Document doc = sh.searcher.doc(docId);
206207
String rpath = doc.get(QueryBuilder.PATH);
207208
String rpathE = Util.URIEncodePath(rpath);
208-
DateFormat df;
209-
out.write("<tr>");
209+
if (evenRow) {
210+
out.write("<tr class=\"search-result-even-row\">");
211+
} else {
212+
out.write("<tr>");
213+
}
214+
evenRow = !evenRow;
210215
Util.writeHAD(out, sh.contextPath, rpathE, false);
211216
out.write("<td class=\"f\"><a href=\"");
212217
out.write(xrefPrefixE);
213218
out.write(rpathE);
214219
out.write("\"");
215220
if (env.isLastEditedDisplayMode()) {
216-
try {
217-
// insert last edited date if possible
218-
df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
219-
String dd = df.format(DateTools.stringToDate(doc.get("date")));
220-
out.write(" class=\"result-annotate\" title=\"");
221-
out.write("Last modified: ");
222-
out.write(dd);
223-
out.write("\"");
224-
} catch (ParseException ex) {
225-
LOGGER.log(
226-
Level.WARNING, "An error parsing date information", ex);
227-
}
221+
printLastEditedDate(out, doc);
228222
}
229223
out.write(">");
230224
out.write(htmlize(rpath.substring(rpath.lastIndexOf('/') + 1)));
@@ -253,6 +247,20 @@ public static void prettyPrint(Writer out, SearchHelper sh, int start,
253247
out.write("</tt></td></tr>\n");
254248
}
255249
}
250+
out.write("</tbody>");
251+
}
252+
253+
private static void printLastEditedDate(final Writer out, final Document doc) throws IOException {
254+
try {
255+
DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
256+
String dd = df.format(DateTools.stringToDate(doc.get("date")));
257+
out.write(" class=\"result-annotate\" title=\"");
258+
out.write("Last modified: ");
259+
out.write(dd);
260+
out.write("\"");
261+
} catch (ParseException ex) {
262+
LOGGER.log(Level.WARNING, "An error parsing date information", ex);
263+
}
256264
}
257265

258266
private static void printPlain(PrintPlainFinalArgs fargs, Document doc,

web/default/style.css

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,12 @@ thead {
5656
background-color: #c5d5a9;
5757
}
5858

59-
tbody tr:nth-child(EVEN) { /* alternate color for odd rows */
59+
/* alternate color for odd rows, search-result class handles this by itself */
60+
tbody:not(.search-result) tr:nth-child(EVEN) {
61+
background-color: #e8e8f0;
62+
}
63+
64+
.search-result-even-row {
6065
background-color: #e8e8f0;
6166
}
6267

0 commit comments

Comments
 (0)