fix: add pager stats to all grid vue data (fixes view history)

also various other tweaks to modernize
This commit is contained in:
Lance Edgar 2024-08-19 13:48:18 -05:00
parent 41945c5e37
commit 15ab0c9592
4 changed files with 21 additions and 28 deletions

View file

@ -237,7 +237,7 @@ class Grid(WuttaGrid):
kwargs.setdefault('sort_defaults', [(sortkey, sortdir)])
if kwargs.get('pageable'):
warnings.warn("component param is deprecated for Grid(); "
warnings.warn("pageable param is deprecated for Grid(); "
"please use vue_tagname param instead",
DeprecationWarning, stacklevel=2)
kwargs.setdefault('paginated', kwargs.pop('pageable'))
@ -1703,6 +1703,10 @@ class Grid(WuttaGrid):
results['checked_rows_code'] = '[{}]'.format(
', '.join(['{}[{}]'.format(var, i) for i in checked]))
if self.paginated and self.paginate_on_backend:
results['pager_stats'] = self.get_vue_pager_stats()
# TODO: is this actually needed now that we have pager_stats?
if self.paginated and self.pager is not None:
results['total_items'] = self.pager.item_count
results['per_page'] = self.pager.items_per_page

View file

@ -115,7 +115,7 @@
## paging
% if grid.paginated:
paginated
pagination-size="is-small"
pagination-size="${'small' if request.use_oruga else 'is-small'}"
:per-page="perPage"
:current-page="currentPage"
@page-change="onPageChange"

View file

@ -120,9 +120,7 @@
</p>
</div>
<versions-grid ref="versionsGrid"
@view-revision="viewRevision">
</versions-grid>
${versions_grid.render_vue_tag(ref='versionsGrid', **{'@view-revision': 'viewRevision'})}
<${b}-modal :width="1200"
% if request.use_oruga:
@ -237,17 +235,16 @@
</%def>
<%def name="render_row_grid_component()">
<tailbone-grid ref="rowGrid" id="rowGrid"></tailbone-grid>
${rows_grid.render_vue_tag(id='rowGrid', ref='rowGrid')}
</%def>
<%def name="render_this_page_template()">
% if getattr(master, 'has_rows', False):
## TODO: stop using |n filter
${rows_grid.render_complete(allow_save_defaults=False, tools=capture(self.render_row_grid_tools))|n}
${rows_grid.render_vue_template(allow_save_defaults=False, tools=capture(self.render_row_grid_tools))}
% endif
${parent.render_this_page_template()}
% if expose_versions:
${versions_grid.render_complete()|n}
${versions_grid.render_vue_template()}
% endif
</%def>
@ -338,19 +335,12 @@
<%def name="finalize_this_page_vars()">
${parent.finalize_this_page_vars()}
<script type="text/javascript">
% if getattr(master, 'has_rows', False):
TailboneGrid.data = function() { return TailboneGridData }
Vue.component('tailbone-grid', TailboneGrid)
${rows_grid.render_vue_finalize()}
% endif
% if expose_versions:
VersionsGrid.data = function() { return VersionsGridData }
Vue.component('versions-grid', VersionsGrid)
${versions_grid.render_vue_finalize()}
% endif
</script>
</%def>

View file

@ -347,8 +347,6 @@ class MasterView(View):
# return grid data only, if partial page was requested
if self.request.GET.get('partial'):
context = grid.get_table_data()
if grid.paginated and grid.paginate_on_backend:
context['pager_stats'] = grid.get_vue_pager_stats()
return self.json_response(context)
context = {
@ -587,7 +585,8 @@ class MasterView(View):
'filterable': self.rows_filterable,
'use_byte_string_filters': self.use_byte_string_filters,
'sortable': self.rows_sortable,
'pageable': self.rows_pageable,
'sort_multiple': not self.request.use_oruga,
'paginated': self.rows_pageable,
'extra_row_class': self.row_grid_extra_class,
'url': lambda obj: self.get_row_action_url('view', obj),
}
@ -675,7 +674,7 @@ class MasterView(View):
defaults = {
'model_class': continuum.transaction_class(self.get_model_class()),
'width': 'full',
'pageable': True,
'paginated': True,
'url': lambda txn: self.request.route_url(route, uuid=instance.uuid, txnid=txn.id),
}
if 'actions' not in kwargs:
@ -1387,8 +1386,8 @@ class MasterView(View):
'vue_tagname': 'versions-grid',
'ajax_data_url': self.get_action_url('revisions_data', obj),
'sortable': True,
'default_sortkey': 'changed',
'default_sortdir': 'desc',
'sort_multiple': not self.request.use_oruga,
'sort_defaults': ('changed', 'desc'),
'actions': [
self.make_action('view', icon='eye', url='#',
click_handler='viewRevision(props.row)'),