blob: b4c5d91766e964e472af132d59029a00b026353c [file] [log] [blame]
Nils Diewald1eba6572014-06-17 19:49:53 +00001package Korap::Info;
2use Mojo::Base 'Mojolicious::Controller';
3
4sub about_match {
5 my $c = shift;
Nils Diewald1eba6572014-06-17 19:49:53 +00006
Nils Diewald4af3f0b2014-06-25 01:43:17 +00007 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 Diewald7cad8402014-07-08 17:06:56 +000011 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 Diewald4af3f0b2014-06-25 01:43:17 +000020 return $c->respond_to(
21 json => sub {
Nils Diewald7cad8402014-07-08 17:06:56 +000022 $c->render(json => $c->notifications(json => $c->match_info($corpus_id, $doc_id, $match_id, %query)))
Nils Diewald4af3f0b2014-06-25 01:43:17 +000023 },
24 html => sub {
Nils Diewald7cad8402014-07-08 17:06:56 +000025 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 Diewald4af3f0b2014-06-25 01:43:17 +000031 $c->render(
32 layout => 'default',
33 template => 'match_info',
Nils Diewald7cad8402014-07-08 17:06:56 +000034 match => $match
Nils Diewald4af3f0b2014-06-25 01:43:17 +000035 )
36 }
37 );
Nils Diewald1eba6572014-06-17 19:49:53 +000038};
39
Nils Diewald7cad8402014-07-08 17:06:56 +000040# Todo: Return info for all collections
41sub 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 Diewald1eba6572014-06-17 19:49:53 +0000541;
55
56__END__