|
From: <tob...@us...> - 2014-05-14 17:09:04
|
Revision: 8319
http://sourceforge.net/p/bigdata/code/8319
Author: tobycraig
Date: 2014-05-14 17:09:02 +0000 (Wed, 14 May 2014)
Log Message:
-----------
Highlight errors in queries/updates
Modified Paths:
--------------
branches/NEW_WORKBENCH_1_3_2_BRANCH/bigdata-war/src/html/css/style.css
branches/NEW_WORKBENCH_1_3_2_BRANCH/bigdata-war/src/html/js/workbench.js
Modified: branches/NEW_WORKBENCH_1_3_2_BRANCH/bigdata-war/src/html/css/style.css
===================================================================
--- branches/NEW_WORKBENCH_1_3_2_BRANCH/bigdata-war/src/html/css/style.css 2014-05-14 17:01:37 UTC (rev 8318)
+++ branches/NEW_WORKBENCH_1_3_2_BRANCH/bigdata-war/src/html/css/style.css 2014-05-14 17:09:02 UTC (rev 8319)
@@ -280,6 +280,19 @@
font-family: monospace;
}
+/* make cursor visible in error highlighting */
+div.CodeMirror-cursors {
+ z-index: 3;
+}
+
+.error-line {
+ background: red;
+}
+
+.error-character {
+ background: green;
+}
+
#page-selector {
float: right;
}
Modified: branches/NEW_WORKBENCH_1_3_2_BRANCH/bigdata-war/src/html/js/workbench.js
===================================================================
--- branches/NEW_WORKBENCH_1_3_2_BRANCH/bigdata-war/src/html/js/workbench.js 2014-05-14 17:01:37 UTC (rev 8318)
+++ branches/NEW_WORKBENCH_1_3_2_BRANCH/bigdata-war/src/html/js/workbench.js 2014-05-14 17:09:02 UTC (rev 8319)
@@ -2,9 +2,15 @@
// global variables
var DEFAULT_NAMESPACE, NAMESPACE, NAMESPACE_URL, NAMESPACES_READY, NAMESPACE_SHORTCUTS, FILE_CONTENTS, QUERY_RESULTS;
-var QUERY_EDITOR, UPDATE_EDITOR;
+var CODEMIRROR_DEFAULTS, EDITORS = {}, ERROR_LINE_MARKERS = {}, ERROR_CHARACTER_MARKERS = {};
var PAGE_SIZE = 50, TOTAL_PAGES, CURRENT_PAGE;
+CODEMIRROR_DEFAULTS = {
+ lineNumbers: true,
+ mode: 'sparql',
+ extraKeys: {'Ctrl-,': moveTabLeft, 'Ctrl-.': moveTabRight}
+};
+
// debug to access closure variables
$('html, textarea, select').bind('keydown', 'ctrl+d', function() { debugger; });
@@ -49,10 +55,8 @@
if(!nohash && window.location.hash.substring(1).indexOf(tab) != 0) {
window.location.hash = tab;
}
- if(tab == 'query') {
- QUERY_EDITOR.refresh();
- } else if(tab == 'update') {
- UPDATE_EDITOR.refresh();
+ if(EDITORS[tab]) {
+ EDITORS[tab].refresh();
}
}
@@ -379,7 +383,7 @@
mode = rdf_modes[type];
}
}
- UPDATE_EDITOR.setOption('mode', mode);
+ EDITORS.update.setOption('mode', mode);
}
// .xml is used for both RDF and TriX, assume it's RDF
@@ -420,9 +424,14 @@
$('#update-update').click(submitUpdate);
-UPDATE_EDITOR = CodeMirror.fromTextArea($('#update-box')[0], {lineNumbers: true, mode: 'sparql',
- extraKeys: {'Ctrl-Enter': submitUpdate, 'Ctrl-,': moveTabLeft, 'Ctrl-.': moveTabRight}
+EDITORS.update = CodeMirror.fromTextArea($('#update-box')[0], CODEMIRROR_DEFAULTS);
+EDITORS.update.on('change', function() {
+ if(ERROR_LINE_MARKERS.update) {
+ ERROR_LINE_MARKERS.update.clear();
+ ERROR_CHARACTER_MARKERS.update.clear();
+ }
});
+EDITORS.update.addKeyMap({'Ctrl-Enter': submitUpdate});
function submitUpdate(e) {
// Updates are submitted as a regular form for SPARQL updates in monitor mode, and via AJAX for non-monitor SPARQL, RDF & file path updates.
@@ -437,7 +446,7 @@
var settings = {
type: 'POST',
- data: FILE_CONTENTS == null ? UPDATE_EDITOR.getValue() : FILE_CONTENTS,
+ data: FILE_CONTENTS == null ? EDITORS.update.getValue() : FILE_CONTENTS,
success: updateResponseXML,
error: updateResponseError
}
@@ -538,9 +547,14 @@
}
});
-QUERY_EDITOR = CodeMirror.fromTextArea($('#query-box')[0], {lineNumbers: true, mode: 'sparql',
- extraKeys: {'Ctrl-Enter': submitQuery, 'Ctrl-,': moveTabLeft, 'Ctrl-.': moveTabRight}
+EDITORS.query = CodeMirror.fromTextArea($('#query-box')[0], CODEMIRROR_DEFAULTS);
+EDITORS.query.on('change', function() {
+ if(ERROR_LINE_MARKERS.query) {
+ ERROR_LINE_MARKERS.query.clear();
+ ERROR_CHARACTER_MARKERS.query.clear();
+ }
});
+EDITORS.query.addKeyMap({'Ctrl-Enter': submitQuery});
function submitQuery(e) {
try {
@@ -548,8 +562,13 @@
} catch(e) {}
// transfer CodeMirror content to textarea
- QUERY_EDITOR.save();
+ EDITORS.query.save();
+ // do nothing if query is empty
+ if($('#query-box').val().trim() == '') {
+ return;
+ }
+
var settings = {
type: 'POST',
data: $('#query-form').serialize(),
@@ -811,21 +830,9 @@
if(match) {
// highlight character at error position
var line = match[1] - 1;
- var column = match[2] - 1;
- var input = $('#' + pane + '-box').val();
- var lines = input.split('\n');
- var container = '#' + pane + '-errors';
- $(container).html('');
- for(var i=0; i<line; i++) {
- var p = $('<p>').text(lines[i]);
- $(container).append(p);
- }
- $(container).append('<p class="error-line">');
- $(container + ' .error-line').append(document.createTextNode(lines[line].substr(0, column)));
- $(container + ' .error-line').append($('<span class="error-character">').text(lines[line].charAt(column) || ' '));
- $(container + ' .error-line').append(document.createTextNode(lines[line].substr(column + 1)));
- $(container).show();
- $('#' + pane + '-box').scrollTop(0);
+ var character = match[2] - 1;
+ ERROR_LINE_MARKERS[pane] = EDITORS.query.doc.markText({line: line, ch: 0}, {line: line}, {className: 'error-line'});
+ ERROR_CHARACTER_MARKERS[pane] = EDITORS.query.doc.markText({line: line, ch: character}, {line: line, ch: character + 1}, {className: 'error-character'});
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|