Commit | Line | Data |
5c9ecf66 |
1 | package stemmaweb::Controller::Root; |
dbcf12a6 |
2 | use Moose; |
3 | use namespace::autoclean; |
3837c155 |
4 | use Text::Tradition::Analysis qw/ run_analysis /; |
5 | |
dbcf12a6 |
6 | |
7 | BEGIN { extends 'Catalyst::Controller' } |
8 | |
9 | # |
10 | # Sets the actions in this controller to be registered with no prefix |
11 | # so they function identically to actions created in MyApp.pm |
12 | # |
13 | __PACKAGE__->config(namespace => ''); |
14 | |
15 | =head1 NAME |
16 | |
5c9ecf66 |
17 | stemmaweb::Controller::Root - Root Controller for stemmaweb |
dbcf12a6 |
18 | |
19 | =head1 DESCRIPTION |
20 | |
6b70c348 |
21 | Serves up the main container pages. |
dbcf12a6 |
22 | |
6b70c348 |
23 | =head1 URLs |
dbcf12a6 |
24 | |
25 | =head2 index |
26 | |
6b70c348 |
27 | The root page (/). Serves the main container page, from which the various |
28 | components will be loaded. |
dbcf12a6 |
29 | |
30 | =cut |
31 | |
32 | sub index :Path :Args(0) { |
33 | my ( $self, $c ) = @_; |
34 | |
6b70c348 |
35 | $c->stash->{template} = 'index.tt'; |
36 | } |
37 | |
38 | =head1 Elements of index page |
39 | |
40 | =head2 directory |
41 | |
42 | GET /directory |
43 | |
44 | Serves a snippet of HTML that lists the available texts. Eventually this will be available texts by user. |
45 | |
46 | =cut |
2376359f |
47 | sub directory :Local :Args(0) { |
6b70c348 |
48 | my( $self, $c ) = @_; |
3837c155 |
49 | my $m = $c->model('Directory'); |
6b70c348 |
50 | # TODO not used yet, will load user texts later |
51 | my $user = $c->request->param( 'user' ) || 'ALL'; |
52 | my @textlist; |
80dad2e3 |
53 | $m->scan( sub { |
54 | push( @textlist, { |
55 | 'id' => $m->object_to_id( @_ ), |
56 | 'name' => $_[0]->name } ) |
57 | } ); |
6b70c348 |
58 | $c->stash->{texts} = \@textlist; |
59 | $c->stash->{template} = 'directory.tt'; |
60 | } |
61 | |
cf9626aa |
62 | =head2 variantgraph |
63 | |
64 | GET /variantgraph/$textid |
65 | |
66 | Returns the variant graph for the text specified at $textid, in SVG form. |
67 | |
68 | =cut |
69 | |
70 | sub variantgraph :Local :Args(1) { |
71 | my( $self, $c, $textid ) = @_; |
72 | my $m = $c->model('Directory'); |
73 | my $collation = $m->tradition( $textid )->collation; |
74 | |
75 | $c->stash->{'result'} = $collation->as_svg; |
76 | $c->forward('View::SVG'); |
77 | } |
78 | |
6b70c348 |
79 | =head2 alignment |
80 | |
81 | GET /alignment/$textid |
82 | |
83 | Returns an alignment table for the text specified at $textid. |
84 | |
85 | =cut |
86 | |
2376359f |
87 | sub alignment :Local :Args(1) { |
6b70c348 |
88 | my( $self, $c, $textid ) = @_; |
89 | my $m = $c->model('Directory'); |
90 | my $collation = $m->tradition( $textid )->collation; |
91 | my $alignment = $collation->make_alignment_table; |
92 | |
93 | # Turn the table, so that witnesses are by column and the rows |
94 | # are by rank. |
95 | my $wits = [ map { $_->{'witness'} } @{$alignment->{'alignment'}} ]; |
96 | my $rows; |
97 | foreach my $i ( 0 .. $alignment->{'length'} - 1 ) { |
98 | my @rankrdgs = map { $_->{'tokens'}->[$i]->{'t'} } |
99 | @{$alignment->{'alignment'}}; |
100 | push( @$rows, { 'rank' => $i+1, 'readings' => \@rankrdgs } ); |
101 | } |
102 | $c->log->debug( Dumper( $rows ) ); |
103 | $c->stash->{'witnesses'} = $wits; |
104 | $c->stash->{'table'} = $rows; |
105 | $c->stash->{'template'} = 'alignment.tt'; |
106 | } |
107 | |
108 | =head2 stemma |
109 | |
110 | GET /stemma/$textid |
111 | POST /stemma/$textid, { 'dot' => $dot_string } |
112 | |
113 | Returns an SVG representation of the stemma hypothesis for the text. If |
114 | the URL is called with POST and a new dot string, updates the stemma and |
115 | returns the SVG as with GET. |
116 | |
117 | =cut |
118 | |
2376359f |
119 | sub stemma :Local :Args(1) { |
6b70c348 |
120 | my( $self, $c, $textid ) = @_; |
121 | my $m = $c->model('Directory'); |
122 | my $tradition = $m->tradition( $textid ); |
123 | |
124 | if( $c->req->method eq 'POST' ) { |
125 | # Update the stemma |
126 | my $dot = $c->request->body_params->{'dot'}; |
127 | $tradition->add_stemma( $dot ); |
128 | $m->store( $tradition ); |
129 | } |
130 | |
3e420a82 |
131 | $c->stash->{'result'} = $tradition->stemma_count |
132 | ? $tradition->stemma(0)->as_svg |
80dad2e3 |
133 | : ''; |
6b70c348 |
134 | $c->forward('View::SVG'); |
dbcf12a6 |
135 | } |
136 | |
6b70c348 |
137 | =head2 stemmadot |
12720144 |
138 | |
6b70c348 |
139 | GET /stemmadot/$textid |
140 | |
141 | Returns the 'dot' format representation of the current stemma hypothesis. |
142 | |
143 | =cut |
144 | |
2376359f |
145 | sub stemmadot :Local :Args(1) { |
6b70c348 |
146 | my( $self, $c, $textid ) = @_; |
147 | my $m = $c->model('Directory'); |
148 | my $tradition = $m->tradition( $textid ); |
149 | |
150 | $c->response->body( $tradition->stemma->editable ); |
151 | $c->forward('View::Plain'); |
152 | } |
12720144 |
153 | |
dbcf12a6 |
154 | =head2 default |
155 | |
156 | Standard 404 error page |
157 | |
158 | =cut |
159 | |
160 | sub default :Path { |
161 | my ( $self, $c ) = @_; |
162 | $c->response->body( 'Page not found' ); |
163 | $c->response->status(404); |
164 | } |
165 | |
166 | =head2 end |
167 | |
168 | Attempt to render a view, if needed. |
169 | |
170 | =cut |
171 | |
172 | sub end : ActionClass('RenderView') {} |
173 | |
174 | =head1 AUTHOR |
175 | |
176 | Tara L Andrews |
177 | |
178 | =head1 LICENSE |
179 | |
180 | This library is free software. You can redistribute it and/or modify |
181 | it under the same terms as Perl itself. |
182 | |
183 | =cut |
184 | |
185 | __PACKAGE__->meta->make_immutable; |
186 | |
187 | 1; |