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