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 => '*'); |
| 13 | if ($c->stash('foundry')) { |
| 14 | $query{foundry} = $c->stash('foundry'); |
| 15 | if ($c->stash('layer')) { |
| 16 | $query{layer} = $c->stash('layer'); |
| 17 | }; |
| 18 | }; |
| 19 | |
Nils Diewald | 4af3f0b | 2014-06-25 01:43:17 +0000 | [diff] [blame] | 20 | return $c->respond_to( |
| 21 | json => sub { |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame^] | 22 | $c->render(json => $c->notifications(json => $c->match_info($corpus_id, $doc_id, $match_id, %query))) |
Nils Diewald | 4af3f0b | 2014-06-25 01:43:17 +0000 | [diff] [blame] | 23 | }, |
| 24 | html => sub { |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame^] | 25 | my $match = $c->match_info($corpus_id, $doc_id, $match_id); |
| 26 | if ($match->{error}) { |
| 27 | $c->notify(error => $match->{error}); |
| 28 | return $c->render_exception('error'); |
| 29 | }; |
| 30 | |
Nils Diewald | 4af3f0b | 2014-06-25 01:43:17 +0000 | [diff] [blame] | 31 | $c->render( |
| 32 | layout => 'default', |
| 33 | template => 'match_info', |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame^] | 34 | match => $match |
Nils Diewald | 4af3f0b | 2014-06-25 01:43:17 +0000 | [diff] [blame] | 35 | ) |
| 36 | } |
| 37 | ); |
Nils Diewald | 1eba657 | 2014-06-17 19:49:53 +0000 | [diff] [blame] | 38 | }; |
| 39 | |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame^] | 40 | # Todo: Return info for all collections |
| 41 | sub about_collection { |
| 42 | my $c = shift; |
| 43 | my $api = $c->config('KorAP')->{'api0.1'}; |
| 44 | my $src = $c->stash('collection_id'); |
| 45 | if ($src) { |
| 46 | $c->render( |
| 47 | json => $c->notifications( |
| 48 | json => $c->info_on($src) |
| 49 | ) |
| 50 | ); |
| 51 | }; |
| 52 | }; |
| 53 | |
Nils Diewald | 1eba657 | 2014-06-17 19:49:53 +0000 | [diff] [blame] | 54 | 1; |
| 55 | |
| 56 | __END__ |