From cd3e762ec2244149e284b2677cd208a2a29f872e Mon Sep 17 00:00:00 2001 From: Michal Vaner Date: Mon, 1 Sep 2008 14:47:11 +0200 Subject: [PATCH] Implemented search --- PciIds/Address/Pci.pm | 14 ++++++++++++++ PciIds/Address/PciClass.pm | 13 +++++++++++++ PciIds/Address/Toplevel.pm | 4 ++++ PciIds/DBQ.pm | 11 +++++++++-- PciIds/Html/Jump.pm | 32 ++++++++++++++++++++++++++++---- 5 files changed, 68 insertions(+), 6 deletions(-) diff --git a/PciIds/Address/Pci.pm b/PciIds/Address/Pci.pm index 27e1236..5fc5443 100644 --- a/PciIds/Address/Pci.pm +++ b/PciIds/Address/Pci.pm @@ -10,6 +10,20 @@ sub new( $ ) { return bless PciIds::Address::Base::new( $address ); } +sub fullPretty( $ ) { + $_ = shift->get(); + s/^PC\/?//; + s/\//:/g; + if( /:.*:/ ) { + s/^/PCI subsystem /; + } elsif( /:/ ) { + s/^/PCI device /; + } else { + s/^/PCI vendor /; + } + return $_; +} + sub pretty( $ ) { my $self = shift; $_ = $self->get(); diff --git a/PciIds/Address/PciClass.pm b/PciIds/Address/PciClass.pm index cb81c34..c94e389 100644 --- a/PciIds/Address/PciClass.pm +++ b/PciIds/Address/PciClass.pm @@ -10,6 +10,19 @@ sub new( $ ) { return bless PciIds::Address::Base::new( $address ); } +sub fullPretty( $ ) { + $_ = shift->get(); + s/^PC\/?//; + s/\//:/g; + if( /:.*:/ ) { + s/^/Program interface /; + } elsif( /:/ ) { + s/^/PCI device subclass /; + } else { + s/^/PCI device class /; + } + return $_; +} sub pretty( $ ) { my $self = shift; $_ = $self->get(); diff --git a/PciIds/Address/Toplevel.pm b/PciIds/Address/Toplevel.pm index 2185989..229c96c 100644 --- a/PciIds/Address/Toplevel.pm +++ b/PciIds/Address/Toplevel.pm @@ -21,6 +21,10 @@ sub pretty( $ ) { } } +sub fullPretty( $ ) { + return pretty( shift ); +} + sub restrictRex( $$ ) { my( $self, $restrict ) = @_; return PciIds::Address::new( $self->get().'/0000' )->restrictRex( $restrict );#Nasty trick, get the right address of any subnode and try it there diff --git a/PciIds/DBQ.pm b/PciIds/DBQ.pm index 4eeb33e..7b2de18 100644 --- a/PciIds/DBQ.pm +++ b/PciIds/DBQ.pm @@ -91,8 +91,9 @@ sub new( $ ) { pending.user, pending.reason, history.time, history.location', 'dropnotifsxmpp' => 'DELETE FROM pending WHERE notification = 1 AND EXISTS ( SELECT 1 FROM users WHERE users.id = pending.user AND nextxmpp <= ? )', 'dropnotifsmail' => 'DELETE FROM pending WHERE notification = 0 AND EXISTS ( SELECT 1 FROM users WHERE users.id = pending.user AND nextmail <= ? )', - 'time' => 'SELECT NOW()' - + 'time' => 'SELECT NOW()', + 'searchname' => 'SELECT l.id, l.name, p.name FROM locations AS l JOIN locations AS p ON l.parent = p.id WHERE l.name LIKE ? ORDER BY l.id', + 'searchlocalname' => 'SELECT l.id, l.name, p.name FROM locations AS l JOIN locations AS p ON l.parent = p.id WHERE l.name LIKE ? AND l.id LIKE ? ORDER BY l.id' } ); } @@ -321,4 +322,10 @@ sub dropNotifs( $$ ) { $self->command( 'dropnotifsxmpp', [ $time ] ); } +sub searchName( $$$ ) { + my( $self, $search, $prefix ) = @_; + return $self->query( 'searchlocalname', [ "%$search%", "$prefix/%" ] ) if defined $prefix; + return $self->query( 'searchname', [ "%$search%" ] ); +} + 1; diff --git a/PciIds/Html/Jump.pm b/PciIds/Html/Jump.pm index 7655c71..9b650f2 100644 --- a/PciIds/Html/Jump.pm +++ b/PciIds/Html/Jump.pm @@ -5,6 +5,7 @@ use base 'Exporter'; use PciIds::Html::Forms; use PciIds::Html::Users; use PciIds::Html::Util; +use PciIds::Html::Format; use PciIds::Address; use Apache2::Const qw(:common :http); @@ -33,11 +34,11 @@ sub itemExists( $$ ) { 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\//; + #Is it absolute address? my $saddr = PciIds::Address::new( $search ); return redirect( $req, $args, $saddr->get() ) if( defined $saddr && itemExists( $tables, $saddr->get() ) ); while( defined $address ) { @@ -55,13 +56,36 @@ sub jump( $$$$ ) { my $idOnly = $search =~ s/^#//; my $direct = tryDirect( $req, $args, $tables, $search ); return $direct if defined $direct; - unless( $idOnly ) {#Try extended search - + my $address = PciIds::Address::new( $req->uri() ); + unless( $idOnly || length $search < 3 ) {#Try extended search + my( $prefix ) = $address->get() =~ /^([^\/]+)/; + $prefix = undef if $search =~ s/^\*//; + my $result = $tables->searchName( $search, $prefix ); + if( @{$result} ) { + genHtmlHead( $req, 'Search results', undef ); + print "
\n"; + print "

Search results

\n"; + genMenu( $req, $address, $args, $auth, [ [ 'Help', 'help', 'jump' ], [ '', 'jump' ] ] ); + print "
\n"; + print "
\n"; + genPath( $req, $address, 1 ); + print "

Found items

\n"; + genTableHead( 'found', [ 'ID', 'Name', 'Parent' ], [] ); + my $prefix = 'http://'.$req->hostname().'/'.( ( !defined $args->{'action'} || $args->{'action'} eq '' || $args->{'action'} eq 'list' ) ? 'read/' : 'mods/' ); + my $suffix = buildArgs( $args ); + htmlFormatTable( $result, 3, [], [ sub { + my $addr = shift; + my $address = PciIds::Address::new( $addr ); + return "".encode( $address->fullPretty() ).""; + } ], sub { 1; }, sub { ' class="item"'; } ); + genTableTail(); + genHtmlTail(); + return OK; + } } 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 ""; -- 2.39.2