=head2 download
- GET /download/$textid
+ GET /download/$textid/$format
-Returns the full XML definition of the tradition and its stemmata, if any.
+Returns a file for download of the tradition in the requested format.
=cut
-sub download :Local :Args(1) {
- my( $self, $c, $textid ) = @_;
+sub download :Local :Args(2) {
+ my( $self, $c, $textid, $format ) = @_;
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;
+
+ my $outmethod = "as_" . lc( $format );
+ my $view = "View::$format";
+ $c->stash->{'name'} = $tradition->name();
+ $c->stash->{'download'} = 1;
try {
- $c->stash->{'result'} = $tradition->collation->as_graphml();
+ $c->stash->{'result'} = $tradition->collation->$outmethod();
} catch( Text::Tradition::Error $e ) {
return _json_error( $c, 500, $e->message );
}
- $c->forward('View::GraphML');
+ $c->forward( $view );
}
####################
my( $self, $c ) = @_;
my $dot = $c->request->param('dot');
my @layerwits = $c->request->param('layerwits[]');
- open my $stemma_fh, '<', \$dot;
- binmode( $stemma_fh, ':encoding(UTF-8)' );
- my $tempstemma = Text::Tradition::Stemma->new( 'dot' => $stemma_fh );
+ my $tempstemma = Text::Tradition::Stemma->new( 'dot' => $dot );
my $svgopts = {};
if( @layerwits ) {
$svgopts->{'layerwits'} = \@layerwits;
--- /dev/null
+package stemmaweb::View::CSV;
+use Moose;
+use namespace::autoclean;
+
+extends 'Catalyst::View';
+
+sub process {
+ my( $self, $c ) = @_;
+ $c->res->content_type( 'text/csv' );
+ $c->res->content_encoding( 'UTF-8' );
+ $c->res->header( 'Content-Disposition',
+ sprintf( "attachment; filename=\"%s.csv\"", $c->stash->{name} ) );
+ $c->res->output( $c->stash->{result} );
+}
+
+=head1 NAME
+
+stemmaweb::View::CSV - Catalyst View
+
+=head1 DESCRIPTION
+
+Catalyst View.
+
+
+=encoding utf8
+
+=head1 AUTHOR
+
+Tara L Andrews
+
+=head1 LICENSE
+
+This library is free software. You can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
+
+__PACKAGE__->meta->make_immutable;
+
+1;
my( $self, $c ) = @_;
$c->res->content_type( 'application/graphml+xml' );
$c->res->content_encoding( 'UTF-8' );
+ if( $c->stash->{download} ) {
+ $c->res->header( 'Content-Disposition',
+ sprintf( "attachment; filename=\"%s.xml\"", $c->stash->{name} ) );
+ }
$c->res->output( $c->stash->{result} );
}
use strict;
use base 'Catalyst::View';
-use Encode qw( decode_utf8 );
sub process {
- my( $self, $c ) = @_;
- $c->res->content_type( 'image/svg+xml' );
- $c->res->content_encoding( 'UTF-8' );
- $c->res->output( decode_utf8( $c->stash->{result} ) );
+ my( $self, $c ) = @_;
+ $c->res->content_type( 'image/svg+xml' );
+ $c->res->content_encoding( 'UTF-8' );
+ if( $c->stash->{download} ) {
+ $c->res->header( 'Content-Disposition',
+ sprintf( "attachment; filename=\"%s.svg\"", $c->stash->{name} ) );
+ }
+ $c->res->output( $c->stash->{result} );
}
1;
--- /dev/null
+package stemmaweb::View::TSV;
+use Moose;
+use namespace::autoclean;
+
+extends 'Catalyst::View';
+
+sub process {
+ my( $self, $c ) = @_;
+ $c->res->content_type( 'text/tab-separated-values' );
+ $c->res->content_encoding( 'UTF-8' );
+ $c->res->header( 'Content-Disposition',
+ sprintf( "attachment; filename=\"%s.tsv\"", $c->stash->{name} ) );
+ $c->res->output( $c->stash->{result} );
+}
+
+=head1 NAME
+
+stemmaweb::View::TSV - Catalyst View
+
+=head1 DESCRIPTION
+
+Catalyst View.
+
+
+=encoding utf8
+
+=head1 AUTHOR
+
+Tara L Andrews
+
+=head1 LICENSE
+
+This library is free software. You can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
+
+__PACKAGE__->meta->make_immutable;
+
+1;
}
});
+ // Set up the download dialog
+ $('#download-dialog').dialog({
+ autoOpen: false,
+ height: 150,
+ width: 300,
+ modal: true,
+ buttons: {
+ Download: function (evt) {
+ var dlurl = _get_url([ "download", $('#download_tradition').val(), $('#download_format').val() ]);
+ window.location = dlurl;
+ $('download-dialog').dialog('close');
+ },
+ Cancel: function() {
+ $('#download-dialog').dialog('close');
+ }
+ },
+ open: function() {
+ $('#download_tradition').attr('value', selectedTextID );
+ },
+ }).ajaxError( function(event, jqXHR, ajaxSettings, thrownError) {
+ $(event.target).parent().find('.ui-button').button("enable");
+ if( ajaxSettings.url.indexOf( 'download' ) > -1
+ && ajaxSettings.type == 'POST' ) {
+ display_error( jqXHR, $("#download_status") );
+ }
+ });
+
$('#upload-collation-dialog').dialog({
autoOpen: false,
height: 360,
<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>
+ <form id="dl_tradition" action="" method="GET" name="run_downloader">
+ <div class="button" id="download_button"
+ onClick="$('#download-dialog').dialog('open');">
+ <span id='dlbutton_label'>Download tradition</span>
</div>
- </a>
+ </form>
</div>
<div id="stemma_load_status"></div>
<div id="stemma_graph"></div>
</div>
</div>
+ <!-- Data download dialog box -->
+ <div id="download-dialog" title="Download tradition data">
+ <div id="download_container">
+ <form id="download_form">
+ <input id="download_tradition" type="hidden" name="tradition"/><br/>
+ <label for="download_format">Choose a format for download: </label>
+ <select id="download_format" name="format">
+ <option value="GraphML">Native XML format</option>
+ <option value="CSV">Comma-separated values (collation only)</option>
+ <option value="TSV">Tab-separated values (collation only)</option>
+ <option value="SVG">SVG graph display (collation and relationships)</option>
+ <!-- option value="tei_ps" -->
+ <!-- option value="tei_dea" -->
+ </select>
+ </form>
+ <div id="download_status"></div>
+ </div>
+ </div>
+
<!-- File upload dialog box -->
<div id="upload-collation-dialog" title="Upload a collation">
<div id="upload_container">
--- /dev/null
+use strict;
+use warnings;
+use Test::More;
+
+
+BEGIN { use_ok 'stemmaweb::View::CSV' }
+
+done_testing();
--- /dev/null
+use strict;
+use warnings;
+use Test::More;
+
+
+BEGIN { use_ok 'stemmaweb::View::TSV' }
+
+done_testing();