NAME
Metadata::DB::Search::InterfaceHTML
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.
METHODS
html_search_form_output()
returns output with interface, just the form guts
cgiapp_search_form_output()
returns search form appropriate for CGI::Application usage optional arg is next runmode name (the runmode receiving the params);
_html_tmpl_code_default()
returns the HTML::Template code that will be used you can override this in various ways see HTML::Template::Default
tmpl()
returns HTML::Template object.
GENERATE A SEARCH INTERFACE
You dont *have*to use these. These ouptut for HTML::Template loops, params, etc.
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->tmpl->param( SEARCH_OPTS_LOOP => \@search_opts_loop ):
4) now get the output, this is the interface you should show the user.
my $output = $i->tmpl->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 the keys are
'attribute_name' the label of the attribute, the name
'select_options' the values to select from, if there were few of them
'input_type' this holds 'select' or 'text', the type of field suggested in a web interface
'input_type_text' boolean
'input_type_select' boolean
Example template:
<TMPL_LOOP SEARCH_INTERFACE_LOOP>
<div>
<b><TMPL_VAR ATTRIBUTE_NAME></b><TMPL_IF INPUT_TYPE_SELECT>
<select name="<TMPL_VAR ATTRIBUTE_NAME>"><TMPL_LOOP SELECT_OPTIONS>
<option><TMPL_VAR OPTION_NAME></option></TMPL_LOOP>
</select><TMPL_ELSE>
<input type="text" name="<TMPL_VAR ATTRIBUTE_NAME>"></TMPL_IF>
</div>
</TMPL_LOOP>
Usage:
$tmpl->param( SEARCH_INTERFACE_LOOP => generate_search_interface_loop($dbh) );
=