{% if record['list'] %}
--
cgit v1.2.3
From dee0caa3162420a67b39db92f81f762048cb7ad0 Mon Sep 17 00:00:00 2001
From: Pjotr Prins
Date: Fri, 15 May 2020 10:00:26 -0500
Subject: Change submit button on click
---
bh20simplewebuploader/main.py | 43 ++++++++++++++++---------------
bh20simplewebuploader/static/main.js | 31 +++++++++++++---------
bh20simplewebuploader/templates/form.html | 2 +-
3 files changed, 42 insertions(+), 34 deletions(-)
diff --git a/bh20simplewebuploader/main.py b/bh20simplewebuploader/main.py
index e80713f..f4eabe6 100644
--- a/bh20simplewebuploader/main.py
+++ b/bh20simplewebuploader/main.py
@@ -48,10 +48,10 @@ def name_to_label(field_name):
"""
Turn a filed name like "host_health_status" from the metadata schema into a human-readable label.
"""
-
+
# May end in a number, which should be set off by a space
set_off_number = re.sub('([0-9]+)$', r' \1', field_name)
-
+
return string.capwords(set_off_number.replace('_', ' '))
def is_iri(string):
@@ -72,13 +72,13 @@ def generate_form(schema, options):
Each dict either has a 'heading' (in which case we put a heading for a
form section in the template) or an 'id', 'label', 'type', and 'required'
(in which case we make a form field in the template).
-
+
Non-heading dicts with type 'select' will have an 'options' field, with a
list of (name, value) tuples, and represent a form dropdown element.
-
+
Non-heading dicts with type 'number' may have a 'step', which, if <1 or
'any', allows the number to be a float.
-
+
Non-heading dicts may have a human-readable 'docstring' field describing
them.
@@ -125,7 +125,7 @@ def generate_form(schema, options):
docstring = None
if not isinstance(field_type, str):
# If the type isn't a string
-
+
# It may have documentation
docstring = field_type.get('doc', None)
@@ -159,7 +159,7 @@ def generate_form(schema, options):
optional = True
# Drop the ?
field_type = field_type[:-1]
-
+
# Decide if the field is a list (type ends in [])
is_list = False
if field_type.endswith('[]'):
@@ -280,6 +280,7 @@ def receive_files():
Receive the uploaded files.
"""
+ return 0
# We're going to work in one directory per request
dest_dir = tempfile.mkdtemp()
# The uploader will happily accept a FASTQ with this name
@@ -310,7 +311,7 @@ def receive_files():
elif request.form.get('metadata_type', None) == 'fill':
# Build a metadata dict
metadata = {}
-
+
# When we have metadata for an item, use this to set it.
# If it is an item in a list, set is_list=True
def set_metadata(item_id, value, is_list=False):
@@ -324,7 +325,7 @@ def receive_files():
if parent not in dest_dict:
dest_dict[parent] = {}
dest_dict = dest_dict[parent]
-
+
if not is_list:
dest_dict[key] = value
else:
@@ -336,22 +337,22 @@ def receive_files():
# Pull all the field values we wanted from the form
if 'heading' in item:
continue
-
+
if item['list']:
# This is a list, serialized into form fields
-
+
# We count how many values we got
value_count = 0
-
+
for index in itertools.count():
# Get [0] through [n], until something isn't there.
entry_id = '{}[{}]'.format(item['id'], index)
-
+
if index == 1000:
# Don't let them provide too much stuff.
return (render_template('error.html',
error_message="You provided an extremely large number of values for the metadata item {}".format(item['id'])), 403)
-
+
if entry_id in request.form:
if len(request.form[entry_id]) > 0:
# Put an entry in the list
@@ -371,7 +372,7 @@ def receive_files():
else:
# We have run out of form fields for this list.
break
-
+
if item['required'] and value_count == 0:
# They forgot a required item. Maybe all entries were empty.
return (render_template('error.html',
@@ -450,7 +451,7 @@ def getDetailsForSeq():
@app.route('/api/getSEQCountbytech', methods=['GET'])
def getSEQCountbytech():
- query="""SELECT ?tech ?tech_label (count(?fasta) as ?fastaCount) WHERE
+ query="""SELECT ?tech ?tech_label (count(?fasta) as ?fastaCount) WHERE
{?fasta ?x [ ?tech] .
OPTIONAL {?tech ?tech_tmp_label } .
BIND(IF(BOUND(?tech_tmp_label), ?tech_tmp_label,?tech) as ?tech_label)}
@@ -466,8 +467,8 @@ def getSEQCountbytech():
## Is this one really necessary or should we just use getSEQCountbytech instead?
@app.route('/api/getAvailableTech', methods=['GET'])
def getAvailableTech():
- query="""SELECT distinct ?tech ?tech_label WHERE
- {?fasta ?x [ ?tech]
+ query="""SELECT distinct ?tech ?tech_label WHERE
+ {?fasta ?x [ ?tech]
BIND (concat(?tech,"_label") as ?tech_label)
} """
payload = {'query': query, 'format': 'json'}
@@ -479,7 +480,7 @@ def getAvailableTech():
## Has to be encoded again so should be --> http%3A%2F%2Fpurl.obolibrary.org%2Fobo%2FOBI_0000759
@app.route('/api/getSEQbytech', methods=['GET'])
def getSEQbytech():
- query="""SELECT ?fasta WHERE
+ query="""SELECT ?fasta WHERE
{?fasta ?x [] }
"""
tech = request.args.get('tech')
@@ -565,7 +566,7 @@ def getSEQCountbyHostHealthStatus():
@app.route('/api/getSEQbyLocationAndTech', methods=['GET'])
def getSEQbyLocationAndTech():
- query="""SELECT ?fasta WHERE { ?fasta ?x [
+ query="""SELECT ?fasta WHERE { ?fasta ?x [
; ]}"""
location=request.args.get('location')
tech=request.args.get('tech')
@@ -582,7 +583,7 @@ def getSEQbyLocationAndTech():
# Example specimen http%3A%2F%2Fpurl.obolibrary.org%2Fobo%2FNCIT_C155831
@app.route('/api/getSEQbyLocationAndSpecimenSource', methods=['GET'])
def getSEQbyLocationAndSpecimenSource():
- query="""SELECT ?fasta WHERE { ?fasta ?x [
+ query="""SELECT ?fasta WHERE { ?fasta ?x [
; ]}
"""
location = request.args.get('location')
diff --git a/bh20simplewebuploader/static/main.js b/bh20simplewebuploader/static/main.js
index 56213fa..7084e1f 100644
--- a/bh20simplewebuploader/static/main.js
+++ b/bh20simplewebuploader/static/main.js
@@ -49,7 +49,7 @@ let fetchAllaccessions = () => {
let uploadForm = document.getElementById('metadata_upload_form')
let uploadFormSpot = document.getElementById('metadata_upload_form_spot')
let fillForm = document.getElementById('metadata_fill_form')
-let fillFormSpot = document.getElementById('metadata_fill_form_spot')
+let fillFormSpot = document.getElementById('metadata_fill_form_spot')
function setUploadMode() {
// Make the upload form the one in use.
@@ -91,20 +91,20 @@ setMode()
function addField(e) {
// Find our parent field-group div
let fieldGroup = this.parentElement
-
+
// Get its keypath
let keypath = fieldGroup.dataset.keypath
-
+
// Find its last field child
let existingFields = fieldGroup.getElementsByClassName('field')
let templateField = existingFields[existingFields.length - 1]
-
+
// Get its number
let fieldNumber = templateField.dataset.number
-
+
// Duplicate it
let newField = templateField.cloneNode(true)
-
+
// Increment the number and use the keypath and number to set IDs and cross
// references.
// TODO: Heavily dependent on the form field HTML. Maybe we want custom
@@ -117,13 +117,13 @@ function addField(e) {
newControl.setAttribute('name', newID)
let newLabel = newField.getElementsByTagName('label')[0]
newLabel.setAttribute('for', newID)
-
+
// Find the minus button
let minusButton = fieldGroup.getElementsByClassName('remove-field')[0]
-
+
// Put new field as a child before the minus button
fieldGroup.insertBefore(newField, minusButton)
-
+
// Enable the minus button
minusButton.classList.remove('invisible')
}
@@ -134,16 +134,16 @@ function addField(e) {
function removeField(e) {
// Find our parent field-group div
let fieldGroup = this.parentElement
-
+
// Find its field children
let existingFields = fieldGroup.getElementsByClassName('field')
-
+
if (existingFields.length > 1) {
// There is a last field we can safely remove.
let lastField = existingFields[existingFields.length - 1]
fieldGroup.removeChild(lastField)
}
-
+
if (existingFields.length <= 1) {
// Collection auto-updates. Now there's only one element. Don't let the
// user remove it. If they don't want it, they can leave it empty.
@@ -159,3 +159,10 @@ for (let button of document.getElementsByClassName('remove-field')) {
button.addEventListener('click', removeField)
}
+// Change the submit button after hitting
+
+function on_submit_button() {
+ var elem = document.getElementById("submit");
+ elem.value = "Submitting...";
+ elem.disabled = true;
+}
diff --git a/bh20simplewebuploader/templates/form.html b/bh20simplewebuploader/templates/form.html
index f9b1ecf..37a7b72 100644
--- a/bh20simplewebuploader/templates/form.html
+++ b/bh20simplewebuploader/templates/form.html
@@ -165,7 +165,7 @@
-
+
--
cgit v1.2.3