Skip to content

Commit cfb2aeb

Browse files
jfunezGustavo Fonseca
authored and
Gustavo Fonseca
committed
Fixes #910
Navegabilidade entre o xml annotado e na lista de erros
1 parent 6d1355f commit cfb2aeb

File tree

13 files changed

+264
-112
lines changed

13 files changed

+264
-112
lines changed

scielomanager/articletrack/templates/articletrack/notice_detail.html

+4-2
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@
5858

5959
{# DO REVIEW #}
6060
{% if checkin.can_be_reviewed %}
61-
61+
6262
{# LEVEL 1 #}
63-
{% if user.get_profile.can_review_l1_checkins and not checkin.is_level1_reviewed %}
63+
{% if user.get_profile.can_review_l1_checkins and not checkin.is_level1_reviewed %}
6464
<li>
6565
<a href="{% url checkin_review checkin.pk 1 %}">
6666
<i class='icon-ok-circle'></i> <span class="label label-success">{% trans "Review" %}</span>
@@ -491,4 +491,6 @@ <h3>{% trans "Reject this Check-in?" %}</h3>
491491

492492
});
493493
</script>
494+
<script type="text/javascript" src="{% static 'js/jquery.scrollTo.min.js' %}"></script>
495+
<script type="text/javascript" src="{% static 'js/scroll_to_error_message.js' %}"></script>
494496
{% endblock %}

scielomanager/articletrack/tests/doubles.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ def validate(self):
8585

8686
def validate_style(self):
8787
class Error(object):
88-
line = None
89-
column = None
90-
message = u"Element 'funding-group': This element is not filled-in correctly."
91-
level_name = u'ERROR'
88+
line = 1
89+
column = 6
90+
message = u'Premature end of data in tag xml line 1, line 1, column 6'
91+
level_name = 'ERROR'
9292
return (False, [Error(), ])

scielomanager/articletrack/tests/tests_pages.py

+39-10
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,18 @@ def get_xml_uri(self, attempt_id, target_name):
295295
self.assertTrue(xml_data['can_be_analyzed'][0])
296296
self.assertIsNone(xml_data['annotations'])
297297
self.assertEqual(xml_data['uri'], expected_response['uri'])
298-
self.assertIsNone(xml_data['validation_errors'])
298+
expect_errors = {
299+
'error_lines': '1',
300+
'results': [
301+
{
302+
'column': 6,
303+
'line': 1,
304+
'message': u'Premature end of data in tag xml line 1, line 1, column 6',
305+
'level': 'ERROR'
306+
}
307+
]
308+
}
309+
self.assertEqual(xml_data['validation_errors'], expect_errors)
299310
self.assertEqual(xml_data['file_name'], expected_response['filename'])
300311

301312
def test_annotations_warning_if_balaio_breaks(self):
@@ -366,14 +377,21 @@ def get_xml_uri(self, attempt_id, target_name):
366377
self.assertEqual(xml_data['uri'], expected_response['uri'])
367378
self.assertEqual(xml_data['file_name'], expected_response['filename'])
368379
self.assertIsNotNone(xml_data['validation_errors'])
369-
self.assertEqual('', xml_data['validation_errors']['error_lines'])
380+
self.assertEqual('1', xml_data['validation_errors']['error_lines'])
370381
self.assertEqual(1, len(xml_data['validation_errors']['results']))
371-
self.assertEqual(
372-
xml_data['validation_errors']['results'],
373-
[{'column': '--',
374-
'line': '--',
375-
'message': u"Element 'funding-group': This element is not filled-in correctly.",
376-
'level': u'ERROR'}])
382+
expect_errors = {
383+
'error_lines': '1',
384+
'results': [
385+
{
386+
'column': 6,
387+
'line': 1,
388+
'message': u'Premature end of data in tag xml line 1, line 1, column 6',
389+
'level': 'ERROR'
390+
}
391+
]
392+
}
393+
self.assertEqual(xml_data['validation_errors'], expect_errors)
394+
377395

378396
def test_xml_not_found(self):
379397
self._addWaffleFlag()
@@ -406,11 +424,22 @@ def get_xml_uri(self, attempt_id, target_name):
406424

407425
self.assertEqual(response.status_code, 200)
408426
self.assertFalse(xml_data['can_be_analyzed'][0])
409-
self.assertEqual(xml_data['can_be_analyzed'][1], "Error while starting Stylechecker.XML()")
427+
self.assertEqual(xml_data['can_be_analyzed'][1], "IOError while starting Stylechecker.XML(), please verify if the input is correct")
410428
self.assertIsNone(xml_data['annotations'])
411429
self.assertEqual(xml_data['uri'], expected_response['uri'])
412430
self.assertEqual(xml_data['file_name'], expected_response['filename'])
413-
self.assertIsNone(xml_data['validation_errors'])
431+
expect_errors = {
432+
'error_lines': '1',
433+
'results': [
434+
{
435+
'column': 6,
436+
'line': 1,
437+
'message': u'Premature end of data in tag xml line 1, line 1, column 6',
438+
'level': 'ERROR'
439+
}
440+
]
441+
}
442+
self.assertEqual(xml_data['validation_errors'], expect_errors)
414443

415444
def test_annotations_of_syntax_error(self):
416445
self._addWaffleFlag()

scielomanager/articletrack/views.py

+7-15
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from . import models
2626
from .forms import CommentMessageForm, TicketForm, CheckinListFilterForm, CheckinRejectForm
2727
from .balaio import BalaioAPI, BalaioRPC
28-
from validator.utils import extract_validation_errors, extract_syntax_errors
28+
from validator.utils import StyleCheckerAnalyzer
2929

3030

3131
AUTHZ_REDIRECT_URL = '/accounts/unauthorized/'
@@ -503,6 +503,9 @@ def notice_detail(request, checkin_id):
503503

504504
xml_data['file_name'] = files['xml'][0] # assume only ONE xml per package
505505
xml_data['can_be_analyzed'] = (True, '')
506+
else:
507+
xml_data['can_be_analyzed'] = (False, "The package's files could not requested")
508+
506509

507510
except ValueError as e:
508511
# Service Unavailable
@@ -524,20 +527,9 @@ def notice_detail(request, checkin_id):
524527
xml_data['can_be_analyzed'] = (False, "XML's URI is invalid (%s)" % xml_data['uri'])
525528

526529
if xml_data['can_be_analyzed'][0]:
527-
try:
528-
xml_check = stylechecker.XML(xml_data['uri'])
529-
except lxml.etree.XMLSyntaxError as e:
530-
xml_data['annotations'] = e.message
531-
xml_data['validation_errors'] = extract_syntax_errors(e)
532-
except Exception as e: # any exception will stop the process
533-
xml_data['can_be_analyzed'] = (False, "Error while starting Stylechecker.XML()")
534-
logger.error('ValueError while creating: Stylechecker.XML(%s) for checkin.pk == %s. Traceback: %s' % (xml_data['file_name'], checkin.pk, e))
535-
else:
536-
status, errors = xml_check.validate_style()
537-
if not status: # have errors
538-
xml_check.annotate_errors()
539-
xml_data['annotations'] = str(xml_check)
540-
xml_data['validation_errors'] = extract_validation_errors(errors)
530+
analyzer = StyleCheckerAnalyzer(xml_data['uri'])
531+
analyzer_results = analyzer.analyze()
532+
xml_data.update(analyzer_results)
541533

542534
context['files'] = files_list
543535
context['xml_data'] = xml_data

scielomanager/scielomanager/static/css/style.css

+7-3
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ table._listings h4 {
249249
margin: 5px 0 5px 20px;
250250
}
251251

252-
.force-no-margin {
252+
.force-no-margin {
253253
margin:0 !important;
254254
}
255255

@@ -441,7 +441,7 @@ table._listings h4 {
441441
}
442442

443443
.log-item {
444-
border-left: 2px solid #DDDDDD;
444+
border-left: 2px solid #DDDDDD;
445445
padding-left: 5px;
446446
padding-top: 0;
447447
}
@@ -458,4 +458,8 @@ table._listings h4 {
458458
border-radius: 10px;
459459
padding: 0;
460460
margin: 0;
461-
}
461+
}
462+
463+
.longer-tab {
464+
width: 178px;
465+
}
Binary file not shown.

scielomanager/scielomanager/static/js/jquery.scrollTo.min.js

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
$(function () {
2+
3+
function blink_background($el){
4+
5+
/* adaptado de: http://stackoverflow.com/a/15681223/1503 */
6+
var x = 300;
7+
var originalColor = $el.css("background-color");
8+
var new_color = '#B3D4FC';
9+
var i = 3; //counter
10+
11+
(function loop() { //recurisve IIFE
12+
$el.css("background-color", new_color);
13+
setTimeout(function () {
14+
$el.css("background-color", originalColor);
15+
if (--i) setTimeout(loop, x); //restart loop
16+
}, x);
17+
}());
18+
19+
}
20+
21+
$("a.error_message").click(function(event){
22+
event.preventDefault();
23+
var code_block = $('#code-block');
24+
$('html, body').animate(
25+
{ scrollTop: code_block.offset().top },
26+
200
27+
);
28+
var search_term = $(this).data('search-term');
29+
var exact_search_term = "<!--SPS-ERROR: " + search_term + "-->";
30+
/* token is a span contains the SPS-ERROR message */
31+
var token = $('span.token.comment').filter("*:contains('" + exact_search_term + "')");
32+
/* scroll to token */
33+
code_block.scrollTo(
34+
token,
35+
300,
36+
{
37+
axis: 'y',
38+
offset: function() { return {top:-45, left:0}; },
39+
onAfter: function(){
40+
blink_background(token);
41+
}
42+
}
43+
)
44+
});
45+
46+
$("#back-to-errors").click(function(event){
47+
event.preventDefault();
48+
var table = $('#validation_errors_table')
49+
$('html, body').animate(
50+
{ scrollTop: table.offset().top - 100 },
51+
200
52+
);
53+
});
54+
55+
});

scielomanager/validator/templates/validator/includes/xml_annotated.html

+13-7
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ <h4><i class="icon-minus-sign"></i> {% trans "The XML could not be analyzed" %}<
3737
<h4 class="alert-heading"> {% trans "The XML have some errors" %}:</h4>
3838
</div>
3939
{% if xml_data.validation_errors %}
40-
<table class="table table-striped table-condensed">
40+
<table id="validation_errors_table" class="table table-striped table-condensed">
4141
<thead>
4242
<tr>
4343
<th>{% trans "Level" %}:</th>
@@ -50,20 +50,26 @@ <h4 class="alert-heading"> {% trans "The XML have some errors" %}:</h4>
5050
{% for error in xml_data.validation_errors.results %}
5151
<tr>
5252
<td><span class="label label-{% trans_status error.level to_label='True' %}">{{ error.level }}</span></td>
53-
<td>{{ error.line }}</td>
54-
<td>{{ error.column }}</td>
55-
<td>{{ error.message }}</td>
53+
<td>{{ error.line|default:"--" }}</td>
54+
<td>{{ error.column|default:"--" }}</td>
55+
<td><a class="error_message" href="#" data-search-term="{{ error.message }}">{{ error.message }}</a></td>
5656
</tr>
5757
{% endfor %}
5858
</tbody>
5959
</table>
6060
{% endif %}
61-
{# XML ANNOTATED #}
62-
<pre
61+
{# XML ANNOTATED #}
62+
<pre id="code-block"
6363
class="line-numbers language-markup pre-scrollable"
6464
{% if xml_data.validation_errors and xml_data.validation_errors.error_lines %}
6565
data-line='{{ xml_data.validation_errors.error_lines }}'
6666
{% endif %}
6767
><code class="language-markup">{{ xml_data.annotations }}</code></pre>
68+
69+
<p style="text-align: center">
70+
<a id="back-to-errors" href="#" class="btn btn-mini btn-primary">
71+
{% trans "Back to Errors" %}
72+
</a>
73+
</p>
6874
{% endif %}
69-
<script type="text/javascript" src="{% static 'js/prism.js' %}"></script>
75+
<script type="text/javascript" src="{% static 'js/prism.js' %}"></script>

scielomanager/validator/templates/validator/packtools.html

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
{% load i18n %}
44
{% load field_attrs %}
5+
{% load static %}
56

67
{% block main_content %}
78
<style type="text/css">
@@ -243,4 +244,7 @@ <h2>{% trans "SciELO Style Checker" %}</h2>
243244
});
244245
</script>
245246

247+
<script type="text/javascript" src="{% static 'js/jquery.scrollTo.min.js' %}"></script>
248+
<script type="text/javascript" src="{% static 'js/scroll_to_error_message.js' %}"></script>
249+
246250
{% endblock extrafooter %}

scielomanager/validator/tests/tests_pages.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,17 @@ def test_submit_valid_url_then_form_is_valid(self):
166166
self.assertEqual(response.status_code, 200)
167167
self.assertTrue(response.context['form'].is_valid())
168168
expected_results = {
169-
'validation_errors': None,
169+
'validation_errors': {
170+
'error_lines': '1',
171+
'results': [
172+
{
173+
'column': 6,
174+
'level': 'ERROR',
175+
'line': 1,
176+
'message': u'Premature end of data in tag xml line 1, line 1, column 6'
177+
}
178+
]
179+
},
170180
'annotations': None,
171181
'can_be_analyzed': (True, None)
172182
}

0 commit comments

Comments
 (0)