Say how many trails a month filter leaves out for having no season on file, with a way to show them

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Fable 5.2 committed 2026-11-19 13:27:01 -07:00
1 parent 92ee879399
commit dea144fd11
4 files changed
+71 -1

No files matched your search

+21
View File
@@ -1715,6 +1715,8 @@
var count = resultsRoot.querySelector('.results-count');
var noun = (count && count.dataset.noun) || 'trails';
var empty = resultsRoot.querySelector('.empty-state');
var unseasoned = resultsRoot.querySelector('[data-unseasoned]');
var unseasonedText = resultsRoot.querySelector('[data-unseasoned-text]');
var active = form.querySelector('.filters__active');
var lenHint = document.getElementById('len-hint');
var listHead = resultsRoot.querySelector('.list-head');
@@ -2088,6 +2090,17 @@
count.appendChild(document.createTextNode(' ' + words));
}
if (empty) empty.hidden = shown.length > 0;
/* With a month chosen, say how many trails that pass everything else are left out for having no
season on file, counted over the same rows as the list. */
if (unseasoned && el.month) {
var noSeason = 0;
if (s.month) rows.forEach(function (d) { if (!d.months.length && FacetCount.passes(d, s, 'month')) noSeason++; });
unseasoned.hidden = noSeason === 0;
if (noSeason) {
unseasonedText.textContent = noSeason + (noSeason === 1 ? ' trail with no season on file is not shown.'
: ' trails with no season on file are not shown.');
}
}
if (listHead) listHead.hidden = shown.length === 0;
relabel(s, c);
setText(lenHint, describeLength(s));
@@ -2115,6 +2128,14 @@
form.addEventListener('change', function () { apply(true); });
form.addEventListener('submit', function (e) { e.preventDefault(); });
form.addEventListener('reset', function () { setTimeout(function () { apply(true); }, 0); });
resultsRoot.querySelectorAll('[data-unseasoned-show]').forEach(function (b) {
/* Showing them is clearing the month; the rest of the filters stay. */
b.addEventListener('click', function () {
if (!el.month) return;
el.month.value = '';
el.month.dispatchEvent(new Event('change', { bubbles: true }));
});
});
resultsRoot.querySelectorAll('[data-reset]').forEach(function (b) {
b.addEventListener('click', function () { form.reset(); el.q.focus(); });
});
+3
View File
@@ -1244,6 +1244,9 @@ html.js .filters__panels:not([data-open]) { display: none; }
.results[data-finder] .results-sort__label { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.results[data-finder] .results-count { flex: none; }
}
.results-note { margin-block: calc(-1 * var(--space-1)) var(--space-3); color: var(--ink-2); font: 400 var(--step--1)/1.4 var(--font-sans); }
.results-note[hidden] { display: none; }
.results-note__show { padding: 0; border: 0; background: none; color: var(--link); font: inherit; text-decoration: underline; cursor: pointer; }
.key {
display: flex;
flex-wrap: wrap;
+6 -1
View File
@@ -618,13 +618,18 @@ def results(recs=None, *, finder=False, groups=None, routes_list=False, default_
tools = sort_select(default_sort, saved=saved, ranked=ranked, wholly=wholly)
dflt = SAVED_ORDER[0] if saved else "rank" if ranked else HERE_ORDER if wholly else default_sort
finder_attr = " data-finder" if finder else ""
# Under the count, while a month is chosen: how many trails are left out for having no season on
# file, and a way to see them (app.js fills it in from the rows, the same ones the list is).
unseasoned = ('\n <p class="results-note" data-unseasoned hidden><span data-unseasoned-text></span> '
'<button class="results-note__show" type="button" data-unseasoned-show>Show them</button></p>'
if finder else "")
return Markup(f"""<div class="results"{finder_attr} data-sortable data-default-sort="{esc(dflt)}">
<div class="results-head">
{count}
<div class="results-tools">
{tools}
</div>
</div>
</div>{unseasoned}
{key(official=not only_routes)}
{list_head(default_sort)}{lists}{empty}
</div>""")
+41
View File
@@ -365,5 +365,46 @@ class PanelInTheFlowTest(unittest.TestCase):
self.assertIn("if (window.location.hash === '#filters') showPanels(true);", js)
class UnseasonedNoteTest(unittest.TestCase):
"""A month filter says how many trails it leaves out for having no season on file."""
def test_a_finder_list_has_the_note_and_it_starts_hidden(self):
recs = recordsmod.load_records(ROOT)
body = str(home.results(recs, finder=True))
self.assertIn('<p class="results-note" data-unseasoned hidden>', body)
self.assertIn('data-unseasoned-show>Show them</button>', body)
self.assertNotIn("data-unseasoned", str(home.results(recs)))
def test_the_script_counts_it_over_the_rows_of_the_list_and_show_them_clears_the_month(self):
js = read(WEB, "assets", "app.js")
self.assertIn("if (!d.months.length && FacetCount.passes(d, s, 'month')) noSeason++;", js)
self.assertIn("' trails with no season on file are not shown.'", js)
self.assertIn("el.month.value = '';", js)
@unittest.skipUnless(NODE, "node is not installed")
def test_the_number_is_the_trails_that_pass_everything_else_and_have_no_season(self):
recs = recordsmod.load_records(ROOT)
rows = rows_of(home.render(recs, SITE, ROOT))
prog = facet_count_source() + """
var input = JSON.parse(require('fs').readFileSync(0, 'utf8'));
input.s.max = Infinity;
var n = 0, shown = 0;
input.rows.forEach(function (d) {
if (FacetCount.passes(d, input.s, '')) shown++;
else if (!d.months.length && FacetCount.passes(d, input.s, 'month')) n++;
});
process.stdout.write(JSON.stringify([shown, n]));
"""
for s in (state(month="8"), state(month="8", kind="route"), state(month="8", where="US-CA")):
out = subprocess.run([NODE, "-e", prog], input=json.dumps({"rows": rows, "s": s}),
capture_output=True, text=True, check=True)
shown, n = json.loads(out.stdout)
def base(r):
return ((not s["kind"] or facets.kind(r) == s["kind"])
and (not s["where"] or s["where"] in facets.where_tokens(r)))
self.assertEqual(shown, sum(1 for r in recs if base(r) and 8 in facets.months(r)))
self.assertEqual(n, sum(1 for r in recs if base(r) and not facets.months(r)))
if __name__ == "__main__":
unittest.main()