|
From: <tob...@us...> - 2014-02-13 23:42:18
|
Revision: 7847
http://bigdata.svn.sourceforge.net/bigdata/?rev=7847&view=rev
Author: tobycraig
Date: 2014-02-13 23:42:11 +0000 (Thu, 13 Feb 2014)
Log Message:
-----------
SPARQL updates, RDF and file paths can all be sent to the server and added to the database.
Modified Paths:
--------------
branches/RDR/bigdata-war/src/html/index.html
branches/RDR/bigdata-war/src/html/workbench.js
Modified: branches/RDR/bigdata-war/src/html/index.html
===================================================================
--- branches/RDR/bigdata-war/src/html/index.html 2014-02-12 00:58:18 UTC (rev 7846)
+++ branches/RDR/bigdata-war/src/html/index.html 2014-02-13 23:42:11 UTC (rev 7847)
@@ -145,10 +145,12 @@
-->
<h2>Multi-purpose textarea</h2>
-<form method="post" id="mp-form" enctype="multipart/form-data">
<input id="mp-file" type="file" name="file">
+<br>
<input id="mp-hidden" type="hidden" name="large-file-contents">
-<textarea id="mp-box" name="textarea"></textarea>
+<p id="large-file-message" style="display: none;">Your file is too large to display here, but will be uploaded as normal.</p>
+<textarea id="mp-box" name="textarea" rows="10" cols="80"></textarea>
+<br>
<select id="mp-type">
<option value="sparql" selected="selected">SPARQL</option>
<option value="rdf">RDF</option>
@@ -164,8 +166,13 @@
<option value="trix">TriX</option>
<option value="turtle">Turtle</option>
</select>
-<input type="submit">
-</form>
+<br>
+Tenant Namespace <input type="text" name="namespace" title="Tenant namespace."> (leave empty for default KB)
+<br>
+<button type="button" id="mp-send">Send</button>
+<br>
+Response:
+<pre id="response"></pre>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="/jquery.min.js"><\/script>')</script>
Modified: branches/RDR/bigdata-war/src/html/workbench.js
===================================================================
--- branches/RDR/bigdata-war/src/html/workbench.js 2014-02-12 00:58:18 UTC (rev 7846)
+++ branches/RDR/bigdata-war/src/html/workbench.js 2014-02-13 23:42:11 UTC (rev 7847)
@@ -27,18 +27,20 @@
$('#mp-box').val('/path/to/' + f.name);
setType('path');
$('#mp-file').val('');
+ $('#large-file-message').hide();
return;
}
// if file is small enough, populate the textarea with it
- var holder;
if(f.size < 10 * 1024) {
holder = '#mp-box';
$('#mp-hidden').val('');
+ $('#large-file-message').hide();
} else {
// store file contents in hidden input and clear textarea
holder = '#mp-hidden';
$('#mp-box').val('');
+ $('#large-file-message').show();
}
var fr = new FileReader();
fr.onload = function(e2) {
@@ -59,24 +61,36 @@
setType('rdf', rdf_types[extension]);
} else {
// extension is no help, see if we can find some SPARQL commands
- content = content.toUpperCase();
- for(var i=0, found=false; i<sparql_update_commands.length; i++) {
- if(content.indexOf(sparql_update_commands[i]) != -1) {
- setType('sparql');
- found = true;
- break;
- }
+ setType(identify(content));
+ }
+}
+
+function identify(text, considerPath) {
+ text = text.toUpperCase();
+
+ if(considerPath) {
+ // match Unix or Windows paths
+ var re = /^(((\/[^\/]+)+)|([A-Z]:([\\\/][^\\\/]+)+))$/;
+ if(re.test(text.trim())) {
+ return 'path';
}
- if(!found) {
- setType('rdf', '');
+ }
+
+ for(var i=0; i<sparql_update_commands.length; i++) {
+ if(text.indexOf(sparql_update_commands[i]) != -1) {
+ return 'sparql';
}
}
+
+ return 'rdf';
}
-function handlePaste(e) {
- alert('pasted!');
- e.stopPropagation();
- e.preventDefault();
+function handlePaste(e) {
+ // if the input is currently empty, try to identify the pasted content
+ var that = this;
+ if(this.value == '') {
+ setTimeout(function() { setType(identify(that.value, true)); }, 10);
+ }
}
function handleTypeChange(e) {
@@ -106,8 +120,18 @@
'trix': 'trix',
//'xml': 'trix',
'ttl': 'turtle'};
+
+var rdf_content_types = {'n-quads': 'application/n-quads',
+ 'n-triples': 'text/plain',
+ 'n3': 'text/n3',
+ 'rdf/xml': 'application/rdf+xml',
+ 'trig': 'application/trig',
+ 'trix': 'application/trix',
+ 'turtle': 'text/turtle'};
var sparql_update_commands = ['INSERT', 'DELETE'];
+// stores the id of the element that contains the data to be sent
+var holder = '#mp-box';
$('#mp-file').change(handleFile);
$('#mp-box').on('dragover', handleDragOver);
@@ -115,7 +139,45 @@
$('#mp-box').on('paste', handlePaste);
$('#mp-type').change(handleTypeChange);
-$('#mp-form').submit(function() {
+$('#mp-send').click(function() {
// determine action based on type
-
+ var settings = {
+ type: 'POST',
+ data: $(holder).val(),
+ success: updateResponseXML,
+ error: updateResponseError
+ }
+ switch($('#mp-type').val()) {
+ case 'sparql':
+ settings.data = 'update=' + encodeURI(settings.data);
+ settings.success = updateResponseHTML;
+ break;
+ case 'rdf':
+ var type = $('#rdf-type').val();
+ if(!type) {
+ alert('Please select an RDF content type.');
+ return;
+ }
+ settings.contentType = rdf_content_types[type];
+ break;
+ case 'path':
+ settings.data = 'uri=file://' + encodeURI(settings.data);
+ break;
+ }
+
+ $.ajax('/sparql', settings);
});
+
+function updateResponseHTML(data, textStatus, jqXHR) {
+ $('#response').html(data);
+}
+
+function updateResponseXML(data, textStatus, jqXHR) {
+ var modified = data.childNodes[0].attributes['modified'].value;
+ var milliseconds = data.childNodes[0].attributes['milliseconds'].value;
+ $('#response').text('Modified: ' + modified + '\nMilliseconds: ' + milliseconds);
+}
+
+function updateResponseError(jqXHR, textStatus, errorThrown) {
+ $('#response').text('Error! ' + textStatus + ' ' + errorThrown);
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|