Add basic Buefy support for row grids

possibly even "complete" support...guess we'll see
This commit is contained in:
Lance Edgar 2019-05-06 19:53:59 -05:00
parent a3ca6abb7a
commit 9d6cc86e60
4 changed files with 51 additions and 17 deletions

View file

@ -123,7 +123,14 @@
</div> </div>
${rows_grid|n} % if use_buefy:
<br /><br />
## TODO: stop using |n filter
${rows_grid.render_buefy(allow_save_defaults=False, tools=rows_grid_tools)|n}
% else:
## no buefy, so do the traditional thing
${rows_grid|n}
% endif
% if master.handler.executable(batch) and not batch.executed: % if master.handler.executable(batch) and not batch.executed:
<div id="execution-options-dialog" style="display: none;"> <div id="execution-options-dialog" style="display: none;">

View file

@ -6,17 +6,21 @@
<%def name="extra_javascript()"> <%def name="extra_javascript()">
${parent.extra_javascript()} ${parent.extra_javascript()}
% if master.has_rows: % if master.has_rows:
% if use_buefy:
${h.javascript_link(request.static_url('tailbone:static/js/tailbone.buefy.gridfilters.js') + '?ver={}'.format(tailbone.__version__))}
% else:
<script type="text/javascript"> <script type="text/javascript">
$(function() { $(function() {
$('.grid-wrapper').gridwrapper(); $('.grid-wrapper').gridwrapper();
}); });
</script> </script>
% endif
% endif % endif
</%def> </%def>
<%def name="extra_styles()"> <%def name="extra_styles()">
${parent.extra_styles()} ${parent.extra_styles()}
% if master.has_rows: % if master.has_rows and not use_buefy:
<style type="text/css"> <style type="text/css">
.grid-wrapper { .grid-wrapper {
margin-top: 10px; margin-top: 10px;
@ -83,5 +87,12 @@
</div> </div>
% if master.has_rows: % if master.has_rows:
${rows_grid|n} % if use_buefy:
<br /><br />
## TODO: stop using |n filter
${rows_grid.render_buefy(allow_save_defaults=False, tools=rows_grid_tools)|n}
% else:
## no buefy, so do the traditional thing
${rows_grid|n}
% endif
% endif % endif

View file

@ -556,6 +556,8 @@ class BatchMasterView(MasterView):
g.set_label('status_code', "Status") g.set_label('status_code', "Status")
g.set_label('item_id', "Item ID") g.set_label('item_id', "Item ID")
g.set_link('sequence')
def get_row_status_enum(self): def get_row_status_enum(self):
return self.model_row_class.STATUS return self.model_row_class.STATUS
@ -650,23 +652,25 @@ class BatchMasterView(MasterView):
# TODO: most of this logic is copied from MasterView, should refactor/merge somehow... # TODO: most of this logic is copied from MasterView, should refactor/merge somehow...
if 'main_actions' not in kwargs: if 'main_actions' not in kwargs:
actions = [] actions = []
use_buefy = self.get_use_buefy()
# view action # view action
if self.rows_viewable: if self.rows_viewable:
view = lambda r, i: self.get_row_action_url('view', r) view = lambda r, i: self.get_row_action_url('view', r)
actions.append(grids.GridAction('view', icon='zoomin', url=view)) icon = 'eye' if use_buefy else 'zoomin'
actions.append(self.make_action('view', icon=icon, url=view))
# edit and delete are NOT allowed after execution, or if batch is "complete" # edit and delete are NOT allowed after execution, or if batch is "complete"
if not batch.executed and not batch.complete: if not batch.executed and not batch.complete:
# edit action # edit action
if self.rows_editable: if self.rows_editable:
actions.append(grids.GridAction('edit', icon='pencil', url=self.row_edit_action_url)) actions.append(self.make_action('edit', icon='pencil', url=self.row_edit_action_url))
# delete action # delete action
permission_prefix = self.get_permission_prefix() permission_prefix = self.get_permission_prefix()
if self.rows_deletable and self.request.has_perm('{}.delete_row'.format(permission_prefix)): if self.rows_deletable and self.request.has_perm('{}.delete_row'.format(permission_prefix)):
actions.append(grids.GridAction('delete', icon='trash', url=self.row_delete_action_url)) actions.append(self.make_action('delete', icon='trash', url=self.row_delete_action_url))
kwargs.setdefault('delete_speedbump', self.rows_deletable_speedbump) kwargs.setdefault('delete_speedbump', self.rows_deletable_speedbump)
kwargs['main_actions'] = actions kwargs['main_actions'] = actions

View file

@ -446,19 +446,21 @@ class MasterView(View):
if self.has_rows and 'main_actions' not in defaults: if self.has_rows and 'main_actions' not in defaults:
actions = [] actions = []
use_buefy = self.get_use_buefy()
# view action # view action
if self.rows_viewable: if self.rows_viewable:
view = lambda r, i: self.get_row_action_url('view', r) view = lambda r, i: self.get_row_action_url('view', r)
actions.append(grids.GridAction('view', icon='zoomin', url=view)) icon = 'eye' if use_buefy else 'zoomin'
actions.append(self.make_action('view', icon=icon, url=view))
# edit action # edit action
if self.rows_editable: if self.rows_editable:
actions.append(grids.GridAction('edit', icon='pencil', url=self.row_edit_action_url)) actions.append(self.make_action('edit', icon='pencil', url=self.row_edit_action_url))
# delete action # delete action
if self.rows_deletable and self.request.has_perm('{}.delete_row'.format(permission_prefix)): if self.rows_deletable and self.request.has_perm('{}.delete_row'.format(permission_prefix)):
actions.append(grids.GridAction('delete', icon='trash', url=self.row_delete_action_url)) actions.append(self.make_action('delete', icon='trash', url=self.row_delete_action_url))
defaults['delete_speedbump'] = self.rows_deletable_speedbump defaults['delete_speedbump'] = self.rows_deletable_speedbump
defaults['main_actions'] = actions defaults['main_actions'] = actions
@ -968,6 +970,7 @@ class MasterView(View):
View for viewing details of an existing model record. View for viewing details of an existing model record.
""" """
self.viewing = True self.viewing = True
use_buefy = self.get_use_buefy()
if instance is None: if instance is None:
instance = self.get_instance() instance = self.get_instance()
form = self.make_form(instance) form = self.make_form(instance)
@ -983,13 +986,16 @@ class MasterView(View):
if self.request.GET.get('reset-to-default-filters') == 'true': if self.request.GET.get('reset-to-default-filters') == 'true':
return self.redirect(self.request.current_route_url(_query=None)) return self.redirect(self.request.current_route_url(_query=None))
# return grid only, if partial page was requested
if self.request.params.get('partial'): if self.request.params.get('partial'):
if six.PY3: if use_buefy:
self.request.response.content_type = 'text/html' # render grid data only, as JSON
else: return render_to_response('json', grid.get_buefy_data(),
self.request.response.content_type = b'text/html' request=self.request)
self.request.response.text = grid.render_grid() else: # just do traditional thing, render grid HTML
return self.request.response self.request.response.content_type = str('text/html')
self.request.response.text = grid.render_grid()
return self.request.response
context = { context = {
'instance': instance, 'instance': instance,
@ -1000,9 +1006,15 @@ class MasterView(View):
} }
if hasattr(form, 'make_deform_form'): if hasattr(form, 'make_deform_form'):
context['dform'] = form.make_deform_form() context['dform'] = form.make_deform_form()
if self.has_rows: if self.has_rows:
context['rows_grid'] = grid.render_complete(allow_save_defaults=False, if use_buefy:
tools=self.make_row_grid_tools(instance)) context['rows_grid'] = grid
context['rows_grid_tools'] = HTML(self.make_row_grid_tools(instance) or '').strip()
else:
context['rows_grid'] = grid.render_complete(allow_save_defaults=False,
tools=self.make_row_grid_tools(instance))
return self.render_to_response('view', context) return self.render_to_response('view', context)
def image(self): def image(self):