Skip to content
Snippets Groups Projects
Commit 9bcfc867 authored by André Anjos's avatar André Anjos :speech_balloon:
Browse files

[algo,libs] Properly handle error conditions

parent b5992b52
No related branches found
No related tags found
1 merge request!209Issue 425
Pipeline #
......@@ -2,21 +2,21 @@
{% comment %}
* Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/
* Contact: beat.support@idiap.ch
*
*
* This file is part of the beat.web module of the BEAT platform.
*
*
* Commercial License Usage
* Licensees holding valid commercial BEAT licenses may use this file in
* accordance with the terms contained in a written agreement between you
* and Idiap. For further information contact tto@idiap.ch
*
*
* Alternatively, this file may be used under the terms of the GNU Affero
* Public License version 3 as published by the Free Software and appearing
* in the file LICENSE.AGPL included in the packaging of this file.
* The BEAT platform is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE.
*
*
* You should have received a copy of the GNU Affero Public License along
* with the BEAT platform. If not, see http://www.gnu.org/licenses/.
{% endcomment %}
......@@ -129,13 +129,6 @@ function process_diff(lines, editor, diff_line_numbers_classname)
</div>
</div>
<div id="errors" class="row" style="display:none">
<div class="col-sm-offset-1 col-sm-10">
<h2></h2>
<p></p>
</div>
</div>
<script type="text/javascript">
jQuery(document).ready(function() {
......@@ -143,79 +136,58 @@ jQuery(document).ready(function() {
$('h4').hide();
$('#progress').show();
$.get('{% url 'api_algorithms:diff' algorithm1_author algorithm1_name algorithm1_version algorithm2_author algorithm2_name algorithm2_version %}')
.done(function(data) {
$('#progress').hide();
$('h4').show();
var source_code_lines = data.source_code_diff.split('\n')
var code = '';
for (var i = 0; i < source_code_lines.length; ++i)
code += source_code_lines[i].substr(2) + '\n';
var declaration_lines = data.diff.split('\n')
var declaration = '';
for (var i = 0; i < declaration_lines.length; ++i)
declaration += declaration_lines[i].substr(2) + '\n';
var diff_line_numbers_classname = (Math.log10(Math.max(source_code_lines.length, declaration_lines.length)) > 3 ?
'diff_line_numbers_large' :
'diff_line_numbers');
var code_editor = CodeMirror($('#code_editor_container')[0],
{
value: code,
mode: 'python',
readOnly: true,
lineNumbers: false,
gutters: [diff_line_numbers_classname, 'diff_addition_deletion'],
}
);
var declaration_editor = CodeMirror($('#declaration_container')[0],
{
value: declaration,
mode: 'javascript',
readOnly: true,
lineNumbers: false,
gutters: [diff_line_numbers_classname, 'diff_addition_deletion'],
}
);
process_diff(source_code_lines, code_editor, diff_line_numbers_classname);
process_diff(declaration_lines, declaration_editor, diff_line_numbers_classname);
})
.fail(function(jqXHR, textStatus, errorThrown) {
$('#title').hide();
var errors_box = $('.container #errors');
if (jqXHR.status == 404)
{
errors_box.find('h2').text('Algorithm not found');
errors_box.find('p').html("We are sorry, but the algorithm called <strong>" +
jqXHR.responseText + "</strong> could not be found.");
}
else if (jqXHR.status == 401)
{
errors_box.find('h2').text('Unauthorized access');
errors_box.find('p').html("We are sorry, but your aren't authorized to access the algorithm called <strong>" +
jqXHR.responseText + "</strong>.");
}
else if (jqXHR.responseText.length > 0)
{
errors_box.find('h2').text(textStatus);
errors_box.find('p').html(jqXHR.responseText);
var d = $.get('{% url 'api_algorithms:diff' algorithm1_author algorithm1_name algorithm1_version algorithm2_author algorithm2_name algorithm2_version %}');
d.done(function(data) {
$('#progress').hide();
$('h4').show();
var source_code_lines = data.source_code_diff.split('\n');
var code = '';
for (var i = 0; i < source_code_lines.length; ++i) {
code += source_code_lines[i].substr(2) + '\n';
}
else
{
errors_box.find('h2').text(textStatus);
var declaration_lines = data.diff.split('\n');
var declaration = '';
for (var i = 0; i < declaration_lines.length; ++i) {
declaration += declaration_lines[i].substr(2) + '\n';
}
errors_box.show();
var diff_line_numbers_classname = (Math.log10(Math.max(source_code_lines.length, declaration_lines.length)) > 3 ?
'diff_line_numbers_large' :
'diff_line_numbers');
var code_editor = CodeMirror($('#code_editor_container')[0],
{
value: code,
mode: 'python',
readOnly: true,
lineNumbers: false,
gutters: [diff_line_numbers_classname, 'diff_addition_deletion'],
}
);
var declaration_editor = CodeMirror($('#declaration_container')[0],
{
value: declaration,
mode: 'javascript',
readOnly: true,
lineNumbers: false,
gutters: [diff_line_numbers_classname, 'diff_addition_deletion'],
}
);
process_diff(source_code_lines, code_editor, diff_line_numbers_classname);
process_diff(declaration_lines, declaration_editor, diff_line_numbers_classname);
});
d.fail(function (data, status_text) {
$('#progress').hide();
process_error(data, status_text, document.referrer);
});
});
......
......@@ -2,21 +2,21 @@
{% comment %}
* Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/
* Contact: beat.support@idiap.ch
*
*
* This file is part of the beat.web module of the BEAT platform.
*
*
* Commercial License Usage
* Licensees holding valid commercial BEAT licenses may use this file in
* accordance with the terms contained in a written agreement between you
* and Idiap. For further information contact tto@idiap.ch
*
*
* Alternatively, this file may be used under the terms of the GNU Affero
* Public License version 3 as published by the Free Software and appearing
* in the file LICENSE.AGPL included in the packaging of this file.
* The BEAT platform is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE.
*
*
* You should have received a copy of the GNU Affero Public License along
* with the BEAT platform. If not, see http://www.gnu.org/licenses/.
{% endcomment %}
......@@ -129,93 +129,61 @@ function process_diff(lines, editor, diff_line_numbers_classname)
</div>
</div>
<div id="errors" class="row" style="display:none">
<div class="col-sm-offset-1 col-sm-10">
<h2></h2>
<p></p>
</div>
</div>
<script type="text/javascript">
jQuery(document).ready(function() {
$('#progress').show();
$('h4').hide();
$.get('{% url 'api_libraries:diff' library1_author library1_name library1_version library2_author library2_name library2_version %}')
.done(function(data) {
$('#progress').hide();
$('h4').show();
var source_code_lines = data.source_code_diff.split('\n')
var code = '';
for (var i = 0; i < source_code_lines.length; ++i)
code += source_code_lines[i].substr(2) + '\n';
var declaration_lines = data.diff.split('\n')
var declaration = '';
for (var i = 0; i < declaration_lines.length; ++i)
declaration += declaration_lines[i].substr(2) + '\n';
var diff_line_numbers_classname = (Math.log10(Math.max(source_code_lines.length, declaration_lines.length)) > 3 ?
'diff_line_numbers_large' :
'diff_line_numbers');
var code_editor = CodeMirror($('#code_editor_container')[0],
{
value: code,
mode: 'python',
readOnly: true,
lineNumbers: false,
gutters: [diff_line_numbers_classname, 'diff_addition_deletion'],
}
);
var declaration_editor = CodeMirror($('#declaration_container')[0],
{
value: declaration,
mode: 'javascript',
readOnly: true,
lineNumbers: false,
gutters: [diff_line_numbers_classname, 'diff_addition_deletion'],
}
);
process_diff(source_code_lines, code_editor, diff_line_numbers_classname);
process_diff(declaration_lines, declaration_editor, diff_line_numbers_classname);
})
.fail(function(jqXHR, textStatus, errorThrown) {
var d = $.get('{% url 'api_libraries:diff' library1_author library1_name library1_version library2_author library2_name library2_version %}');
d.done(function(data) {
$('#progress').hide();
$('#title').hide();
$('h4').show();
var errors_box = $('.container #errors');
var source_code_lines = data.source_code_diff.split('\n');
if (jqXHR.status == 404)
{
errors_box.find('h2').text('Library not found');
errors_box.find('p').html("We are sorry, but the library called <strong>" +
jqXHR.responseText + "</strong> could not be found.");
}
else if (jqXHR.status == 401)
{
errors_box.find('h2').text('Unauthorized access');
errors_box.find('p').html("We are sorry, but your aren't authorized to access the library called <strong>" +
jqXHR.responseText + "</strong>.");
var code = '';
for (var i = 0; i < source_code_lines.length; ++i) {
code += source_code_lines[i].substr(2) + '\n';
}
else if (jqXHR.responseText.length > 0)
{
errors_box.find('h2').text(textStatus);
errors_box.find('p').html(jqXHR.responseText);
}
else
{
errors_box.find('h2').text(textStatus);
var declaration_lines = data.diff.split('\n');
var declaration = '';
for (var i = 0; i < declaration_lines.length; ++i) {
declaration += declaration_lines[i].substr(2) + '\n';
}
errors_box.show();
var diff_line_numbers_classname = (Math.log10(Math.max(source_code_lines.length, declaration_lines.length)) > 3 ?
'diff_line_numbers_large' :
'diff_line_numbers');
var code_editor = CodeMirror($('#code_editor_container')[0],
{
value: code,
mode: 'python',
readOnly: true,
lineNumbers: false,
gutters: [diff_line_numbers_classname, 'diff_addition_deletion'],
}
);
var declaration_editor = CodeMirror($('#declaration_container')[0],
{
value: declaration,
mode: 'javascript',
readOnly: true,
lineNumbers: false,
gutters: [diff_line_numbers_classname, 'diff_addition_deletion'],
}
);
process_diff(source_code_lines, code_editor, diff_line_numbers_classname);
process_diff(declaration_lines, declaration_editor, diff_line_numbers_classname);
});
d.fail(process_error);
});
</script>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment