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 / ];
$c->forward('View::JSON');
}
-=head2 set_relationship
+=head2 relationship
POST relation/$textid/relationship
source_id: $source, target_id: $target, rel_type: $type, scope: $scope
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');
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' );
=cut
-sub get_relationships :Private {
+sub relationships :Private {
my( $self, $c ) = @_;
my $collation = delete $c->stash->{'collation'};
# TODO make this API
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