Nils Diewald | 1eba657 | 2014-06-17 19:49:53 +0000 | [diff] [blame] | 1 | package Korap::Info; |
| 2 | use Mojo::Base 'Mojolicious::Controller'; |
| 3 | |
| 4 | sub about_match { |
| 5 | my $c = shift; |
Nils Diewald | 1eba657 | 2014-06-17 19:49:53 +0000 | [diff] [blame] | 6 | |
Nils Diewald | 4af3f0b | 2014-06-25 01:43:17 +0000 | [diff] [blame] | 7 | my $corpus_id = $c->stash('corpus_id'); |
| 8 | my $doc_id = $c->stash('doc_id'); |
| 9 | my $match_id = $c->stash('match_id'); |
| 10 | |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame] | 11 | my $foundry = '*'; |
| 12 | my %query = (foundry => '*'); |
Nils Diewald | f2e02a9 | 2014-11-12 18:31:05 +0000 | [diff] [blame^] | 13 | if ($c->param('foundry')) { |
| 14 | $query{foundry} = $c->param('foundry'); |
| 15 | if ($c->param('layer')) { |
| 16 | $query{layer} = $c->param('layer'); |
| 17 | }; |
| 18 | if ($c->param('spans')) { |
| 19 | $query{spans} = 'true'; |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame] | 20 | }; |
| 21 | }; |
| 22 | |
Nils Diewald | 4af3f0b | 2014-06-25 01:43:17 +0000 | [diff] [blame] | 23 | return $c->respond_to( |
| 24 | json => sub { |
Nils Diewald | 4e9fbcb | 2014-07-15 11:45:09 +0000 | [diff] [blame] | 25 | $c->render(json => $c->notifications( |
| 26 | json => $c->match_info($corpus_id, $doc_id, $match_id, %query)) |
| 27 | ) |
Nils Diewald | 4af3f0b | 2014-06-25 01:43:17 +0000 | [diff] [blame] | 28 | }, |
| 29 | html => sub { |
Nils Diewald | f2e02a9 | 2014-11-12 18:31:05 +0000 | [diff] [blame^] | 30 | my $match = $c->match_info($corpus_id, $doc_id, $match_id, %query); |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame] | 31 | if ($match->{error}) { |
| 32 | $c->notify(error => $match->{error}); |
| 33 | return $c->render_exception('error'); |
| 34 | }; |
| 35 | |
Nils Diewald | 4af3f0b | 2014-06-25 01:43:17 +0000 | [diff] [blame] | 36 | $c->render( |
| 37 | layout => 'default', |
| 38 | template => 'match_info', |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame] | 39 | match => $match |
Nils Diewald | 4af3f0b | 2014-06-25 01:43:17 +0000 | [diff] [blame] | 40 | ) |
| 41 | } |
| 42 | ); |
Nils Diewald | 1eba657 | 2014-06-17 19:49:53 +0000 | [diff] [blame] | 43 | }; |
| 44 | |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame] | 45 | # Todo: Return info for all collections |
| 46 | sub about_collection { |
| 47 | my $c = shift; |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame] | 48 | my $src = $c->stash('collection_id'); |
| 49 | if ($src) { |
| 50 | $c->render( |
| 51 | json => $c->notifications( |
| 52 | json => $c->info_on($src) |
| 53 | ) |
| 54 | ); |
| 55 | }; |
| 56 | }; |
| 57 | |
Nils Diewald | 1eba657 | 2014-06-17 19:49:53 +0000 | [diff] [blame] | 58 | 1; |
| 59 | |
| 60 | __END__ |