[879b32]: / qiita_pet / templates / analysis_selected.html

Download this file

287 lines (269 with data), 12.6 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
{% extends sitebase.html %}
{% block head %}
{% from itertools import chain %}
<script type="text/javascript">
function error(evt) { $('#ws-error').html("<b>Server communication error. Sample removal will not be recorded. Please try again later.</b>"); };
function check_empty() {
if($('.row').length <= 1) {
$('#dflt-sel-info').removeAttr('style');
$('.topfloat').hide();
$('#no-selected').show();
}
}
function clear() {
if(confirm('Are you sure you want to remove all samples?')) {
qiita_websocket.send('clear', {'pids': {% raw [int(p) for p in chain.from_iterable(pid.keys() for sid, pid in sel_data.items())] %} });
}
}
function clear_from_html(data) {
$.each($('.row'), function(index, value) { value.remove(); });
check_empty();
}
function remove_proc_data(pid, sid) {
if(confirm('Are you sure you want to remove all samples for this processed data?')) {
qiita_websocket.send('remove_pd', {'proc_data': pid, 'samples': [], 'sid': sid});
}
}
function remove_pd_from_html(data) {
pid = data.proc_data;
sid = data.sid;
$('#proc' + pid).remove();
$('#proc' + pid + '-samples').remove();
// remove study if all proc data removed
if($('#study'+ sid + '-table tbody').children().length === 1) { $('#study'+sid).remove(); }
check_empty();
}
function remove_sample(sid, pid, sample) { qiita_websocket.send('remove_sample', {'proc_data': pid, 'samples': [sample], 'sid': sid}); }
function remove_sample_from_html(data) {
pid = data.proc_data;
sample = data.samples[0];
sid = data.sid;
document.getElementById(pid + '@' + sample).remove();
//decriment sample count for pid
var count = $('#proc' + pid + '-sample-count');
count.text(parseInt(count.text(), 10) - 1);
// remove proc data if all samples removed
if($('#proc' + pid + '-samples-table tbody').children().length === 0) { $('#proc'+pid).remove(); $('#proc' + pid + '-samples').remove(); }
// remove study if all proc data removed
if($('#study'+ sid + '-table tbody').children().length === 1) { $('#study'+sid).remove(); }
check_empty();
}
$(document).ready(function() {
qiita_websocket.init(window.location.host + '{% raw qiita_config.portal_dir %}/analysis/selected/socket/', error, error);
qiita_websocket.add_callback('remove_pd', remove_pd_from_html);
qiita_websocket.add_callback('remove_sample', remove_sample_from_html);
qiita_websocket.add_callback('clear', clear_from_html);
$('#clear-button').on('click', clear);
{% if sel_data %}$('#no-selected').hide(){% end %}
var common_sample_fields = {% raw list(common['sample']) %};
var common_prep_fields = {% raw list(common['prep']) %};
$.each($(".chosen-select"), function (_, element){
var is_sample = element.id.startsWith('sample-metadata');
$.each(element.options, function (_, option){
if (is_sample) {
if (jQuery.inArray(option.text, common_sample_fields) >= 0) {
option.selected=true;
if (!$('#analysis-metadata').val().includes(option.text)) {
$('#analysis-metadata').append(
$('<option>', { value: option.value, text: option.text,
selected: true}));
}
}
} else {
if (jQuery.inArray(option.text, common_prep_fields) >= 0) {
option.selected=true;
if (!$('#analysis-metadata').val().includes(option.text)) {
$('#analysis-metadata').append(
$('<option>', { value: option.value, text: option.text,
selected: true}));
}
}
}
});
});
$('#analysis-metadata').chosen({
width: "95%"
});
$(".chosen-select").chosen({
width: "95%",
no_results_text: "Oops, nothing found!",
display_disabled_options: false,
display_selected_options: false,
}).change(function(event, object) {
var item = $(this).attr('id');
var key = Object.keys(object)[0];
var toggle = key == 'selected';
var selection = object[key];
if (toggle && !$('#analysis-metadata').val().includes(selection)) {
$('#analysis-metadata').append(
$('<option>', { value: selection, text: selection,
selected: true}));
} else {
$(".analysis-metadata option[value='" + selection + "']").remove();
}
// we need to update the chosen element AKA this line is needed for
// things to work fine
$("#analysis-metadata").trigger("chosen:updated");
if (jQuery.inArray(object[key], common_sample_fields) >= 0) {
$.each($(".chosen-select"), function (_, element){
if (item != element.id) {
$.each(element.options, function (_, option){
if (option.text == selection) {
option.selected=toggle;
}
});
}
});
} else if (jQuery.inArray(object[key], common_sample_fields) >= 0) {
$.each($(".chosen-select"), function (_, element){
if (item != element.id) {
$.each(element.options, function (_, option){
if (option.text == selection) {
option.selected=toggle;
}
});
}
});
}
});
});
</script>
{% end %}
{% block content %}
<h1>Selected Samples</h1>
<span id="ws-error" style="color:red"></span>
<div id="no-selected" class="jumbotron">
<h1>No samples selected</h1>
<h3><a href="{% raw qiita_config.portal_dir %}/study/list/">Please select at least one sample to continue</a><h3>
</div>
{% if sel_data %}
<div class="row">
<div class="col-lg-12">
<button type="button" class="btn btn-success btn-sm" id="create-button" name="create-button" data-toggle="modal" data-target="#create-analysis-modal-view">
Create Analysis
</button>
<button type="button" class="btn btn-danger btn-sm" id="clear-button" name="clear-button">
Clear Selected
</button>
</div>
</div>
<br/>
{% end %}
{% for study, proc_datas in sel_data.items() %}
<div class="row" id="study{{study.id}}">
<div class="col-md-12" style="border:2px solid #a1a1a1; border-radius: 15px;">
<h2><a href="{% raw qiita_config.portal_dir %}/study/description/{{study.id}}">{{study.title}}</a></h2>
<h4>Processed Data</h4>
<table class='table table-striped' id='study{{study.id}}-table'>
<tr>
<th class="col-sm-1">id</th><th class="col-sm-1">Datatype</th><th class="col-sm-2">Processed Date</th><th class="col-sm-2">Parent processing</th><th class="col-sm-2">Merging Scheme</th><th class="col-sm-1">Samples selected from Prep Info</th><th></th><th></th>
</tr>
{% for pid, samples in proc_datas.items() %}
<tr id="proc{{pid}}">
<td>{{pid}} <a href="#" data-toggle="modal" data-target="#proc{{pid}}-settings-modal" onclick="return false;"><span class="glyphicon glyphicon-info-sign"></span></a></td>
<td>{{proc_info[pid]["data_type"]}}</td>
<td>{{proc_info[pid]["processed_date"]}}</td>
<td>{{proc_info[pid]["merging_scheme"][1]}}</td>
<td>{{proc_info[pid]["merging_scheme"][0]}}</td>
<td><span id="proc{{pid}}-sample-count">{% raw len(samples) %}</span></td>
<td><a href="#" onclick="$('#proc{{pid}}-samples').toggle(); return false;">Show/Hide samples</a></td>
<td><a href="#" onclick = 'remove_proc_data({{pid}}, {{study.id}})'>Remove</a></td>
</tr>
<tr id="proc{{pid}}-samples" hidden><td colspan=7>
<table class="table table-striped sample-table" id="proc{{pid}}-samples-table" style="width:50%">
{% for samp in samples %}
<tr id="{{pid}}@{{samp}}"><td>{{samp}}</td><td><a href="#" onclick="remove_sample('{{study.id}}', '{{pid}}', '{{samp}}')">Remove</a></td></tr>
{% end %}
</table>
</td></tr>
{% for pid in proc_datas %}
<!-- modal view to enter analysis information -->
<div class="modal fade" id="proc{{pid}}-settings-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title" id="myModalLabel">Processed Data {{pid}}</h4>
</div>
<form role="form" action="{% raw qiita_config.portal_dir %}/analysis/create/" method="post">
<input type="hidden" name="action" value="create">
<div class="modal-body">
<b>Datatype</b>: {{proc_info[pid]["data_type"]}} <br/>
<b>Processed Date</b>: {{proc_info[pid]["processed_date"]}} <br/>
<b>Parent processing</b>: {{proc_info[pid]["merging_scheme"][1]}} <br/>
<b>Merging Scheme</b>: {{proc_info[pid]["merging_scheme"][0]}}
</div>
<div class="modal-footer">
</div>
</div>
</div>
</div>
{% end %}
{% end %}
</table>
<hr>
<h4>Metadata Selection <small>Common fields for all studies are preselected. Click to view/add unique fields from each dataset.</small></h4>
<table border="0" style="width: 100%;">
<tr>
<td style="width: 50%;">
Sample Information
<select data-placeholder="Choose Sample Metadata..." multiple class="chosen-select" id="sample-metadata-{{study.id}}">
{% for field in sorted(metadata[study.id]['sample']) %}
<option value="{{field}}">{{field}}</option>
{% end %}
</select>
</td>
<td style="width: 50%;">
Preparation Information
<select data-placeholder="Choose Preparation Metadata..." multiple class="chosen-select" id="prep-metadata-{{study.id}}">
{% for field in sorted(metadata[study.id]['prep']) %}
<option value="{{field}}">{{field}}</option>
{% end %}
</td>
</tr>
</table>
</div>
</div>
{% end %}
<!-- modal view to enter analysis information -->
<div class="modal fade" id="create-analysis-modal-view" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title" id="myModalLabel">Create new analysis</h4>
</div>
<form role="form" action="{% raw qiita_config.portal_dir %}/analysis/create/" method="post">
<input type="hidden" name="action" value="create">
<div class="modal-body">
<div>
<div class="form-group">
<label for="name">Analysis name</label>
<input type="text" class="form-control" id="name" name="name" placeholder="Analysis name">
</div>
<div class="form-group">
<label for="description">Description</label>
<input type="text" class="form-control" id="description" name="description" placeholder="Short description">
</div>
<div class="form-group">
<label for="description">Merge samples with the same name <br/><small>useful when merging multiple preparation artifacts</small></label>
<input type="checkbox" class="form-control" id="merge_duplicated_sample_ids" name="merge_duplicated_sample_ids">
</div>
<div class="form-group">
<label for="description">Metadata selected <small>(to update use the main page)</small></label>
<select name="analysis-metadata" id="analysis-metadata" class="analysis-metadata" multiple disabled></select>
</div>
<div class="form-group">
<label for="description">Reservation (optional)</label>
<input type="text" class="form-control" id="reservation" name="reservation" placeholder="Reservation (optional)">
</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" onclick="$('#analysis-metadata').removeAttr('disabled');" "class="btn btn-primary">Create analysis</button>
</div>
</form>
</div>
</div>
</div>
{% end %}