NAME
Metadata::DB::Search::InterfaceHTML - generate html search form
DESCRIPTION
This generates html output suitable for a web search interface to the metadata this is not meant to specifially mean the metadata is about files, people, or anything this JUST provides an interface to the stuff this is NOT meant to be used live- this is meant to be used as an update tool only.
This code is separate from Metadata::DB::Analizer, because that code could be used to gen interface for tk, etc, any gui. This module IS specifically for a HTML gui.
This module usea Metadata::DB::Analizer as base.
All relevant fields are prepended with 'search_interface' by default, to change
$o->search_form_field_prepend('new_prepend_string');
METHODS
search_form_template_output()
output is html
search_form_template_code()
returns the HTML::Template code that will be used to generate the static html output returns by search_form_template_output()
you can override this in various ways see HTML::Template::Default
search_form_template_object()
returns HTML::Template object.
generate_search_form_template_params()
returns hash ref for params to load into template object
GENERATE A SEARCH INTERFACE
Generating the search form interface should be done offline.
You dont *have*to use these. These ouptut for HTML::Template loops, params, etc. You generate a search interface and save it to a static file.
generate_search_attribute_params()
argument is attribute name, and optionally a limit number if the attribute does not exist in database, warns and returns undef
returns hash ref suitable for HTML::Template
if your tmpl is:
<TMPL_LOOP SEARCH_OPTS_LOOP>
<div>
<b><TMPL_VAR ATTRIBUTE_NAME></b>
<TMPL_IF INPUT_TYPE_SELECT>
<select name="<TMPL_VAR ATTRIBUTE_NAME>">
<TMPL_LOOP SELECT_OPTIONS>
<option value="<TMPL_VAR OPTION_VALUE>"><TMPL_VAR OPTION_NAME></option>
</TMPL_LOOP>
</select>
<TMPL_ELSE>
<input type="text" name="<TMPL_VAR ATTRIBUTE_NAME>">
</TMPL_IF>
</div>
</TMPL_LOOP>
<TMPL_VAR SEARCH_INTERFACE_HIDDEN_VARS>
The following means that if there are more then 40 name possible values, show a text field, if less, show a drop down. For cars, if there are less the 20 choices (possible metadata values for they key 'car'), show dropdown, else, show text field. (The default for all of these is 15.)
my $i = Metadata::DB::Search::InterfaceHTML({ DBH => $dbh });
1) get the params for the attributes you want
my $name_opt = $i->generate_search_attribute_params('name',40);
my $car_opt = $i->generate_search_attribute_parmas('car',20);
2) build the main search options loop
my @search_opts_loop = [ $name_opt, $age_opt ];
3) feed it to the template
$i->search_form_template_object->param( SEARCH_OPTS_LOOP => \@search_opts_loop ):
4) now get the output, this is the interface you should show the user.
my $output = $i->search_form_template_object->output;
open(FILE,'>','/home/myself/public_html/search_meta.html');
print FILE $output;
close FILE;
generate_search_interface_loop()
argument is dbh returns array ref each element is a hash ref as returned by
generate_search_attribute_params($attribute_name, $limit);
Usage:
$tmpl->param( SEARCH_INTERFACE_LOOP => $self->generate_search_interface_loop($dbh) );
HOW TO CUSTOMIZE THE INTERFACE GENERATED
Please see Metadata::DB::Search::InterfaceHTML
If you alter limits for atts or change the atts selected, when you call search_template_form_output() or search_template_form_code(), they will reflect the changes
my @attribute_names = sort grep { !/path/ } @{ $self->get_search_attributes };
$self->search_attributes_selected_clear;
$self->search_attributes_selected_add( @attribute_names );
# change limit to 1000 for all atts matching 'client'
for my $att ( grep { /client/ } @attribute_names ){
$self->search_attribute_option_list_limit( $att, 1000 );
}
# output the template code, or the template output
$self->search_form_template_code;
$self->search_form_template_output;