fix: merge filters into main grid template

to better match wuttaweb
This commit is contained in:
Lance Edgar 2024-08-22 19:58:27 -05:00
parent cea3e4b927
commit 37f760959d
3 changed files with 64 additions and 91 deletions

View file

@ -1318,28 +1318,6 @@ class Grid(WuttaGrid):
return data return data
def render_filters(self, template='/grids/filters.mako', **kwargs):
"""
Render the filters to a Unicode string, using the specified template.
Additional kwargs are passed along as context to the template.
"""
# Provide default data to filters form, so renderer can do some of the
# work for us.
data = {}
for filtr in self.iter_active_filters():
data['{}.active'.format(filtr.key)] = filtr.active
data['{}.verb'.format(filtr.key)] = filtr.verb
data[filtr.key] = filtr.value
form = gridfilters.GridFiltersForm(self.filters,
request=self.request,
defaults=data)
kwargs['request'] = self.request
kwargs['grid'] = self
kwargs['form'] = form
return render(template, kwargs)
def render_actions(self, row, i): # pragma: no cover def render_actions(self, row, i): # pragma: no cover
""" """ """ """
warnings.warn("grid.render_actions() is deprecated!", warnings.warn("grid.render_actions() is deprecated!",

View file

@ -10,8 +10,70 @@
<div style="display: flex; flex-direction: column; justify-content: end;"> <div style="display: flex; flex-direction: column; justify-content: end;">
<div class="filters"> <div class="filters">
% if getattr(grid, 'filterable', False): % if getattr(grid, 'filterable', False):
## TODO: stop using |n filter <form method="GET" @submit.prevent="applyFilters()">
${grid.render_filters(allow_save_defaults=allow_save_defaults)|n}
<div style="display: flex; flex-direction: column; gap: 0.5rem;">
<grid-filter v-for="key in filtersSequence"
:key="key"
:filter="filters[key]"
ref="gridFilters">
</grid-filter>
</div>
<div style="display: flex; gap: 0.5rem; margin-top: 0.5rem;">
<b-button type="is-primary"
native-type="submit"
icon-pack="fas"
icon-left="check">
Apply Filters
</b-button>
<b-button v-if="!addFilterShow"
icon-pack="fas"
icon-left="plus"
@click="addFilterInit()">
Add Filter
</b-button>
<b-autocomplete v-if="addFilterShow"
ref="addFilterAutocomplete"
:data="addFilterChoices"
v-model="addFilterTerm"
placeholder="Add Filter"
field="key"
:custom-formatter="formatAddFilterItem"
open-on-focus
keep-first
icon-pack="fas"
clearable
clear-on-select
@select="addFilterSelect">
</b-autocomplete>
<b-button @click="resetView()"
icon-pack="fas"
icon-left="home">
Default View
</b-button>
<b-button @click="clearFilters()"
icon-pack="fas"
icon-left="trash">
No Filters
</b-button>
% if allow_save_defaults and request.user:
<b-button @click="saveDefaults()"
icon-pack="fas"
icon-left="save"
:disabled="savingDefaults">
{{ savingDefaults ? "Working, please wait..." : "Save Defaults" }}
</b-button>
% endif
</div>
</form>
% endif % endif
</div> </div>
</div> </div>

View file

@ -1,67 +0,0 @@
## -*- coding: utf-8; -*-
<form action="${form.action_url}" method="GET" @submit.prevent="applyFilters()">
<div style="display: flex; flex-direction: column; gap: 0.5rem;">
<grid-filter v-for="key in filtersSequence"
:key="key"
:filter="filters[key]"
ref="gridFilters">
</grid-filter>
</div>
<div style="display: flex; gap: 0.5rem; margin-top: 0.5rem;">
<b-button type="is-primary"
native-type="submit"
icon-pack="fas"
icon-left="check">
Apply Filters
</b-button>
<b-button v-if="!addFilterShow"
icon-pack="fas"
icon-left="plus"
@click="addFilterInit()">
Add Filter
</b-button>
<b-autocomplete v-if="addFilterShow"
ref="addFilterAutocomplete"
:data="addFilterChoices"
v-model="addFilterTerm"
placeholder="Add Filter"
field="key"
:custom-formatter="formatAddFilterItem"
open-on-focus
keep-first
icon-pack="fas"
clearable
clear-on-select
@select="addFilterSelect">
</b-autocomplete>
<b-button @click="resetView()"
icon-pack="fas"
icon-left="home">
Default View
</b-button>
<b-button @click="clearFilters()"
icon-pack="fas"
icon-left="trash">
No Filters
</b-button>
% if allow_save_defaults and request.user:
<b-button @click="saveDefaults()"
icon-pack="fas"
icon-left="save"
:disabled="savingDefaults">
{{ savingDefaults ? "Working, please wait..." : "Save Defaults" }}
</b-button>
% endif
</div>
</form>