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. Eventually this will be available texts by user.
47 sub directory :Local :Args(0) {
49 my $m = $c->model('Directory');
50 # TODO not used yet, will load user texts later
51 my $user = $c->request->param( 'user' ) || 'ALL';
52 my @textlist = $m->traditionlist();
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 my $needsave = !$collation->has_cached_svg;
71 $c->stash->{'result'} = $collation->as_svg;
72 $m->save( $tradition );
73 $c->forward('View::SVG');
78 GET /alignment/$textid
80 Returns an alignment table for the text specified at $textid.
84 sub alignment :Local :Args(1) {
85 my( $self, $c, $textid ) = @_;
86 my $m = $c->model('Directory');
87 my $collation = $m->tradition( $textid )->collation;
88 my $alignment = $collation->alignment_table;
90 # Turn the table, so that witnesses are by column and the rows
92 my $wits = [ map { $_->{'witness'} } @{$alignment->{'alignment'}} ];
94 foreach my $i ( 0 .. $alignment->{'length'} - 1 ) {
95 my @rankrdgs = map { $_->{'tokens'}->[$i]->{'t'} }
96 @{$alignment->{'alignment'}};
97 push( @$rows, { 'rank' => $i+1, 'readings' => \@rankrdgs } );
99 $c->log->debug( Dumper( $rows ) );
100 $c->stash->{'witnesses'} = $wits;
101 $c->stash->{'table'} = $rows;
102 $c->stash->{'template'} = 'alignment.tt';
108 POST /stemma/$textid, { 'dot' => $dot_string }
110 Returns an SVG representation of the stemma hypothesis for the text. If
111 the URL is called with POST and a new dot string, updates the stemma and
112 returns the SVG as with GET.
116 sub stemma :Local :Args(1) {
117 my( $self, $c, $textid ) = @_;
118 my $m = $c->model('Directory');
119 my $tradition = $m->tradition( $textid );
121 if( $c->req->method eq 'POST' ) {
123 my $dot = $c->request->body_params->{'dot'};
124 $tradition->add_stemma( $dot );
125 $m->store( $tradition );
128 $c->stash->{'result'} = $tradition->stemma_count
129 ? $tradition->stemma(0)->as_svg
131 $c->forward('View::SVG');
136 GET /stemmadot/$textid
138 Returns the 'dot' format representation of the current stemma hypothesis.
142 sub stemmadot :Local :Args(1) {
143 my( $self, $c, $textid ) = @_;
144 my $m = $c->model('Directory');
145 my $tradition = $m->tradition( $textid );
147 $c->response->body( $tradition->stemma->editable );
148 $c->forward('View::Plain');
153 Standard 404 error page
158 my ( $self, $c ) = @_;
159 $c->response->body( 'Page not found' );
160 $c->response->status(404);
165 Attempt to render a view, if needed.
169 sub end : ActionClass('RenderView') {}
177 This library is free software. You can redistribute it and/or modify
178 it under the same terms as Perl itself.
182 __PACKAGE__->meta->make_immutable;