blob: 2780ebb0b2109a16943d69f80a1c13ff40650e8b [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 Diewald4e9fbcb2014-07-15 11:45:09 +000022 $c->render(json => $c->notifications(
23 json => $c->match_info($corpus_id, $doc_id, $match_id, %query))
24 )
Nils Diewald4af3f0b2014-06-25 01:43:17 +000025 },
26 html => sub {
Nils Diewald7cad8402014-07-08 17:06:56 +000027 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 Diewald4af3f0b2014-06-25 01:43:17 +000033 $c->render(
34 layout => 'default',
35 template => 'match_info',
Nils Diewald7cad8402014-07-08 17:06:56 +000036 match => $match
Nils Diewald4af3f0b2014-06-25 01:43:17 +000037 )
38 }
39 );
Nils Diewald1eba6572014-06-17 19:49:53 +000040};
41
Nils Diewald7cad8402014-07-08 17:06:56 +000042# Todo: Return info for all collections
43sub about_collection {
44 my $c = shift;
Nils Diewald7cad8402014-07-08 17:06:56 +000045 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 Diewald1eba6572014-06-17 19:49:53 +0000551;
56
57__END__