1 package stemmaweb::Controller::Root;
3 use namespace::autoclean;
4 use Text::Tradition::Analysis qw/ run_analysis /;
7 BEGIN { extends 'Catalyst::Controller' }
10 # Sets the actions in this controller to be registered with no prefix
11 # so they function identically to actions created in MyApp.pm
13 __PACKAGE__->config(namespace => '');
17 stemmaweb::Controller::Root - Root Controller for stemmaweb
21 Serves up the main container pages.
27 The root page (/). Serves the main container page, from which the various
28 components will be loaded.
32 sub index :Path :Args(0) {
33 my ( $self, $c ) = @_;
35 $c->stash->{template} = 'index.tt';
38 =head1 Elements of index page
44 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.
48 sub directory :Local :Args(0) {
50 my $m = $c->model('Directory');
51 my $user = $c->user_exists ? $c->user->get_object : 'public';
52 my @textlist = $m->traditionlist($user);
53 $c->stash->{texts} = \@textlist;
54 $c->stash->{template} = 'directory.tt';
59 GET /variantgraph/$textid
61 Returns the variant graph for the text specified at $textid, in SVG form.
65 sub variantgraph :Local :Args(1) {
66 my( $self, $c, $textid ) = @_;
67 my $m = $c->model('Directory');
68 my $tradition = $m->tradition( $textid );
69 my $collation = $tradition->collation;
70 $c->stash->{'result'} = $collation->as_svg;
71 $c->forward('View::SVG');
76 GET /alignment/$textid
78 Returns an alignment table for the text specified at $textid.
82 sub alignment :Local :Args(1) {
83 my( $self, $c, $textid ) = @_;
84 my $m = $c->model('Directory');
85 my $collation = $m->tradition( $textid )->collation;
86 my $alignment = $collation->alignment_table;
88 # Turn the table, so that witnesses are by column and the rows
90 my $wits = [ map { $_->{'witness'} } @{$alignment->{'alignment'}} ];
92 foreach my $i ( 0 .. $alignment->{'length'} - 1 ) {
93 my @rankrdgs = map { $_->{'tokens'}->[$i]->{'t'} }
94 @{$alignment->{'alignment'}};
95 push( @$rows, { 'rank' => $i+1, 'readings' => \@rankrdgs } );
97 $c->stash->{'witnesses'} = $wits;
98 $c->stash->{'table'} = $rows;
99 $c->stash->{'template'} = 'alignment.tt';
105 POST /stemma/$textid, { 'dot' => $dot_string }
107 Returns an SVG representation of the stemma hypothesis for the text. If
108 the URL is called with POST and a new dot string, updates the stemma and
109 returns the SVG as with GET.
113 sub stemma :Local :Args(1) {
114 my( $self, $c, $textid ) = @_;
115 my $m = $c->model('Directory');
116 my $tradition = $m->tradition( $textid );
118 if( $c->req->method eq 'POST' ) {
120 my $dot = $c->request->body_params->{'dot'};
121 $tradition->add_stemma( $dot );
122 $m->store( $tradition );
125 $c->stash->{'result'} = $tradition->stemma_count
126 ? $tradition->stemma(0)->as_svg( { size => [ 500, 375 ] } )
128 $c->forward('View::SVG');
133 GET /stemmadot/$textid
135 Returns the 'dot' format representation of the current stemma hypothesis.
139 sub stemmadot :Local :Args(1) {
140 my( $self, $c, $textid ) = @_;
141 my $m = $c->model('Directory');
142 my $tradition = $m->tradition( $textid );
144 $c->response->body( $tradition->stemma->editable );
145 $c->forward('View::Plain');
150 Standard 404 error page
155 my ( $self, $c ) = @_;
156 $c->response->body( 'Page not found' );
157 $c->response->status(404);
162 Attempt to render a view, if needed.
166 sub end : ActionClass('RenderView') {}
174 This library is free software. You can redistribute it and/or modify
175 it under the same terms as Perl itself.
179 __PACKAGE__->meta->make_immutable;