From 871452fe48d25d2c28b4c72af4bdda12fb50ee4b Mon Sep 17 00:00:00 2001 From: Michal Vaner Date: Mon, 1 Sep 2008 13:54:44 +0200 Subject: [PATCH] Direct jump works Jump to a given ID works, needs to implement search in names --- PciIds/Html/Handler.pm | 4 ++- PciIds/Html/Jump.pm | 62 ++++++++++++++++++++++++++++++++++++++++++ PciIds/Html/Util.pm | 8 ++++-- 3 files changed, 70 insertions(+), 4 deletions(-) diff --git a/PciIds/Html/Handler.pm b/PciIds/Html/Handler.pm index 879086a..dfb518a 100644 --- a/PciIds/Html/Handler.pm +++ b/PciIds/Html/Handler.pm @@ -11,6 +11,7 @@ use PciIds::Html::Changes; use PciIds::Html::Admin; use PciIds::Html::Notifications; use PciIds::Html::Help; +use PciIds::Html::Jump; use Apache2::Const qw(:common :http); $ENV{'PATH'} = ''; @@ -52,7 +53,8 @@ my %handlers = ( 'respass-confirm' => \&PciIds::Html::Users::resetPasswdConfirmFormSubmit, 'profile' => \&PciIds::Html::Users::profileFormSubmit, 'admin' => \&PciIds::Html::Admin::submitAdminForm, - 'notifications' => \&PciIds::Html::Notifications::notifFormSubmit + 'notifications' => \&PciIds::Html::Notifications::notifFormSubmit, + 'jump' => \&PciIds::Html::Jump::jump } ); diff --git a/PciIds/Html/Jump.pm b/PciIds/Html/Jump.pm index 58f7f2a..7655c71 100644 --- a/PciIds/Html/Jump.pm +++ b/PciIds/Html/Jump.pm @@ -1,6 +1,12 @@ +package PciIds::Html::Jump; use strict; use warnings; use base 'Exporter'; +use PciIds::Html::Forms; +use PciIds::Html::Users; +use PciIds::Html::Util; +use PciIds::Address; +use Apache2::Const qw(:common :http); our @EXPORT = qw(&jumpWindow); @@ -11,3 +17,59 @@ sub jumpWindow( $$ ) { print "\n"; print "\n"; } + +sub redirect( $$$ ) { + my( $req, $args, $addr ) = @_; + my $prefix = ( !defined $args->{'action'} || $args->{'action'} eq '' || $args->{'action'} eq 'list' ) ? 'read' : 'mods'; + my $url = "http://".$req->hostname()."/$prefix/$addr".buildArgs( $args ); + return HTTPRedirect( $req, $url ); +} + +sub itemExists( $$ ) { + my( $tables, $addr ) = @_; + return defined $tables->item( $addr ); +} + +sub tryDirect( $$$$ ) { + my( $req, $args, $tables, $search ) = @_; + my $address = PciIds::Address::new( $req->uri() ); + #Is it absolute address? + $search =~ s/:/\//g; + $search =~ s/ //g; + my( $top ) = $address->get() =~ /^([^\/]+)/; + $search =~ s/^\//$top\//; + my $saddr = PciIds::Address::new( $search ); + return redirect( $req, $args, $saddr->get() ) if( defined $saddr && itemExists( $tables, $saddr->get() ) ); + while( defined $address ) { + $saddr = PciIds::Address::new( $address->get()."/$search" ); + return redirect( $req, $args, $saddr->get() ) if( defined $saddr && itemExists( $tables, $saddr->get() ) ); + $address = $address->parent(); + } + return undef; +} + +sub jump( $$$$ ) { + my( $req, $args, $tables, $auth ) = @_; + $args->{'action'} = delete $args->{'origin'}; + my $search = getFormValue( 'where', '' ); + my $idOnly = $search =~ s/^#//; + my $direct = tryDirect( $req, $args, $tables, $search ); + return $direct if defined $direct; + unless( $idOnly ) {#Try extended search + + } + genHtmlHead( $req, 'No matches', undef ); + print "
\n"; + print '

No matches

'; + my $address = PciIds::Address::new( $req->uri() ); + genMenu( $req, $address, $args, $auth, [ [ 'Help', 'help', 'jump' ] ] ); + print "
\n"; + print ""; + genPath( $req, $address, 1 ); + print "

Your search request matches no item. Would you like to try again?\n

\n"; + jumpWindow( $req, $args ); + genHtmlTail(); + return OK; +} + +1; diff --git a/PciIds/Html/Util.pm b/PciIds/Html/Util.pm index e912ef7..060dff1 100644 --- a/PciIds/Html/Util.pm +++ b/PciIds/Html/Util.pm @@ -4,7 +4,6 @@ use warnings; use HTML::Entities; use base 'Exporter'; use PciIds::Users; -use PciIds::Html::Jump; use Apache2::Const qw(:common :http); use APR::Table; @@ -53,7 +52,8 @@ sub genCustomMenu( $$$$ ) { my( $label, $action, $param ) = @{$_}; if( $action eq 'jump' ) { print "

  • \n"; - jumpWindow( $req, $args ); + require PciIds::Html::Jump; + PciIds::Html::Jump::jumpWindow( $req, $args ); } else { my $prefix = '/mods'; $prefix = '/read' if( !defined( $action ) or ( $action eq 'list' ) or ( $action eq '' ) or ( $action eq 'help' ) ); @@ -125,7 +125,9 @@ sub parseArgs( $ ) { sub buildArgs( $ ) { my( $args ) = @_; my $result = ''; - $result .= "?$_=".$args->{$_} foreach( keys %{$args} ); + foreach( keys %{$args} ) { + $result .= "?$_=".$args->{$_} if( defined $args->{$_} ); + } return $result; } -- 2.39.5