incorporate user auth functionality
[scpubgit/stemmaweb.git] / lib / stemmaweb / Controller / Root.pm
index cd6cb76..90f9e8a 100644 (file)
@@ -41,20 +41,15 @@ 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;
-    $m->scan( sub { 
-       push( @textlist, {
-               'id' => $m->object_to_id( @_ ),
-               'name' => $_[0]->name } ) 
-       } );    
+    my $user = $c->user_exists ? $c->user->get_object : 'public';
+    my @textlist = $m->traditionlist($user);
     $c->stash->{texts} = \@textlist;
        $c->stash->{template} = 'directory.tt';
 }
@@ -74,7 +69,7 @@ sub variantgraph :Local :Args(1) {
        my $collation = $tradition->collation;
        my $needsave = !$collation->has_cached_svg;
        $c->stash->{'result'} = $collation->as_svg;
-       $m->save( $tradition );
+       $m->save( $tradition );  # to save generate SVG in the cache
        $c->forward('View::SVG');
 }
        
@@ -101,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';
@@ -131,7 +125,7 @@ sub stemma :Local :Args(1) {
        }
        
        $c->stash->{'result'} = $tradition->stemma_count
-               ? $tradition->stemma(0)->as_svg
+               ? $tradition->stemma(0)->as_svg( { size => [ 500, 375 ] } )
                : '';
        $c->forward('View::SVG');
 }