|
| 1 | +@(extractors: List[ExtractorInfo], ds: Dataset)(implicit user: Option[models.User]) |
| 2 | +@import _root_.util.Formatters._ |
| 3 | +@import play.api.libs.json._ |
| 4 | + |
| 5 | +@main("Extractions") { |
| 6 | + <ol class="breadcrumb"> |
| 7 | + <li><span class="glyphicon glyphicon-user"></span> <a href = "@routes.Profile.viewProfileUUID(ds.author.id)"> @ds.author.fullName</a></li> |
| 8 | + <li> <span class="glyphicon glyphicon-briefcase"></span> <a href="@routes.Datasets.dataset(ds.id)" title="@ds.name"> @Html(ellipsize(ds.name, 18))</a></li> |
| 9 | + <li><span class="glyphicon glyphicon-fullscreen"></span> Marked Files</li> |
| 10 | + |
| 11 | + </ol> |
| 12 | + <div class="row"> |
| 13 | + <div id="submission_header" class="col-xs-12"> |
| 14 | + <h1>Submit marked files for extraction</h1> |
| 15 | + </div> |
| 16 | + </div> |
| 17 | + <div class="row"> |
| 18 | + <div class="col-xs-12"> |
| 19 | + <p>Submit these files to a specific extractor below by providing parameters and clicking |
| 20 | + the submit button. Some parameters may be left empty.</p> |
| 21 | + </div> |
| 22 | + </div> |
| 23 | + <div class="row"> |
| 24 | + <div class="col-xs-12"> |
| 25 | + <table class="table"> |
| 26 | + <thead> |
| 27 | + <tr> |
| 28 | + <th>Extractor's Name</th> |
| 29 | + <th>Description</th> |
| 30 | + <th>Parameters</th> |
| 31 | + <th>Submit</th> |
| 32 | + </tr> |
| 33 | + </thead> |
| 34 | + <tbody> |
| 35 | + <script src="https://cdn.jsdelivr.net/npm/jsonform@@2.1.5/deps/underscore.js"></script> |
| 36 | + <script src="https://cdn.jsdelivr.net/npm/jsonform@@2.1.5/lib/jsonform.min.js"></script> |
| 37 | + @for(e <- extractors) { |
| 38 | + <tr> |
| 39 | + <td> |
| 40 | + <a href="@routes.Extractors.showExtractorInfo(e.name)">@e.name</a> |
| 41 | + </td> |
| 42 | + <td>@e.description</td> |
| 43 | + <td> |
| 44 | + <form id="@(e.name.replaceAll("\\.", "_"))_parameters"></form> |
| 45 | + </td> |
| 46 | + <td><button id="@e.id" class="btn btn-primary" onclick="submit('@e.name','@(e.name.replaceAll("\\.", "_"))_parameters','@ds.id','@e.id')">Submit</button></td> |
| 47 | + </tr> |
| 48 | + |
| 49 | + <script> |
| 50 | + var params = JSON.parse("@Json.stringify(e.parameters)".replace(/"/g, "\"")); |
| 51 | + var selector = "#@(e.name.replaceAll("\\.", "_"))_parameters"; |
| 52 | + if (Object.keys(params).length != 0) { |
| 53 | + $(selector).jsonForm(params); |
| 54 | + } |
| 55 | + </script> |
| 56 | + } |
| 57 | + </tbody> |
| 58 | + </table> |
| 59 | + </div> |
| 60 | + </div> |
| 61 | + <script type="text/javascript"> |
| 62 | + function disableSubmit(btn) { |
| 63 | + btn.attr('disabled', true); |
| 64 | + btn.addClass('disabled'); |
| 65 | + btn.removeClass('btn-primary'); |
| 66 | + btn.addClass('btn-success'); |
| 67 | + btn.html('Submitted'); |
| 68 | + } |
| 69 | + |
| 70 | + function enableSubmit(btn) { |
| 71 | + btn.html('Submit'); |
| 72 | + btn.removeClass('disabled'); |
| 73 | + btn.removeClass('btn-success'); |
| 74 | + btn.addClass('btn-primary'); |
| 75 | + btn.attr('disabled', false); |
| 76 | + } |
| 77 | + |
| 78 | + function submit(extractor_name, textbox_id, file_id, submit_id) { |
| 79 | + var clickedBtn = $('#' + submit_id); |
| 80 | + |
| 81 | + var selected = $.cookie('[email protected]'); |
| 82 | + |
| 83 | + // Throttle submissions to one every 3 seconds |
| 84 | + disableSubmit(clickedBtn); |
| 85 | + setTimeout(function() { |
| 86 | + enableSubmit(clickedBtn); |
| 87 | + }, 3000); |
| 88 | + |
| 89 | + var params = $('#'+textbox_id).jsonFormValue(); |
| 90 | + if (params === "") params = "{}"; |
| 91 | + var dataBody = {'extractor': extractor_name, 'parameters': params}; |
| 92 | + var request = jsRoutes.api.Extractions.submitFilesToExtractor("@ds.id", selected).ajax({ |
| 93 | + data: JSON.stringify(dataBody), |
| 94 | + type: 'POST', |
| 95 | + contentType: "application/json", |
| 96 | + }); |
| 97 | + |
| 98 | + request.done(function (response, textStatus, jqXHR){ |
| 99 | + notify("Submitted successfully", "success"); |
| 100 | + }); |
| 101 | + |
| 102 | + request.fail(function (jqXHR, textStatus, errorThrown){ |
| 103 | + console.error("The following error occured: " + textStatus, errorThrown); |
| 104 | + }); |
| 105 | + } |
| 106 | + |
| 107 | + $(document).ready(function() { |
| 108 | + var selected = $.cookie('[email protected]'); |
| 109 | + if (selected) { |
| 110 | + var fileUUIDs = selected.split(','); |
| 111 | + $('#submission_header')[0].innerHTML = "<h1>Submit "+fileUUIDs.length+" marked files for extraction</h1>" |
| 112 | + } |
| 113 | + }); |
| 114 | + </script> |
| 115 | +} |
| 116 | + |
0 commit comments