Add auto-filter hyperlinks for batch row status breakdown

This commit is contained in:
Lance Edgar 2022-02-20 19:40:32 -06:00
parent 5b697cdf26
commit 4d404cb20b
6 changed files with 93 additions and 17 deletions

View file

@ -79,7 +79,7 @@ class Grid(object):
sortable=False, sorters={}, default_sortkey=None, default_sortdir='asc',
pageable=False, default_pagesize=20, default_page=1,
checkboxes=False, checked=None, check_handler=None, check_all_handler=None,
clicking_row_checks_box=False,
clicking_row_checks_box=False, click_handlers=None,
main_actions=[], more_actions=[], delete_speedbump=False,
ajax_data_url=None, component='tailbone-grid',
**kwargs):
@ -136,6 +136,8 @@ class Grid(object):
self.check_all_handler = check_all_handler
self.clicking_row_checks_box = clicking_row_checks_box
self.click_handlers = click_handlers or {}
self.main_actions = main_actions or []
self.more_actions = more_actions or []
self.delete_speedbump = delete_speedbump
@ -261,6 +263,15 @@ class Grid(object):
if self.linked_columns and key in self.linked_columns:
self.linked_columns.remove(key)
def set_click_handler(self, key, handler):
if handler:
self.click_handlers[key] = handler
else:
self.click_handlers.pop(key, None)
def has_click_handler(self, key):
return key in self.click_handlers
def set_renderer(self, key, renderer):
self.renderers[key] = renderer

View file

@ -154,13 +154,18 @@
</%def>
<%def name="render_status_breakdown()">
% if status_breakdown is not Undefined and status_breakdown is not None:
% if use_buefy:
<div class="object-helper">
<h3>Row Status Breakdown</h3>
<div class="object-helper-content">
% if use_buefy:
${status_breakdown_grid.render_buefy_table_element(data_prop='statusBreakdownData', empty_labels=True)|n}
% elif status_breakdown:
${status_breakdown_grid|n}
</div>
</div>
% elif status_breakdown is not Undefined and status_breakdown is not None:
<div class="object-helper">
<h3>Row Status Breakdown</h3>
<div class="object-helper-content">
% if status_breakdown:
<div class="grid full">
<table>
% for i, (status, count) in enumerate(status_breakdown):
@ -407,7 +412,18 @@
${parent.modify_this_page_vars()}
<script type="text/javascript">
ThisPageData.statusBreakdownData = ${json.dumps(status_breakdown_grid.get_buefy_data()['data'])|n}
ThisPageData.statusBreakdownData = ${json.dumps(status_breakdown_data)|n}
ThisPage.methods.autoFilterStatus = function(row) {
this.$refs.rowGrid.setFilters([
{key: 'status_code',
verb: 'equal',
value: row.code},
])
document.getElementById('rowGrid').scrollIntoView({
behavior: 'smooth',
})
}
% if master.has_worksheet_file and master.allow_worksheet(batch) and master.has_perm('worksheet'):

View file

@ -40,6 +40,13 @@
% endif
>
</a>
% elif grid.has_click_handler(column['field']):
<span>
<a href="#"
@click.prevent="${grid.click_handlers[column['field']]}"
v-html="props.row.${column['field']}">
</a>
</span>
% else:
<span v-html="props.row.${column['field']}"></span>
% endif

View file

@ -434,6 +434,41 @@
this.applyFilters()
},
// explicitly set filters for the grid, to the given set.
// this totally overrides whatever might be current. the
// new filter set should look like:
//
// [
// {key: 'status_code',
// verb: 'equal',
// value: 1},
// {key: 'description',
// verb: 'contains',
// value: 'whatever'},
// ]
//
setFilters(newFilters) {
for (let key in this.filters) {
let filter = this.filters[key]
let active = false
for (let newFilter of newFilters) {
if (newFilter.key == key) {
active = true
filter.active = true
filter.visible = true
filter.verb = newFilter.verb
filter.value = newFilter.value
break
}
}
if (!active) {
filter.active = false
filter.visible = false
}
}
this.applyFilters()
},
saveDefaults() {
// apply current filters as normal, but add special directive

View file

@ -104,7 +104,7 @@
% if master.has_rows:
% if use_buefy:
<br />
<tailbone-grid></tailbone-grid>
<tailbone-grid ref="rowGrid" id="rowGrid"></tailbone-grid>
% else:
${rows_grid|n}
% endif

View file

@ -188,13 +188,23 @@ class BatchMasterView(MasterView):
else:
kwargs['why_not_execute'] = self.handler.why_not_execute(batch)
kwargs['status_breakdown'] = self.make_status_breakdown(batch)
breakdown = self.make_status_breakdown(batch)
if use_buefy:
data = [{'title': title, 'count': count}
for title, count in kwargs['status_breakdown']]
Grid = self.get_grid_factory()
kwargs['status_breakdown_grid'] = Grid('batch_row_status_breakdown',
data, ['title', 'count'])
factory = self.get_grid_factory()
g = factory('batch_row_status_breakdown', [],
columns=['title', 'count'])
g.set_click_handler('title', "autoFilterStatus(props.row)")
kwargs['status_breakdown_data'] = breakdown
kwargs['status_breakdown_grid'] = HTML.literal(
g.render_buefy_table_element(data_prop='statusBreakdownData',
empty_labels=True))
else:
kwargs['status_breakdown'] = [
(status['title'], status['count'])
for status in breakdown]
return kwargs
def make_upload_worksheet_form(self, batch):
@ -281,10 +291,7 @@ class BatchMasterView(MasterView):
'count': 0,
}
breakdown[row.status_code]['count'] += 1
breakdown = [
(status['title'], status['count'])
for code, status in six.iteritems(breakdown)]
return breakdown
return list(breakdown.values())
def allow_worksheet(self, batch):
return not batch.executed and not batch.complete