X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=stemmaweb%2Flib%2Fstemmaweb%2FController%2FRoot.pm;h=90f9e8a82e848d55b8dfa9ffaf0475c45a769d89;hb=HEAD;hp=9d497c88f8a6d35e49fcdfe5fbdf474969ca469d;hpb=5c9ecf6629514c0b83ccf41052f13f5f02e982f2;p=scpubgit%2Fstemmatology.git diff --git a/stemmaweb/lib/stemmaweb/Controller/Root.pm b/stemmaweb/lib/stemmaweb/Controller/Root.pm index 9d497c8..90f9e8a 100644 --- a/stemmaweb/lib/stemmaweb/Controller/Root.pm +++ b/stemmaweb/lib/stemmaweb/Controller/Root.pm @@ -41,27 +41,38 @@ sub index :Path :Args(0) { GET /directory -Serves a snippet of HTML that lists the available texts. Eventually this will be available texts by user. +Serves a snippet of HTML that lists the available texts. This returns texts belonging to the logged-in user if any, otherwise it returns all public texts. =cut + sub directory :Local :Args(0) { my( $self, $c ) = @_; my $m = $c->model('Directory'); - # TODO not used yet, will load user texts later - my $user = $c->request->param( 'user' ) || 'ALL'; - my @textlist; - foreach my $id ( $m->tradition_ids ) { - my $data = { - 'id' => $id, - 'name' => $m->name( $id ), - }; - push( @textlist, $data ); - } - + my $user = $c->user_exists ? $c->user->get_object : 'public'; + my @textlist = $m->traditionlist($user); $c->stash->{texts} = \@textlist; $c->stash->{template} = 'directory.tt'; } +=head2 variantgraph + + GET /variantgraph/$textid + +Returns the variant graph for the text specified at $textid, in SVG form. + +=cut + +sub variantgraph :Local :Args(1) { + my( $self, $c, $textid ) = @_; + my $m = $c->model('Directory'); + my $tradition = $m->tradition( $textid ); + my $collation = $tradition->collation; + my $needsave = !$collation->has_cached_svg; + $c->stash->{'result'} = $collation->as_svg; + $m->save( $tradition ); # to save generate SVG in the cache + $c->forward('View::SVG'); +} + =head2 alignment GET /alignment/$textid @@ -74,7 +85,7 @@ sub alignment :Local :Args(1) { my( $self, $c, $textid ) = @_; my $m = $c->model('Directory'); my $collation = $m->tradition( $textid )->collation; - my $alignment = $collation->make_alignment_table; + my $alignment = $collation->alignment_table; # Turn the table, so that witnesses are by column and the rows # are by rank. @@ -85,7 +96,6 @@ sub alignment :Local :Args(1) { @{$alignment->{'alignment'}}; push( @$rows, { 'rank' => $i+1, 'readings' => \@rankrdgs } ); } - $c->log->debug( Dumper( $rows ) ); $c->stash->{'witnesses'} = $wits; $c->stash->{'table'} = $rows; $c->stash->{'template'} = 'alignment.tt'; @@ -114,7 +124,9 @@ sub stemma :Local :Args(1) { $m->store( $tradition ); } - $c->stash->{'result'} = $tradition->stemma->as_svg; + $c->stash->{'result'} = $tradition->stemma_count + ? $tradition->stemma(0)->as_svg( { size => [ 500, 375 ] } ) + : ''; $c->forward('View::SVG'); }