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 # TODO not used yet, will load user texts later
52 my $user = $c->user_exists ? $c->user->get_object : 'public';
53 # my $user = $c->request->param( 'user' ) || 'ALL';
54 my @textlist = $m->traditionlist($user);
55 $c->stash->{texts} = \@textlist;
56 $c->stash->{template} = 'directory.tt';
61 GET /variantgraph/$textid
63 Returns the variant graph for the text specified at $textid, in SVG form.
67 sub variantgraph :Local :Args(1) {
68 my( $self, $c, $textid ) = @_;
69 my $m = $c->model('Directory');
70 my $tradition = $m->tradition( $textid );
71 my $collation = $tradition->collation;
72 my $needsave = !$collation->has_cached_svg;
73 $c->stash->{'result'} = $collation->as_svg;
74 $m->save( $tradition ); # to save generate SVG in the cache
75 $c->forward('View::SVG');
80 GET /alignment/$textid
82 Returns an alignment table for the text specified at $textid.
86 sub alignment :Local :Args(1) {
87 my( $self, $c, $textid ) = @_;
88 my $m = $c->model('Directory');
89 my $collation = $m->tradition( $textid )->collation;
90 my $alignment = $collation->alignment_table;
92 # Turn the table, so that witnesses are by column and the rows
94 my $wits = [ map { $_->{'witness'} } @{$alignment->{'alignment'}} ];
96 foreach my $i ( 0 .. $alignment->{'length'} - 1 ) {
97 my @rankrdgs = map { $_->{'tokens'}->[$i]->{'t'} }
98 @{$alignment->{'alignment'}};
99 push( @$rows, { 'rank' => $i+1, 'readings' => \@rankrdgs } );
101 $c->stash->{'witnesses'} = $wits;
102 $c->stash->{'table'} = $rows;
103 $c->stash->{'template'} = 'alignment.tt';
109 POST /stemma/$textid, { 'dot' => $dot_string }
111 Returns an SVG representation of the stemma hypothesis for the text. If
112 the URL is called with POST and a new dot string, updates the stemma and
113 returns the SVG as with GET.
117 sub stemma :Local :Args(1) {
118 my( $self, $c, $textid ) = @_;
119 my $m = $c->model('Directory');
120 my $tradition = $m->tradition( $textid );
122 if( $c->req->method eq 'POST' ) {
124 my $dot = $c->request->body_params->{'dot'};
125 $tradition->add_stemma( $dot );
126 $m->store( $tradition );
129 $c->stash->{'result'} = $tradition->stemma_count
130 ? $tradition->stemma(0)->as_svg
132 $c->forward('View::SVG');
137 GET /stemmadot/$textid
139 Returns the 'dot' format representation of the current stemma hypothesis.
143 sub stemmadot :Local :Args(1) {
144 my( $self, $c, $textid ) = @_;
145 my $m = $c->model('Directory');
146 my $tradition = $m->tradition( $textid );
148 $c->response->body( $tradition->stemma->editable );
149 $c->forward('View::Plain');
154 Standard 404 error page
159 my ( $self, $c ) = @_;
160 $c->response->body( 'Page not found' );
161 $c->response->status(404);
166 Attempt to render a view, if needed.
170 sub end : ActionClass('RenderView') {}
178 This library is free software. You can redistribute it and/or modify
179 it under the same terms as Perl itself.
183 __PACKAGE__->meta->make_immutable;