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

Download this file

412 lines (362 with data), 14.8 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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
{% extends sitebase.html %}
{% block head %}
<script type="text/javascript">
var jobsTable;
// This modal view is used to display job details when a job has errored or
// succeeded. Needs to be in the main scope because this function is called
// from the "onclick" attribute of some elements.
var populate_modal = function(title, main, artifact_id) {
$('#job-output-modal').find('[name="modal-title"]').html(title);
var $main = $('#job-output-modal').find('[name="modal-main-text"]');
if (artifact_id === undefined) {
$main.html(unescape(decodeURIComponent(main)));
}
else {
$.get('/artifact/' + artifact_id + '/summary/', function(data){
$main.html(data);
})
.fail(function(object, status, error_msg) {
$main.html("Error loading artifact information: " + status + " " + object.statusText);
}
);
}
}
// Initialize the previous jobs table once the document is ready
$(function() {
var renderJobArguments = function(data, type, row, meta) {
// select how you want to render the data
var lines = [], container;
for (key in data) {
lines.push('<b>' + key + '</b>:');
if (typeof data[key] === 'string'){
lines.push(data[key]);
}
else if (typeof data[key] === 'object') {
container = data[key];
// if we have all these attributes then render a named hyperlink to
//download the data
if (container['body'] !== undefined &&
container['filename'] !== undefined &&
container['content_type'] !== undefined) {
lines.push('<a download="' + container['filename'] +
'" href="data:text/plain;charset=utf-8,' +
encodeURIComponent(container['body']) + '">' +
container['filename'] + '</a>');
}
else {
lines.push('Unsupported JavaScript Object')
}
}
else {
lines.push(data[key]);
}
}
return lines.join('<br>');
}
var renderRichDescription = function(data, type, row, meta) {
var out = [], status = row[2];
var statusToClass = {
'error': 'text-danger',
'success': 'text-success',
'queued': 'text-muted',
'running': 'text-info'
};
out.push('<b class="' + statusToClass[status] + '">' + status + ' ' +
row[0] + ' (' + row[8] + ') </b> [ ' + row[9] + ' ]</br>');
if (status === 'running' || status === 'queued') {
// row[0] is qiita job-id
// row[3] is status 'Step n of 6' and other messages
out.push('<i>' + row[3] + '</i>')
}
else {
// We write a callback attribute on the link to be able to display a
// modal window with the additional success/error details. Note, the
// quotation is a bit hard to follow but all in all it's ensuring any
// text we get back from the server is properly formatted for
// inclusion in an HTML attribute.
var callback = 'populate_modal("' + row[0] + " completed on " +
row[6] + '",';
out.push('<a href="#" data-toggle="modal" data-target="#job-output-modal" onclick=\'' + callback)
if (status === 'success') {
// job output is in the fourth element
// We only expect one output with the artifact id in the 2 element
out.push('undefined, ' + row[4][0][1] +')\'');
out.push('><br>View results</a>')
}
else if (status === 'error') {
out.push('"' + escape(encodeURIComponent(row[3])) + '")\'');
out.push('><br>View error log summary</a>')
}
}
return out.join('');
}
jobsTable = $('#private-jobs-table').DataTable({
"order": [[2, "desc"]],
"oLanguage": {
"sZeroRecords": "There are no jobs available",
"search": "Filter results",
"loadingRecords": "Please wait - loading previous jobs ...",
},
"destroy": true,
"autoWidth": false,
"columnDefs": [
{'width': '80%', 'targets': 0, 'data': 0, 'render': renderRichDescription},
{'width': '10%', 'targets': 1, 'data': 7, 'render': renderJobArguments},
{'width': '10%', 'targets': 2, 'data': 6},
],
});
// update the table every 10 seconds
setInterval(function () {
if (jobsTable.ajax.url()) {
// user paging is not reset on reload
jobsTable.ajax.reload(null, false);
}
}, 10000);
});
/**
* This is a modified version of loadParameterGUI in networkVue.js
**/
function loadParameterGUI(p_name, param_info, sel_artifacts_info, target, dflt_val) {
let vm = this;
// Create the parameter interface
var $rowDiv = $('<div>').addClass('row').addClass('form-group').appendTo(target);
// Replace the '_' by ' ' in the parameter name for readability
$('<label>').addClass('col-sm-2').addClass('col-form-label').text(p_name.replace('_', ' ') + ': ').appendTo($rowDiv).attr('for', p_name);
var $colDiv = $('<div>').addClass('col-sm-3').appendTo($rowDiv);
var p_type = param_info[0];
var allowed_types = param_info[1];
var $inp;
if (p_type == 'artifact' || p_type.startsWith('choice') || p_type.startsWith('mchoice')) {
// The parameter type is an artifact or choice, the input type is a dropdown
$inp = $('<select>');
// show a dropdown menu with the
var options = [];
if (p_type.startsWith('choice') || p_type.startsWith('mchoice')) {
$.each(JSON.parse(p_type.split(':')[1]), function (idx, val) { options.push([val, val]); });
if (p_type.startsWith('mchoice')) {
$inp.attr('multiple', true);
}
}
options.sort(function(a, b){return a[0].localeCompare(b[0], 'en', {'sensitivity': 'base'});});
$.each(options, function(idx, val) {
$inp.append($("<option>").attr('value', val[0]).text(val[1]));
});
}
else {
// The rest of parameter types are represented with an input
$inp = $('<input>');
// It just changes the type of input
if (p_name.startsWith("qp-hide")) {
// adding the hide attributes
$inp.attr('type', 'hidden');
$rowDiv.css('display', 'none');
}
else if (p_type == 'integer') {
// For the integer type, show an input of type number
$inp.attr('type', 'number');
}
else if (p_type == 'float') {
// For the float type, show an input of type number, with a step of 0.001
$inp.attr('type', 'number').attr('step', 0.001);
}
else if (p_type == 'string') {
// For the float type, show an input of type text
$inp.attr('type', 'text');
}
else if (p_type == 'boolean') {
// For the boolean type, show an input of type checkbox
$inp.attr('type', 'checkbox');
}
else if (p_type == 'prep_template') {
$inp.attr('type', 'file');
}
else {
bootstrapAlert("Error: Parameter type (" + p_type + ") not recognized. Please, take a screenshot and <a href='mailto:{% raw qiita_config.portal_dir %}'>contact us</a>", "danger");
}
}
if (dflt_val !== undefined) {
if (p_type == 'boolean') {
// The boolean type works differently than the others, so we needed
// to special case it here.
if (dflt_val !== 'false' && dflt_val !== false) {
$inp.prop('checked', true);
} else {
$inp.prop('checked', false);
}
}
else {
$inp.val(dflt_val);
}
$inp.addClass('parameter');
}
else {
$inp.addClass('parameter');
}
$inp.appendTo($colDiv).attr('id', p_name).attr('name', p_name).addClass('form-control');
}
function add_and_submit_job(command_id) {
// creating a form to send data, this is neccesary so we can send the
// file; we could do a regular $.post if we didn't need to send a file
var fd = new FormData(), params = {}, missing = [], files = {};
$(".parameter").each( function () {
var value = this.value;
// file is a special case
if ( $(this).attr('type') === 'file' ){
fd.set(this.id, this.files[0]);
} else {
if ( $(this).attr('type') === 'checkbox' ) {
value = this.checked;
}
if (value === "") {
missing.push(this.id)
}
params[this.id] = value;
}
});
if (missing.length !== 0){
alert('You are missing these parameters: ' + missing)
return false;
}
fd.set('command_id', command_id);
fd.set('params', JSON.stringify(params));
function _helper_clean_objects(){
$('#cmd-description').empty();
$('#parameters').empty();
$("#cmd_select").val([]);
}
// Creating Job
$('#parameters').empty();
$('#parameters').html("Creating Job");
$.ajax({
url: '/study/process/workflow/',
type: 'POST',
processData: false,
contentType: false,
data: fd,
success: function(data) {
// Submitting Job
$('#parameters').html("Submitting Job: <b>" + data.job + '</b>');
$.post("/study/process/workflow/run/", {workflow_id: data.workflow_id}, function(data_submit){
bootstrapAlert("Workflow " + data.workflow_id + " submitted", "success");
})
.fail(function(object, status, error_msg) {
bootstrapAlert("Error submitting workflow: " + object.statusText, "danger");
})
.always(function() {
_helper_clean_objects();
// trigger a courtesy reload of the table to show the new job
jobsTable.ajax.reload(null, false);
});
},
error: function (object, status, error_msg) {
bootstrapAlert(error_msg, "danger");
_helper_clean_objects();
}
});
return false
}
function generate_summary(option_selected){
var command_id = option_selected.attr('value');
var command_name = option_selected.text();
$('#cmd-description').html(option_selected.attr('description'));
$("#parameters").empty();
$.get('/study/process/commands/options/', {command_id: command_id})
.done(function(data){
$('<div>').appendTo($("#parameters")).attr('id', 'cmd-opts-div').attr('name', 'cmd-opts-div');
sel_artifacts_info = ''
$("#cmd-opts-div").append($('<h4>').text('Parameters:'));
var keys = Object.keys(data.req_options).sort(function(a, b){return a.localeCompare(b, 'en', {'sensitivity': 'base'});});
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
loadParameterGUI(key, data.req_options[key], sel_artifacts_info, $("#cmd-opts-div"));
}
var keys = Object.keys(data.opt_options).sort(function(a, b){return a.localeCompare(b, 'en', {'sensitivity': 'base'});});
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
loadParameterGUI(key, data.opt_options[key], sel_artifacts_info, $("#cmd-opts-div"));
}
$('<button>').appendTo($("#cmd-opts-div")).addClass('btn btn-info').text('Create Job').click(
function() {
this.disabled = true;
add_and_submit_job(command_id);
this.disabled = false;
});
// load the jobs table for the selected command
$('#previous-jobs').show();
$('#previous-jobs-tin').html('Previous "' + command_name + '" jobs');
// update the table
jobsTable.ajax.url("/admin/processing_jobs/list?sEcho=" + Math.floor(Math.random()*10001) + "&commandId=" + command_id).load();
});
}
</script>
{% end %}
{%block content %}
<h3 class="gray-msg">Available Commands</h3>
<table border="0">
<tr>
<td>
<select id="cmd_select" class="select" size="5" onchange="generate_summary($('option:selected', this));">
{% for ps in private_software %}
<optgroup label="{{ps.name}}">
{% for cmd in ps.commands %}
<option value="{{cmd.id}}" description="{{cmd.description}}">{{cmd.name}}</option>
{% end %}
</optgroup>
{% end %}
</select>
</td>
<td width="10px"></td>
<td width="300px">
<div id="cmd-description"></div>
</td>
</tr>
</table>
<div id="artifact-info"></div>
<div id="parameters"></div>
<div class="modal fade" id="modal-artifact-description" tabindex="-1" role="dialog" aria-labelledby="title" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="title">Artifact Summary</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body" id="modal-body"></div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<!-- Job Output Modal -->
<div class="modal fade" tabindex="-1" role="dialog" aria-hidden="true" id="job-output-modal">
<div class="modal-dialog modal-med">
<div class="modal-content">
<div class="modal-header">
<h3 name="modal-title"></h3>
</div>
<div class="modal-body" name="modal-main-text">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div id="previous-jobs" style="display: none;" class="row">
<div class="col-sm-12">
<h3 id="previous-jobs-tin" class="gray-msg">Previous Jobs</h3>
<table id="private-jobs-table" class="table table-bordered gray-msg" style="width: 30px!">
<thead>
<tr>
<th class="sorting sorting_asc" tabindex="0" aria-controls="private-jobs-table" rowspan="1" colspan="1" aria-sort="ascending" aria-label="Last Updated">Summary</th>
<th class="sorting sorting_asc" tabindex="0" aria-controls="private-jobs-table" rowspan="1" colspan="1" aria-sort="ascending" aria-label="Last Updated">Arguments</th>
<th class="sorting sorting_asc" tabindex="0" aria-controls="private-jobs-table" rowspan="1" colspan="1" aria-sort="ascending" aria-label="Last Updated">Last Updated</th>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
{% end %}