Skip to content
This repository has been archived by the owner on Mar 8, 2019. It is now read-only.

Commit

Permalink
PROW-210: Add filtering to main page
Browse files Browse the repository at this point in the history
  • Loading branch information
Natsuhiro Arita committed Feb 22, 2016
1 parent 9d617c5 commit 8cb5fa4
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 4 deletions.
39 changes: 36 additions & 3 deletions src/main/resources/META-INF/resources/WEB-INF/jsp/matrix/list.jsp
Expand Up @@ -12,6 +12,42 @@
<c:set var="testMatrix" value="${testMatrixVersion.testMatrixDefinition}"/>
<layout:base title="Proctor - current test matrix" session="${session}">
<h2>${branch.name} test matrix</h2>
<div id="filter-container">
<ui:grid-row>
<ui:grid-columns width="two">
<label class="inline">
<select class="js-filter-type" style="padding: 6px;">
<option value="all" selected="selected">Any field</option>
<option value="testName">Test name</option>
<option value="description">Description</option>
<option value="rule">Rule</option>
<option value="bucket">Bucket name</option>
<option value="bucketDescription">Bucket description</option>
</select>
</label>
</ui:grid-columns>
<ui:grid-columns width="ten">
<label>
<input type="text" name="test name" class="js-filter-text" placeholder="Filter">
</label>
</ui:grid-columns>
</ui:grid-row>
<div class="js-filter-active" style="padding-left: 5px;">
<label>
<input type="radio" name="filterActive" value="all" checked>
All
</label>
<label>
<input type="radio" name="filterActive" value="active">
<span>Active: Some allocations are occupied by multiple buckets</span>
</label>
<label>
<input type="radio" name="filterActive" value="inactive">
<span>Inactive: All allocations are occupied by 100% buckets</span>
</label>
</div>
<p>Showing <span class="js-num-matched" style="font-weight: bold;">0</span> / <span class="js-num-all" style="font-weight: bold;">0</span> tests</p>
</div>
<c:forEach items="${testMatrix.tests}" var="test">
<c:set var="testDefinition" value="${test.value}" />
<div class="panel radius">
Expand Down Expand Up @@ -45,7 +81,4 @@
indeed.proctor.app.matrix.list.start(${testMatrixDefinition});
//]]>
</script>
<!--
<c:out value="${testMatrixDefinition}" />
-->
</layout:base>
@@ -0,0 +1,107 @@
goog.provide('indeed.proctor.filter');

indeed.proctor.filter.Filter = function (matrix, container) {
this.textNode = container.querySelector(".js-filter-text");
this.filterTypeNode = container.querySelector(".js-filter-type");
this.filterActiveNode = container.querySelector(".js-filter-active");
this.numMatchedNode = container.querySelector(".js-num-matched");
this.numAllNode = container.querySelector(".js-num-all");
this.models = this.createModels(matrix);
goog.events.listen(this.filterTypeNode, "change", this.refreshFilter.bind(this));
goog.events.listen(this.filterActiveNode, "change", this.refreshFilter.bind(this));

this.textNode.focus();

var timer;
goog.events.listen(this.textNode, "input", function (e) {
if (timer) {
clearTimeout(timer);
}
setTimeout(this.refreshFilter.bind(this), 400);
}.bind(this));
};
indeed.proctor.filter.Filter.prototype.refreshFilter = function () {
var radios = this.filterActiveNode.querySelectorAll("input");
var active = "all";
for (var i = 0; i < radios.length; i++) {
var radio = radios[i];
if (radio.checked) {
active = radio.value;
}
}
this.filter(this.textNode.value, this.filterTypeNode.value, active);
};
indeed.proctor.filter.Filter.prototype.filter = function (text, key, active) {
var texts = text.toLowerCase().split(" ");
var numMatched = 0;

this.models.forEach(function (model) {
var matched = texts.every(function (text) {
return model.texts[key].indexOf(text) >= 0;
});
if (matched) {
if (active == "active") {
matched = model.definition.allocations.some(function (allocation) {
return allocation.ranges.every(function (range) {
return range.length < 1;
});
});
} else if (active == "inactive") {
matched = model.definition.allocations.every(function (allocation) {
return allocation.ranges.some(function (range) {
return range.length == 1;
});
});
}
}
if (matched) {
numMatched++;
model.dom.style.display = "";
} else {
model.dom.style.display = "none";
}
});
this.numMatchedNode.textContent = numMatched;
};

indeed.proctor.filter.Filter.prototype.createModels = function (matrix) {
var models = [];
var divs = document.querySelectorAll("div.ui-test-definition");
for (var i = 0; i < divs.length; i++) {
var div = divs[i];
var testName = div.querySelector(".mtn").textContent;
var definition = matrix.tests[testName];
var model = {
definition: definition,
dom: div.parentNode,
texts: {
testName: normalize(testName),
description: normalize(definition.description || ""),
rule: normalize((definition.rule || "") + definition.allocations.map(function (allocation) {
return allocation.rule || "";
}).join(" ")),
bucket: normalize(definition.buckets.map(function (bucket) {
return bucket.name;
}).join(" ")),
bucketDescription: normalize(definition.buckets.map(function (bucket) {
return bucket.description;
}).join(" ")),
testType: normalize(definition.testType),
salt: normalize(definition.salt)
}
};
var all = [];
for (var j in model.texts) {
all.push(model.texts[j]);
}
model.texts.all = all.join(" ");
models.push(model);
}
this.numMatchedNode.textContent = this.numAllNode.textContent = models.length;
return models;

function normalize(text) {
return text.toLowerCase().replace(/\s+/g, " ");
}
};

Expand Up @@ -13,12 +13,13 @@ goog.require('indeed.foundation.Tabs');
goog.require('indeed.proctor.JobMonitor');
goog.require('indeed.proctor.editor.AllocationsEditor');
goog.require('indeed.proctor.editor.CleanWorkspace');
goog.require('indeed.proctor.filter');


/**
* entry point for the matrix.list
*/
indeed.proctor.app.matrix.list.start = function() {
indeed.proctor.app.matrix.list.start = function(matrix) {
goog.events.listen(window, 'load', function() {

indeed.expandcollapse.ExpandCollapse.detect(document.body);
Expand All @@ -28,6 +29,7 @@ indeed.proctor.app.matrix.list.start = function() {
goog.array.forEach(tabs, function(tab) {
var uiTab = new indeed.foundation.Tabs(tab);
});
new indeed.proctor.filter.Filter(matrix, goog.dom.getElement("filter-container"));
});
};

Expand Down

0 comments on commit 8cb5fa4

Please sign in to comment.