fixes for stemma retrieval and for relative paths in JS
[scpubgit/stemmatology.git] / stemmaweb / lib / stemmaweb / Controller / Root.pm
index 9d497c8..de51958 100644 (file)
@@ -50,18 +50,32 @@ sub directory :Local :Args(0) {
     # 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 );
-    }
-    
+    $m->scan( sub { 
+       push( @textlist, {
+               'id' => $m->object_to_id( @_ ),
+               'name' => $_[0]->name } ) 
+       } );    
     $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 $collation = $m->tradition( $textid )->collation;
+
+       $c->stash->{'result'} = $collation->as_svg;
+       $c->forward('View::SVG');
+}
+       
 =head2 alignment
 
  GET /alignment/$textid
@@ -114,7 +128,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
+               : '';
        $c->forward('View::SVG');
 }