Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Add URL input option #87

Merged
merged 34 commits into from
Jun 25, 2020
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
5d9dcd7
Admin changes
aguilerapy Mar 19, 2020
75eb374
Merge branch 'master' into 42-in_out_options_2
aguilerapy Mar 25, 2020
f1a5145
Merge branch 'master' into 42-in_out_options_2
aguilerapy Apr 1, 2020
99f5700
Merge branch 'master' into 42-in_out_options_2
aguilerapy Apr 21, 2020
5f32495
Add url_uploader.js
aguilerapy Apr 28, 2020
8e116cd
Add translations
aguilerapy Apr 28, 2020
e0bce00
Update views
aguilerapy Apr 28, 2020
83d1a21
Reorder imports
aguilerapy Apr 28, 2020
b61ce39
Update user info
aguilerapy Apr 30, 2020
1f2d2c7
Update translations
aguilerapy Apr 30, 2020
836efd2
Add tests
aguilerapy May 7, 2020
a267379
Merge branch 'master' into 42-in_out_options_2
aguilerapy May 7, 2020
f6892d3
Fix delete url button
aguilerapy May 8, 2020
3ec389b
Delete duplicate code
aguilerapy May 12, 2020
8f4bdef
Update url uploader snippet
aguilerapy May 12, 2020
e838a8f
Update changes
aguilerapy May 12, 2020
9cc94b9
Update translations
aguilerapy May 12, 2020
720ac78
Update tests
aguilerapy May 12, 2020
1601321
Update test
aguilerapy May 20, 2020
621cddc
Update error messages on the client side
aguilerapy May 22, 2020
d32b3aa
Update translations
aguilerapy May 22, 2020
5f6521d
Update tests
aguilerapy May 23, 2020
e81005c
Upload option selected by default
aguilerapy May 26, 2020
1d2d1ef
Move block to base-uploader
aguilerapy May 26, 2020
4ea561e
Update performAction
aguilerapy May 26, 2020
0075996
Delete response-fail-url
aguilerapy May 26, 2020
2beecbe
Remove getCookie
aguilerapy May 26, 2020
55edbf4
Update messages and translations
aguilerapy May 27, 2020
168ef4c
Verify URLs files format
aguilerapy Jun 3, 2020
ea16276
Add processed files feedback
aguilerapy Jun 3, 2020
cb6ebc0
Update translations
aguilerapy Jun 3, 2020
4d98302
Update tests
aguilerapy Jun 3, 2020
229bc28
Clear URL input text
aguilerapy Jun 18, 2020
061fc78
Clear URL input text
aguilerapy Jun 18, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 120 additions & 0 deletions default/static/js/url_uploader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
var app = {};
aguilerapy marked this conversation as resolved.
Show resolved Hide resolved

function inputDelete(button) {
aguilerapy marked this conversation as resolved.
Show resolved Hide resolved
$(button).parents('.form-group').remove();
if ($('.input-url-container .btn.input-delete').length < 2) {
$('.input-url-container .btn.input-delete').attr('disabled', true);
}
}

function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie !== '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i].trim();
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) === (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}

(function () {

var _paramSetters = [];
var _done = false;

this.setParams = function (func) {
_paramSetters.push(func);
};

/** functions **/

function hideMessages() {
$('.response-warning')
.addClass('hidden');
}

function showProcessingModal() {
$('#processing-modal').modal('show');
}

function hideProcessingModal() {
$('#processing-modal').modal('hide');
}

function whenAjaxReqFails(jqXHR) {
$('.response-fail').removeClass('hidden');
hideProcessingModal();
}

function performUrlAction() {
var actionParams = {};
_paramSetters.forEach(function (f) {
f(actionParams);
});
$.ajax($('#url-button').attr('data-perform-action'), {data: actionParams})
.done(function (data) {
$('.response-success .file-size').html(utils.readableFileSize(data.size));
$('.response-success .download').attr('href', data.url);
$('.response-success').removeClass('hidden');
hideProcessingModal();
})
.fail(whenAjaxReqFails)
.always(function () {
_done = true
});
}

function upload_url() {
hideMessages();
showProcessingModal();
$.ajax('/upload-url/',
{'dataType': 'json', type: 'POST',
'data': $('.input-url-container .form-group .input-group .form-control').serialize(),
headers: { "X-CSRFToken": getCookie('csrftoken') }
} )
.done(function (data) {
performUrlAction();
})
.fail(function(jqXHR, textStatus, errorThrown) {
$('.response-warning.url-process-failed .message-url').html(
( jqXHR.responseText || textStatus )
);
$('.response-warning.url-process-failed').removeClass('hidden');
hideProcessingModal();
})
;
}

/** upload url **/
$("#url-button").click(upload_url);

$('.choice-header').on('change', function() {
if ($(this).is(':checked')) {
var allClasses = $(this).attr('class');
var operationIndex = allClasses.search(/toucan-nav-[^\s]+/);
var operationClass = allClasses.substring(operationIndex);
$('.panel-collapse.collapse ').not(this).collapse('hide');
$('.panel-collapse.collapse.' + operationClass).collapse('show');
}
});

$('#add-url').click(function () {
var numInputs = $('.input-url-container').children().length;
$('.input-url-container .btn.btn-danger').attr('disabled', false);
$('.input-url-container').append('<div class="form-group">' +
'<div class="input-group">' +
'<input type="text" class="form-control" name="input_url_' + numInputs + '" id="id_' + numInputs + '"/>' +
'<span class="input-group-btn">' +
'<button class="btn btn-danger input-delete" onclick="inputDelete(this)" type="button">x</button>' +
'</span>' +
'</div>' +
'</div>')
});

}).apply(app);
126 changes: 91 additions & 35 deletions default/templates/default/base-uploader.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
{% trans "You can add more files or remove them, then click on <b>Start</b> again." %}
{% trans "Files with validation issues will be ignored by default." %}
</div>
<div class="response-warning url-process-failed alert alert-warning hidden">
{% trans "There was an error when trying to access the entered URL: " %}
"<span class="message-url"></span>"
</div>
<div class="response-fail alert alert-danger hidden">
<b>{% trans "An error has occurred!" %}</b>
{% trans "Please verify that all your files are valid OCDS JSON, and try again in a few minutes." %}
Expand All @@ -32,41 +36,20 @@
{% block info %}{% endblock %}
</div>
</div>
<form
id="fileupload"
method="POST"
action="/upload/"
onsubmit="return false;"
data-accept-file-types="/(\.|\/)json$/i"
data-files-container=".files"
data-sequential-uploads="true"
data-form-data='{"csrfmiddlewaretoken": "{{csrf_token}}"{% block form-options %}{% endblock %}}'
data-max-number-of-files="{{maxNumOfFiles}}"
data-max-file-size="{{maxFileSize}}"
data-perform-action="{{performAction}}"
>
<div class="action-extra-params form-inline">{% block extraoptions %}{% endblock %}</div>
<!-- The container for the uploaded files -->
<div class="drop-area empty">
<!-- The file input field used as target for the file upload widget -->
<input type="file" name="file" id="file" accept=".json" multiple/>
<span class="file-selector-empty"><label for="file">{% trans "Add a file" %}</label> {% trans "or drag and drop here." %}</span>
<div class="files hidden">
</div>
</div>
<div class="actions hidden">
<div class="buttons">
<div class="btn btn-default fileinput-button">
<i class="glyphicon glyphicon-plus"></i>
<label for="file" id="file-selector">{% trans "Add more files" %}</label>
</div>
<button type="submit" class="btn btn-primary pull-right start" id="upload-button" disabled>
<i class="glyphicon glyphicon-cloud-upload"></i>
<span>{% trans "Start" %}</span>
</button>
</div>
</div>
</form>
<div class="text-danger">{{ form.type.errors }}</div>
<div class="btn-group schema-nav" data-toggle="buttons" style="margin-top: 0px;margin-bottom: 15px;">
<label class="btn btn-default ">
<input type="radio" name="type" class="choice-header toucan-nav-file" autocomplete="off" value="file">
{% trans "Upload a file" %}
aguilerapy marked this conversation as resolved.
Show resolved Hide resolved
</label>
<label class="btn btn-default ">
<input type="radio" name="type" class="choice-header toucan-nav-input" autocomplete="off" value="input">
{% trans "Provide a URL" %}
aguilerapy marked this conversation as resolved.
Show resolved Hide resolved
</label>
</div>
<div class="action-extra-params form-inline"style="margin-bottom: 10px;">
{% block extraoptions %}{% endblock %}
</div>
<!-- Processing modal, active when all files has been uploaded and the requested operation is in progress -->
<div id="processing-modal" class="modal fade" tabindex="-1" role="dialog" data-backdrop="static" data-keyboard="false">
<div class="modal-dialog modal-sm" role="document">
Expand All @@ -81,6 +64,78 @@
</div>
</div>
</div>

<div role="tabpanel" class="panel-collapse collapse {% if form.type.value == 'input' %}in{% endif %} toucan-nav-input">
<div class="input-url-container">
<div class="form-group {% if field.errors %}has-error{% endif %}">
<label>{% blocktrans trimmed %}
Provide the URL to a file:
{% endblocktrans %}</label>
<div class="input-group">
<input type="text" name="input_url_0" id="id_0'"
class="form-control" value="{{ field.value }}"/>
<span class="input-group-btn">
<button class="btn btn-danger input-delete"
type="button"
onclick="inputDelete(this)"
disabled="disabled">
x
</button>
</span>
</div>
{% if field.errors %}
<div class="help-block">{{ field.errors }}</div>{% endif %}
</div>
</div>
<div class="buttons">
<a class="pull-right" href="#" id="add-url" style="margin-top: 5px;">+{% trans "Add URL" %}</a>
<button type="submit" class="btn btn-primary" id="url-button" data-perform-action="{{performAction}}">
{% trans "Start" %}
<i class="glyphicon glyphicon-play-circle"></i>
</button>
</div>
</div>

<div role="tabpanel" class="panel-collapse collapse {% if form.type.value == 'file' %}in{% endif %} toucan-nav-file">
<div class="form-group {% if form.custom_file.errors %}has-error{% endif %}">
<form
id="fileupload"
method="POST"
action="/upload/"
onsubmit="return false;"
data-accept-file-types="/(\.|\/)json$/i"
data-files-container=".files"
data-sequential-uploads="true"
data-form-data='{"csrfmiddlewaretoken": "{{csrf_token}}"{% block form-options %}{% endblock %}}'
data-max-number-of-files="{{maxNumOfFiles}}"
data-max-file-size="{{maxFileSize}}"
data-perform-action="{{performAction}}"
>
<!-- The container for the uploaded files -->
<div class="drop-area empty">
<!-- The file input field used as target for the file upload widget -->
<input type="file" name="file" id="file" accept=".json" multiple/>
<span class="file-selector-empty"><label for="file">{% trans "Add a file" %}</label> {% trans "or drag and drop here." %}</span>
<div class="files hidden">
</div>
</div>
<div class="actions hidden">
<div class="buttons">
<div class="btn btn-default fileinput-button">
<i class="glyphicon glyphicon-plus"></i>
<label for="file" id="file-selector">{% trans "Add more files" %}</label>
</div>
<button type="submit" class="btn btn-primary pull-right start" id="upload-button" disabled>
<i class="glyphicon glyphicon-cloud-upload"></i>
<span>{% trans "Start" %}</span>
</button>
</div>
</div>
</form>
{% if form.custom_file.errors %}
<div class="help-block">{{ form.custom_file.errors }}</div>{% endif %}
</div>
</div>
{% endblock body %}

{% block scripts %}
Expand All @@ -96,5 +151,6 @@
{% include "jquery-file-upload/download.html"%}
<script src="{% static "js/utils.js" %}"></script>
<script src="{% static "js/uploader.js" %}"></script>
<script src="{% static "js/url_uploader.js" %}"></script>
<script type="text-javascript"></script>
{% endblock scripts %}
22 changes: 17 additions & 5 deletions default/templates/default/combine-packages.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,29 @@
{% block info %}
<p>
{% blocktrans trimmed %}
Drag and drop two or more
<a href="https://standard.open-contracting.org/latest/en/schema/release_package/" target="_blank">release packages</a>
Use this tool to combine <a href="https://standard.open-contracting.org/latest/en/schema/release_package/" target="_blank">release packages</a>
or <a href="https://standard.open-contracting.org/latest/en/schema/record_package/" target="_blank">record packages</a>
to combine them into a single package.
into a single package.
{% endblocktrans %}
{% trans "You can also click the <strong>Add a file</strong> link below." %}
</p>
<p>
{% trans "Fill in the <strong>Published date</strong> textbox to set <code>publishedDate</code> in the output package." %}
{% trans "Select the correct <strong>Package type</strong> option before uploading." %}
{% trans "Select the correct <strong>Package type</strong> option before start." %}
aguilerapy marked this conversation as resolved.
Show resolved Hide resolved
</p>
<p>
aguilerapy marked this conversation as resolved.
Show resolved Hide resolved
{% trans "The options available for input files are:" %}
</p>
<ul class="list-unstyled">
<li>
<strong>{% trans "Upload a file:" %}</strong>
{% trans "Drag and drop one or more files." %}
{% trans "You can also click the <strong>Add a file</strong> link below." %}
</li>
<li>
<strong>{% trans "Provide a URL:" %}</strong>
{% trans "Enter one or more URLs to each file. Click <strong>Add URL</strong> to provide more URLs." %}
</li>
</ul>
<p>
{% trans "Each input file must be a JSON file containing either a single package or an array of packages." %}
</p>
Expand Down
27 changes: 19 additions & 8 deletions default/templates/default/compile.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,11 @@
{% block info %}
<p>
{% blocktrans trimmed %}
Drag and drop one or more
<a href="https://standard.open-contracting.org/latest/en/schema/release_package/" target="_blank">release packages</a>
to create a
Use this tool to create a
<a href="https://standard.open-contracting.org/latest/en/schema/record_package/" target="_blank">record package</a>
with compiled releases included.
with compiled releases included from <a href="https://standard.open-contracting.org/latest/en/schema/release_package/" target="_blank">release packages</a>.
{% endblocktrans %}
{% trans "You can also click the <strong>Add a file</strong> link below." %}
</p>

<p>
{% trans "Fill in the <strong>Published date</strong> textbox to set <code>publishedDate</code> in the output package." %}
{% blocktrans trimmed %}
Expand All @@ -25,8 +21,23 @@
<a href="https://standard.open-contracting.org/latest/en/schema/merging/" target="_blank">OCDS documentation</a>.
{% endblocktrans %}
</p>

<p>{% trans "Please verify that your files are release packages before uploading." %}</p>
<p>
{% trans "The options available for input files are:" %}
</p>
<ul class="list-unstyled">
<li>
<strong>{% trans "Upload a file:" %}</strong>
{% trans "Drag and drop one or more files." %}
{% trans "You can also click the <strong>Add a file</strong> link below." %}
</li>
<li>
<strong>{% trans "Provide a URL:" %}</strong>
{% trans "Enter one or more URLs to each file. Click <strong>Add URL</strong> to provide more URLs." %}
</li>
</ul>
<p>
{% trans "Please verify that your files are release packages before uploading." %}
</p>
{% endblock %}

{% block extraoptions %}
Expand Down
1 change: 1 addition & 0 deletions default/templates/default/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
{% blocktrans trimmed %}
You can upload up to 20 files to each tool, and each file should be less than 20MB.
Results remain available for 2 days.
Another option is to enter the URLs to the input files on each page.
{% endblocktrans %}
</p>
<p>
Expand Down
21 changes: 16 additions & 5 deletions default/templates/default/package-releases.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,27 @@
{% block info %}
<p>
{% blocktrans trimmed %}
Drag and drop one or more
<a href="https://standard.open-contracting.org/latest/en/getting_started/releases_and_records/#releases" target="_blank">releases</a>
to create a
<a href="https://standard.open-contracting.org/latest/en/schema/release_package/" target="_blank">release package</a>.
Use this tool to create a <a href="https://standard.open-contracting.org/latest/en/schema/release_package/" target="_blank">release package</a>
from <a href="https://standard.open-contracting.org/latest/en/getting_started/releases_and_records/#releases" target="_blank">releases</a>.
{% endblocktrans %}
{% trans "You can also click the <strong>Add a file</strong> link below." %}
</p>
<p>
{% trans "Fill in the <strong>Published date</strong> textbox to set <code>publishedDate</code> in the output package." %}
</p>
<p>
{% trans "The options available for input files are:" %}
</p>
<ul class="list-unstyled">
<li>
<strong>{% trans "Upload a file:" %}</strong>
{% trans "Drag and drop one or more files." %}
{% trans "You can also click the <strong>Add a file</strong> link below." %}
</li>
<li>
<strong>{% trans "Provide a URL:" %}</strong>
{% trans "Enter one or more URLs to each file. Click <strong>Add URL</strong> to provide more URLs." %}
</li>
</ul>
<p>
{% trans "Each input file must be a JSON file containing either one release or an array of releases." %}
</p>
Expand Down
Loading