use new stemma util interface; configure correct IDP server. Fixes #31
[scpubgit/stemmaweb.git] / lib / stemmaweb / Controller / Stexaminer.pm
index 37c2dea..ff4f69b 100644 (file)
@@ -5,11 +5,21 @@ 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' }
 
+has idp_solver_url => (
+       is => 'ro',
+       isa => 'Str',
+       predicate => 'has_idp_solver_url',
+       );
+
+has idp_calcdsn => (
+       is => 'ro',
+       isa => 'Str',
+       predicate => 'has_idp_calcdsn',
+       );
 
 =head1 NAME
 
@@ -33,16 +43,30 @@ graph identified by $stemmaid.
 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 ) {
+       
+       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 );
-               $c->stash->{svg} = $stemma->as_svg( { size => [ 600, 350 ] } );
+               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' );
@@ -59,8 +83,12 @@ sub index :Path :Args(2) {
                } elsif( $ignore_sort eq 'orthographic' ) {
                        $analysis_options{'merge_types'} = 'orthographic';
                }
+               if( $self->has_idp_solver_url ) {
+                       $analysis_options{'solver_url'} = $self->idp_solver_url;
+               } elsif( $self->has_idp_calcdsn ) {
+                       $analysis_options{'calcdsn'} = $self->idp_calcdsn;
+               }
 
-               # Do the deed
                my $t = run_analysis( $tradition, %analysis_options );
                # Stringify the reading groups
                foreach my $loc ( @{$t->{'variants'}} ) {
@@ -110,8 +138,7 @@ sub _check_permission {
 
        # ...nope. Forbidden!
        $c->response->status( 403 );
-       $c->response->body( 'You do not have permission to view this tradition' );
-       $c->forward('View::Plain');
+       $c->stash->{'error'} = 'You do not have permission to view this tradition';
        return 0;
 }
 
@@ -132,10 +159,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;
        }