-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: filters in table searializer and naive filters/search for model…
… data
- Loading branch information
1 parent
747579b
commit 8175728
Showing
8 changed files
with
173 additions
and
44 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
ckanext/collection/templates/collection/serialize/htmx_table/filter.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{% extends "collection/serialize/table/filter.html" %} |
65 changes: 26 additions & 39 deletions
65
ckanext/collection/templates/collection/serialize/htmx_table/form.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,30 @@ | ||
{% set form_id = collection.serializer.form_id %} | ||
{% set base_class = collection.serializer.base_class %} | ||
{% extends "collection/serialize/table/form.html" %} | ||
{% set render_url = collection.serializer.render_url %} | ||
|
||
{% block form %} | ||
<form | ||
class="{{ base_class }}--form" id="{{ form_id }}" | ||
hx-on:htmx:config-request=" | ||
{% if collection.serializer.debug %}console.debug(event.detail.parameters);{% endif %} | ||
{% if collection.serializer.push_url %} | ||
const url = new URL(window.location) | ||
url.searchParams.delete('{{ collection.name }}:page') | ||
Object.entries(event.detail.parameters).forEach(([k, v]) => url.searchParams.set(k, v)); | ||
window.history.pushState({}, null, url); | ||
{% endif %} | ||
" | ||
{# catch plain submission/changes as well as changes from elements that | ||
live outside the form and select2-dropdowns that emit special change | ||
event and require a small delay for clearing them all at once via | ||
ClearFilters #} | ||
hx-trigger=' | ||
change, | ||
submit, | ||
change from:[form="{{ form_id }}"], | ||
collection-trigger from:[data-collection="{{ collection.name }}"], | ||
change.htmx-select2 from:[form="{{ form_id }}"] delay:20' | ||
hx-target="closest .{{ base_class }}" | ||
hx-indicator="closest .{{ base_class }}" | ||
hx-get="{{ render_url }}" | ||
hx-swap="outerHTML" | ||
> | ||
|
||
{% block counter %} | ||
{% snippet collection.serializer.counter_template, collection=collection %} | ||
{% endblock counter %} | ||
<form{% block form_attrs %} | ||
{{ super() }} | ||
hx-on:htmx:config-request=" | ||
{% if collection.serializer.debug %}console.debug(event.detail.parameters);{% endif %} | ||
{% if collection.serializer.push_url %} | ||
const url = new URL(window.location) | ||
url.searchParams.delete('{{ collection.name }}:page') | ||
Object.entries(event.detail.parameters).forEach(([k, v]) => url.searchParams.set(k, v)); | ||
window.history.pushState({}, null, url); | ||
{% endif %} | ||
" | ||
{# catch plain submission/changes as well as changes from elements that | ||
live outside the form and select2-dropdowns that emit special change event | ||
and require a small delay for clearing them all at once via ClearFilters #} | ||
hx-trigger=' | ||
change, | ||
submit, | ||
change from:[form="{{ form_id }}"], | ||
collection-trigger from:[data-collection="{{ collection.name }}"], | ||
change.htmx-select2 from:[form="{{ form_id }}"] delay:20' | ||
hx-target="closest .{{ base_class }}" | ||
hx-indicator="closest .{{ base_class }}" | ||
hx-get="{{ render_url }}" | ||
hx-swap="outerHTML" | ||
|
||
{# this input catches search field submissions. Without it, submission | ||
will include one of page navigation links, which are also implemented | ||
as a submit #} | ||
<input type="submit" hidden> | ||
|
||
</form> | ||
{% endblock form%} | ||
{% endblock form_attrs %}> |
44 changes: 44 additions & 0 deletions
44
ckanext/collection/templates/collection/serialize/table/filter.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{% import 'macros/form.html' as form %} | ||
|
||
{#% set form_id = collection.serializer.form_id %#} | ||
{% set base_class = collection.serializer.base_class %} | ||
|
||
{% for filter in collection.filters.filters %} | ||
{% set name = collection.name ~ ":" ~ filter.name %} | ||
|
||
<div class="{{ base_class }}--filter"> | ||
{% if filter.type == "input" %} | ||
{{ form.input(name, | ||
label=_(filter.options.label or filter.name), | ||
value=request.args[name], | ||
placeholder=_(filter.options.placeholder) if filter.options.placeholder else null, | ||
type=filter.options.type or 'text') }} | ||
|
||
{% elif filter.type == "select" %} | ||
{{ form.select(name, | ||
label=_(filter.options.label or filter.name), | ||
options=filter.options.options or [], | ||
selected=request.args[name]) }} | ||
|
||
{% elif filter.type == "link" %} | ||
{% if filter.options.href %} | ||
{% set url = filter.options.href %} | ||
|
||
{% elif filter.options.endpoint %} | ||
{% set url = h.url_for(filter.options.endpoint, **(filter.options.kwargs or {})) %} | ||
|
||
{% else %} | ||
{% set url = "" %} | ||
|
||
{% endif %} | ||
|
||
<a href="{{ url }}" class="btn btn-primary">{{ _(filter.options.label or filter.name) }}</a> | ||
|
||
{% elif filter.type == "button" %} | ||
<button type="{{ filter.options.type or 'submit' }}" class="btn btn-primary"> | ||
{{ _(filter.options.label or filter.name) }} | ||
</button> | ||
|
||
{% endif %} | ||
</div> | ||
{% endfor %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters