Skip to content

Commit 00c11df

Browse files
Add support for version filtering
1 parent 59ccebe commit 00c11df

File tree

1 file changed

+50
-8
lines changed

1 file changed

+50
-8
lines changed

util/gh-pages/script.js

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,6 @@ function toggleExpansion(expand) {
262262
);
263263
}
264264

265-
function clearVersionFilters() {
266-
onEachLazy(document.querySelectorAll("#version-filter-count input"), el => el.value = "");
267-
}
268-
269265
const GROUPS_FILTER_DEFAULT = {
270266
cargo: true,
271267
complexity: true,
@@ -307,11 +303,16 @@ window.filters = {
307303
filters.allLints = Array.prototype.slice.call(
308304
document.getElementsByTagName("article"),
309305
).map(elem => {
306+
let version = elem.querySelector(".label-version").innerText;
307+
// Strip the "pre " prefix for pre 1.29.0 lints
308+
if (version.startsWith("pre ")) {
309+
version = version.slice(4);
310+
}
310311
return {
311312
elem: elem,
312313
group: elem.querySelector(".label-lint-group").innerText,
313314
level: elem.querySelector(".label-lint-level").innerText,
314-
version: elem.querySelector(".label-version").innerText,
315+
version: parseInt(version.split(".")[1]),
315316
applicability: elem.querySelector(".label-applicability").innerText,
316317
filteredOut: false,
317318
searchFilteredOut: false,
@@ -324,7 +325,11 @@ window.filters = {
324325
for (const lint of filters.getAllLints()) {
325326
lint.filteredOut = (!filters.groups_filter[lint.group]
326327
|| !filters.levels_filter[lint.level]
327-
|| !filters.applicabilities_filter[lint.applicability]);
328+
|| !filters.applicabilities_filter[lint.applicability]
329+
|| !(filters.version_filter["="] === null || lint.version === filters.version_filter["="])
330+
|| !(filters.version_filter["≥"] === null || lint.version > filters.version_filter["≥"])
331+
|| !(filters.version_filter["≤"] === null || lint.version < filters.version_filter["≤"])
332+
);
328333
if (lint.filteredOut || lint.searchFilteredOut) {
329334
lint.elem.style.display = "none";
330335
} else {
@@ -344,6 +349,38 @@ function updateFilter(elem, filter) {
344349
}
345350
}
346351

352+
function updateVersionFilters(elem, comparisonKind) {
353+
let value = elem.value.trim();
354+
if (value.length === 0) {
355+
value = null;
356+
} else if (/^\d+$/.test(value)) {
357+
value = parseInt(value);
358+
} else {
359+
console.error(`Failed to get version number from "${value}"`);
360+
return;
361+
}
362+
if (filters.version_filter[comparisonKind] !== value) {
363+
filters.version_filter[comparisonKind] = value;
364+
filters.filterLints();
365+
}
366+
}
367+
368+
function clearVersionFilters() {
369+
let needsUpdate = false;
370+
371+
onEachLazy(document.querySelectorAll("#version-filter input"), el => {
372+
el.value = "";
373+
const comparisonKind = el.getAttribute("data-value");
374+
if (filters.version_filter[comparisonKind] !== null) {
375+
needsUpdate = true;
376+
filters.version_filter[comparisonKind] = null;
377+
}
378+
});
379+
if (needsUpdate) {
380+
filters.filterLints();
381+
}
382+
}
383+
347384
function resetGroupsToDefault() {
348385
let needsUpdate = false;
349386

@@ -414,10 +451,15 @@ function generateSettings() {
414451
<span>1.</span> \
415452
<input type="number" \
416453
min="29" \
417-
id="filter-${kind}" \
418454
class="version-filter-input form-control filter-input" \
419455
maxlength="2" \
420-
onchange="updateVersionFilters()" />\
456+
data-value="${kind}" \
457+
onchange="updateVersionFilters(this, '${kind}')" \
458+
oninput="updateVersionFilters(this, '${kind}')" \
459+
onkeydown="updateVersionFilters(this, '${kind}')" \
460+
onkeyup="updateVersionFilters(this, '${kind}')" \
461+
onpaste="updateVersionFilters(this, '${kind}')" \
462+
/>
421463
<span>.0</span>\
422464
</li>`;
423465
}

0 commit comments

Comments
 (0)