Skip to content

Commit

Permalink
Add support for version filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Oct 3, 2024
1 parent 59ccebe commit 00c11df
Showing 1 changed file with 50 additions and 8 deletions.
58 changes: 50 additions & 8 deletions util/gh-pages/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,6 @@ function toggleExpansion(expand) {
);
}

function clearVersionFilters() {
onEachLazy(document.querySelectorAll("#version-filter-count input"), el => el.value = "");
}

const GROUPS_FILTER_DEFAULT = {
cargo: true,
complexity: true,
Expand Down Expand Up @@ -307,11 +303,16 @@ window.filters = {
filters.allLints = Array.prototype.slice.call(
document.getElementsByTagName("article"),
).map(elem => {
let version = elem.querySelector(".label-version").innerText;
// Strip the "pre " prefix for pre 1.29.0 lints
if (version.startsWith("pre ")) {
version = version.slice(4);
}
return {
elem: elem,
group: elem.querySelector(".label-lint-group").innerText,
level: elem.querySelector(".label-lint-level").innerText,
version: elem.querySelector(".label-version").innerText,
version: parseInt(version.split(".")[1]),
applicability: elem.querySelector(".label-applicability").innerText,
filteredOut: false,
searchFilteredOut: false,
Expand All @@ -324,7 +325,11 @@ window.filters = {
for (const lint of filters.getAllLints()) {
lint.filteredOut = (!filters.groups_filter[lint.group]
|| !filters.levels_filter[lint.level]
|| !filters.applicabilities_filter[lint.applicability]);
|| !filters.applicabilities_filter[lint.applicability]
|| !(filters.version_filter["="] === null || lint.version === filters.version_filter["="])
|| !(filters.version_filter["≥"] === null || lint.version > filters.version_filter["≥"])
|| !(filters.version_filter["≤"] === null || lint.version < filters.version_filter["≤"])
);
if (lint.filteredOut || lint.searchFilteredOut) {
lint.elem.style.display = "none";
} else {
Expand All @@ -344,6 +349,38 @@ function updateFilter(elem, filter) {
}
}

function updateVersionFilters(elem, comparisonKind) {
let value = elem.value.trim();
if (value.length === 0) {
value = null;
} else if (/^\d+$/.test(value)) {
value = parseInt(value);
} else {
console.error(`Failed to get version number from "${value}"`);
return;
}
if (filters.version_filter[comparisonKind] !== value) {
filters.version_filter[comparisonKind] = value;
filters.filterLints();
}
}

function clearVersionFilters() {
let needsUpdate = false;

onEachLazy(document.querySelectorAll("#version-filter input"), el => {
el.value = "";
const comparisonKind = el.getAttribute("data-value");
if (filters.version_filter[comparisonKind] !== null) {
needsUpdate = true;
filters.version_filter[comparisonKind] = null;
}
});
if (needsUpdate) {
filters.filterLints();
}
}

function resetGroupsToDefault() {
let needsUpdate = false;

Expand Down Expand Up @@ -414,10 +451,15 @@ function generateSettings() {
<span>1.</span> \
<input type="number" \
min="29" \
id="filter-${kind}" \
class="version-filter-input form-control filter-input" \
maxlength="2" \
onchange="updateVersionFilters()" />\
data-value="${kind}" \
onchange="updateVersionFilters(this, '${kind}')" \
oninput="updateVersionFilters(this, '${kind}')" \
onkeydown="updateVersionFilters(this, '${kind}')" \
onkeyup="updateVersionFilters(this, '${kind}')" \
onpaste="updateVersionFilters(this, '${kind}')" \
/>
<span>.0</span>\
</li>`;
}
Expand Down

0 comments on commit 00c11df

Please sign in to comment.