split stemma lib into util and object; make phylip_input microservice
[scpubgit/stemmatology.git] / TreeOfTexts / lib / TreeOfTexts / Controller / Root.pm
CommitLineData
dbcf12a6 1package TreeOfTexts::Controller::Root;
2use Moose;
3use namespace::autoclean;
3837c155 4use Text::Tradition::Analysis qw/ run_analysis /;
5
dbcf12a6 6
7BEGIN { 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
17TreeOfTexts::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 27The root page (/). Lists the traditions available in the DB to work on,
28and should also eventually have an 'Upload new' interface.
dbcf12a6 29
30=cut
31
32sub 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
51The main page for a tradition, with information about it and links to the
52available tools.
53
54=head2 relationships
55
56The relationship editor tool.
57
58=cut
59
3837c155 60sub relationships :Local {
61 my( $self, $c ) = @_;
62 my $m = $c->model('Directory');
63 my $tradition = $m->tradition( $c->request->params->{'textid'} );
b90c84a0 64 my $table = $tradition->collation->make_alignment_table();
68454b71 65 my $witlist = map { $_->{'witness'} } @{$table->{'alignment'}};
66 $c->stash->{witnesses} = $witlist;
b90c84a0 67 $c->stash->{alignment} = $table;
68 $c->stash->{template} = 'relate.tt';
3837c155 69}
70
12720144 71=head2 stexaminer
72
73The stemma analysis tool with the pretty colored table.
74
75=cut
76
3837c155 77sub stexaminer :Local {
e367f5c0 78 my( $self, $c ) = @_;
3837c155 79 my $m = $c->model('Directory');
12720144 80 my $tradition = $m->tradition( $c->request->params->{'textid'} );
81 my $stemma = $tradition->stemma;
82 # TODO Think about caching the stemma in a session
3837c155 83 $c->stash->{svg} = $stemma->as_svg;
3837c155 84 $c->stash->{text_title} = $tradition->name;
12720144 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'};
e367f5c0 89 $c->stash->{total} = $t->{'variant_count'};
90 $c->stash->{genealogical} = $t->{'genealogical_count'};
91 $c->stash->{conflict} = $t->{'conflict_count'};
e367f5c0 92}
a275e7e6 93
b90c84a0 94=head2 alignment_table
95
96Return a JSON alignment table of a given text.
97
98=cut
99
100sub 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();
68454b71 105 $c->stash->{'result'} = $table;
b90c84a0 106 $c->forward-( 'View::JSON' );
107}
108
12720144 109=head1 OPENSOCIAL URLs
110
111=head2 view_table
112
113Simple gadget to return the analysis table for the stexaminer
114
115=cut
116
a275e7e6 117sub view_table :Local {
118 my( $self, $c ) = @_;
3837c155 119 my $m = $c->model('Directory');
120 my $id = $c->request->params->{'textid'};
121 my $t = run_analysis( $m->tradition( $id ), $m->stemma( $id ) );
a275e7e6 122 $c->stash->{variants} = $t->{'variants'};
123 $c->stash->{template} = 'table_gadget.tt';
124}
125
12720144 126=head2 view_svg
127
128Simple gadget to return the SVG for a given stemma
129
130=cut
131
a275e7e6 132sub view_svg :Local {
133 my( $self, $c ) = @_;
3837c155 134 my $m = $c->model('Directory');
12720144 135 my $stemma = $m->tradition( $c->request->params->{'textid'} )->stemma;
3837c155 136 if( $stemma ) {
137 $c->stash->{svg} = $stemma->as_svg;
138 }
eb1ac99d 139 $c->stash->{template} = 'stemma_gadget.tt';
a275e7e6 140}
141
dbcf12a6 142=head2 default
143
144Standard 404 error page
145
146=cut
147
148sub default :Path {
149 my ( $self, $c ) = @_;
150 $c->response->body( 'Page not found' );
151 $c->response->status(404);
152}
153
154=head2 end
155
156Attempt to render a view, if needed.
157
158=cut
159
160sub end : ActionClass('RenderView') {}
161
162=head1 AUTHOR
163
164Tara L Andrews
165
166=head1 LICENSE
167
168This library is free software. You can redistribute it and/or modify
169it under the same terms as Perl itself.
170
171=cut
172
173__PACKAGE__->meta->make_immutable;
174
1751;