r1850@llin: dpavlin | 2009-04-26 02:07:56 +0200
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 26 Apr 2009 00:07:58 +0000 (00:07 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 26 Apr 2009 00:07:58 +0000 (00:07 +0000)
 implement attribute labels in webpac2.cgi

git-svn-id: svn+ssh://mjesec/home/dpavlin/svn/webpac2/trunk@1174 07558da8-63fa-0310-ba24-9fe276d99e06

TODO
vhost/ecas/ecas-labels.txt [new file with mode: 0644]
vhost/ecas/ecas-operators.txt [new file with mode: 0644]
vhost/webpac2.cgi

diff --git a/TODO b/TODO
index df6b591..48b2516 100644 (file)
--- a/TODO
+++ b/TODO
@@ -55,6 +55,7 @@
 + use UTF-8 as internal encoding
 + dump stats into var/stats.yml
 + WebPAC::Output::SWISH for indexing with swish-e [2.35]
+- implement attribute labels in webpac2.cgi
 - fix encoding for swish-e and/or webpac2.cgi
 - marc_clone to copy records/fields/indicators from input marc
 - rewrite WebPAC::Input to be based on Module::Pluggable or Moose
diff --git a/vhost/ecas/ecas-labels.txt b/vhost/ecas/ecas-labels.txt
new file mode 100644 (file)
index 0000000..4e443c2
--- /dev/null
@@ -0,0 +1,7 @@
+title          Naslov
+issn           ISSN
+collection     Zbirka
+url            URL
+language       Jezik
+keyword                Kljucne rijeci
+publisher      Izdavac
diff --git a/vhost/ecas/ecas-operators.txt b/vhost/ecas/ecas-operators.txt
new file mode 100644 (file)
index 0000000..9f7ecf0
--- /dev/null
@@ -0,0 +1,3 @@
+Q*                     Bilo koja riječ
+BW Q                   Početak
+BW Q EW                        Točan oblik
index 8cadc19..a5a5c92 100755 (executable)
@@ -106,24 +106,25 @@ my $stats;
 
 my $db = $config->{databases}->{$database};
 
-my @attr = keys %{ $stats->{attr} }; # FIXME replace with real gnerated lookup
+sub read_config_txt {
+       my ( $file ) = @_;
+       my $input;
+       foreach ( split(/[\n\r]+/, read_file( "$dir/$path/$path-$file.txt" ) ) ) {
+               my ( $val,$label ) = split(/\s*\t\s*/,$_,2);
+               push @{ $input->{ '-values' } }, $val;
+                               $input->{ '-labels' }->{$val} = $label;
+       }
+       return $input;
+}
 
-# XXX pipe delimit list!
-my $select_attr_operators = << '__ATTR_OPERATORS__';
-Q*                     |       Bilo koja riječ
-BW Q           |       Početak
-BW Q EW                |       Točan oblik
-__ATTR_OPERATORS__
+my $attr_labels    = read_config_txt 'labels';
+my $attr_operators = read_config_txt 'operators';
 
-my $attr_operator;
+my @attr = @{ $attr_labels->{'-values'} };
+@attr = keys %{ $stats->{attr} } unless @attr;
 
-foreach ( split(/[\n\r]+/, $select_attr_operators ) ) {
-       my ( $operator,$label ) = split(/\s+\|\s+/,$_,2);
-       push @{ $attr_operator->{ '-values' } }, $operator;
-               $attr_operator->{ '-labels' }->{$operator} = $label;
-}
 
-warn "## attr_operator = ", dump( $attr_operator );
+warn dump( $attr_labels, $attr_operators );
 
 my $only_input;
 
@@ -151,11 +152,11 @@ print
        start_form( -action => self_url( query => 0 ) ),
                radio_group(
                        -name => 'attr',
-                       -values => [ @attr ],
+                       %$attr_labels,
 #                      -linebreak => 0,
                ),
                textfield( -name => 'search' ),
-               popup_menu( -name => 'attr_operator', %$attr_operator ),
+               popup_menu( -name => 'attr_operator', %$attr_operators ),
                submit,
                hidden( -name => 'entries_per_page', -default => $entries_per_page ),
                # we need current_page fixed at 1 so that every submit through form will reset it
@@ -263,7 +264,8 @@ if ( my $search = param('search') ) {
                                                $html_markup_skip->{$attr} = $@;
                                        }
                                }
-                               print qq|<div><label>$attr</label><span class=$attr>$v</span></div>\n|;
+                               my $label = $attr_labels->{'-labels'}->{$attr} || $attr;
+                               print qq|<div><label>$label</label><span class=$attr>$v</span></div>\n|;
                        }
                        print qq|</li>\n|;
                }