Display proper status indication after validation for each input line

parent 3a59c04e
......@@ -16,7 +16,7 @@ from tornado.web import RequestHandler, Application
from src.parser import Parser
from tests.parser import ParserWrapper
from src.validation import validate as validate_expression
from src.validation import validate as validate_expression, VALIDATE_SUCCESS
import sys
import traceback
......@@ -134,6 +134,8 @@ class Validate(RequestHandler):
break
status = []
# Validate each none empty line with the following none empty line.
for i in range(i + 1, len(lines)):
line = lines[i].strip()
......@@ -142,13 +144,16 @@ class Validate(RequestHandler):
skipped += 1
continue
if not validate_expression(last_line, line):
last_status = validate_expression(last_line, line)
status.append(last_status)
if not last_status:
i -= 1
break
last_line = line
self.write({'validated': i - skipped})
self.write({'validated': i - skipped, 'status': status})
except Exception as e:
i -= 1
self.write(format_exception(e) + {'validated': i - skipped})
......
......@@ -77,6 +77,10 @@ body {
background-image: url(/static/img/cross.png);
}
#math .box.no-progress {
background-image: url(/static/img/error.png);
}
#math .hint {
padding: 10px 15px 0 40px;
background: url(/static/img/info.png) no-repeat scroll 15px 13px transparent;
......
......@@ -260,18 +260,33 @@
var i = 0;
// Mark every line as correct (and remove previous class names).
for(; i < math_lines.length && i <= response.validated; i++)
$(math_lines[i]).removeClass('wrong').addClass('correct');
// Remove the status indicator from all remaining lines.
for(; i < math_lines.length; i++) {
$(math_lines[i])
.removeClass('correct')
.removeClass('wrong')
.removeClass('no-progress');
}
i = 0;
// Check if the first line has a correct syntax, since there is
// nothing to validate here.
if (i < math_lines.length && i <= response.validated) {
$(math_lines[i]).addClass('correct');
i++;
}
// Mark every line as {wrong,no-progress,correct,error}.
for (; i < math_lines.length && i <= response.validated; i++) {
status_classes = ['wrong', 'no-progress', 'correct', 'error'];
status_class = status_classes[response.status[i - 1]];
$(math_lines[i]).addClass(status_class);
}
if (i < math_lines.length) {
// Mark the current line as wrong.
$(math_lines[i]).removeClass('correct').addClass('wrong');
// Remove the status indicator from the remaining lines.
for(i += 1; i < math_lines.length; i++)
$(math_lines[i]).removeClass('correct')
.removeClass('wrong');
$(math_lines[i]).addClass('wrong');
}
hide_loader();
......
......@@ -13,8 +13,6 @@
# You should have received a copy of the GNU Affero General Public License
# along with TRS. If not, see <http://www.gnu.org/licenses/>.
from parser import Parser, MAXIMUM_REWRITE_STEPS
from possibilities import apply_suggestion
from strategy import find_possibilities
from tests.parser import ParserWrapper
......@@ -35,7 +33,7 @@ def validate(a, b):
b = parser.run([b])
if a.equals(b):
return VALIDATION_NOPROGRESS
return VALIDATE_NOPROGRESS
# Evaluate a and b, counting the number of steps
# Optimization: if b is encountered while evaluating a, return
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment