use File::Temp;
use JSON;
use Text::Tradition::Analysis qw/ run_analysis wit_stringify /;
-use Text::Tradition::Collation;
use Text::Tradition::Stemma;
BEGIN { extends 'Catalyst::Controller' }
sub index :Path :Args(2) {
my( $self, $c, $textid, $stemid ) = @_;
my $m = $c->model('Directory');
+ $c->stash->{template} = 'stexaminer.tt';
+
+ # Make sure the tradition exists and is viewable
my $tradition = $m->tradition( $textid );
+ unless( $tradition ) {
+ $c->response->status( 404 );
+ $c->stash->{'error'} = "No tradition with ID $textid";
+ return;
+ }
my $ok = _check_permission( $c, $tradition );
return unless $ok;
+
if( $tradition->stemma_count ) {
- my $stemma = $tradition->stemma(0);
- $c->stash->{svg} = $stemma->as_svg( { size => [ 600, 350 ] } );
+ my $stemma = $tradition->stemma( $stemid );
+ my $svgstr = $stemma->as_svg();
+ $svgstr =~ s/\n/ /g;
+ $c->stash->{svg} = $svgstr;
$c->stash->{graphdot} = $stemma->editable({ linesep => ' ' });
+ $c->stash->{text_id} = $textid;
$c->stash->{text_title} = $tradition->name;
- $c->stash->{template} = 'stexaminer.tt';
# Get the analysis options
my( $use_type1, $ignore_sort ) = ( 0, 'none' );
my( $c, $tradition ) = @_;
my $user = $c->user_exists ? $c->user->get_object : undef;
if( $user ) {
- $c->stash->{'permission'} = 'full'
- if( $user->is_admin ||
- ( $tradition->has_user && $tradition->user->id eq $user->id ) );
- return 1;
- }
- # Is it public?
- if( $tradition->public ) {
- $c->stash->{'permission'} = 'readonly';
- return 1;
- }
- # Forbidden!
+ return 'full' if ( $user->is_admin ||
+ ( $tradition->has_user && $tradition->user->id eq $user->id ) );
+ }
+ # Text doesn't belong to us, so maybe it's public?
+ return 'readonly' if $tradition->public;
+
+ # ...nope. Forbidden!
$c->response->status( 403 );
- $c->response->body( 'You do not have permission to view this tradition.' );
- $c->detach( 'View::Plain' );
+ $c->stash->{'error'} = 'You do not have permission to view this tradition';
return 0;
}
my @layerwits = $c->request->param('layerwits[]');
open my $stemma_fh, '<', \$dot;
binmode( $stemma_fh, ':encoding(UTF-8)' );
- my $emptycoll = Text::Tradition::Collation->new();
- my $tempstemma = Text::Tradition::Stemma->new(
- collation => $emptycoll, 'dot' => $stemma_fh );
- my $svgopts = { size => [ 600, 350 ] };
+ my $tempstemma = Text::Tradition::Stemma->new( 'dot' => $stemma_fh );
+ my $svgopts = {};
if( @layerwits ) {
$svgopts->{'layerwits'} = \@layerwits;
}