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)}';
});
% 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() {
$(this)
.button('option', 'disabled', true)
@ -32,7 +32,15 @@
<%def name="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">
.grid-wrapper {
@ -68,7 +76,7 @@
</%def>
<%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:
## TODO: this should surely use a POST request?
<once-button tag="a"
@ -81,30 +89,6 @@
% endif
</%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()">
${self.render_status_breakdown()}
${self.render_execute_helper()}
@ -147,14 +131,49 @@
by ${batch.executed_by}
</p>
% 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>
% if use_buefy:
% if master.has_execution_options(batch):
<p>TODO: must implement execution with options</p>
% else:
<execute-form></execute-form>
% endif
<br />
<b-button type="is-primary"
% if not execute_enabled:
disabled
% if why_not_execute:
title="${why_not_execute}"
% 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:
## no buefy, do legacy thing
<button type="button"
@ -188,7 +207,7 @@
<%def name="render_this_page()">
${parent.render_this_page()}
% 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;">
${execute_form.render_deform(form_kwargs={'name': 'batch-execution'}, buttons=False)|n}
</div>
@ -198,9 +217,9 @@
<%def name="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
${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
</%def>
@ -210,34 +229,29 @@
ThisPageData.statusBreakdownData = ${json.dumps(status_breakdown_grid.get_buefy_data()['data'])|n}
% if not batch.executed and master.has_perm('execute'):
ThisPageData.showExecutionDialog = false
ThisPage.methods.submitExecuteBatch = function() {
this.$refs.executeBatchForm.submit()
}
${execute_form.component_studly}.methods.submit = function() {
this.$refs.actualExecuteForm.submit()
}
% endif
</script>
% if not batch.executed and request.has_perm('{}.execute'.format(permission_prefix)):
<script type="text/javascript">
${execute_form.component_studly}Data.executeFormButtonText = "${execute_title}"
${execute_form.component_studly}Data.executeFormSubmitting = false
${execute_form.component_studly}.methods.executeBatch = function() {
alert("TODO: implement options dialog for batch execution")
}
${execute_form.component_studly}.methods.submitExecuteForm = function() {
this.executeFormSubmitting = true
this.executeFormButtonText = "Executing, please wait..."
}
</script>
% endif
</%def>
<%def name="finalize_this_page_vars()">
${parent.finalize_this_page_vars()}
% if not batch.executed and request.has_perm('{}.execute'.format(permission_prefix)):
<%def name="make_this_page_component()">
${parent.make_this_page_component()}
% if not batch.executed and master.has_perm('execute'):
<script type="text/javascript">
## ExecuteForm
${execute_form.component_studly}.data = function() { return ${execute_form.component_studly}Data }
Vue.component('${execute_form.component}', ${execute_form.component_studly})
</script>

View file

@ -49,6 +49,7 @@ from rattail.progress import SocketProgress
import colander
import deform
from deform import widget as dfwidget
from pyramid.renderers import render_to_response
from pyramid.response import FileResponse
from webhelpers2.html import HTML, tags
@ -800,6 +801,7 @@ class BatchMasterView(MasterView):
"""
defaults = {}
route_prefix = self.get_route_prefix()
use_buefy = self.get_use_buefy()
if self.has_execution_options(batch):
if batch is None:
@ -818,10 +820,14 @@ class BatchMasterView(MasterView):
labels = kwargs.setdefault('labels', {})
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:
schema = colander.Schema()
kwargs['use_buefy'] = self.get_use_buefy()
kwargs['use_buefy'] = use_buefy
kwargs['component'] = 'execute-form'
return forms.Form(schema=schema, request=self.request, defaults=defaults, **kwargs)