Skip to content

Commit

Permalink
feat(projects): Data Use Report templates
Browse files Browse the repository at this point in the history
  • Loading branch information
b32147 committed Oct 14, 2024
1 parent 060f04f commit 23f41c5
Show file tree
Hide file tree
Showing 4 changed files with 325 additions and 6 deletions.
19 changes: 19 additions & 0 deletions app/templates/email/email_data_use_report.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{% extends "email/email_base.html" %}

{% block title %}DBMI Data Portal - Data Use Report{% endblock %}

{% block content %}

<p style="font-family:sans-serif;font-size:14px;font-weight:normal;margin:0;Margin-bottom:15px;">Hi,</p>

<p style="font-family:sans-serif;font-size:14px;font-weight:normal;margin:0;Margin-bottom:15px;">This is a request to complete your annual data use report as a condition of the signed Data Use Agreement for {{ project.name }}</p>

<p style="font-family:sans-serif;font-size:14px;font-weight:normal;margin:0;Margin-bottom:15px;">Please <a href="{{ data_use_report_url }}">click here</a> or use the following link to complete your data use report</p>

<p style="font-family:sans-serif;font-size:14px;font-weight:normal;margin:0;Margin-bottom:15px;">{{ data_use_report_url }}</p>

<p style="font-family:sans-serif;font-size:14px;font-weight:bold;margin:0;Margin-bottom:15px;"><span style="font-family:sans-serif;font-size:18px;font-weight:bold;margin:0;Margin-bottom:15px;">Important:</span> If a report is not completed within {{ grace_period_days }} days from the date this email was sent, your access to the Data will be automatically terminated.</p>

<p style="font-family:sans-serif;font-size:14px;font-weight:normal;margin:0;Margin-bottom:15px;">Thank you</p>

{% endblock %}
19 changes: 19 additions & 0 deletions app/templates/email/email_data_use_report.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{% extends "email/email_base.html" %}

{% block title %}DBMI Data Portal - Data Use Report{% endblock %}

{% block content %}

Hi,

This is a request to complete your annual data use report as a condition of the signed Data Use Agreement for {{ project.name }}

Please use the following link to complete your data use report:

{{ data_use_report_url }}

Important: If a report is not completed within {{ grace_period_days }} days from the date this email was sent, your access to the Data will be automatically terminated.

Thank you

{% endblock %}
195 changes: 189 additions & 6 deletions app/templates/manage/project-base.html
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,43 @@ <h2 class="panel-title">
</div>
</div>

{% if project.data_use_report_agreement_form %}
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading panel-heading-toggle heading-description" role="tab" data-toggle="collapse" data-target="#data-use-reporting-participants-collapse">
<h2 class="panel-title">
Data use reporting participant list
</h2>
</div>
<div id="data-use-reporting-participants-collapse" class="panel-collapse collapse in">
<div class="panel-body">
<div class="table-responsive">
<table id="data-use-reporting-participant-table" class="table table-bordered table-hover">
<thead>
<tr>
<th>Email</th>
{% if project.has_teams %}
<th>Team</th>
{% endif %}
<th>Access</th>
<th>Forms</th>
<th>Actions</th>
<th>Request Date</th>
</tr>
</thead>
<tbody>
{# Loaded via DataTables.js #}
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
{% endif %}

<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
Expand Down Expand Up @@ -675,6 +712,7 @@ <h5 class="modal-title" id="export-modal-title">Submissions Export</h5>
"dom": 'Blfrtip',
"processing": true,
"serverSide": true,
"bAutoWidth": false,
"ajax": "{% url 'manage:get-project-pending-participants' project_key=project_key %}",
"initComplete": function(settings, json) {
var textBox = $('#pending-participant-table_filter label input');
Expand Down Expand Up @@ -750,7 +788,7 @@ <h5 class="modal-title" id="export-modal-title">Submissions Export</h5>

// Return the button to revoke
return '<button type="button" class="btn btn-default btn-xs" ic-post-to="' + buttonUrl +
'" ic-on-success="$(\'#pending-participant-table\').DataTable().draw(false);$(\'#participant-table\').DataTable().draw(false);">Revoke access ' +
'" ic-on-success="$(\'#pending-participant-table\').DataTable().draw(false);$(\'#data-use-reporting-participant-table\').DataTable().draw(false);$(\'#participant-table\').DataTable().draw(false);">Revoke access ' +
'<span class="glyphicon glyphicon-ban-circle" ' +
'aria-hidden="true"></span></button>';

Expand All @@ -762,7 +800,7 @@ <h5 class="modal-title" id="export-modal-title">Submissions Export</h5>
// Return button to approve user
return '<button type="button" class="btn btn-default btn-xs btn-success" ' +
'ic-post-to="' + buttonUrl +
'" ic-on-success="$(\'#pending-participant-table\').DataTable().draw(false);$(\'#participant-table\').DataTable().draw(false);">Grant access ' +
'" ic-on-success="$(\'#pending-participant-table\').DataTable().draw(false);$(\'#data-use-reporting-participant-table\').DataTable().draw(false);$(\'#participant-table\').DataTable().draw(false);">Grant access ' +
'<span class="glyphicon glyphicon-alert" aria-hidden="true"></span>' +
'</button>';

Expand Down Expand Up @@ -817,6 +855,7 @@ <h5 class="modal-title" id="export-modal-title">Submissions Export</h5>
// Order by the Access column to prioritize pending access.
"dom": 'Blfrtip',
"searching": true,
"bAutoWidth": false,
"search": {
"return": true
},
Expand Down Expand Up @@ -904,23 +943,23 @@ <h5 class="modal-title" id="export-modal-title">Submissions Export</h5>

// Return the button to revoke
return '<button type="button" class="btn btn-default btn-xs" ic-post-to="' + buttonUrl +
'" ic-on-success="$(\'#participant-table\').DataTable().draw(false);$(\'#pending-participant-table\').DataTable().draw(false);">Revoke access ' +
'" ic-on-success="$(\'#participant-table\').DataTable().draw(false);$(\'#pending-participant-table\').DataTable().draw(false);$(\'#data-use-reporting-participant-table\').DataTable().draw(false);">Revoke access ' +
'<span class="glyphicon glyphicon-ban-circle" ' +
'aria-hidden="true"></span></button>';

} else if(data['signed'] == data['required'] && !data['team']) {
} else if(data['signed'] >= data['required'] && !data['team']) {

// Set the URL for approving access
var buttonUrl = '{% url "manage:grant-view-permission" project_key=project_key user_email='USER_EMAIL' %}'.replace('USER_EMAIL', data['email']);

// Return button to approve user
return '<button type="button" class="btn btn-default btn-xs btn-success" ' +
'ic-post-to="' + buttonUrl +
'" ic-on-success="$(\'#participant-table\').DataTable().draw(false);$(\'#pending-participant-table\').DataTable().draw(false);">Grant access ' +
'" ic-on-success="$(\'#participant-table\').DataTable().draw(false);$(\'#pending-participant-table\').DataTable().draw(false);$(\'#data-use-reporting-participant-table\').DataTable().draw(false);">Grant access ' +
'<span class="glyphicon glyphicon-alert" aria-hidden="true"></span>' +
'</button>';

} else if(data['signed'] == data['required'] && data['team']) {
} else if(data['signed'] >= data['required'] && data['team']) {

return 'Grant approval via team management.';

Expand Down Expand Up @@ -998,6 +1037,150 @@ <h5 class="modal-title" id="export-modal-title">Submissions Export</h5>
}
}]
});

var dataUseReportingParticipantTable = $('#data-use-reporting-participant-table').DataTable({
// Order by the Access column to prioritize pending access.
"dom": 'Blfrtip',
"processing": true,
"serverSide": true,
"bAutoWidth": false,
"ajax": "{% url 'manage:get-project-data-use-reporting-participants' project_key=project_key %}",
"initComplete": function(settings, json) {
var textBox = $('#data-use-reporting-participant-table_filter label input');
textBox.unbind();
textBox.bind('keyup input', function(e) {
if(e.keyCode == 8 && !textBox.val() || e.keyCode == 46 && !textBox.val()) {
// do nothing ¯\_(ツ)_/¯
} else if(e.keyCode == 13 || !textBox.val()) {
pendingParticipantTable.search(this.value).draw();
}
});
},
"order": [[{% if project.has_teams %}5{% else %}4{% endif %}, "desc"]],
"columnDefs": [
{
"targets": [{% if project.has_teams %}1, 2, 3{% else %}1, 2{% endif %}],
"orderable": false
},
{
"targets": {% if project.has_teams %}3{% else %}2{% endif %},
"render": function(data, type, full, meta) {

// Build HTML render
var html = '';

// Data is an array of forms
for (index = 0; index < data.length; index++) {

// Get the form
var form = data[index];

// Set the base URL for the forms
var formUrl = '{% url "projects:signed_agreement_form" %}?project_key=' + form['project'] + '&signed_form_id=' + form['id'];

// Set form type and icon classes
var formClasses = (function(formStatus) {
switch(formStatus) {
case 'P':
return ['btn-warning', 'glyphicon-alert'];
case 'A':
return ['btn-default', 'glyphicon-ok'];
case 'R':
return ['btn-danger', 'glyphicon-ban-circle'];
default:
return ['btn-warning', 'glyphicon-alert'];
}
})(form['status']);

// Set link HTML with placeholders for button classes
var link = '<a style="display: block; margin: 2px;" ' +
'class="btn btn-default btn-xs ' + formClasses[0] +
' download-signed-form" href="' + formUrl +
'" target="_blank" role="button">' + form['name'] +
' <span class="glyphicon ' + formClasses[1] +
'" aria-hidden="true"></span></a>';

// Append it to the other elements
html += link
}

return html;
}
},
{
"targets": {% if project.has_teams %}4{% else %}3{% endif %},
"render": function(data, type, full, meta) {

// Determine output based on access, forms signed, etc.
if(data['access']) {

// Set the URL for revoking access
var buttonUrl = '{% url "manage:remove-view-permission" project_key=project_key user_email='USER_EMAIL' %}'.replace('USER_EMAIL', data['email']);

// Return the button to revoke
return '<button type="button" class="btn btn-default btn-xs" ic-post-to="' + buttonUrl +
'" ic-on-success="$(\'#pending-participant-table\').DataTable().draw(false);$(\'#data-use-reporting-participant-table\').DataTable().draw(false);$(\'#participant-table\').DataTable().draw(false);">Revoke access ' +
'<span class="glyphicon glyphicon-ban-circle" ' +
'aria-hidden="true"></span></button>';

} else if(data['signed'] + 1 == data['required'] && !data['team']) {

// Set the URL for approving access
var buttonUrl = '{% url "manage:grant-view-permission" project_key=project_key user_email='USER_EMAIL' %}'.replace('USER_EMAIL', data['email']);

// Return button to approve user
return '<button type="button" class="btn btn-default btn-xs btn-success" ' +
'ic-post-to="' + buttonUrl +
'" ic-on-success="$(\'#pending-participant-table\').DataTable().draw(false);$(\'#data-use-reporting-participant-table\').DataTable().draw(false);$(\'#participant-table\').DataTable().draw(false);">Grant access ' +
'<span class="glyphicon glyphicon-alert" aria-hidden="true"></span>' +
'</button>';

} else if(data['signed'] >= data['required'] && data['team']) {

return 'Grant approval via team management.';

} else {

return 'Forms incomplete or awaiting your approval';
}
}
},
{
"targets": [{% if project.has_teams %}5{% else %}4{% endif %}],
"render": function (data, type, full, meta) {

// Return raw dates for sorting
if (type === 'sort' || type === 'type')
return data;

// Parse date and get components
var date = new Date(data);
var y = date.getFullYear();
var m = date.getMonth() + 1;
var d = date.getDate();
var h = date.getHours();
var min = ("0" + date.getMinutes()).slice(-2);

return m + '-' + d + '-' + y + ' ' + h + ':' + min;
}
}
],
"drawCallback": function( settings ) {

// Collect all Intercooler links
$('#data-use-reporting-participant-table [ic-get-from], #data-use-reporting-participant-table [ic-post-to], ' +
'#data-use-reporting-participant-table [ic-put-to], #data-use-reporting-participant-table [ic-patch-to], ' +
'#data-use-reporting-participant-table [ic-delete-from]').each(function() {

// Check attribute
if( !$(this).attr('ic-id') ) {

// Process it
Intercooler.processNodes($(this));
}
});
},
});
});
</script>

Expand Down
98 changes: 98 additions & 0 deletions app/templates/projects/participate/data-use-report.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{% extends 'sub-base.html' %}
{% load projects_extras %}
{% load bootstrap3 %}

{% block headscripts %}
{% endblock %}

{% block tab_name %}{{ project.name }}{% endblock %}
{% block title %}{{ project.name }}{% endblock %}
{% block subtitle %}{{ project.short_description }}{% endblock %}

{% block subcontent %}

{% if messages %}
{% include 'messages.html' %}
{% endif %}

<div class="col-md-offset-2 col-md-8 col-sm-12">
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="heading-description">
<h2 class="panel-title">{{ agreement_form.name }}</h2>
</div>
<div id="data-use-report-container" class="panel-body">
<form id="sign-agreement-form" name="agreement-form-container" action="{% url 'projects:save_signed_agreement_form' %}" method="post">
{% if agreement_form.description is not None and agreement_form.description != "" %}
<div class="alert alert-warning" role="alert">
{{ agreement_form.description }}
</div>
{% endif %}

<div id="agreement-form-container" class="agreement_form_contents">
{# Check source of agreement form content #}
{% if agreement_form.type == 'MODEL' %}
{{ agreement_form.content | safe }}
{% else %}
{% get_agreement_form_template agreement_form.form_file_path form_context %}
{% endif %}
</div>

<input type="hidden" class="project_key" name="project_key" value="{{ project.project_key }}" />
<input type="hidden" class="agreement_form_id" name="agreement_form_id" value="{{ agreement_form.id }}" />
<input type="hidden" class="agreement_text" name="agreement_text" value="" />
<hr>

<div class="row">
<div class="col-xs-12 col-sm-6 submit_form">
<button id="agreement-form-submit" type="submit" class="btn btn-primary" data-loading-text="Processing <i class='fa fa-spinner fa-spin'></i>">Submit</button>
</div>
</div>

{% csrf_token %}
</form>
<div id="data-use-report-submitted" style="display: none;">

</div>
</div>
</div>
</div>
{% endblock %}

{% block footerscripts %}
<script type="application/javascript">
$( document ).ready(function() {

$('form[name=agreement-form-container]').submit(function(e){
e.preventDefault();

// Get the submit button
var submit_button = $("#agreement-form-submit");

// Set button to loading
submit_button.button("loading");

// Serialize form fields
var formFields = $(this).serialize();

$.post($(this).attr('action'), formFields, function(res){
// $("#loading").hide();
}).done(function() {
notify('success', "Agreement form submitted!", 'thumbs-up');
$(submit_button).html("Form Saved &nbsp;<i class='fa fa-check'></i>").prop("disabled", "disabled").toggleClass("btn-primary btn-success");
setTimeout(function() {
// Replace form content with a thank you message.
$("#data-use-report-container").html("<p>Thank you for your input!</p>");
}, 1000);

}).fail(function() {
// Add error message
notify('danger', "Agreement form failed to submit. Please try again or contact support.", 'exclamation-sign');
console.log("An error occurred, the form couldn't be sent!");

// Set button to loading
submit_button.button("reset");
});
});
});
</script>
{% endblock %}

0 comments on commit 23f41c5

Please sign in to comment.