Add support for batch execution options in Buefy themes

i.e. from "view batch" page
This commit is contained in:
Lance Edgar 2020-08-23 13:46:32 -05:00
parent 7a0f975b31
commit d2d632092b
2 changed files with 79 additions and 59 deletions

View file

@ -16,7 +16,7 @@
location.href = '${url('{}.worksheet'.format(route_prefix), uuid=batch.uuid)}'; location.href = '${url('{}.worksheet'.format(route_prefix), uuid=batch.uuid)}';
}); });
% endif % endif
% if master.batch_refreshable(batch) and request.has_perm('{}.refresh'.format(permission_prefix)): % if master.batch_refreshable(batch) and master.has_perm('refresh'):
$('#refresh-data').click(function() { $('#refresh-data').click(function() {
$(this) $(this)
.button('option', 'disabled', true) .button('option', 'disabled', true)
@ -32,7 +32,15 @@
<%def name="extra_styles()"> <%def name="extra_styles()">
${parent.extra_styles()} ${parent.extra_styles()}
% if not use_buefy: % if use_buefy:
<style type="text/css">
.modal-card-body label {
white-space: nowrap;
}
</style>
% else:
<style type="text/css"> <style type="text/css">
.grid-wrapper { .grid-wrapper {
@ -68,7 +76,7 @@
</%def> </%def>
<%def name="refresh_button()"> <%def name="refresh_button()">
% if master.batch_refreshable(batch) and request.has_perm('{}.refresh'.format(permission_prefix)): % if master.batch_refreshable(batch) and master.has_perm('refresh'):
% if use_buefy: % if use_buefy:
## TODO: this should surely use a POST request? ## TODO: this should surely use a POST request?
<once-button tag="a" <once-button tag="a"
@ -81,30 +89,6 @@
% endif % endif
</%def> </%def>
<%def name="execute_submit_button()">
<b-button type="is-primary"
% if master.has_execution_options(batch):
@click="executeBatch"
% else:
native-type="submit"
% endif
% if not execute_enabled:
disabled
% elif not master.has_execution_options(batch):
:disabled="executeFormSubmitting"
% endif
% if why_not_execute:
title="${why_not_execute}"
% endif
>
% if master.has_execution_options(batch):
${execute_title}
% else:
{{ executeFormButtonText }}
% endif
</b-button>
</%def>
<%def name="object_helpers()"> <%def name="object_helpers()">
${self.render_status_breakdown()} ${self.render_status_breakdown()}
${self.render_execute_helper()} ${self.render_execute_helper()}
@ -147,14 +131,49 @@
by ${batch.executed_by} by ${batch.executed_by}
</p> </p>
% elif master.handler.executable(batch): % elif master.handler.executable(batch):
% if request.has_perm('{}.execute'.format(permission_prefix)): % if master.has_perm('execute'):
<p>Batch has not yet been executed.</p> <p>Batch has not yet been executed.</p>
% if use_buefy: % if use_buefy:
% if master.has_execution_options(batch): <br />
<p>TODO: must implement execution with options</p> <b-button type="is-primary"
% else: % if not execute_enabled:
<execute-form></execute-form> disabled
% if why_not_execute:
title="${why_not_execute}"
% endif % endif
% endif
@click="showExecutionDialog = true"
icon-pack="fas"
icon-left="arrow-circle-right">
${execute_title}
</b-button>
<b-modal has-modal-card
:active.sync="showExecutionDialog">
<div class="modal-card">
<header class="modal-card-head">
<p class="modal-card-title">Execute ${model_title}</p>
</header>
<section class="modal-card-body">
<${execute_form.component} ref="executeBatchForm"></${execute_form.component}>
</section>
<footer class="modal-card-foot">
<b-button @click="showExecutionDialog = false">
Cancel
</b-button>
<once-button type="is-primary"
@click="submitExecuteBatch()"
icon-left="arrow-circle-right"
text="Execute Batch">
</once-button>
</footer>
</div>
</b-modal>
% else: % else:
## no buefy, do legacy thing ## no buefy, do legacy thing
<button type="button" <button type="button"
@ -188,7 +207,7 @@
<%def name="render_this_page()"> <%def name="render_this_page()">
${parent.render_this_page()} ${parent.render_this_page()}
% if not use_buefy: % if not use_buefy:
% if master.handler.executable(batch) and request.has_perm('{}.execute'.format(permission_prefix)): % if master.handler.executable(batch) and master.has_perm('execute'):
<div id="execution-options-dialog" style="display: none;"> <div id="execution-options-dialog" style="display: none;">
${execute_form.render_deform(form_kwargs={'name': 'batch-execution'}, buttons=False)|n} ${execute_form.render_deform(form_kwargs={'name': 'batch-execution'}, buttons=False)|n}
</div> </div>
@ -198,9 +217,9 @@
<%def name="render_this_page_template()"> <%def name="render_this_page_template()">
${parent.render_this_page_template()} ${parent.render_this_page_template()}
% if use_buefy and master.handler.executable(batch) and request.has_perm('{}.execute'.format(permission_prefix)): % if use_buefy and master.handler.executable(batch) and master.has_perm('execute'):
## TODO: stop using |n filter ## TODO: stop using |n filter
${execute_form.render_deform(buttons=capture(execute_submit_button), form_kwargs={'@submit': 'submitExecuteForm'})|n} ${execute_form.render_deform(form_kwargs={'ref': 'actualExecuteForm'}, buttons=False)|n}
% endif % endif
</%def> </%def>
@ -210,34 +229,29 @@
ThisPageData.statusBreakdownData = ${json.dumps(status_breakdown_grid.get_buefy_data()['data'])|n} ThisPageData.statusBreakdownData = ${json.dumps(status_breakdown_grid.get_buefy_data()['data'])|n}
</script> % if not batch.executed and master.has_perm('execute'):
% if not batch.executed and request.has_perm('{}.execute'.format(permission_prefix)): ThisPageData.showExecutionDialog = false
<script type="text/javascript">
${execute_form.component_studly}Data.executeFormButtonText = "${execute_title}" ThisPage.methods.submitExecuteBatch = function() {
${execute_form.component_studly}Data.executeFormSubmitting = false this.$refs.executeBatchForm.submit()
${execute_form.component_studly}.methods.executeBatch = function() {
alert("TODO: implement options dialog for batch execution")
} }
${execute_form.component_studly}.methods.submitExecuteForm = function() { ${execute_form.component_studly}.methods.submit = function() {
this.executeFormSubmitting = true this.$refs.actualExecuteForm.submit()
this.executeFormButtonText = "Executing, please wait..."
} }
</script>
% endif % endif
</script>
</%def> </%def>
<%def name="finalize_this_page_vars()"> <%def name="make_this_page_component()">
${parent.finalize_this_page_vars()} ${parent.make_this_page_component()}
% if not batch.executed and request.has_perm('{}.execute'.format(permission_prefix)): % if not batch.executed and master.has_perm('execute'):
<script type="text/javascript"> <script type="text/javascript">
## ExecuteForm
${execute_form.component_studly}.data = function() { return ${execute_form.component_studly}Data } ${execute_form.component_studly}.data = function() { return ${execute_form.component_studly}Data }
Vue.component('${execute_form.component}', ${execute_form.component_studly}) Vue.component('${execute_form.component}', ${execute_form.component_studly})
</script> </script>

View file

@ -49,6 +49,7 @@ from rattail.progress import SocketProgress
import colander import colander
import deform import deform
from deform import widget as dfwidget
from pyramid.renderers import render_to_response from pyramid.renderers import render_to_response
from pyramid.response import FileResponse from pyramid.response import FileResponse
from webhelpers2.html import HTML, tags from webhelpers2.html import HTML, tags
@ -800,6 +801,7 @@ class BatchMasterView(MasterView):
""" """
defaults = {} defaults = {}
route_prefix = self.get_route_prefix() route_prefix = self.get_route_prefix()
use_buefy = self.get_use_buefy()
if self.has_execution_options(batch): if self.has_execution_options(batch):
if batch is None: if batch is None:
@ -818,10 +820,14 @@ class BatchMasterView(MasterView):
labels = kwargs.setdefault('labels', {}) labels = kwargs.setdefault('labels', {})
labels[field.name] = field.title labels[field.name] = field.title
# auto-convert select widgets for buefy theme
if use_buefy and isinstance(field.widget, forms.widgets.PlainSelectWidget):
field.widget = dfwidget.SelectWidget(values=field.widget.values)
else: else:
schema = colander.Schema() schema = colander.Schema()
kwargs['use_buefy'] = self.get_use_buefy() kwargs['use_buefy'] = use_buefy
kwargs['component'] = 'execute-form' kwargs['component'] = 'execute-form'
return forms.Form(schema=schema, request=self.request, defaults=defaults, **kwargs) return forms.Form(schema=schema, request=self.request, defaults=defaults, **kwargs)