convert Catalyst app to use KiokuDB backend
[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 (/)
28
29 =cut
30
31 sub index :Path :Args(0) {
32     my ( $self, $c ) = @_;
33
34     my $m = $c->model('Directory');
35     my @all_texts;
36     foreach my $id ( $m->traditions ) {
37         my $data = { 
38                 'id' => $id,
39                 'name' => $m->tradition( $id )->name,
40                 'has_stemma' => defined $m->stemma( $id ),
41         };
42         push( @all_texts, $data );
43     }
44     
45     $c->stash->{texts} = \@all_texts;
46     $c->stash->{template} = 'frontpage.tt';
47 }
48
49 sub relationships :Local {
50         my( $self, $c ) = @_;
51         my $m = $c->model('Directory');
52         my $tradition = $m->tradition( $c->request->params->{'textid'} );
53         $c->stash->{alignment} = $tradition->collation->make_alignment_table( 'refs' );
54         $c->stash->{template} = 'relationships.tt';     
55 }
56
57 sub stexaminer :Local {
58     my( $self, $c ) = @_;
59     my $m = $c->model('Directory');
60         my $id = $c->request->params->{'textid'};
61         my $tradition = $m->tradition( $id );
62         my $stemma = $m->stemma( $id );
63         my $t = run_analysis( $tradition, $stemma );
64         $c->stash->{svg} = $stemma->as_svg;
65         $c->stash->{variants} = $t->{'variants'};
66         $c->stash->{text_title} = $tradition->name;
67         $c->stash->{total} = $t->{'variant_count'};
68         $c->stash->{genealogical} = $t->{'genealogical_count'};
69         $c->stash->{conflict} = $t->{'conflict_count'};
70         $c->stash->{template} = 'index.tt'; 
71 }
72
73 sub view_table :Local {
74     my( $self, $c ) = @_;
75     my $m = $c->model('Directory');
76         my $id = $c->request->params->{'textid'};
77         my $t = run_analysis( $m->tradition( $id ), $m->stemma( $id ) );
78         $c->stash->{variants} = $t->{'variants'};
79     $c->stash->{template} = 'table_gadget.tt';
80 }
81
82 sub view_svg :Local {
83     my( $self, $c ) = @_;
84     my $m = $c->model('Directory');
85         my $stemma = $m->stemma( $c->request->params->{'textid'} );
86         if( $stemma ) {
87                 $c->stash->{svg} = $stemma->as_svg;
88         }
89     $c->stash->{template} = 'stemma_gadget.tt';
90 }
91
92 =head2 default
93
94 Standard 404 error page
95
96 =cut
97
98 sub default :Path {
99     my ( $self, $c ) = @_;
100     $c->response->body( 'Page not found' );
101     $c->response->status(404);
102 }
103
104 =head2 end
105
106 Attempt to render a view, if needed.
107
108 =cut
109
110 sub end : ActionClass('RenderView') {}
111
112 =head1 AUTHOR
113
114 Tara L Andrews
115
116 =head1 LICENSE
117
118 This library is free software. You can redistribute it and/or modify
119 it under the same terms as Perl itself.
120
121 =cut
122
123 __PACKAGE__->meta->make_immutable;
124
125 1;