From: Tara L Andrews Date: Mon, 10 Jun 2013 10:30:49 +0000 (+0200) Subject: add download button for viewable traditions; fixes #8 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=38627d20c7f0a0f82ec820b716842d69e905d643;p=scpubgit%2Fstemmaweb.git add download button for viewable traditions; fixes #8 --- diff --git a/lib/stemmaweb/Controller/Root.pm b/lib/stemmaweb/Controller/Root.pm index 59fa097..30cc644 100644 --- a/lib/stemmaweb/Controller/Root.pm +++ b/lib/stemmaweb/Controller/Root.pm @@ -433,6 +433,30 @@ sub stemmadot :Local :Args(2) { $c->forward('View::JSON'); } +=head2 download + + GET /download/$textid + +Returns the full XML definition of the tradition and its stemmata, if any. + +=cut + +sub download :Local :Args(1) { + my( $self, $c, $textid ) = @_; + my $tradition = $c->model('Directory')->tradition( $textid ); + unless( $tradition ) { + return _json_error( $c, 404, "No tradition with ID $textid" ); + } + my $ok = _check_permission( $c, $tradition ); + return unless $ok; + try { + $c->stash->{'result'} = $tradition->collation->as_graphml(); + } catch( Text::Tradition::Error $e ) { + return _json_error( $c, 500, $e->message ); + } + $c->forward('View::GraphML'); +} + #################### ### Helper functions #################### diff --git a/lib/stemmaweb/View/GraphML.pm b/lib/stemmaweb/View/GraphML.pm new file mode 100644 index 0000000..3560dfc --- /dev/null +++ b/lib/stemmaweb/View/GraphML.pm @@ -0,0 +1,13 @@ +package stemmaweb::View::GraphML; + +use strict; +use base 'Catalyst::View'; + +sub process { + my( $self, $c ) = @_; + $c->res->content_type( 'application/graphml+xml' ); + $c->res->content_encoding( 'UTF-8' ); + $c->res->output( $c->stash->{result} ); +} + +1; \ No newline at end of file diff --git a/root/js/componentload.js b/root/js/componentload.js index ba8e48d..da3ad7f 100644 --- a/root/js/componentload.js +++ b/root/js/componentload.js @@ -75,6 +75,9 @@ function loadTradition( textid, textname, editable ) { load_stemma( selectedStemmaID ); // Set up the relationship mapper button $('#run_relater').attr( 'action', _get_url([ "relation", textid ]) ); + // Set up the download button + $('#dl_tradition').attr( 'href', _get_url([ "download", textid ]) ); + $('#dl_tradition').attr( 'download', selectedTextInfo.name + '.xml' ); }); } diff --git a/root/src/index.tt b/root/src/index.tt index e473c24..41bd149 100644 --- a/root/src/index.tt +++ b/root/src/index.tt @@ -76,6 +76,11 @@ var textOnLoad = "[% withtradition %]"; View collation and relationships + +
+ Download tradition as XML +
+