From: Tara L Andrews <tla@mit.edu>
Date: Fri, 3 Feb 2012 12:13:14 +0000 (+0100)
Subject: path and API bugfixes
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9c2e7b8029c8696c9fcdaa3c85285d66892afa65;p=scpubgit%2Fstemmaweb.git

path and API bugfixes
---

diff --git a/lib/stemmaweb/Controller/Relation.pm b/lib/stemmaweb/Controller/Relation.pm
index 536269a..25b91de 100644
--- a/lib/stemmaweb/Controller/Relation.pm
+++ b/lib/stemmaweb/Controller/Relation.pm
@@ -37,19 +37,19 @@ sub index :Path :Args(1) {
 
 sub dispatcher :Path :Args(2) {
 	my( $self, $c, $textid, $forward ) = @_;
-	$c->stash->{'collation'} = $c->model('Directory')->tradition( $textid )->collation;
+	$c->stash->{'tradition'} = $c->model('Directory')->tradition( $textid );
 	$c->forward( $forward );	
 }
 
 =head2 relationship_definition
 
- GET relation/relationship_definition
+ GET relation/definitions
  
 Returns a data structure giving the valid types and scopes for a relationship.
 
 =cut
 
-sub relationship_definition :Local :Args(0) {
+sub definitions :Local :Args(0) {
 	my( $self, $c ) = @_;
 	my $valid_relationships = [ qw/ spelling orthographic grammatical meaning / ];
 	my $valid_scopes = [ qw/ local global / ];
@@ -57,7 +57,7 @@ sub relationship_definition :Local :Args(0) {
 	$c->forward('View::JSON');
 }
 
-=head2 set_relationship
+=head2 relationship
 
  POST relation/$textid/relationship
    source_id: $source, target_id: $target, rel_type: $type, scope: $scope
@@ -70,7 +70,8 @@ returns 403 and an { error: message } struct on failure.
 
 sub relationship :Private {
 	my( $self, $c ) = @_;
-	my $collation = delete $c->stash->{'collation'};
+	my $tradition = delete $c->stash->{'tradition'};
+	my $collation = $tradition->collation;
 	my $node = $c->request->param('source_id');
 	my $target = $c->request->param('target_id');
 	my $relation = $c->request->param('rel_type');
@@ -82,6 +83,8 @@ sub relationship :Private {
 	
 	try {
 		my @vectors = $collation->add_relationship( $node, $target, $opts );
+		my $m = $c->model('Directory');
+		$m->save( $tradition );
 		$c->stash->{'result'} = \@vectors;
 	} catch( Text::Tradition::Error $e ) {
 		$c->response->status( '403' );
@@ -101,7 +104,7 @@ relationship is returned in a struct that looks like:
 
 =cut
 
-sub get_relationships :Private {
+sub relationships :Private {
 	my( $self, $c ) = @_;
 	my $collation = delete $c->stash->{'collation'};
 	# TODO make this API
diff --git a/lib/stemmaweb/Controller/Stexaminer.pm b/lib/stemmaweb/Controller/Stexaminer.pm
index bdabcaa..46c0359 100644
--- a/lib/stemmaweb/Controller/Stexaminer.pm
+++ b/lib/stemmaweb/Controller/Stexaminer.pm
@@ -30,17 +30,22 @@ sub index :Path :Args(1) {
     my( $self, $c, $textid ) = @_;
     my $m = $c->model('Directory');
 	my $tradition = $m->tradition( $textid );
-	my $stemma = $tradition->stemma;
-	# TODO Think about caching the stemma in a session 
-	$c->stash->{svg} = $stemma->as_svg;
-	$c->stash->{text_title} = $tradition->name;
-	$c->stash->{template} = 'stexaminer.tt'; 
-	# TODO Run the analysis as AJAX from the loaded page.
-	my $t = run_analysis( $tradition );
-	$c->stash->{variants} = $t->{'variants'};
-	$c->stash->{total} = $t->{'variant_count'};
-	$c->stash->{genealogical} = $t->{'genealogical_count'};
-	$c->stash->{conflict} = $t->{'conflict_count'};
+	if( $tradition->stemma_count ) {
+		my $stemma = $tradition->stemma(0);
+		# TODO Think about caching the stemma in a session 
+		$c->stash->{svg} = $stemma->as_svg;
+		$c->stash->{text_title} = $tradition->name;
+		$c->stash->{template} = 'stexaminer.tt'; 
+		# TODO Run the analysis as AJAX from the loaded page.
+		my $t = run_analysis( $tradition );
+		$c->stash->{variants} = $t->{'variants'};
+		$c->stash->{total} = $t->{'variant_count'};
+		$c->stash->{genealogical} = $t->{'genealogical_count'};
+		$c->stash->{conflict} = $t->{'conflict_count'};
+	} else {
+		$c->stash->{error} = 'Tradition ' . $tradition->name 
+			. 'has no stemma for analysis.';
+	}
 }
 
 =head2 end