You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by ij...@apache.org on 2013/11/14 18:22:53 UTC
svn commit: r1541985 - in /jena/branches/jena-fuseki-new-ui/pages:
js/app/services/validation-service.js validation.html
Author: ijd
Date: Thu Nov 14 17:22:53 2013
New Revision: 1541985
URL: http://svn.apache.org/r1541985
Log:
Update to use new JSON API for validation
Modified:
jena/branches/jena-fuseki-new-ui/pages/js/app/services/validation-service.js
jena/branches/jena-fuseki-new-ui/pages/validation.html
Modified: jena/branches/jena-fuseki-new-ui/pages/js/app/services/validation-service.js
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/pages/js/app/services/validation-service.js?rev=1541985&r1=1541984&r2=1541985&view=diff
==============================================================================
--- jena/branches/jena-fuseki-new-ui/pages/js/app/services/validation-service.js (original)
+++ jena/branches/jena-fuseki-new-ui/pages/js/app/services/validation-service.js Thu Nov 14 17:22:53 2013
@@ -1,5 +1,6 @@
-define( ['underscore', 'jquery', 'fui', 'codemirror/codemirror'],
- function( _, $, fui ) {
+define( ['underscore', 'jquery', 'fui',
+ 'codemirror/codemirror', 'codemirror/javascript', 'codemirror/sparql'],
+ function( _, $, fui, CodeMirror ) {
var ValidationService = function( editor_el, output_el ) {
this.editor_el = editor_el;
@@ -8,8 +9,8 @@ define( ['underscore', 'jquery', 'fui',
_.extend( ValidationService.prototype, {
init: function() {
+ _.bindAll( this, "handleValidationOutput", "handleJsonValidationOutput" );
this.editorElement();
- this.outputElement();
},
/** Return the DOM node representing the query editor */
@@ -24,15 +25,17 @@ define( ['underscore', 'jquery', 'fui',
},
/** Return the DOM node representing the output editor */
- outputElement: function() {
- if (!this._output) {
- this._output = new CodeMirror( $(this.output_el).get(0), {
- lineNumbers: true,
- mode: "text",
- readOnly: true
- } );
- }
- return this._output;
+ outputElement: function( mode, lineNumbers, data ) {
+ $(this.output_el).empty();
+
+ var cm = new CodeMirror( $(this.output_el).get(0), {
+ lineNumbers: lineNumbers,
+ mode: mode || "text",
+ readOnly: true,
+ value: data
+ } );
+
+ return cm;
},
/** Return the current code editor contents */
@@ -42,7 +45,9 @@ define( ['underscore', 'jquery', 'fui',
/** Perform the given action to validate the current content */
performValidation: function( optionsModel ) {
+ var context = {optionsModel: optionsModel};
var self = this;
+
var content = {};
content[optionsModel.payloadParam()] = this.editorContent();
@@ -52,9 +57,37 @@ define( ['underscore', 'jquery', 'fui',
};
$.ajax( optionsModel.validationURL(), options )
- .done( function( data ) {
- self.outputElement().setValue( data );
+ .done( function( data, status, xhr ) {
+ self.handleValidationOutput( data, status, xhr, context );
} );
+ },
+
+ /** Respond to validation output from the server */
+ handleValidationOutput: function( data, status, xhr, context ) {
+ var ct = xhr.getResponseHeader("content-type") || "";
+ if (ct.match( /json/ )) {
+ this.handleJsonValidationOutput( data, context );
+ }
+ else {
+ // in HTML output, we look for a .error div
+ var errors = $(data).find( "div.error" ).text();
+ this.outputElement( "text", true, errors || "No warnings or errors reported." );
+ }
+ },
+
+ handleJsonValidationOutput: function( json, context ) {
+ var outputFormat = context.optionsModel.outputFormat();
+ console.log( "output format = " + outputFormat );
+ var jsonString = null;
+
+ if (outputFormat && json[outputFormat]) {
+ jsonString = json[outputFormat];
+ }
+ else {
+ jsonString = JSON.stringify( json, null, ' ' );
+ }
+
+ this.outputElement( "application/json", false, jsonString );
}
} );
Modified: jena/branches/jena-fuseki-new-ui/pages/validation.html
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/pages/validation.html?rev=1541985&r1=1541984&r2=1541985&view=diff
==============================================================================
--- jena/branches/jena-fuseki-new-ui/pages/validation.html (original)
+++ jena/branches/jena-fuseki-new-ui/pages/validation.html Thu Nov 14 17:22:53 2013
@@ -84,11 +84,11 @@
<div class="output-format-options options-list">
<h2>Output format:</h2>
<ul class="list-inline">
- <li><a class="btn btn-custom2 btn-sm" data-toggle="button" data-output-format="sparql">SPARQL</a></li>
+ <li><a class="btn btn-custom2 btn-sm" data-toggle="button" data-output-format="formatted">SPARQL</a></li>
<li><a class="btn btn-custom2 btn-sm active" data-toggle="button" data-output-format="algebra">SPARQL algebra</a></li>
- <li><a class="btn btn-custom2 btn-sm" data-toggle="button" data-output-format="quads">SPARQL algebra (quads)</a></li>
- <li><a class="btn btn-custom2 btn-sm" data-toggle="button" data-output-format="opt">SPARQL algebra (with optimizations)</a></li>
- <li><a class="btn btn-custom2 btn-sm" data-toggle="button" data-output-format="optquads">SPARQL algebra (quads, with optimizations)</a></li>
+ <li><a class="btn btn-custom2 btn-sm" data-toggle="button" data-output-format="algebra-quads">SPARQL algebra (quads)</a></li>
+ <li><a class="btn btn-custom2 btn-sm" data-toggle="button" data-output-format="algebra-opt">SPARQL algebra (with optimizations)</a></li>
+ <li><a class="btn btn-custom2 btn-sm" data-toggle="button" data-output-format="algebra-opt-quads">SPARQL algebra (quads, with optimizations)</a></li>
</ul>
</div><!-- /.output-format-options -->