Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Per sample summary #79

Merged
merged 3 commits into from
May 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions microsetta_admin/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,52 @@ def urlify_account_id(id_):
projects=projects)


@app.route('/per_sample_summary', methods=['GET', 'POST'])
def per_sample_summary():
strip_sampleid = request.form.get('strip_sampleid', 'off')
strip_sampleid = strip_sampleid.lower() == 'on'

if request.method == 'GET':
sample_barcode = request.args.get('sample_barcode')
if sample_barcode is None:
return render_template('per_sample_summary.html',
resource=None,
**build_login_variables())
sample_barcodes = [sample_barcode, ]
elif request.method == 'POST':
sample_barcodes, upload_err = upload_util.parse_request_csv_col(
request,
'file',
'sample_name'
)
if upload_err is not None:
return render_template('per_sample_summary.html',
resource=None,
**build_login_variables(),
search_error=[{'error': upload_err}])

payload = {'sample_barcodes': sample_barcodes}
status, result = APIRequest.post('/api/admin/account_barcode_summary?'
'strip_sampleid=%s' % str(strip_sampleid),
json=payload)
if status != 200:
return render_template('per_sample_summary.html',
resource=None,
error_message=result,
**build_login_variables())
else:
resource = pd.DataFrame(result)
order = ['sampleid', 'project', 'account-email', 'source-email',
'source-type', 'site-sampled', 'sample-status',
'sample-received', 'ffq-taken', 'ffq-complete',
'vioscreen_username']
order.extend(sorted(set(resource.columns) - set(order)))
resource = resource[order]
return render_template('per_sample_summary.html',
resource=resource,
**build_login_variables())


@app.route('/create_kits', methods=['GET', 'POST'])
def new_kits():
_, result = _get_projects(include_stats=False, is_active=True)
Expand Down
64 changes: 64 additions & 0 deletions microsetta_admin/templates/per_sample_summary.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{% extends "sitebase.html" %}
{% block head %}
<link rel="stylesheet" type="text/css" href="/static/vendor/DataTables/DataTables-1.10.21/css/jquery.dataTables.css">
<script src="/static/vendor/DataTables/DataTables-1.10.21/js/jquery.dataTables.js"></script>
<script src="/static/vendor/DataTables/Buttons-1.6.2/js/dataTables.buttons.min.js"></script>
<script src="/static/vendor/DataTables/Buttons-1.6.2/js/buttons.html5.min.js"></script>
<script>
function remove_error_messages () {
block = document.getElementById("search_errors");
if (block !== null) {
block.innerHTML = "";
}
};
$(document).ready(function() {
{% if resource is not none %}
$('#search_results').DataTable({
// more information on "dom" can be found here:
// https://datatables.net/reference/option/dom
dom: 'Bfrtip',
buttons: ['csv']
}
);
{% endif %}
} );
</script>
{% endblock %}
{% block content %}
<h3>Microsetta Per Sample Summary</h3>
<div style="height: 400px;">
{% if error_message %}
<p style="color:red">
{{ error_message |e }}
</p>
{% endif %}
<form name="search_form" id="search_form" method="GET">
<table>
<tr>
<td><label for="sample_barcode">Barcode: </label></td>
<td><input type="text" name="sample_barcode" id="sample_barcode" {% if info %} value="{{info.barcode}}"{% endif %}></td>
<td></td>
<td><input type="submit" value="Retrieve Summary"></td>
</tr>
</table>
<script>
document.search_form.sample_barcode.focus()
</script>
</form>
<br/>
Or upload a file of barcodes listed in the column "sample_name" (max: 1000)
<br/>
<form name="upload_csv" id="search_csv" method="POST" enctype="multipart/form-data" onsubmit="return remove_error_messages()">
<input type="checkbox" id="strip_sampleid" name="strip_sampleid">
<label for="strip_sampleid"> Check to remove sample IDs from summary</label><br/>
<input type=file name=file><br/>
<input type=submit value=Upload>
</form>
{% if resource is not none %}
<div class="result_container">
{{resource.to_html(table_id="search_results", classes=["display"], render_links=True, escape=False) |safe}}
</div>
</div>
{% endif %}
{{blob}}
{% endblock %}
1 change: 1 addition & 0 deletions microsetta_admin/templates/sitebase.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ <h3>Microsetta Utilities</h3>
<li><a href="/create_kits">Create Kit</a></li>
<li><a href="/scan">Scan Barcode</a></li>
<li><a href="/metadata_pulldown">Retrieve Metadata</a></li>
<li><a href="/per_sample_summary">Per sample summary</a></li>
<li><a href="/submit_daklapack_order">Submit Daklapack Order</a></li>
<li><a href="{{authrocket_url}}/logout?redirect_uri={{endpoint}}/logout">Log Out <br> ({{email |e}})</a></li>
{% else %}
Expand Down