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'} ); |
64 | $c->stash->{alignment} = $tradition->collation->make_alignment_table( 'refs' ); |
65 | $c->stash->{template} = 'relationships.tt'; |
66 | } |
67 | |
12720144 |
68 | =head2 stexaminer |
69 | |
70 | The stemma analysis tool with the pretty colored table. |
71 | |
72 | =cut |
73 | |
3837c155 |
74 | sub stexaminer :Local { |
e367f5c0 |
75 | my( $self, $c ) = @_; |
3837c155 |
76 | my $m = $c->model('Directory'); |
12720144 |
77 | my $tradition = $m->tradition( $c->request->params->{'textid'} ); |
78 | my $stemma = $tradition->stemma; |
79 | # TODO Think about caching the stemma in a session |
3837c155 |
80 | $c->stash->{svg} = $stemma->as_svg; |
3837c155 |
81 | $c->stash->{text_title} = $tradition->name; |
12720144 |
82 | $c->stash->{template} = 'index.tt'; |
83 | # TODO Run the analysis as AJAX from the loaded page. |
84 | my $t = run_analysis( $tradition ); |
85 | $c->stash->{variants} = $t->{'variants'}; |
e367f5c0 |
86 | $c->stash->{total} = $t->{'variant_count'}; |
87 | $c->stash->{genealogical} = $t->{'genealogical_count'}; |
88 | $c->stash->{conflict} = $t->{'conflict_count'}; |
e367f5c0 |
89 | } |
a275e7e6 |
90 | |
12720144 |
91 | =head1 OPENSOCIAL URLs |
92 | |
93 | =head2 view_table |
94 | |
95 | Simple gadget to return the analysis table for the stexaminer |
96 | |
97 | =cut |
98 | |
a275e7e6 |
99 | sub view_table :Local { |
100 | my( $self, $c ) = @_; |
3837c155 |
101 | my $m = $c->model('Directory'); |
102 | my $id = $c->request->params->{'textid'}; |
103 | my $t = run_analysis( $m->tradition( $id ), $m->stemma( $id ) ); |
a275e7e6 |
104 | $c->stash->{variants} = $t->{'variants'}; |
105 | $c->stash->{template} = 'table_gadget.tt'; |
106 | } |
107 | |
12720144 |
108 | =head2 view_svg |
109 | |
110 | Simple gadget to return the SVG for a given stemma |
111 | |
112 | =cut |
113 | |
a275e7e6 |
114 | sub view_svg :Local { |
115 | my( $self, $c ) = @_; |
3837c155 |
116 | my $m = $c->model('Directory'); |
12720144 |
117 | my $stemma = $m->tradition( $c->request->params->{'textid'} )->stemma; |
3837c155 |
118 | if( $stemma ) { |
119 | $c->stash->{svg} = $stemma->as_svg; |
120 | } |
eb1ac99d |
121 | $c->stash->{template} = 'stemma_gadget.tt'; |
a275e7e6 |
122 | } |
123 | |
dbcf12a6 |
124 | =head2 default |
125 | |
126 | Standard 404 error page |
127 | |
128 | =cut |
129 | |
130 | sub default :Path { |
131 | my ( $self, $c ) = @_; |
132 | $c->response->body( 'Page not found' ); |
133 | $c->response->status(404); |
134 | } |
135 | |
136 | =head2 end |
137 | |
138 | Attempt to render a view, if needed. |
139 | |
140 | =cut |
141 | |
142 | sub end : ActionClass('RenderView') {} |
143 | |
144 | =head1 AUTHOR |
145 | |
146 | Tara L Andrews |
147 | |
148 | =head1 LICENSE |
149 | |
150 | This library is free software. You can redistribute it and/or modify |
151 | it under the same terms as Perl itself. |
152 | |
153 | =cut |
154 | |
155 | __PACKAGE__->meta->make_immutable; |
156 | |
157 | 1; |