Commit | Line | Data |
dbcf12a6 |
1 | package TreeOfTexts::Controller::Root; |
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 | |
17 | TreeOfTexts::Controller::Root - Root Controller for TreeOfTexts |
18 | |
19 | =head1 DESCRIPTION |
20 | |
21 | [enter your description here] |
22 | |
23 | =head1 METHODS |
24 | |
25 | =head2 index |
26 | |
12720144 |
27 | The root page (/). Lists the traditions available in the DB to work on, |
28 | and should also eventually have an 'Upload new' interface. |
dbcf12a6 |
29 | |
30 | =cut |
31 | |
32 | sub index :Path :Args(0) { |
33 | my ( $self, $c ) = @_; |
34 | |
3837c155 |
35 | my $m = $c->model('Directory'); |
36 | my @all_texts; |
12720144 |
37 | foreach my $id ( $m->tradition_ids ) { |
3837c155 |
38 | my $data = { |
39 | 'id' => $id, |
12720144 |
40 | 'name' => $m->name( $id ), |
3837c155 |
41 | }; |
42 | push( @all_texts, $data ); |
43 | } |
44 | |
e367f5c0 |
45 | $c->stash->{texts} = \@all_texts; |
46 | $c->stash->{template} = 'frontpage.tt'; |
dbcf12a6 |
47 | } |
48 | |
12720144 |
49 | =head2 tradition (TODO) |
50 | |
51 | The main page for a tradition, with information about it and links to the |
52 | available tools. |
53 | |
54 | =head2 relationships |
55 | |
56 | The relationship editor tool. |
57 | |
58 | =cut |
59 | |
3837c155 |
60 | sub relationships :Local { |
61 | my( $self, $c ) = @_; |
62 | my $m = $c->model('Directory'); |
63 | my $tradition = $m->tradition( $c->request->params->{'textid'} ); |
b90c84a0 |
64 | my $table = $tradition->collation->make_alignment_table(); |
65 | my $witlist = shift @$table; |
66 | $c->stash->{witnesses} = $wits; |
67 | $c->stash->{alignment} = $table; |
68 | $c->stash->{template} = 'relate.tt'; |
3837c155 |
69 | } |
70 | |
12720144 |
71 | =head2 stexaminer |
72 | |
73 | The stemma analysis tool with the pretty colored table. |
74 | |
75 | =cut |
76 | |
3837c155 |
77 | sub stexaminer :Local { |
e367f5c0 |
78 | my( $self, $c ) = @_; |
3837c155 |
79 | my $m = $c->model('Directory'); |
12720144 |
80 | my $tradition = $m->tradition( $c->request->params->{'textid'} ); |
81 | my $stemma = $tradition->stemma; |
82 | # TODO Think about caching the stemma in a session |
3837c155 |
83 | $c->stash->{svg} = $stemma->as_svg; |
3837c155 |
84 | $c->stash->{text_title} = $tradition->name; |
12720144 |
85 | $c->stash->{template} = 'index.tt'; |
86 | # TODO Run the analysis as AJAX from the loaded page. |
87 | my $t = run_analysis( $tradition ); |
88 | $c->stash->{variants} = $t->{'variants'}; |
e367f5c0 |
89 | $c->stash->{total} = $t->{'variant_count'}; |
90 | $c->stash->{genealogical} = $t->{'genealogical_count'}; |
91 | $c->stash->{conflict} = $t->{'conflict_count'}; |
e367f5c0 |
92 | } |
a275e7e6 |
93 | |
b90c84a0 |
94 | =head2 alignment_table |
95 | |
96 | Return a JSON alignment table of a given text. |
97 | |
98 | =cut |
99 | |
100 | sub alignment_table :Local { |
101 | my( $self, $c ) = @_; |
102 | my $m = $c->model( 'Directory' ); |
103 | my $tradition = $m->tradition( $c->request->params->{'textid'} ); |
104 | my $table = $tradition->collation->make_alignment_table(); |
105 | $c->stash->{'result'} => $table; |
106 | $c->forward-( 'View::JSON' ); |
107 | } |
108 | |
12720144 |
109 | =head1 OPENSOCIAL URLs |
110 | |
111 | =head2 view_table |
112 | |
113 | Simple gadget to return the analysis table for the stexaminer |
114 | |
115 | =cut |
116 | |
a275e7e6 |
117 | sub view_table :Local { |
118 | my( $self, $c ) = @_; |
3837c155 |
119 | my $m = $c->model('Directory'); |
120 | my $id = $c->request->params->{'textid'}; |
121 | my $t = run_analysis( $m->tradition( $id ), $m->stemma( $id ) ); |
a275e7e6 |
122 | $c->stash->{variants} = $t->{'variants'}; |
123 | $c->stash->{template} = 'table_gadget.tt'; |
124 | } |
125 | |
12720144 |
126 | =head2 view_svg |
127 | |
128 | Simple gadget to return the SVG for a given stemma |
129 | |
130 | =cut |
131 | |
a275e7e6 |
132 | sub view_svg :Local { |
133 | my( $self, $c ) = @_; |
3837c155 |
134 | my $m = $c->model('Directory'); |
12720144 |
135 | my $stemma = $m->tradition( $c->request->params->{'textid'} )->stemma; |
3837c155 |
136 | if( $stemma ) { |
137 | $c->stash->{svg} = $stemma->as_svg; |
138 | } |
eb1ac99d |
139 | $c->stash->{template} = 'stemma_gadget.tt'; |
a275e7e6 |
140 | } |
141 | |
dbcf12a6 |
142 | =head2 default |
143 | |
144 | Standard 404 error page |
145 | |
146 | =cut |
147 | |
148 | sub default :Path { |
149 | my ( $self, $c ) = @_; |
150 | $c->response->body( 'Page not found' ); |
151 | $c->response->status(404); |
152 | } |
153 | |
154 | =head2 end |
155 | |
156 | Attempt to render a view, if needed. |
157 | |
158 | =cut |
159 | |
160 | sub end : ActionClass('RenderView') {} |
161 | |
162 | =head1 AUTHOR |
163 | |
164 | Tara L Andrews |
165 | |
166 | =head1 LICENSE |
167 | |
168 | This library is free software. You can redistribute it and/or modify |
169 | it under the same terms as Perl itself. |
170 | |
171 | =cut |
172 | |
173 | __PACKAGE__->meta->make_immutable; |
174 | |
175 | 1; |