hide the unused dialog form in readonly mapper
[scpubgit/stemmatology.git] / stemmaweb / lib / stemmaweb / Controller / Root.pm
CommitLineData
5c9ecf66 1package stemmaweb::Controller::Root;
dbcf12a6 2use Moose;
3use namespace::autoclean;
3837c155 4use Text::Tradition::Analysis qw/ run_analysis /;
5
dbcf12a6 6
7BEGIN { 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 17stemmaweb::Controller::Root - Root Controller for stemmaweb
dbcf12a6 18
19=head1 DESCRIPTION
20
6b70c348 21Serves up the main container pages.
dbcf12a6 22
6b70c348 23=head1 URLs
dbcf12a6 24
25=head2 index
26
6b70c348 27The root page (/). Serves the main container page, from which the various
28components will be loaded.
dbcf12a6 29
30=cut
31
32sub 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
7c256818 44Serves 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.
6b70c348 45
46=cut
7c256818 47
2376359f 48sub directory :Local :Args(0) {
6b70c348 49 my( $self, $c ) = @_;
3837c155 50 my $m = $c->model('Directory');
7d52d62b 51 my $user = $c->user_exists ? $c->user->get_object : 'public';
7c256818 52 my @textlist = $m->traditionlist($user);
6b70c348 53 $c->stash->{texts} = \@textlist;
54 $c->stash->{template} = 'directory.tt';
55}
56
cf9626aa 57=head2 variantgraph
58
59 GET /variantgraph/$textid
60
61Returns the variant graph for the text specified at $textid, in SVG form.
62
63=cut
64
65sub variantgraph :Local :Args(1) {
66 my( $self, $c, $textid ) = @_;
67 my $m = $c->model('Directory');
b365fbae 68 my $tradition = $m->tradition( $textid );
69 my $collation = $tradition->collation;
cf9626aa 70 $c->stash->{'result'} = $collation->as_svg;
71 $c->forward('View::SVG');
72}
73
6b70c348 74=head2 alignment
75
76 GET /alignment/$textid
77
78Returns an alignment table for the text specified at $textid.
79
80=cut
81
2376359f 82sub alignment :Local :Args(1) {
6b70c348 83 my( $self, $c, $textid ) = @_;
84 my $m = $c->model('Directory');
85 my $collation = $m->tradition( $textid )->collation;
7f52eac8 86 my $alignment = $collation->alignment_table;
6b70c348 87
88 # Turn the table, so that witnesses are by column and the rows
89 # are by rank.
90 my $wits = [ map { $_->{'witness'} } @{$alignment->{'alignment'}} ];
91 my $rows;
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 } );
96 }
6b70c348 97 $c->stash->{'witnesses'} = $wits;
98 $c->stash->{'table'} = $rows;
99 $c->stash->{'template'} = 'alignment.tt';
100}
101
102=head2 stemma
103
104 GET /stemma/$textid
105 POST /stemma/$textid, { 'dot' => $dot_string }
106
107Returns an SVG representation of the stemma hypothesis for the text. If
108the URL is called with POST and a new dot string, updates the stemma and
109returns the SVG as with GET.
110
111=cut
112
2376359f 113sub stemma :Local :Args(1) {
6b70c348 114 my( $self, $c, $textid ) = @_;
115 my $m = $c->model('Directory');
116 my $tradition = $m->tradition( $textid );
117
118 if( $c->req->method eq 'POST' ) {
119 # Update the stemma
120 my $dot = $c->request->body_params->{'dot'};
121 $tradition->add_stemma( $dot );
122 $m->store( $tradition );
123 }
124
3e420a82 125 $c->stash->{'result'} = $tradition->stemma_count
91b888ed 126 ? $tradition->stemma(0)->as_svg( { size => [ 500, 375 ] } )
80dad2e3 127 : '';
6b70c348 128 $c->forward('View::SVG');
dbcf12a6 129}
130
6b70c348 131=head2 stemmadot
12720144 132
6b70c348 133 GET /stemmadot/$textid
134
135Returns the 'dot' format representation of the current stemma hypothesis.
136
137=cut
138
2376359f 139sub stemmadot :Local :Args(1) {
6b70c348 140 my( $self, $c, $textid ) = @_;
141 my $m = $c->model('Directory');
142 my $tradition = $m->tradition( $textid );
143
144 $c->response->body( $tradition->stemma->editable );
145 $c->forward('View::Plain');
146}
12720144 147
dbcf12a6 148=head2 default
149
150Standard 404 error page
151
152=cut
153
154sub default :Path {
155 my ( $self, $c ) = @_;
156 $c->response->body( 'Page not found' );
157 $c->response->status(404);
158}
159
160=head2 end
161
162Attempt to render a view, if needed.
163
164=cut
165
166sub end : ActionClass('RenderView') {}
167
168=head1 AUTHOR
169
170Tara L Andrews
171
172=head1 LICENSE
173
174This library is free software. You can redistribute it and/or modify
175it under the same terms as Perl itself.
176
177=cut
178
179__PACKAGE__->meta->make_immutable;
180
1811;