diff --git a/web/assets/app.js b/web/assets/app.js index 5239271..2d77853 100644 --- a/web/assets/app.js +++ b/web/assets/app.js @@ -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(); }); }); diff --git a/web/assets/style.css b/web/assets/style.css index c3cb1e3..342659e 100644 --- a/web/assets/style.css +++ b/web/assets/style.css @@ -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; diff --git a/web/olt/home.py b/web/olt/home.py index a0493e1..ffd053a 100644 --- a/web/olt/home.py +++ b/web/olt/home.py @@ -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
' + '
' + if finder else "") return Markup(f"""', body) + self.assertIn('data-unseasoned-show>Show them', 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()