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';
53 foreach my $id ( $m->tradition_ids ) {
56 'name' => $m->name( $id ),
58 push( @textlist, $data );
61 $c->stash->{texts} = \@textlist;
62 $c->stash->{template} = 'directory.tt';
67 GET /alignment/$textid
69 Returns an alignment table for the text specified at $textid.
73 sub alignment :Local :Args(1) {
74 my( $self, $c, $textid ) = @_;
75 my $m = $c->model('Directory');
76 my $collation = $m->tradition( $textid )->collation;
77 my $alignment = $collation->make_alignment_table;
79 # Turn the table, so that witnesses are by column and the rows
81 my $wits = [ map { $_->{'witness'} } @{$alignment->{'alignment'}} ];
83 foreach my $i ( 0 .. $alignment->{'length'} - 1 ) {
84 my @rankrdgs = map { $_->{'tokens'}->[$i]->{'t'} }
85 @{$alignment->{'alignment'}};
86 push( @$rows, { 'rank' => $i+1, 'readings' => \@rankrdgs } );
88 $c->log->debug( Dumper( $rows ) );
89 $c->stash->{'witnesses'} = $wits;
90 $c->stash->{'table'} = $rows;
91 $c->stash->{'template'} = 'alignment.tt';
97 POST /stemma/$textid, { 'dot' => $dot_string }
99 Returns an SVG representation of the stemma hypothesis for the text. If
100 the URL is called with POST and a new dot string, updates the stemma and
101 returns the SVG as with GET.
105 sub stemma :Local :Args(1) {
106 my( $self, $c, $textid ) = @_;
107 my $m = $c->model('Directory');
108 my $tradition = $m->tradition( $textid );
110 if( $c->req->method eq 'POST' ) {
112 my $dot = $c->request->body_params->{'dot'};
113 $tradition->add_stemma( $dot );
114 $m->store( $tradition );
117 $c->stash->{'result'} = $tradition->stemma->as_svg;
118 $c->forward('View::SVG');
123 GET /stemmadot/$textid
125 Returns the 'dot' format representation of the current stemma hypothesis.
129 sub stemmadot :Local :Args(1) {
130 my( $self, $c, $textid ) = @_;
131 my $m = $c->model('Directory');
132 my $tradition = $m->tradition( $textid );
134 $c->response->body( $tradition->stemma->editable );
135 $c->forward('View::Plain');
140 Standard 404 error page
145 my ( $self, $c ) = @_;
146 $c->response->body( 'Page not found' );
147 $c->response->status(404);
152 Attempt to render a view, if needed.
156 sub end : ActionClass('RenderView') {}
164 This library is free software. You can redistribute it and/or modify
165 it under the same terms as Perl itself.
169 __PACKAGE__->meta->make_immutable;