swish/commit

New upstream files

authorJan Wielemaker
Wed Mar 11 09:52:26 2015 +0100
committerJan Wielemaker
Wed Mar 11 09:52:26 2015 +0100
commit2b4cb0dd4a8d382292737c9230c1c17daae0ea50
treea78aca2e9903610255670c59ce1c0b5c285234bd
parent055ac132011427213d5045ee523e07db882f3d92
Diff style: patch stat
diff --git a/lib/swish/csv.pl b/lib/swish/csv.pl
index 88b484b..b591118 100644
--- a/lib/swish/csv.pl
+++ b/lib/swish/csv.pl
@@ -80,6 +80,7 @@ success(Answers, VarTerm) :-
 	write_answers(Answers, VarTerm), !.
 success(Answers, VarTerm) :-
 	maplist(csv_answer, Answers, Rows),
+	format('Content-disposition: attachment; filename="swish-result.csv"~n'),
 	format('Content-type: text/csv~n~n'),
 	csv_write_stream(current_output, [VarTerm|Rows], []).
 
diff --git a/lib/swish/gitty.pl b/lib/swish/gitty.pl
index 442f6dc..8c2cc78 100644
--- a/lib/swish/gitty.pl
+++ b/lib/swish/gitty.pl
@@ -352,6 +352,7 @@ gitty_scan_sync(Store) :-
 %	named entry.
 
 gitty_scan_latest(Store) :-
+	retractall(head(Store, _, _)),
 	retractall(latest(_, _, _)),
 	(   gitty_hash(Store, Hash),
 	    load_object(Store, Hash, Data, commit, _Size),
diff --git a/lib/swish/include.pl b/lib/swish/include.pl
index 31244c6..0d826e0 100644
--- a/lib/swish/include.pl
+++ b/lib/swish/include.pl
@@ -51,6 +51,7 @@ shared gitty store. It realises this using the following steps:
 swish:term_expansion(:- include(File),
 		     :- include(stream(Id, Stream, [close(true)]))) :-
 	setting(web_storage:directory, Store),
+	atomic(File),
 	add_extension(File, FileExt),
 	catch(gitty_data(Store, FileExt, Data, _Meta), _, fail),
 	atom_concat('swish://', FileExt, Id),
diff --git a/lib/swish/render.pl b/lib/swish/render.pl
index ee80729..498bd86 100644
--- a/lib/swish/render.pl
+++ b/lib/swish/render.pl
@@ -177,7 +177,10 @@ alt_renderer(Specialised, Term, Options) -->
 		 \specialised(Specialised, Term, Options))).
 
 specialised([], Term, Options) -->
-	html(span('data-render'('Prolog term'), \term(Term, Options))).
+	html(span([ class('render-as-prolog'),
+		    'data-render'('Prolog term')
+		  ],
+		  \term(Term, Options))).
 specialised([H|T], Term, Options) -->
 	tokens(H),
 	specialised(T, Term, Options).
diff --git a/web/help/background.html b/web/help/background.html
index ec754ac..67c3dbb 100644
--- a/web/help/background.html
+++ b/web/help/background.html
@@ -5,71 +5,104 @@
   <title>SWISH: SWI-Prolog for SHaring</title>
   </head>
 <body>
-<h4>Table of Contents</h4>
+<h2>Table of Contents</h2>
   <ul>
     <li><a href="#motivation">Motivation</a></li>
-    <li><a href="#exampls">Examples</a></li>
-    <li><a href="#time_limit">Time limit</a></li>
     <li><a href="#browsers">Supported browsers</a></li>
     <li><a href="#swishapp">Adding SWISH to your application</a></li>
     <li><a href="#technology">Technology</a></li>
     <li><a href="#source_code">Source code</a></li>
   </ul>
 
-<h4 id="motivation">Motivation</h4>
-                <p>
-                    <span style="color:darkblue">SWI</span><span style="color:maroon">SH</span> is inspired by web-based tools such as <a target="_blank" href="http://jsfiddle.net/">JSFIDDLE</a> in that it allows you to develop a program and then share it with others on the Web. However, lacking both debugger and profiler, <span style="color:darkblue">SWI</span><span style="color:maroon">SH</span> is far from a full-fledged IDE for Prolog, and to avoid compromising the server it does not allow you to execute "dangerous" predicates such as predicates reading and writing files.  It does however allow you to use predicates such as <code>read/1</code> and <code>write/1</code> but they will only read from and write to your web browser.
-                </p>
-                <p>
-We intend to make <span style="color:darkblue">SWI</span><span style="color:maroon">SH</span>
-useful in an educational setting.  For example, if you are a teacher, you may want to tell
-your students to share with you the solutions to exercises by sending you a link to
-<span style="color:darkblue">SWI</span><span style="color:maroon">SH</span> loaded
-with their solutions ready to run.  There is still work to do before this is a good
-alternative to a local installation though.
-                </p>
-                <h4 id="time_limit">Time limit</h4>
-                <p>
-                    When you click the First button, your goal will be allowed to execute on the server for 300 seconds before aborting and returning with a message stating that the time limit has been exceeded.
-                </p>
-                <h4 id="browsers">Supported browsers</h4>
-                <p>
-<span style="color:darkblue">SWI</span><span style="color:maroon">SH</span> works fine
-recent versions of in Safari, Firefox, Chrome and Internet Explorer (tested IE 11).
-                <p>
-                <h4 id="swishapp">Adding SWISH to your application</h4>
-		<p>
-<span style="color:darkblue">SWI</span><span style="color:maroon">SH</span> can be added easily to any
-SWI-Prolog web application.  For example, it is available as an extension pack for
-<a target="_blank" href="http://cliopatria.swi-prolog.org/">ClioPatria</a>, the SWI-Prolog RDF
-framework.  It can be added to ClioPatria using the command below, providing an alternative
-for SPARQL for exploring the database (requires SWI-Prolog 7.1.23 or later).
-		</p>
-                <pre style="font-size:80%">
-?- pack_install(swish).</pre>
-                <h4 id="technology">Technology</h4>
-                <p>
-                    <span style="color:darkblue">SWI</span><span style="color:maroon">SH</span>
-is implemented as a set of <a target="_blank" href="http://jquery.com/">jQuery</a> plugins,
-using <a target="_blank" href="http://getbootstrap.com/">Bootstrap</a> for menus, modal windows
-and various styling aspects and <a target="_blank" href="http://codemirror.net/">CodeMirror</a>
-for editing the Prolog source and query.  Queries are executed by sending both the source text
-(left editor) and query (bottom-right editor) to the server, which creates a <a target="_blank"
-href="http://www.swi-prolog.org/pldoc/man?section=pengines">Pengine</a> (<i>Prolog Engine</i>)
-to execute the query.
-		</p>
-		<p>
-Pengines have many other applications, such as supporting Prolog RPC (<i>Remote Procedure
-Calls</i>, which allows you to execute a query fully transparent, including backtracking,
-on a remote server.  An interesting aspect is that they provide a generic query language
-on top of an arbitrary Prolog program that can be used from JavaScript.  A
-<a target="_blank" href="http://pengines.swi-prolog.org/">demo is available</a>
-                </p>
-
-                <h4 id="source_code">Source code</h4>
-                <p>
-                    The source code for <span style="color:darkblue">SWI</span><span style="color:maroon">SH</span> is available on <a target="_blank" href="https://github.com/SWI-Prolog/swish">GitHub</a>.
-                </p>
+<h2 id="motivation">Motivation</h2>
+<p>
+<span style="color:darkblue">SWI</span><span
+style="color:maroon">SH</span> is inspired by web-based tools such as <a
+target="_blank" href="http://jsfiddle.net/">JSFIDDLE</a> in that it
+allows you to develop a program and then share it with others on the
+Web. Besides sharing basic Prolog code fragments, we see several
+opportunities for deploying <span style="color:darkblue">SWI</span><span
+style="color:maroon">SH</span>:
+
+  <ul>
+  <li>
+<span style="color:darkblue">SWI</span><span
+style="color:maroon">SH</span> can be <b>associated with a dataset</b>,
+either in pure Prolog, RDF (<a target="_blank"
+href="http://cliopatria.swi-prolog.org/">ClioPatria</a>) or a
+traditional relational database through ODBC and <a target="_blank"
+href="http://www.swi-prolog.org/pldoc/man?section=cql">CQL</a>. In this
+setting it can facilitate collaboratively management of increasingly
+complex queries against this dataset. Query results can be downloaded as
+CSV and queries can be executed through an HTTP API. See the
+<b>File/Help ...</b> for details.
+
+  <li>
+<span style="color:darkblue">SWI</span><span
+style="color:maroon">SH</span> can be embedded in Prolog <b>course
+material</b>. See <a target="_blank" href="http://lpn.swi-prolog.org">Learn
+Prolog Now!</a> for a prototype. The menu <b>File/Help ...</b> explains
+how <span style="color:darkblue">SWI</span><span
+style="color:maroon">SH</span> can be preloaded with source and example
+queries.
+
+  <li>
+<span style="color:darkblue">SWI</span><span
+style="color:maroon">SH</span> can be used as a shared <b>management and
+development</b> interface for web services.  The <a target="_blank"
+href="http://cliopatria.swi-prolog.org/">ClioPatria</a> version allows
+for executing arbitrary management commands through the web interface,
+provided the user is logged in with <em>administrative</em> rights.
+  </ul>
+
+<h2 id="browsers">Supported browsers</h2>
+<p>
+<span style="color:darkblue">SWI</span><span
+style="color:maroon">SH</span> works fine recent versions of in Safari,
+Firefox, Chrome and Internet Explorer (tested IE 11).
+
+<h2 id="swishapp">Adding SWISH to your application</h2>
+<p>
+<span style="color:darkblue">SWI</span><span
+style="color:maroon">SH</span> can be added easily to any SWI-Prolog web
+application. For example, it is available as an extension pack for <a
+target="_blank" href="http://cliopatria.swi-prolog.org/">ClioPatria</a>,
+the SWI-Prolog RDF framework. It can be added to ClioPatria using the
+command below, providing an alternative for SPARQL for exploring the
+database (requires SWI-Prolog 7.1.32 or later).
+
+<pre style="font-size:80%">
+?- cpack_install(swish).</pre>
+<h2 id="technology">Technology</h2>
+
+<p>
+<span style="color:darkblue">SWI</span><span
+style="color:maroon">SH</span> is implemented as a set of <a
+target="_blank" href="http://jquery.com/">jQuery</a> plugins, using <a
+target="_blank" href="http://getbootstrap.com/">Bootstrap</a> for menus,
+modal windows and various styling aspects. <span
+style="color:darkblue">SWI</span><span style="color:maroon">SH</span>
+uses <a target="_blank" href="http://codemirror.net/">CodeMirror</a> for
+editing the Prolog source and query. Queries are executed by sending
+both the source text (left editor) and query (bottom-right editor) to
+the server, which creates a <a target="_blank"
+href="http://www.swi-prolog.org/pldoc/man?section=pengines">Pengine</a>
+(<i>Prolog Engine</i>) to execute the query.
+
+<p>
+Pengines have many other applications, such as supporting Prolog RPC
+(<i>Remote Procedure Calls</i>, which allows you to execute a query
+fully transparent, including backtracking, on a remote server. An
+interesting aspect is that they provide a generic query language on top
+of an arbitrary Prolog program that can be used from JavaScript. A <a
+target="_blank" href="http://pengines.swi-prolog.org/">demo is
+available</a>
+
+<h2 id="source_code">Source code</h2>
+<p>
+The source code for <span style="color:darkblue">SWI</span><span
+style="color:maroon">SH</span> is available on <a target="_blank"
+href="https://github.com/SWI-Prolog/swish">GitHub</a>.
 </body>
 </html>
 
diff --git a/web/help/beware.html b/web/help/beware.html
index 0d6fa90..7a17a4e 100644
--- a/web/help/beware.html
+++ b/web/help/beware.html
@@ -23,7 +23,7 @@
 </head>
 <body>
 <p>
-<a href="http://www.swi-prolog.org">SWI-Prolog</a> is a Prolog
+<a target="_blank" href="http://www.swi-prolog.org">SWI-Prolog</a> is a Prolog
 implementation that specifically aims at <b>large and real-world
 applications</b>.
 
@@ -35,11 +35,11 @@ This is not what you will experience!
 SWI-Prolog provides rich libraries for web programming, RDF handling,
 database access, networking, etc. We can not expose the full system in
 the web version for various reasons, security being the most important.
-If you want to <strong>work on a real application</strong>, <a
+If you want to <strong>work on a real application</strong>, <a target="_blank"
 href="http://www.swi-prolog.org/Download.html">download</a> your own
 copy of SWI-Prolog.
 
-<h4>So, why then this online version?</h4>
+<h2>So, why then this online version?</h2>
 
 <p>
 Well, the online version can offer things that a local copy can not.
@@ -59,7 +59,7 @@ Here are some examples.
 </ul>
 
 
-<h4>The future of the online version</h4>
+<h2>The future of the online version</h2>
 
 <p>
 The current online version is an early <em>prototype</em>. We have
@@ -67,12 +67,15 @@ several plans with it. If you are not impressed, please visit this page
 again in a couple of months. These are the main plans:
 
 <ul>
-  <li>More structured (versioned) saving of sources.  Provide authenticated
-      users to add example code that can be found by others.
-  <li>Enhanced editing mode with smart autocompletion, insert of code templates, etc.
+  <li>Better shared source management.  Show dependencies, better
+      search for source code, (dis)like code fragments, integrate
+      source management with the examples menu, etc.
+  <li>Enhanced editing mode with smart autocompletion, insert of code
+      templates, etc.
   <li>Provide more rendering plugins, such as graphs and charts.
   <li>Make the debugger available through the web interface.
-  <li>Integrate the web interface in online tutorials.
+  <li>Further enhance embedding in course material such as <a target="_blank"
+      href="http://lpn.swi-prolog.org">Learn Prolog Now!</a>
 </ul>
 
 <p>
diff --git a/web/help/caveats.html b/web/help/caveats.html
index 11f9bbe..8b07163 100644
--- a/web/help/caveats.html
+++ b/web/help/caveats.html
@@ -5,13 +5,13 @@
   <title>Caveats of the web version of SWI-Prolog</title>
   </head>
   <body>
-<h4>Table of Contents</h4>
+<h2>Table of Contents</h2>
                 <ul>
                     <li><a href="#sandboxing">Sandboxing</a></li>
                     <li><a href="#io">Input and output</a></li>
 		</ul>
 
-<h4 id="sandboxing">Sandboxing</h4>
+<h2 id="sandboxing">Sandboxing</h2>
 <p>
 SWISH cannot provide unrestricted access to Prolog because Prolog gives
 unrestricted access to the operating system.  Therefore, SWISH examines
@@ -37,7 +37,7 @@ Note that the whitelist is incomplete, i.e., there are many
 predicates that can be considered safe that are not on the list.
 Please report such omissions as bugs.
 </p>
-		<h4 id="io">Input and output</h4>
+		<h2 id="io">Input and output</h2>
 <p>
 Normal read and write do not work in the web environment.  A number
 of normal Prolog predicates are redefined to provide basic I/O.  Other
diff --git a/web/help/help.html b/web/help/help.html
index 784fb8f..ecee09e 100644
--- a/web/help/help.html
+++ b/web/help/help.html
@@ -11,10 +11,11 @@
     <li><a href="#help-examples">Embedding examples in the program text</a></li>
     <li><a href="#help-share">Save or share your program</a></li>
     <li><a href="#help-include">Include other programs</a></li>
+    <li><a href="#help-csv">Download query results as CVS</a></li>
     <li><a href="#help-preload">Preload SWISH with data</a></li>
   </ul>
 
-<h4 id="help-basics">Basic operation</h4>
+<h2 id="help-basics">Basic operation</h2>
 <p>
 Prolog is about running a <i>query</i> against a <i>program</i>. The
 <i>query</i> goes into the bottom-right editor and the <i>program</i>
@@ -53,7 +54,7 @@ edit the program and use the <b>Run!</b> again.  The new query is
 executed in a completely new environment.  In particular, data that
 you asserted in a previous query is not available in the next.
 
-<h4 id="help-examples">Embedding examples in the program text</h4>
+<h2 id="help-examples">Embedding examples in the program text</h2>
 <p>
 If you include example goals inside comments as shown below,
 they will be used to populate the example menu and make the
@@ -67,7 +68,7 @@ first goal show in the Goal input field.
 
 */</pre>
 
-<h4 id="help-share">Save or share your program</h4>
+<h2 id="help-share">Save or share your program</h2>
 <p>
 The menu <b>File/Save ...</b> can be used to save your program.  There
 are several options:
@@ -90,7 +91,7 @@ are several options:
 The <b>Info &amp; History ...</b> menu can be used to examine and use
 old versions of the program.
 
-<h4 id="help-include">Include other programs</h4>
+<h2 id="help-include">Include other programs</h2>
 <p>
 If you know the name of a saved program (see above), you can reuse this
 program using Prolog's <b>include/1</b> predicate as illustrated below.
@@ -114,7 +115,63 @@ Using <b>File/Collaborate ...</b>, you create a
 <a target="_blank" href="https://togetherjs.com/">TogetherJS</a> session
 that provides shared editing, chat and voice communication.
 
-<h4 id="help-preload">Preload SWISH with data</h4>
+<h2 id="help-csv">Download query results as CSV</h2>
+<p>
+After running a query, the <strong>complete</strong> result set for the
+query can be downloaded as a CSV (Comma Separated Values) document by
+clicking the double down arrow at the <em>runner</em> window. This
+causes a dialogue to appear that allows for specifying the columns,
+optionally the detailed result format (if the server provides multiple
+result formats), whether only <em>distinct</em> results should be
+returned and the maximum number of results to return. The latter is by
+default set to 10&nbsp;000 to avoid sending huge documents by accident.
+The field can be cleared to return all results.
+
+<h3>Download query results through an API</h3>
+<p>
+The CSV results can also be downloaded programmatically by directly
+approaching the Pengine API. Example client code is <a
+href="https://github.com/SWI-Prolog/swish/tree/master/client"
+target="_blank">available</a>.  For example, the `swish-ask.sh` client
+can be used with `bash` to download the results for a query.  The call
+below downloads a CSV file for the <em>sin</em> function.
+
+<pre style="font-size:80%">
+$ bash swish.ask.sh --server=http://swish.swi-prolog.org \
+		    X,Y \
+		    "between(0,90,X),Y is sin(X*pi/180)"
+</pre>
+
+<p>
+The script can ask queries against stored Prolog scripts by specifying
+the script on the commandline.  For example:
+
+<pre style="font-size:80%">
+$ bash swish.ask.sh --server=http://swish.swi-prolog.org \
+		    sin_table.pl X,Y "sin_table(X,Y)"
+</pre>
+
+<p>
+Prolog can exploit the Pengine API directly.  For example, the above can
+be called as:
+
+<pre style="font-size:80%">
+?- [library(pengines)].
+?- pengine_rpc('http://swish.swi-prolog.org',
+	       sin_table(X,Y),
+	       [ src_text(':- include(sin_table).'),
+		 application(swish)
+	       ]).
+X = 0,
+Y = 0.0 ;
+X = 1,
+Y = 0.01745240643728351 ;
+X = 2
+...
+</pre>
+
+
+<h2 id="help-preload">Preload SWISH with data</h2>
 <p>
 You can make <span style="color:darkblue">SWI</span><span style="color:maroon">SH</span>
 start with a loaded program using the URL <code>http://swish.swi-prolog.org/</code> and
@@ -144,11 +201,3 @@ http://swish.swi-prolog.org/?code=https://github.com/SWI-Prolog/swipl-devel/raw/
 
 </body>
 </html>
-
-
-
-
-
-
-
-
diff --git a/web/help/runner.html b/web/help/runner.html
index d830504..3afe1dd 100644
--- a/web/help/runner.html
+++ b/web/help/runner.html
@@ -29,7 +29,7 @@ table.runner-states tr.group th {
 }
 </style>
 
-<h4>Keyboard shortcuts</h4>
+<h2>Keyboard shortcuts</h2>
 
   <table class="runner-states">
   <tr><th>";", &lt;space&gt;</th><td>Next</td>
@@ -39,7 +39,7 @@ table.runner-states tr.group th {
   <tr><th>&lt;F1&gt;</th><td>Help (this page)</td>
   </table>
 
-<h4>Running states</h4>
+<h2>Running states</h2>
 
   <table class="runner-states">
   <tr class="group"><th colspan="2">Living states</th>
@@ -77,7 +77,17 @@ table.runner-states tr.group th {
 
 <hr>
 <p>
-Note that at maximum, three queries can be open at the same time.
+Note that at maximum, <b>three queries can be open at the same time</b>.
+If the limit is exceeded you must first stop some queries, either by
+clicking the <b>Stop</b> button, closing the query window or using the
+menu at the top-right of the query window do stop or clear all open
+queries.
+
+<h2>Get results as CSV or through an API</h2>
+<p>
+Variable bindings can be downloaded as CSV using the double down arrow
+at the top-right of a runner or using an appropriate client library to
+access the web API. See the <b>Help/help ...</b> for details.
 
 </body>
 </html>