Add auto-filter hyperlinks for batch row status breakdown
This commit is contained in:
parent
5b697cdf26
commit
4d404cb20b
|
@ -79,7 +79,7 @@ class Grid(object):
|
||||||
sortable=False, sorters={}, default_sortkey=None, default_sortdir='asc',
|
sortable=False, sorters={}, default_sortkey=None, default_sortdir='asc',
|
||||||
pageable=False, default_pagesize=20, default_page=1,
|
pageable=False, default_pagesize=20, default_page=1,
|
||||||
checkboxes=False, checked=None, check_handler=None, check_all_handler=None,
|
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,
|
main_actions=[], more_actions=[], delete_speedbump=False,
|
||||||
ajax_data_url=None, component='tailbone-grid',
|
ajax_data_url=None, component='tailbone-grid',
|
||||||
**kwargs):
|
**kwargs):
|
||||||
|
@ -136,6 +136,8 @@ class Grid(object):
|
||||||
self.check_all_handler = check_all_handler
|
self.check_all_handler = check_all_handler
|
||||||
self.clicking_row_checks_box = clicking_row_checks_box
|
self.clicking_row_checks_box = clicking_row_checks_box
|
||||||
|
|
||||||
|
self.click_handlers = click_handlers or {}
|
||||||
|
|
||||||
self.main_actions = main_actions or []
|
self.main_actions = main_actions or []
|
||||||
self.more_actions = more_actions or []
|
self.more_actions = more_actions or []
|
||||||
self.delete_speedbump = delete_speedbump
|
self.delete_speedbump = delete_speedbump
|
||||||
|
@ -261,6 +263,15 @@ class Grid(object):
|
||||||
if self.linked_columns and key in self.linked_columns:
|
if self.linked_columns and key in self.linked_columns:
|
||||||
self.linked_columns.remove(key)
|
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):
|
def set_renderer(self, key, renderer):
|
||||||
self.renderers[key] = renderer
|
self.renderers[key] = renderer
|
||||||
|
|
||||||
|
|
|
@ -154,13 +154,18 @@
|
||||||
</%def>
|
</%def>
|
||||||
|
|
||||||
<%def name="render_status_breakdown()">
|
<%def name="render_status_breakdown()">
|
||||||
% if status_breakdown is not Undefined and status_breakdown is not None:
|
% if use_buefy:
|
||||||
<div class="object-helper">
|
<div class="object-helper">
|
||||||
<h3>Row Status Breakdown</h3>
|
<h3>Row Status Breakdown</h3>
|
||||||
<div class="object-helper-content">
|
<div class="object-helper-content">
|
||||||
% if use_buefy:
|
${status_breakdown_grid|n}
|
||||||
${status_breakdown_grid.render_buefy_table_element(data_prop='statusBreakdownData', empty_labels=True)|n}
|
</div>
|
||||||
% elif status_breakdown:
|
</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">
|
<div class="grid full">
|
||||||
<table>
|
<table>
|
||||||
% for i, (status, count) in enumerate(status_breakdown):
|
% for i, (status, count) in enumerate(status_breakdown):
|
||||||
|
@ -407,7 +412,18 @@
|
||||||
${parent.modify_this_page_vars()}
|
${parent.modify_this_page_vars()}
|
||||||
<script type="text/javascript">
|
<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'):
|
% if master.has_worksheet_file and master.allow_worksheet(batch) and master.has_perm('worksheet'):
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,13 @@
|
||||||
% endif
|
% endif
|
||||||
>
|
>
|
||||||
</a>
|
</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:
|
% else:
|
||||||
<span v-html="props.row.${column['field']}"></span>
|
<span v-html="props.row.${column['field']}"></span>
|
||||||
% endif
|
% endif
|
||||||
|
|
|
@ -434,6 +434,41 @@
|
||||||
this.applyFilters()
|
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() {
|
saveDefaults() {
|
||||||
|
|
||||||
// apply current filters as normal, but add special directive
|
// apply current filters as normal, but add special directive
|
||||||
|
|
|
@ -104,7 +104,7 @@
|
||||||
% if master.has_rows:
|
% if master.has_rows:
|
||||||
% if use_buefy:
|
% if use_buefy:
|
||||||
<br />
|
<br />
|
||||||
<tailbone-grid></tailbone-grid>
|
<tailbone-grid ref="rowGrid" id="rowGrid"></tailbone-grid>
|
||||||
% else:
|
% else:
|
||||||
${rows_grid|n}
|
${rows_grid|n}
|
||||||
% endif
|
% endif
|
||||||
|
|
|
@ -188,13 +188,23 @@ class BatchMasterView(MasterView):
|
||||||
else:
|
else:
|
||||||
kwargs['why_not_execute'] = self.handler.why_not_execute(batch)
|
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:
|
if use_buefy:
|
||||||
data = [{'title': title, 'count': count}
|
factory = self.get_grid_factory()
|
||||||
for title, count in kwargs['status_breakdown']]
|
g = factory('batch_row_status_breakdown', [],
|
||||||
Grid = self.get_grid_factory()
|
columns=['title', 'count'])
|
||||||
kwargs['status_breakdown_grid'] = Grid('batch_row_status_breakdown',
|
g.set_click_handler('title', "autoFilterStatus(props.row)")
|
||||||
data, ['title', 'count'])
|
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
|
return kwargs
|
||||||
|
|
||||||
def make_upload_worksheet_form(self, batch):
|
def make_upload_worksheet_form(self, batch):
|
||||||
|
@ -281,10 +291,7 @@ class BatchMasterView(MasterView):
|
||||||
'count': 0,
|
'count': 0,
|
||||||
}
|
}
|
||||||
breakdown[row.status_code]['count'] += 1
|
breakdown[row.status_code]['count'] += 1
|
||||||
breakdown = [
|
return list(breakdown.values())
|
||||||
(status['title'], status['count'])
|
|
||||||
for code, status in six.iteritems(breakdown)]
|
|
||||||
return breakdown
|
|
||||||
|
|
||||||
def allow_worksheet(self, batch):
|
def allow_worksheet(self, batch):
|
||||||
return not batch.executed and not batch.complete
|
return not batch.executed and not batch.complete
|
||||||
|
|
Loading…
Reference in a new issue