1 package stemmaweb::Controller::Relation;
3 use namespace::autoclean;
6 BEGIN { extends 'Catalyst::Controller' }
11 stemmaweb::Controller::Relation - Controller for the relationship mapper
15 The reading relationship mapper with draggable nodes.
23 Renders the application for the text identified by $textid.
27 sub index :Path :Args(0) {
29 $c->stash->{'template'} = 'relate.tt';
36 Returns the help window HTML.
40 sub help :Local :Args(0) {
42 $c->stash->{'template'} = 'relatehelp.tt';
47 GET relation/definitions
49 Returns a data structure giving the valid types and scopes for a relationship.
53 sub definitions :Local :Args(0) {
55 my $valid_relationships = [ qw/ spelling orthographic grammatical meaning
56 lexical transposition / ];
57 my $valid_scopes = [ qw/ local global / ];
58 $c->stash->{'result'} = { 'types' => $valid_relationships, 'scopes' => $valid_scopes };
59 $c->forward('View::JSON');
66 Runs the relationship mapper for the specified text ID.
70 sub text :Chained('/') :PathPart('relation') :CaptureArgs(1) {
71 my( $self, $c, $textid ) = @_;
72 $c->stash->{'tradition'} = $c->model('Directory')->tradition( $textid );
75 sub main :Chained('text') :PathPart('') :Args(0) {
77 my $tradition = delete $c->stash->{'tradition'};
78 my $collation = $tradition->collation;
79 my $svg_str = $collation->as_svg;
81 $c->stash->{'svg_string'} = $svg_str;
82 $c->stash->{'text_title'} = $tradition->name;
83 $c->stash->{'template'} = 'relate.tt';
89 GET $textid/relationships
91 Returns the list of relationships defined for this text.
93 POST $textid/relationships { request }
95 Attempts to define the requested relationship within the text. Returns 200 on
96 success or 403 on error.
98 DELETE $textid/relationships { request }
103 sub relationships :Chained('text') :PathPart :Args(0) {
104 my( $self, $c ) = @_;
105 my $tradition = delete $c->stash->{'tradition'};
106 my $collation = $tradition->collation;
107 my $m = $c->model('Directory');
108 if( $c->request->method eq 'GET' ) {
109 my @pairs = $collation->relationships; # returns the edges
111 foreach my $p ( @pairs ) {
112 my $relobj = $collation->relations->get_relationship( @$p );
113 my $relhash = { source => $p->[0], target => $p->[1],
114 type => $relobj->type, scope => $relobj->scope };
115 $relhash->{'note'} = $relobj->annotation if $relobj->has_annotation;
116 push( @all_relations, $relhash );
118 $c->stash->{'result'} = \@all_relations;
119 } elsif( $c->request->method eq 'POST' ) {
120 my $node = $c->request->param('source_id');
121 my $target = $c->request->param('target_id');
122 my $relation = $c->request->param('rel_type');
123 my $note = $c->request->param('note');
124 my $scope = $c->request->param('scope');
126 my $opts = { 'type' => $relation,
128 $opts->{'annotation'} = $note if $note;
131 my @vectors = $collation->add_relationship( $node, $target, $opts );
132 $c->stash->{'result'} = \@vectors;
133 $m->save( $tradition );
134 } catch( Text::Tradition::Error $e ) {
135 $c->response->status( '403' );
136 $c->stash->{'result'} = { 'error' => $e->message };
138 } elsif( $c->request->method eq 'DELETE' ) {
139 my $node = $c->request->param('source_id');
140 my $target = $c->request->param('target_id');
143 my @vectors = $collation->del_relationship( $node, $target );
144 $m->save( $tradition );
145 $c->stash->{'result'} = \@vectors;
146 } catch( Text::Tradition::Error $e ) {
147 $c->response->status( '403' );
148 $c->stash->{'result'} = { 'error' => $e->message };
151 $c->forward('View::JSON');
157 Attempt to render a view, if needed.
161 sub end : ActionClass('RenderView') {}
169 This library is free software. You can redistribute it and/or modify
170 it under the same terms as Perl itself.
174 __PACKAGE__->meta->make_immutable;