add download button for viewable traditions; fixes #8
Tara L Andrews [Mon, 10 Jun 2013 10:30:49 +0000 (12:30 +0200)]
lib/stemmaweb/Controller/Root.pm
lib/stemmaweb/View/GraphML.pm [new file with mode: 0644]
root/js/componentload.js
root/src/index.tt

index 59fa097..30cc644 100644 (file)
@@ -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 (file)
index 0000000..3560dfc
--- /dev/null
@@ -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
index ba8e48d..da3ad7f 100644 (file)
@@ -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' );
        });
 }
 
index e473c24..41bd149 100644 (file)
@@ -76,6 +76,11 @@ var textOnLoad = "[% withtradition %]";
               <span id='relatebutton_label'>View collation and relationships</span>
             </div>
           </form>
+          <a id="dl_tradition" href="" download="file.xml">
+            <div class="button" id="download_button">
+              <span id='dlbutton_label'>Download tradition as XML</span>
+            </div>
+          </a>
       </div>
       <div id="stemma_graph"></div>
     </div>