Show the search box and filters on every park, range and wilderness page, however few trails it has
The bar was written only for a set of ten trails or more (home.FILTER_MIN, added with the list and place filters on 2026-11-17), which left the Wind River Range (7 trails), Yosemite (9) and the Ansel Adams Wilderness (5) with neither a search box nor Filters. Place pages now always get it, and a set that nothing can narrow gets the search box alone, with no Filters button and no empty panel. State and province pages keep the ten-trail threshold for now. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
30d03b8069
commit
d90fa49df5
4 files changed
+57
-10
No files matched your search
+22
-8
@@ -234,7 +234,8 @@ def entry(rec, *, level=3, extra="", routes_list=False, hidden=False, eager=Fals
|
|||||||
|
|
||||||
# The filters ------------------------------------------------------------------
|
# The filters ------------------------------------------------------------------
|
||||||
# One bar and one set of panels, on the home page and on every other page that shows a set of at
|
# One bar and one set of panels, on the home page and on every other page that shows a set of at
|
||||||
# least FILTER_MIN trails (listing()). Everything is built from the page's own trails: a facet that
|
# least FILTER_MIN trails (listing()), and on every park, range and wilderness page whatever its
|
||||||
|
# size (the owner's rule: every set of trails gets the bar). Everything is built from the page's own trails: a facet that
|
||||||
# cannot narrow them is left out, and an option none of them has is not written. The numbers written
|
# cannot narrow them is left out, and an option none of them has is not written. The numbers written
|
||||||
# here are for the whole set; app.js counts again from the rows on the page every time anything
|
# here are for the whole set; app.js counts again from the rows on the page every time anything
|
||||||
# changes, and hides an option that would show nothing (its counting is facetCounts(), which
|
# changes, and hides an option that would show nothing (its counting is facetCounts(), which
|
||||||
@@ -315,11 +316,13 @@ def _missing(records, key):
|
|||||||
f'{esc(facets.missing_text(without, key))} They are left out while this filter is on.</p>')
|
f'{esc(facets.missing_text(without, key))} They are left out while this filter is on.</p>')
|
||||||
|
|
||||||
|
|
||||||
def finder_form(records, c=None, steps=None, where="all"):
|
def finder_form(records, c=None, steps=None, where="all", bare_if_empty=False):
|
||||||
"""The bar (search, Filters, Clear) and the panels: the first-rank filters, then Walking, Shape and
|
"""The bar (search, Filters, Clear) and the panels: the first-rank filters, then Walking, Shape and
|
||||||
GPX behind "More". records: the page's own trails. where: the Where filter's scope ("all",
|
GPX behind "More". records: the page's own trails. where: the Where filter's scope ("all",
|
||||||
"g:<group>" on a group's page, "" for none: a state's page). A facet is written only when it can
|
"g:<group>" on a group's page, "" for none: a state's page). A facet is written only when it can
|
||||||
narrow these trails; each field carries data-facet, for app.js to hide it when it no longer can."""
|
narrow these trails; each field carries data-facet, for app.js to hide it when it no longer can.
|
||||||
|
bare_if_empty: a set that nothing can narrow gets the search box alone, with no Filters
|
||||||
|
button and no empty panel."""
|
||||||
c = c or counts(records)
|
c = c or counts(records)
|
||||||
steps = steps or length_steps(records)
|
steps = steps or length_steps(records)
|
||||||
km_steps = length_steps(records, "km")
|
km_steps = length_steps(records, "km")
|
||||||
@@ -398,6 +401,16 @@ def finder_form(records, c=None, steps=None, where="all"):
|
|||||||
{"".join(more)}
|
{"".join(more)}
|
||||||
</div>
|
</div>
|
||||||
</details>""" if more else ""
|
</details>""" if more else ""
|
||||||
|
if bare_if_empty and not first and not more:
|
||||||
|
return """<form class="filters" id="finder-form" role="search" aria-label="Find a trail">
|
||||||
|
<div class="filters__bar">
|
||||||
|
<div class="filters__search field">
|
||||||
|
<label class="vh" for="q">Search</label>
|
||||||
|
<input class="input" id="q" name="q" type="search" placeholder="Search by name, place or author" autocomplete="off" spellcheck="false">
|
||||||
|
</div>
|
||||||
|
<button class="button button--quiet filters__clear" type="reset" hidden>Clear</button>
|
||||||
|
</div>
|
||||||
|
</form>"""
|
||||||
return f"""<form class="filters" id="finder-form" role="search" aria-label="Find a trail">
|
return f"""<form class="filters" id="finder-form" role="search" aria-label="Find a trail">
|
||||||
<div class="filters__bar">
|
<div class="filters__bar">
|
||||||
<div class="filters__search field">
|
<div class="filters__search field">
|
||||||
@@ -420,14 +433,15 @@ def finder_form(records, c=None, steps=None, where="all"):
|
|||||||
</form>"""
|
</form>"""
|
||||||
|
|
||||||
|
|
||||||
def listing(recs=None, *, where="all", groups=None, **kw):
|
def listing(recs=None, *, where="all", groups=None, always=False, **kw):
|
||||||
"""The rows of a page that shows a set of trails, with the filter bar over them when the set
|
"""The rows of a page that shows a set of trails, with the filter bar over them when the set
|
||||||
has at least FILTER_MIN trails (else results() alone). where: the Where filter's scope
|
has at least FILTER_MIN trails (else results() alone); with always, whatever its size (the
|
||||||
(finder_form). The other arguments are results()'s."""
|
bar then holds only the filters that have something to offer). where: the Where filter's
|
||||||
|
scope (finder_form). The other arguments are results()'s."""
|
||||||
trails = [r for g in groups for r in g[1]] if groups is not None else list(recs)
|
trails = [r for g in groups for r in g[1]] if groups is not None else list(recs)
|
||||||
if len(trails) < FILTER_MIN:
|
if len(trails) < FILTER_MIN and not always:
|
||||||
return results(recs, groups=groups, **kw)
|
return results(recs, groups=groups, **kw)
|
||||||
return Markup(f"""<div class="finder__bar">{finder_form(trails, where=where)}</div>
|
return Markup(f"""<div class="finder__bar">{finder_form(trails, where=where, bare_if_empty=always)}</div>
|
||||||
{results(recs, groups=groups, finder=True, **kw)}""")
|
{results(recs, groups=groups, finder=True, **kw)}""")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ def _kind():
|
|||||||
kicker=_kicker, crumbs=_crumbs, lede=_lede, where="all", wholly=False,
|
kicker=_kicker, crumbs=_crumbs, lede=_lede, where="all", wholly=False,
|
||||||
facts_place=lambda info: (_in_name(info), ()), title_options=_title_options,
|
facts_place=lambda info: (_in_name(info), ()), title_options=_title_options,
|
||||||
description=_description, box=lambda info: info.get("box"), nav=_nav,
|
description=_description, box=lambda info: info.get("box"), nav=_nav,
|
||||||
in_name=_in_name, phrase=_phrase)
|
in_name=_in_name, phrase=_phrase, always_filters=True)
|
||||||
|
|
||||||
|
|
||||||
PARK = _kind()
|
PARK = _kind()
|
||||||
|
|||||||
+2
-1
@@ -308,6 +308,7 @@ class PageKind:
|
|||||||
nav: object
|
nav: object
|
||||||
in_name: object = None
|
in_name: object = None
|
||||||
phrase: object = None
|
phrase: object = None
|
||||||
|
always_filters: bool = False # the filter bar whatever the number of trails
|
||||||
|
|
||||||
|
|
||||||
def _state_kicker(info):
|
def _state_kicker(info):
|
||||||
@@ -431,7 +432,7 @@ def place_page(info, records, site, kind, *, facet_pages=(), place_links=""):
|
|||||||
</div></header>
|
</div></header>
|
||||||
</div></div>
|
</div></div>
|
||||||
<div class="container section place">
|
<div class="container section place">
|
||||||
{home.browse_view(home.listing(recs, top=2, where=kind.where, wholly=wholly), home.overview_map(recs, f"Map of the trails {phrase}", place=kind.box(info)),
|
{home.browse_view(home.listing(recs, top=2, where=kind.where, wholly=wholly, always=kind.always_filters), home.overview_map(recs, f"Map of the trails {phrase}", place=kind.box(info)),
|
||||||
about=f"{summary.facts(recs, records, place=place)}{summary.details(recs)}",
|
about=f"{summary.facts(recs, records, place=place)}{summary.details(recs)}",
|
||||||
about_title=f"About the trails {phrase}")}
|
about_title=f"About the trails {phrase}")}
|
||||||
{nav}{place_links}
|
{nav}{place_links}
|
||||||
|
|||||||
@@ -150,6 +150,38 @@ class LabelPrepositionAndTitleTest(unittest.TestCase):
|
|||||||
"Long Hikes in the Vancouver Island Ranges: 18 Trails")
|
"Long Hikes in the Vancouver Island Ranges: 18 Trails")
|
||||||
|
|
||||||
|
|
||||||
|
class SmallPlaceHasTheBarTest(unittest.TestCase):
|
||||||
|
"""The owner's rule: every set of trails gets the search box and the filters, at any size."""
|
||||||
|
|
||||||
|
def test_a_place_with_three_trails_has_the_search_box_and_the_finder(self):
|
||||||
|
built = built_with([entry_of("range", "wind-river-range", "Wind River Range", ["WY"])], n=3)
|
||||||
|
body = str(built["/ranges/wind-river-range/"].body)
|
||||||
|
self.assertIn('class="finder__bar"', body)
|
||||||
|
self.assertIn('id="q"', body)
|
||||||
|
self.assertIn("data-finder", body)
|
||||||
|
self.assertLess(body.index('class="finder__bar"'), body.index('<li class="entry"'))
|
||||||
|
|
||||||
|
def test_only_filters_that_have_something_to_offer_are_written(self):
|
||||||
|
# three identical trails: nothing narrows them, so the bar is the search box alone
|
||||||
|
built = built_with([entry_of("range", "wind-river-range", "Wind River Range", ["WY"])], n=3)
|
||||||
|
body = str(built["/ranges/wind-river-range/"].body)
|
||||||
|
form = body[body.index('<form class="filters"'):body.index("</form>")]
|
||||||
|
self.assertNotIn("data-facet", form)
|
||||||
|
self.assertNotIn("filters__toggle", form)
|
||||||
|
self.assertNotIn("Nothing here narrows", form)
|
||||||
|
|
||||||
|
def test_a_place_whose_trails_differ_offers_those_filters_with_a_button(self):
|
||||||
|
entries = [entry_of("range", "wind-river-range", "Wind River Range", ["WY", "CO"])]
|
||||||
|
records = [rec(400 + i, f"Differ {i}", [("range", "wind-river-range")], km=50 + i * 120,
|
||||||
|
regs=("WY",) if i % 2 else ("CO",)) for i in range(1, 4)]
|
||||||
|
with tempfile.TemporaryDirectory() as d:
|
||||||
|
write_registry(d, entries)
|
||||||
|
body = str(placepages.build(records, S, d)[0].body)
|
||||||
|
form = body[body.index('<form class="filters"'):body.index("</form>")]
|
||||||
|
self.assertIn('data-facet="where"', form)
|
||||||
|
self.assertIn("filters__toggle", form)
|
||||||
|
|
||||||
|
|
||||||
class PlacePageTest(unittest.TestCase):
|
class PlacePageTest(unittest.TestCase):
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
|
|||||||
Reference in new issue
Block a user