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
' - 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']*>([^<]*)([^<]*)
', 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")