11 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
12 |
use SWISH::API; |
use SWISH::API; |
13 |
use JSON; |
use JSON; |
14 |
|
use Text::Unaccent::PurePerl qw/unac_string/; |
15 |
|
use HTML::FillInForm::Lite; |
16 |
|
|
17 |
my $range_around = 5; |
my $range_around = 5; |
18 |
my $entries_per_page = 30; |
my @entries_per_page = ( 30, 50, 100, 500 ); |
19 |
my $debug = param('debug'); |
my $debug = param('debug'); |
20 |
|
|
21 |
print header( |
print header( |
138 |
|
|
139 |
foreach ( @{ $db->{input} } ) { |
foreach ( @{ $db->{input} } ) { |
140 |
my $input = $_->{name} || die "no name in ",dump( $_ ); |
my $input = $_->{name} || die "no name in ",dump( $_ ); |
141 |
|
next unless defined $stats->{input}->{$input}; # skip inputs without data |
142 |
if ( ! $only_input->{'-labels'}->{$input} ) { |
if ( ! $only_input->{'-labels'}->{$input} ) { |
143 |
push @{ $only_input->{'-values'} }, $input; |
push @{ $only_input->{'-values'} }, $input; |
144 |
$only_input->{'-labels'}->{$input} = $_->{description} || $input; |
$only_input->{'-labels'}->{$input} = $_->{description} || $input; |
153 |
dump_yaml( 'style', \@style ); |
dump_yaml( 'style', \@style ); |
154 |
|
|
155 |
sub search_form { |
sub search_form { |
156 |
|
|
157 |
|
my $form_html = "$dir/$path/$path-search.html"; |
158 |
|
if ( -e $form_html ) { |
159 |
|
my $html = read_file( $form_html ); |
160 |
|
my $q = CGI->new(); |
161 |
|
my $h = HTML::FillInForm::Lite->new(); |
162 |
|
return $h->fill(\$html, $q); |
163 |
|
} |
164 |
|
|
165 |
qq|<a name="form"></a>|, |
qq|<a name="form"></a>|, |
166 |
start_form( -action => self_url( query => 0 ) ), |
start_form( -action => self_url( query => 0 ) ), |
167 |
checkbox_group( |
checkbox_group( |
171 |
), |
), |
172 |
textfield( -name => 'search' ), |
textfield( -name => 'search' ), |
173 |
$attr_operators ? popup_menu( -name => 'attr_operator', %$attr_operators ) : '', |
$attr_operators ? popup_menu( -name => 'attr_operator', %$attr_operators ) : '', |
174 |
submit, |
submit( -value => 'Search' ), |
175 |
hidden( -name => 'entries_per_page', -default => $entries_per_page ), |
# hidden( -name => 'entries_per_page', -default => $entries_per_page ), |
176 |
|
popup_menu( -name => 'entries_per_page', -values => [ @entries_per_page ], -title => 'entries per page' ), |
177 |
# we need current_page fixed at 1 so that every submit through form will reset it |
# we need current_page fixed at 1 so that every submit through form will reset it |
178 |
qq|<input type=hidden name=current_page value=1 >|, |
qq|<input type=hidden name=current_page value=1 >|, |
179 |
checkbox( -name => 'debug', -default => 0 ), # FIXME hidden? |
checkbox( -name => 'debug', -default => 0 ), # FIXME hidden? |
202 |
|
|
203 |
if ( my $search = param('search') ) { |
if ( my $search = param('search') ) { |
204 |
|
|
205 |
|
$search = unac_string( $search ); |
206 |
|
|
207 |
print qq| |
print qq| |
208 |
<a href="#form" class="skip" title="skip to search form">#</a> |
<a href="#form" class="skip" title="skip to search form">#</a> |
209 |
<div id="results"> |
<div id="results"> |
295 |
|
|
296 |
while ( my $result = $swish_results->next_result ) { |
while ( my $result = $swish_results->next_result ) { |
297 |
|
|
298 |
my $data = from_json $result->property('data'); |
my $data = $result->property('data'); |
|
|
|
299 |
dump_yaml( 'data', $data ); |
dump_yaml( 'data', $data ); |
300 |
|
# FIXME if we produce valid json we shouldn't need eval here! |
301 |
|
eval { $data = from_json( $data, {utf8 => 1} ); }; |
302 |
|
if ( $@ ) { |
303 |
|
warn "ERROR: $@ from ",dump( $data ); |
304 |
|
next; |
305 |
|
} |
306 |
|
|
307 |
my $li_class = ''; |
my $li_class = ''; |
308 |
$li_class = qq| class="z"| if $nr % 2 == 0; |
$li_class = qq| class="z"| if $nr % 2 == 0; |
311 |
next unless defined $data->{$attr}; |
next unless defined $data->{$attr}; |
312 |
my $v = $data->{$attr}; |
my $v = $data->{$attr}; |
313 |
if ( $html_markup && ! $html_markup_skip->{$attr} ) { |
if ( $html_markup && ! $html_markup_skip->{$attr} ) { |
314 |
eval "\$v = $html_markup->$attr( \$v );"; |
eval "\$v = $html_markup->$attr( \$v, \$data );"; |
315 |
if ( $@ ) { |
if ( $@ ) { |
316 |
warn "disable html markup for $attr: $@"; |
warn "disable html markup for $attr: $@"; |
317 |
$html_markup_skip->{$attr} = $@; |
$html_markup_skip->{$attr} = $@; |