blob: bc8fc057fe6b7770d0e8c0565c4eb63147fc16d4 [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 => '*');
Nils Diewaldf2e02a92014-11-12 18:31:05 +000013 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 Diewald7cad8402014-07-08 17:06:56 +000020 };
21 };
22
Nils Diewald4af3f0b2014-06-25 01:43:17 +000023 return $c->respond_to(
24 json => sub {
Nils Diewald4e9fbcb2014-07-15 11:45:09 +000025 $c->render(json => $c->notifications(
26 json => $c->match_info($corpus_id, $doc_id, $match_id, %query))
27 )
Nils Diewald4af3f0b2014-06-25 01:43:17 +000028 },
29 html => sub {
Nils Diewaldf2e02a92014-11-12 18:31:05 +000030 my $match = $c->match_info($corpus_id, $doc_id, $match_id, %query);
Nils Diewald7cad8402014-07-08 17:06:56 +000031 if ($match->{error}) {
32 $c->notify(error => $match->{error});
33 return $c->render_exception('error');
34 };
35
Nils Diewald4af3f0b2014-06-25 01:43:17 +000036 $c->render(
37 layout => 'default',
38 template => 'match_info',
Nils Diewald7cad8402014-07-08 17:06:56 +000039 match => $match
Nils Diewald4af3f0b2014-06-25 01:43:17 +000040 )
41 }
42 );
Nils Diewald1eba6572014-06-17 19:49:53 +000043};
44
Nils Diewald7cad8402014-07-08 17:06:56 +000045# Todo: Return info for all collections
46sub about_collection {
47 my $c = shift;
Nils Diewald7cad8402014-07-08 17:06:56 +000048 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 Diewald1eba6572014-06-17 19:49:53 +0000581;
59
60__END__