Skip to content

Commit

Permalink
Merge pull request #147 from wasade/add_kit
Browse files Browse the repository at this point in the history
Allow participants to add samples from another kit
  • Loading branch information
wasade committed May 15, 2020
2 parents 705a223 + 5f5f2e7 commit 25bb112
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 29 deletions.
19 changes: 19 additions & 0 deletions microsetta_private_api/example/client.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,25 @@ paths:
'302':
description: Redirecting to necessary action

'/claim_additional_kit':
post:
operationId: microsetta_private_api.example.client_impl.claim_additional_kit
requestBody:
content:
application/x-www-form-urlencoded:
schema:
type: object
additionalProperties: true
responses:
'200':
description: Error report
content:
text/html:
schema:
type: string
'302':
description: Redirecting to necessary action

'/workflow_claim_kit_samples':
get:
operationId: microsetta_private_api.example.client_impl.get_workflow_claim_kit_samples
Expand Down
12 changes: 10 additions & 2 deletions microsetta_private_api/example/client_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,9 @@ def get_workflow_claim_kit_samples():
return render_template("kit_sample_association.jinja2")


def post_workflow_claim_kit_samples(body):
def claim_kit_samples(expected_state, body):
next_state, current_state = determine_workflow_state()
if next_state == NEEDS_SAMPLE:
if next_state == expected_state:
acct_id = current_state["account_id"]
source_id = current_state["human_source_id"]
answered_survey_id = current_state["answered_primary_survey_id"]
Expand Down Expand Up @@ -422,6 +422,14 @@ def post_workflow_claim_kit_samples(body):
return redirect(WORKFLOW_URL)


def claim_additional_kit(body):
return claim_kit_samples(ALL_DONE, body)


def post_workflow_claim_kit_samples(body):
return claim_kit_samples(NEEDS_SAMPLE, body)


def get_workflow_fill_survey(survey_template_id):
next_state, current_state = determine_workflow_state()
if next_state != _NEEDS_SURVEY_PREFIX + str(survey_template_id):
Expand Down
27 changes: 27 additions & 0 deletions microsetta_private_api/static/kit_check.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
function verify_kit_claim(form_name) {
// Initialize form validation
let form_selector = "form[name='" + form_name + "']";
return function() {
$(form_selector).validate({
// Specify validation rules
rules: {
// The key name on the left side is the name attribute
// of an input field. Validation rules are defined
// on the right side
kit_name: {
required: true,
remote: {
url: "/check_acct_inputs",
type: "post"
}
},
// Make sure the form is submitted to the destination defined
// in the "action" attribute of the form when valid
submitHandler: function (form) {
form.submit();
}
}
});
};
};

29 changes: 3 additions & 26 deletions microsetta_private_api/templates/kit_sample_association.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,13 @@
<meta charset="UTF-8">
<title>Microsetta Kit Claim</title>
<link rel="stylesheet" href="/static/vendor/bootstrap-4.4.1-dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="/static/css/minimal_interface.css" />
<script src="/static/vendor/js/jquery-3.4.1.min.js"></script>
<script src="/static/vendor/js/jquery.validate.min.js"></script>
<link rel="stylesheet" href="/static/css/minimal_interface.css" />

<script src="/static/kit_check.js"></script>
<script>
// Wait for the DOM to be ready
$(function() {
// Initialize form validation on the registration form.
// It has the name attribute "registration"
$("form[name='kit_claim_form']").validate({
// Specify validation rules
rules: {
// The key name on the left side is the name attribute
// of an input field. Validation rules are defined
// on the right side
kit_name: {
required: true,
remote: {
url: "/check_acct_inputs",
type: "post"
}
},
// Make sure the form is submitted to the destination defined
// in the "action" attribute of the form when valid
submitHandler: function (form) {
form.submit();
}
}
});
});
$(document).ready(verify_kit_claim('kit_claim_form'));
</script>
</head>
<body>
Expand Down
18 changes: 17 additions & 1 deletion microsetta_private_api/templates/source.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
<link rel="stylesheet" href="/static/vendor/bootstrap-4.4.1-dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="/static/vendor/font-awesome-4.7.0/css/font-awesome.min.css"/>
<link rel="stylesheet" href="/static/css/minimal_interface.css" />
<script src="/static/vendor/js/jquery-3.4.1.min.js"></script>
<script src="/static/vendor/js/jquery.validate.min.js"></script>
<script src="/static/kit_check.js"></script>
<script>
// Wait for the DOM to be ready
$(document).ready(verify_kit_claim('kit_claim_form'));
</script>
</head>
<body>
<a href="https://microsetta.ucsd.edu" title="microsetta.ucsd.edu">
Expand Down Expand Up @@ -54,7 +61,16 @@
</div>
</div>
<div class="container">
Available Surveys:
<form method="post" name="kit_claim_form" action="/claim_additional_kit">
<div class="form-group">
<label for="kit_name" name="kit_name_label">Have another kit with more samples? Please enter the kit ID here:</label>
<input id="kit_name" name="kit_name" class="form-control" type="text"/>
</div>
<input type="submit" class="btn btn-primary" value="Add samples"/>
</form>
</div>
<div class="container">
<p>Surveys taken:</p>
<div class="list-group">
{% for survey in surveys %}
<div class="container list-group-item {{loop.cycle('odd', 'even') }}">
Expand Down

0 comments on commit 25bb112

Please sign in to comment.