From 711ed947a386b4a20dff7421db6ec67c2f91b135 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Fri, 18 Sep 2020 12:17:04 -0500 Subject: [PATCH] Add "worksheet file" pattern for editing batches lets user download a worksheet, edit, then upload back to update the batch --- tailbone/forms/core.py | 3 + tailbone/templates/batch/view.mako | 159 ++++++++++++++++++++++++++++- tailbone/templates/form.mako | 2 +- tailbone/views/batch/core.py | 103 ++++++++++++++++++- tailbone/views/core.py | 9 +- 5 files changed, 262 insertions(+), 14 deletions(-) diff --git a/tailbone/forms/core.py b/tailbone/forms/core.py index 7441e4ab..8f0cbfff 100644 --- a/tailbone/forms/core.py +++ b/tailbone/forms/core.py @@ -623,6 +623,9 @@ class Form(object): if 'required' in kwargs and not kwargs['required']: kw['missing'] = colander.null self.set_node(key, colander.SchemaNode(deform.FileData(), **kw)) + # must explicitly replace node, if we already have a schema + if self.schema: + self.schema[key] = self.nodes[key] else: raise ValueError("unknown type for '{}' field: {}".format(key, type_)) diff --git a/tailbone/templates/batch/view.mako b/tailbone/templates/batch/view.mako index c04ec8c4..b39ea376 100644 --- a/tailbone/templates/batch/view.mako +++ b/tailbone/templates/batch/view.mako @@ -10,7 +10,7 @@ var has_execution_options = ${'true' if master.has_execution_options(batch) else 'false'}; $(function() { - % if master.has_worksheet: + % if master.has_worksheet and master.allow_worksheet(batch) and master.has_perm('worksheet'): $('.load-worksheet').click(function() { disable_button(this); location.href = '${url('{}.worksheet'.format(route_prefix), uuid=batch.uuid)}'; @@ -24,6 +24,36 @@ location.href = '${url('{}.refresh'.format(route_prefix), uuid=batch.uuid)}'; }); % endif + % if master.has_worksheet_file and master.allow_worksheet(batch) and master.has_perm('worksheet'): + $('.upload-worksheet').click(function() { + $('#upload-worksheet-dialog').dialog({ + title: "Upload Worksheet", + width: 600, + modal: true, + buttons: [ + { + text: "Upload & Update Batch", + click: function(event) { + var form = $('form[name="upload-worksheet"]'); + var field = form.find('input[type="file"]').get(0); + if (!field.value) { + alert("Please choose a file to upload."); + return + } + disable_button(dialog_button(event)); + form.submit(); + } + }, + { + text: "Cancel", + click: function() { + $(this).dialog('close'); + } + } + ] + }); + }); + % endif }); @@ -59,6 +89,7 @@
${self.leading_buttons()} ${refresh_button()} + ${self.trailing_buttons()}
@@ -81,7 +112,8 @@ ## TODO: this should surely use a POST request? + text="Refresh Data" + icon-left="fas fa-redo"> % else: @@ -89,6 +121,28 @@ % endif +<%def name="trailing_buttons()"> + % if master.has_worksheet_file and master.allow_worksheet(batch) and master.has_perm('worksheet'): + % if use_buefy: + + Download Worksheet + + + Upload Worksheet + + % else: + ${h.link_to("Download Worksheet", master.get_action_url('download_worksheet', batch), class_='button')} + + % endif + % endif + + <%def name="object_helpers()"> ${self.render_status_breakdown()} ${self.render_execute_helper()} @@ -206,6 +260,54 @@ <%def name="render_this_page()"> ${parent.render_this_page()} + + % if master.has_worksheet_file and master.allow_worksheet(batch) and master.has_perm('worksheet'): + % if use_buefy: + + + + % else: + + % endif + % endif + % if not use_buefy: % if master.handler.executable(batch) and master.has_perm('execute'): % endif % endif + <%def name="render_this_page_template()"> ${parent.render_this_page_template()} - % if use_buefy and master.handler.executable(batch) and master.has_perm('execute'): - ## TODO: stop using |n filter - ${execute_form.render_deform(form_kwargs={'ref': 'actualExecuteForm'}, buttons=False)|n} + % if use_buefy: + % if master.has_worksheet_file and master.allow_worksheet(batch) and master.has_perm('worksheet'): + ${upload_worksheet_form.render_deform(buttons=False, form_kwargs={'ref': 'actualUploadForm'})|n} + % endif + % if master.handler.executable(batch) and master.has_perm('execute'): + ${execute_form.render_deform(form_kwargs={'ref': 'actualExecuteForm'}, buttons=False)|n} + % endif % endif +<%def name="render_buefy_form()"> +
+ <${form.component} @show-upload="showUploadDialog = true"> + +
+ + <%def name="modify_this_page_vars()"> ${parent.modify_this_page_vars()} + % endif + % if not batch.executed and master.has_perm('execute'):