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 = map { $_->{'witness'} } @{$table->{'alignment'}};
66 $c->stash->{witnesses} = $witlist;
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 MICROSERVICE CALLS
113 Parse the passed collation data and return an SVG of the collated text. Takes
114 the following parameters:
118 =item * data - The collation data itself.
120 =item * input - The data format. Valid values include CollateX, Self, TEI (for parallel segmentation) eventually Tabular.
122 =item * name - A name for the text. Not so important for this function.
126 # Utility function to render SVG from a graph input.
127 sub renderSVG :Local {
128 my( $self, $c ) = @_;
129 my $format = $c->request->param('format') || 'string';
130 my $type = $c->request->body_params->{'type'};
131 my $name = $c->request->param('name') || 'Collation graph';
132 my $data = $c->request->body_params->{'data'};
133 $c->log->debug( $data );
134 my $tradition = Text::Tradition->new(
139 $c->log->debug( "Got tradition with " . $tradition->collation->readings . " readings" );
140 $c->stash->{'result'} = $tradition->collation->as_svg;
141 $c->forward('View::SVG');
145 =head1 OPENSOCIAL URLs
149 Simple gadget to return the analysis table for the stexaminer
153 sub view_table :Local {
154 my( $self, $c ) = @_;
155 my $m = $c->model('Directory');
156 my $id = $c->request->params->{'textid'};
157 my $t = run_analysis( $m->tradition( $id ), $m->stemma( $id ) );
158 $c->stash->{variants} = $t->{'variants'};
159 $c->stash->{template} = 'table_gadget.tt';
164 Simple gadget to return the SVG for a given stemma
168 sub view_svg :Local {
169 my( $self, $c ) = @_;
170 my $m = $c->model('Directory');
171 my $stemma = $m->tradition( $c->request->params->{'textid'} )->stemma;
173 $c->stash->{svg} = $stemma->as_svg;
175 $c->stash->{template} = 'stemma_gadget.tt';
180 Standard 404 error page
185 my ( $self, $c ) = @_;
186 $c->response->body( 'Page not found' );
187 $c->response->status(404);
192 Attempt to render a view, if needed.
196 sub end : ActionClass('RenderView') {}
204 This library is free software. You can redistribute it and/or modify
205 it under the same terms as Perl itself.
209 __PACKAGE__->meta->make_immutable;