Skip to content

Commit 990b70d

Browse files
committed
Convert the dashboard filter box from substring search to regular expression.
This fixes a bug where clicking on stats information for a job would show multiple jobs instead of just the clicked-on job.
1 parent 22a4506 commit 990b70d

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

dashboard/dashboard.html

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@
248248
See also <a href="pipelines" class="underlined-a">pipeline</a> or <a href="logs/recent" class="underlined-a">job</a> reports.
249249
Show: <input id="filter-box" type="text" size="21" autofocus>
250250
<input onclick="ds.setFilter('');" type="button" value=" All " class="button">
251-
<input onclick="ds.setFilter('`');" type="button" value="None" class="button">
251+
<input onclick="ds.setFilter('^$');" type="button" value="None" class="button">
252252
</div>
253253
<div>
254254
<input type="button" onclick="ds.toggleAlign()" class="button" value="Align!">
@@ -394,6 +394,23 @@
394394
return head;
395395
};
396396

397+
// Copied from closure-library's goog.string.startsWith
398+
var startsWith = function(str, prefix) {
399+
return str.lastIndexOf(prefix, 0) == 0;
400+
}
401+
402+
// Copied from closure-library's goog.string.endsWith
403+
var endsWith = function(str, suffix) {
404+
var l = str.length - suffix.length;
405+
return l >= 0 && str.indexOf(suffix, l) == l;
406+
};
407+
408+
// Copied from closure-library's goog.string.regExpEscape
409+
var regExpEscape = function(s) {
410+
return String(s).replace(/([-()\[\]{}+?*.$\^|,:#<!\\])/g, '\\$1').
411+
replace(/\x08/g, '\\x08');
412+
};
413+
397414
/**
398415
* [[1, 2], [3, 4]] -> {1: 2, 3: 4}
399416
*/
@@ -654,12 +671,13 @@
654671
// Set the filter on clicks, but not on text selections.
655672
return;
656673
}
657-
if(ds.getFilter() == jobData["url"]) {
674+
var filter = ds.getFilter();
675+
if(RegExp(filter).test(jobData["url"]) && startsWith(filter, "^") && endsWith(filter, "$")) {
658676
// If we're already showing just this log window, go back
659677
// to showing nothing.
660-
ds.setFilter("`");
678+
ds.setFilter("^$");
661679
} else {
662-
ds.setFilter(jobData["url"]);
680+
ds.setFilter("^" + regExpEscape(jobData["url"]) + "$");
663681
}
664682
}}, [
665683
" on ",
@@ -860,7 +878,7 @@
860878
var matches = 0;
861879
for(var i=0; i < this.jobs.sorted.length; i++) {
862880
var job = this.jobs.sorted[i];
863-
if(job["url"].indexOf(query) == -1) {
881+
if(!RegExp(query).test(job["url"])) {
864882
this.renderInfo[job["ident"]].logWindow.style.display = "none";
865883
} else {
866884
this.renderInfo[job["ident"]].logWindow.style.display = "block";

0 commit comments

Comments
 (0)