X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2Fstemmaweb%2FController%2FStexaminer.pm;h=ac4e005880e1a07540588b45b99c3c8042197236;hb=0844ddeebb042ac91b556b6c65da3d5abd61a161;hp=16c515fe84676b67630a2c5668bedbee11a2341e;hpb=ccbe93158a373b6b7202436400ba0c788a725d14;p=scpubgit%2Fstemmaweb.git diff --git a/lib/stemmaweb/Controller/Stexaminer.pm b/lib/stemmaweb/Controller/Stexaminer.pm index 16c515f..ac4e005 100644 --- a/lib/stemmaweb/Controller/Stexaminer.pm +++ b/lib/stemmaweb/Controller/Stexaminer.pm @@ -5,7 +5,6 @@ use Encode qw/ decode_utf8 /; 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' } @@ -23,22 +22,40 @@ The stemma analysis tool with the pretty colored table. =head2 index - GET stexaminer/$textid + GET stexaminer/$textid/$stemmaid -Renders the application for the text identified by $textid. +Renders the application for the text identified by $textid, using the stemma +graph identified by $stemmaid. =cut -sub index :Path :Args(1) { - my( $self, $c, $textid ) = @_; +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 ); - if( $tradition->stemma_count ) { - my $stemma = $tradition->stemma(0); - $c->stash->{svg} = $stemma->as_svg( { size => [ 600, 350 ] } ); + 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( $stemid eq 'help' ) { + # Just show the 'Help/About' popup. + $c->stash->{template} = 'stexaminer_help.tt'; + $c->stash->{text_id} = $textid; + } elsif( $tradition->stemma_count ) { + 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' ); @@ -47,7 +64,9 @@ sub index :Path :Args(1) { $c->stash->{'show_type1'} = $use_type1; $c->stash->{'ignore_variant'} = $ignore_sort; # TODO Run the analysis as AJAX from the loaded page. - my %analysis_options = ( exclude_type1 => !$use_type1 ); + my %analysis_options = ( + stemma_id => $stemid, + exclude_type1 => !$use_type1 ); if( $ignore_sort eq 'spelling' ) { $analysis_options{'merge_types'} = [ qw/ spelling orthographic / ]; } elsif( $ignore_sort eq 'orthographic' ) { @@ -92,6 +111,22 @@ sub _stringify_element { } } +sub _check_permission { + my( $c, $tradition ) = @_; + my $user = $c->user_exists ? $c->user->get_object : undef; + if( $user ) { + 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->stash->{'error'} = 'You do not have permission to view this tradition'; + return 0; +} + =head2 graphsvg POST stexaminer/graphsvg @@ -109,10 +144,8 @@ sub graphsvg :Local { 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; }