Skip to content

Commit 4b4a0f4

Browse files
authored
Merge pull request #464 from ImagingDataCommons/sprint-15-sp
Sprint 15
2 parents e904810 + 4a009ff commit 4b4a0f4

File tree

4 files changed

+81
-35
lines changed

4 files changed

+81
-35
lines changed

idc/settings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@
8080
GCLOUD_PROJECT_NUMBER = os.environ.get('GCLOUD_PROJECT_NUMBER', '')
8181
BIGQUERY_PROJECT_ID = os.environ.get('BIGQUERY_PROJECT_ID', GCLOUD_PROJECT_ID)
8282
BIGQUERY_DATA_PROJECT_ID = os.environ.get('BIGQUERY_DATA_PROJECT_ID', GCLOUD_PROJECT_ID)
83+
BIGQUERY_USER_MANIFEST_DATASET = os.environ.get('BIGQUERY_USER_MANIFEST_DATASET', 'dev_user_dataset')
84+
BIGQUERY_PIVOT_TABLE = os.environ.get('BIGQUERY_PIVOT_TABLE', 'idc-dev.metadata.dicom_pivot_wave1')
8385

8486
# Deployment module
8587
CRON_MODULE = os.environ.get('CRON_MODULE')

static/js/cohorts/cohort-details.js

Lines changed: 62 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ require([
5858
tippy('.manifest-size-warning',{
5959
content: 'Your cohort is too large to be downloaded in its entirety, and will be truncated at 65,000 records ' +
6060
'ordered by PatientID, CollectionID, StudyInstanceUID, SeriesInstanceUID, SOPInstanceUID, SourceDOI, ' +
61-
'CRDCInstanceUUID, and GCSPath.',
61+
'CRDCInstanceUUID, and GCS_URL.',
6262
theme: 'light',
6363
placement: 'left',
6464
arrow: false,
@@ -92,14 +92,16 @@ require([
9292
update_export_option("file-manifest");
9393

9494
var download_manifest = function(file_type, clicked_button, e) {
95+
let manifest_type = $('input[name="manifest-type"]:checked').val();
96+
9597
$('#unallowed-chars-alert').hide();
9698
$('#name-too-long-alert-modal').hide();
9799

98100
var name = $('#export-manifest-name').val();
99101
var unallowed = (name.match(base.blacklist) || []);
100102

101103
if (name.length == 0) {
102-
$('#download-csv').prop('title','Please input the name.');
104+
$('#download-csv').prop('title','Please provide a file name.');
103105
$('#export-manifest-name')[0].focus();
104106
e.preventDefault();
105107
return false;
@@ -123,20 +125,22 @@ require([
123125
return false;
124126
}
125127

126-
$('#export-manifest-form').submit();
127-
128128
$('#download-csv').attr('disabled','disabled');
129129
$('#download-tsv').attr('disabled','disabled');
130130
$('#download-json').attr('disabled','disabled');
131-
132-
$('#download-in-progress').modal('show');
133-
134-
base.blockResubmit(function() {
135-
$('#download-csv').removeAttr('disabled');
136-
$('#download-tsv').removeAttr('disabled');
137-
$('#download-json').removeAttr('disabled');
138-
$('#download-in-progress').modal('hide');
139-
},downloadToken, 'downloadToken');
131+
$('#get-bq-table').attr('disabled','disabled');
132+
133+
$('#manifest-in-progress').modal('show');
134+
135+
if(manifest_type == 'file-manifest') {
136+
base.blockResubmit(function () {
137+
$('#download-csv').removeAttr('disabled');
138+
$('#download-tsv').removeAttr('disabled');
139+
$('#download-json').removeAttr('disabled');
140+
$('#get-bq-table').removeAttr('disabled');
141+
$('#manifest-in-progress').modal('hide');
142+
}, downloadToken, 'downloadToken');
143+
}
140144

141145
var checked_fields = [];
142146
$('.field-checkbox').each(function()
@@ -158,25 +162,52 @@ require([
158162
}
159163
});
160164

161-
var include_header = $('#include-header-checkbox')[0].checked;
162-
163-
var url = BASE_URL + '/cohorts/download_manifest/' + cohort_id + '/';
164-
url += ("?file_type=" + file_type);
165-
url += ("&include_header=" + include_header);
166-
url += ("&file_name=" + name);
167-
url += ("&header_fields=" + JSON.stringify(checked_fields));
168-
url += ("&columns=" + JSON.stringify(checked_columns));
169-
url += ("&downloadToken=" + downloadToken);
165+
$('input[name="file_type"]').val(file_type);
166+
$('input[name="header_fields"]').val(JSON.stringify(checked_fields));
167+
$('input[name="columns"]').val(JSON.stringify(checked_columns));
168+
$('input[name="downloadToken"]').val(downloadToken);
169+
$('input[name="include_header"]').val($('#include-header-checkbox').is(':checked') ? 'true': 'false');
170170

171171
var select_box_div = $('#file-part-select-box');
172172
var select_box = select_box_div.find('select');
173-
if (select_box_div.is(":visible"))
174-
{
173+
if (select_box_div.is(":visible")) {
175174
var selected_file_part = select_box.children("option:selected").val();
176-
url += ("&file_part=" + selected_file_part);
175+
$('input[name="file_part"]').val(selected_file_part);
176+
} else {
177+
$('input[name="file_part"]').val("");
177178
}
178179

179-
location.href = url;
180+
if(manifest_type == 'file-manifest') {
181+
$('#export-manifest-form').submit();
182+
} else {
183+
$.ajax({
184+
url: $('#export-manifest-form').attr('action'),
185+
data: $('#export-manifest-form').serialize(),
186+
method: 'GET',
187+
success: function (data) {
188+
if(data.message) {
189+
base.showJsMessage("info",data.message,true);
190+
}
191+
},
192+
error: function (xhr) {
193+
console.log(xhr);
194+
var responseJSON = $.parseJSON(xhr.responseText);
195+
// If we received a redirect, honor that
196+
if(responseJSON.redirect) {
197+
base.setReloadMsg(responseJSON.level || "error",responseJSON.message);
198+
window.location = responseJSON.redirect;
199+
} else {
200+
base.showJsMessage(responseJSON.level || "error",responseJSON.message,true);
201+
}
202+
},
203+
complete: function(xhr, status) {
204+
$('#manifest-in-progress').modal('hide');
205+
$('#get-bq-table').removeAttr('disabled');
206+
$('#export-manifest-modal').modal('hide');
207+
$('#export-manifest-form')[0].reset();
208+
}
209+
});
210+
}
180211
};
181212

182213
$('.column-checkbox').change(function() {
@@ -213,4 +244,9 @@ require([
213244
};
214245

215246
update_download_manifest_buttons();
247+
248+
$('#get-bq-table').on('click',function(){
249+
download_manifest('',$(this));
250+
});
251+
216252
});

templates/cohorts/cohort_details.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ <h3 class="pull-left" role="heading" aria-level="1">Cohort Name: {{ cohort.name
6868
{% endwith %}
6969

7070
<!-- Download In Progress Modal -->
71-
<div class="modal fade" id="download-in-progress" tabindex="-1" role="dialog" data-backdrop="static" aria-hidden="true">
71+
<div class="modal fade" id="manifest-in-progress" tabindex="-1" role="dialog" data-backdrop="static" aria-hidden="true">
7272
<div class="modal-dialog">
7373
<div class="modal-content">
7474
<div class="modal-header"></div>
7575
<div class="modal-body">
76-
<p><i class="fa fa-cog fa-spin"></i> Preparing manifest for download...</p>
76+
<p><i class="fa fa-cog fa-spin"></i> Preparing cohort manifest...</p>
7777
</div>
7878
<div class="modal-footer"></div>
7979
</div>

templates/cohorts/export-manifest-modal.html

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ <h4 class="modal-title" id="exportManifestModal">Export Cohort Manifest</h4>
2121
</div>
2222
</div>
2323

24-
<form id="export-manifest-form">
24+
<form id="export-manifest-form" method="get" action="{% url 'cohort_manifest' cohort_id %}">
2525
<div class="modal-body">
2626
<div class="form-group">
2727
<!-- Name -->
2828
<div>
2929
<label for="export-manifest-name">Name</label>
30-
<input class="form-control" type="text" id="export-manifest-name" name="name" value="{{ cohort.name }}_{{ cohort.id }}_{% now "Ymd_Gis" %}" required />
30+
<input class="form-control" type="text" id="export-manifest-name" name="file_name" value="{{ cohort.name }}_{{ cohort.id }}_{% now "Ymd_Gis" %}" required />
3131
</div>
3232
<br>
3333

@@ -61,7 +61,7 @@ <h4 class="modal-title" id="exportManifestModal">Export Cohort Manifest</h4>
6161
<li class="checkbox"><label>
6262
<input class="field-checkbox" type="checkbox" value="total_records" checked>
6363
<span class="value">Total Records</span>
64-
</label></li>
64+
</label></li>0
6565
</div>
6666
<br>
6767

@@ -108,24 +108,26 @@ <h4 class="modal-title" id="exportManifestModal">Export Cohort Manifest</h4>
108108
</label></li>
109109

110110
<li class="checkbox"><label>
111-
<input class="column-checkbox" type="checkbox" value="gcs_path" checked>
111+
<input class="column-checkbox" type="checkbox" value="gcs_url" checked>
112112
<span class="value">GCS URL </span>
113113
</label></li>
114114
</div>
115115
<br>
116116

117117
<!-- Export Option -->
118118
<div class="export-option">
119-
<span class="value"><input type="radio" name="colorRadio" value="file-manifest" checked> Files</span>
120-
<span style="margin-left:10px" class="value"><input type="radio" name="colorRadio" value="bq-manifest"> BigQuery</span>
119+
<span class="value"><input type="radio" name="manifest-type" value="file-manifest" checked> Files</span>
120+
<span style="margin-left:10px" class="value" {% if not is_social %}title="Export to BigQuery is only available with a Google Account."{% endif %}>
121+
<input type="radio" name="manifest-type" value="bq-manifest" {% if not is_social %}disabled{% endif %}> BigQuery</span>
121122
</div>
122123
<br>
123-
124+
{% if is_social %}
124125
<div id="bq-manifest">
125126
<a id="get-bq-table" class="btn btn-primary" title="Get BQ Table of this manifest.">
126127
Get BQ Table
127128
</a>
128129
</div>
130+
{% endif %}
129131
<div id="file-manifest">
130132
<div id="file-part-select-box">
131133
<select class="form-control">
@@ -150,6 +152,12 @@ <h4 class="modal-title" id="exportManifestModal">Export Cohort Manifest</h4>
150152
</div>
151153
</div>
152154
</div>
155+
<input type="hidden" name="downloadToken">
156+
<input type="hidden" name="file_type">
157+
<input type="hidden" name="file_part">
158+
<input type="hidden" name="columns">
159+
<input type="hidden" name="header_fields">
160+
<input type="hidden" name="include_header">
153161
</form>
154162
</div>
155163
</div>

0 commit comments

Comments
 (0)