kopia lustrzana https://github.com/simonw/datasette
Show count of facet values if ?_facet_size=max, closes #1423
rodzic
2883098770
commit
adb5b70de5
|
@ -633,6 +633,11 @@ form button[type=button] {
|
||||||
width: 250px;
|
width: 250px;
|
||||||
margin-right: 15px;
|
margin-right: 15px;
|
||||||
}
|
}
|
||||||
|
.facet-info-total {
|
||||||
|
font-size: 0.8em;
|
||||||
|
color: #666;
|
||||||
|
padding-right: 0.25em;
|
||||||
|
}
|
||||||
.facet-info li,
|
.facet-info li,
|
||||||
.facet-info ul {
|
.facet-info ul {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
|
|
@ -156,7 +156,9 @@
|
||||||
{% for facet_info in sorted_facet_results %}
|
{% for facet_info in sorted_facet_results %}
|
||||||
<div class="facet-info facet-{{ database|to_css_class }}-{{ table|to_css_class }}-{{ facet_info.name|to_css_class }}" id="facet-{{ facet_info.name|to_css_class }}">
|
<div class="facet-info facet-{{ database|to_css_class }}-{{ table|to_css_class }}-{{ facet_info.name|to_css_class }}" id="facet-{{ facet_info.name|to_css_class }}">
|
||||||
<p class="facet-info-name">
|
<p class="facet-info-name">
|
||||||
<strong>{{ facet_info.name }}{% if facet_info.type != "column" %} ({{ facet_info.type }}){% endif %}</strong>
|
<strong>{{ facet_info.name }}{% if facet_info.type != "column" %} ({{ facet_info.type }}){% endif %}
|
||||||
|
{% if show_facet_counts %} <span class="facet-info-total">{% if facet_info.truncated %}>{% endif %}{{ facet_info.results|length }}</span>{% endif %}
|
||||||
|
</strong>
|
||||||
{% if facet_info.hideable %}
|
{% if facet_info.hideable %}
|
||||||
<a href="{{ facet_info.toggle_url }}" class="cross">✖</a>
|
<a href="{{ facet_info.toggle_url }}" class="cross">✖</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -928,6 +928,7 @@ class TableView(RowTableShared):
|
||||||
key=lambda f: (len(f["results"]), f["name"]),
|
key=lambda f: (len(f["results"]), f["name"]),
|
||||||
reverse=True,
|
reverse=True,
|
||||||
),
|
),
|
||||||
|
"show_facet_counts": special_args.get("_facet_size") == "max",
|
||||||
"extra_wheres_for_ui": extra_wheres_for_ui,
|
"extra_wheres_for_ui": extra_wheres_for_ui,
|
||||||
"form_hidden_args": form_hidden_args,
|
"form_hidden_args": form_hidden_args,
|
||||||
"is_sortable": any(c["sortable"] for c in display_columns),
|
"is_sortable": any(c["sortable"] for c in display_columns),
|
||||||
|
|
|
@ -479,7 +479,7 @@ def test_facet_display(app_client):
|
||||||
for div in divs:
|
for div in divs:
|
||||||
actual.append(
|
actual.append(
|
||||||
{
|
{
|
||||||
"name": div.find("strong").text,
|
"name": div.find("strong").text.split()[0],
|
||||||
"items": [
|
"items": [
|
||||||
{
|
{
|
||||||
"name": a.text,
|
"name": a.text,
|
||||||
|
@ -1797,3 +1797,23 @@ def test_column_metadata(app_client):
|
||||||
soup.select("th[data-column=address]")[0]["data-column-description"]
|
soup.select("th[data-column=address]")[0]["data-column-description"]
|
||||||
== "The street address for the attraction"
|
== "The street address for the attraction"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("use_facet_size_max", (True, False))
|
||||||
|
def test_facet_total_shown_if_facet_max_size(use_facet_size_max):
|
||||||
|
# https://github.com/simonw/datasette/issues/1423
|
||||||
|
with make_app_client(settings={"max_returned_rows": 100}) as client:
|
||||||
|
path = "/fixtures/sortable?_facet=content&_facet=pk1"
|
||||||
|
if use_facet_size_max:
|
||||||
|
path += "&_facet_size=max"
|
||||||
|
response = client.get(path)
|
||||||
|
assert response.status == 200
|
||||||
|
fragments = (
|
||||||
|
'<span class="facet-info-total">>100</span>',
|
||||||
|
'<span class="facet-info-total">8</span>',
|
||||||
|
)
|
||||||
|
for fragment in fragments:
|
||||||
|
if use_facet_size_max:
|
||||||
|
assert fragment in response.text
|
||||||
|
else:
|
||||||
|
assert fragment not in response.text
|
||||||
|
|
Ładowanie…
Reference in New Issue