1 package TreeOfTexts::Controller::Root;
3 use namespace::autoclean;
4 use Text::Tradition::Analysis qw/ run_analysis /;
7 BEGIN { extends 'Catalyst::Controller' }
10 # Sets the actions in this controller to be registered with no prefix
11 # so they function identically to actions created in MyApp.pm
13 __PACKAGE__->config(namespace => '');
17 TreeOfTexts::Controller::Root - Root Controller for TreeOfTexts
21 [enter your description here]
27 The root page (/). Lists the traditions available in the DB to work on,
28 and should also eventually have an 'Upload new' interface.
32 sub index :Path :Args(0) {
33 my ( $self, $c ) = @_;
35 my $m = $c->model('Directory');
37 foreach my $id ( $m->tradition_ids ) {
40 'name' => $m->name( $id ),
42 push( @all_texts, $data );
45 $c->stash->{texts} = \@all_texts;
46 $c->stash->{template} = 'frontpage.tt';
49 =head2 tradition (TODO)
51 The main page for a tradition, with information about it and links to the
56 The relationship editor tool.
60 sub relationships :Local {
62 my $m = $c->model('Directory');
63 my $tradition = $m->tradition( $c->request->params->{'textid'} );
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';
73 The stemma analysis tool with the pretty colored table.
77 sub stexaminer :Local {
79 my $m = $c->model('Directory');
80 my $tradition = $m->tradition( $c->request->params->{'textid'} );
81 my $stemma = $tradition->stemma;
82 # TODO Think about caching the stemma in a session
83 $c->stash->{svg} = $stemma->as_svg;
84 $c->stash->{text_title} = $tradition->name;
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'};
89 $c->stash->{total} = $t->{'variant_count'};
90 $c->stash->{genealogical} = $t->{'genealogical_count'};
91 $c->stash->{conflict} = $t->{'conflict_count'};
94 =head2 alignment_table
96 Return a JSON alignment table of a given text.
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' );
109 =head1 OPENSOCIAL URLs
113 Simple gadget to return the analysis table for the stexaminer
117 sub view_table :Local {
118 my( $self, $c ) = @_;
119 my $m = $c->model('Directory');
120 my $id = $c->request->params->{'textid'};
121 my $t = run_analysis( $m->tradition( $id ), $m->stemma( $id ) );
122 $c->stash->{variants} = $t->{'variants'};
123 $c->stash->{template} = 'table_gadget.tt';
128 Simple gadget to return the SVG for a given stemma
132 sub view_svg :Local {
133 my( $self, $c ) = @_;
134 my $m = $c->model('Directory');
135 my $stemma = $m->tradition( $c->request->params->{'textid'} )->stemma;
137 $c->stash->{svg} = $stemma->as_svg;
139 $c->stash->{template} = 'stemma_gadget.tt';
144 Standard 404 error page
149 my ( $self, $c ) = @_;
150 $c->response->body( 'Page not found' );
151 $c->response->status(404);
156 Attempt to render a view, if needed.
160 sub end : ActionClass('RenderView') {}
168 This library is free software. You can redistribute it and/or modify
169 it under the same terms as Perl itself.
173 __PACKAGE__->meta->make_immutable;