fix up CTE parser, including an ugly hack I need, with new graph
[scpubgit/stemmatology.git] / TreeOfTexts / lib / TreeOfTexts / Controller / Root.pm
1 package TreeOfTexts::Controller::Root;
2 use Moose;
3 use namespace::autoclean;
4 use Text::Tradition::Analysis qw/ run_analysis /;
5
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
27 The root page (/).  Lists the traditions available in the DB to work on,
28 and should also eventually have an 'Upload new' interface.
29
30 =cut
31
32 sub index :Path :Args(0) {
33     my ( $self, $c ) = @_;
34
35     my $m = $c->model('Directory');
36     my @all_texts;
37     foreach my $id ( $m->tradition_ids ) {
38         my $data = { 
39                 'id' => $id,
40                 'name' => $m->name( $id ),
41         };
42         push( @all_texts, $data );
43     }
44     
45     $c->stash->{texts} = \@all_texts;
46     $c->stash->{template} = 'frontpage.tt';
47 }
48
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
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
68 =head2 stexaminer
69
70 The stemma analysis tool with the pretty colored table.
71
72 =cut
73
74 sub stexaminer :Local {
75     my( $self, $c ) = @_;
76     my $m = $c->model('Directory');
77         my $tradition = $m->tradition( $c->request->params->{'textid'} );
78         my $stemma = $tradition->stemma;
79         # TODO Think about caching the stemma in a session 
80         $c->stash->{svg} = $stemma->as_svg;
81         $c->stash->{text_title} = $tradition->name;
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'};
86         $c->stash->{total} = $t->{'variant_count'};
87         $c->stash->{genealogical} = $t->{'genealogical_count'};
88         $c->stash->{conflict} = $t->{'conflict_count'};
89 }
90
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
99 sub view_table :Local {
100     my( $self, $c ) = @_;
101     my $m = $c->model('Directory');
102         my $id = $c->request->params->{'textid'};
103         my $t = run_analysis( $m->tradition( $id ), $m->stemma( $id ) );
104         $c->stash->{variants} = $t->{'variants'};
105     $c->stash->{template} = 'table_gadget.tt';
106 }
107
108 =head2 view_svg
109
110 Simple gadget to return the SVG for a given stemma
111
112 =cut
113
114 sub view_svg :Local {
115     my( $self, $c ) = @_;
116     my $m = $c->model('Directory');
117     my $stemma = $m->tradition( $c->request->params->{'textid'} )->stemma;
118         if( $stemma ) {
119                 $c->stash->{svg} = $stemma->as_svg;
120         }
121     $c->stash->{template} = 'stemma_gadget.tt';
122 }
123
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;