From 5abd7b1ede27603c0c3fdc9f47d4ff9d67c28ed8 Mon Sep 17 00:00:00 2001
From: Stephen Waits
Date: Wed, 18 Nov 2026 10:06:31 -0700
Subject: [PATCH] Say "35 trails", not "35 of 35 trails", when nothing is
filtered out
The count above each set of rows keeps the "12 of 35 trails" form only
when some are filtered out, in the built pages and in the script alike.
Co-Authored-By: Claude Fable 5.2
---
CHANGELOG.md | 4 ++++
web/assets/app.js | 13 ++++++++++---
web/olt/home.py | 2 +-
web/tests/test_facets.py | 3 ++-
web/tests/test_filter_bar.py | 33 +++++++++++++++++++++++++++++++++
5 files changed, 50 insertions(+), 5 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9fc9566..a57a427 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,9 @@
# Changelog
+## 2026-11-18 - The count above a list drops "of" when nothing is left out
+
+- The count above a list of trails now reads "35 trails" when every trail is shown, instead of "35 of 35 trails". When a search or a filter leaves some out it still reads "12 of 35 trails", and it goes back to "35 trails" when everything is cleared. Lists of routes read the same way ("58 routes", "1 of 58 routes").
+- The page and the script that updates it use the same wording, so the count reads the same before and after the script runs.
## 2026-11-18 - The Rae Lakes Loop now has a track
- The Rae Lakes Loop now has a track from OpenStreetMap (relation 1710944, under the Open Database Licence, credited to OpenStreetMap contributors). The loop itself is 57.6 km (35.8 miles) in one part, from the junction of the Paradise Valley and Bubbs Creek trails by Woods Creek, the Rae Lakes and Glen Pass. The 1.9 mile stem from Road's End to that junction is kept apart, as an alternate.
diff --git a/web/assets/app.js b/web/assets/app.js
index a274232..5101b5a 100644
--- a/web/assets/app.js
+++ b/web/assets/app.js
@@ -1545,7 +1545,13 @@
return out;
}
- return { passes: passes, count: count };
+ /* The words after the figure of the count above a list: "trails" when every one is shown,
+ "of 35 trails" when some are left out. */
+ function countWords(shown, total, noun) {
+ return (shown === total ? '' : 'of ' + total + ' ') + noun;
+ }
+
+ return { passes: passes, count: count, countWords: countWords };
})();
/* facet-counts:end */
@@ -1926,13 +1932,14 @@
ol.hidden = !any;
if (head && head.classList.contains('results__group')) head.hidden = !any;
});
- var text = shown.length + ' of ' + total + ' ' + noun;
+ var words = FacetCount.countWords(shown.length, total, noun);
+ var text = shown.length + ' ' + words;
if (count && count.textContent !== text) {
count.innerHTML = '';
var strong = document.createElement('strong');
strong.textContent = String(shown.length);
count.appendChild(strong);
- count.appendChild(document.createTextNode(' of ' + total + ' ' + noun));
+ count.appendChild(document.createTextNode(' ' + words));
}
if (empty) empty.hidden = shown.length > 0;
if (listHead) listHead.hidden = shown.length === 0;
diff --git a/web/olt/home.py b/web/olt/home.py
index 29049be..d67337e 100644
--- a/web/olt/home.py
+++ b/web/olt/home.py
@@ -578,7 +578,7 @@ def results(recs=None, *, finder=False, groups=None, routes_list=False, default_
lists += f'\n \n{rows}\n
'
if finder:
count = (f''
- f'{total} of {total} {noun}
')
+ f'{total} {noun}
')
empty = f"""
No {noun} match these filters.
diff --git a/web/tests/test_facets.py b/web/tests/test_facets.py
index fa07778..7e99144 100644
--- a/web/tests/test_facets.py
+++ b/web/tests/test_facets.py
@@ -297,7 +297,8 @@ class BuiltVocabularyTest(unittest.TestCase):
doc = self.read("index.html")
n = len(re.findall(r'
{n} of {n} trails", doc)
+ self.assertIn(f"{n} trails", doc)
+ self.assertNotIn(f"{n} of {n}", doc)
self.assertIn(f"{n} trails. Narrow them", doc)
def test_route_badges_link_to_the_routes_list(self):
diff --git a/web/tests/test_filter_bar.py b/web/tests/test_filter_bar.py
index 36d60f3..ba17859 100644
--- a/web/tests/test_filter_bar.py
+++ b/web/tests/test_filter_bar.py
@@ -319,6 +319,39 @@ class CountsAreTrueTest(unittest.TestCase):
self.assertIn("var c = FacetCount.count(rows, s, lengthSteps());", js)
+class CountWordsTest(unittest.TestCase):
+ """The count above a list: "35 trails" when none is left out, "12 of 35 trails" when some are."""
+
+ @staticmethod
+ def count_of(body):
+ m = re.search(r']*>([^<]*)([^<]*)
', str(body))
+ return m.group(1) + m.group(2)
+
+ def test_a_page_with_nothing_filtered_reads_the_plain_count(self):
+ records = Pages.recs()
+ lst = browse.LISTS[0]
+ recs = browse.members(lst, records)
+ pages = {"home": home.render(records, SITE, ROOT),
+ "list": regions.list_page(lst, recs, len(records), SITE, records=records)[2]}
+ for name, body in pages.items():
+ if 'id="results-count"' not in str(body):
+ continue
+ text = self.count_of(body)
+ self.assertRegex(text, r"^[\d,]+ (trails?|routes?)$", name)
+ self.assertNotRegex(str(body), r"\b(\d[\d,]*) of \1\b", name)
+
+ @unittest.skipUnless(NODE, "node is not installed")
+ def test_the_script_words_the_count_both_ways(self):
+ prog = facet_count_source() + """
+var c = [[35, 35, 'trails'], [12, 35, 'trails'], [1, 1, 'trail'], [1, 58, 'routes'], [0, 58, 'routes'], [58, 58, 'routes']]
+ .map(function (a) { return a[0] + ' ' + FacetCount.countWords(a[0], a[1], a[2]); });
+process.stdout.write(JSON.stringify(c));
+"""
+ out = subprocess.run([NODE, "-e", prog], capture_output=True, text=True, check=True)
+ self.assertEqual(json.loads(out.stdout), ["35 trails", "12 of 35 trails", "1 trail", "1 of 58 routes",
+ "0 of 58 routes", "58 routes"])
+
+
class PanelInTheFlowTest(unittest.TestCase):
def test_the_open_panel_is_not_laid_over_the_rows(self):
css = read(WEB, "assets", "style.css")