]> mj.ucw.cz Git - pciids.git/commitdiff
Implemented search
authorMichal Vaner <vorner@ucw.cz>
Mon, 1 Sep 2008 12:47:11 +0000 (14:47 +0200)
committerMichal Vaner <vorner@ucw.cz>
Mon, 1 Sep 2008 12:47:11 +0000 (14:47 +0200)
PciIds/Address/Pci.pm
PciIds/Address/PciClass.pm
PciIds/Address/Toplevel.pm
PciIds/DBQ.pm
PciIds/Html/Jump.pm

index 27e1236ffa573799b028976e5f7ca70784ca7bcf..5fc5443eae07e1d0c179d49e1b00000974acfb19 100644 (file)
@@ -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();
index cb81c34e7a6b93915456b24c0eb2888a78057eae..c94e389da45478c695f3150662d837771e5cb3c1 100644 (file)
@@ -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();
index 2185989faebb6e2da9d336900e6c51b15ec31181..229c96c4894f8c9670e43a9d0347b81d08e46fef 100644 (file)
@@ -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
index 4eeb33e42dbc32ab771951a9900c98213abc1073..7b2de188e8cef621d651ea8cbaa2e4e75f534b90 100644 (file)
@@ -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;
index 7655c711205f5ad50e74763566c6291a07098346..9b650f258d1f84c1cfadb4bcea4b44816a722339 100644 (file)
@@ -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 "<div class='top'>\n";
+                       print "<h1>Search results</h1>\n";
+                       genMenu( $req, $address, $args, $auth, [ [ 'Help', 'help', 'jump' ], [ '', 'jump' ] ] );
+                       print "<div class='clear'></div>\n";
+                       print "</div>\n";
+                       genPath( $req, $address, 1 );
+                       print "<h2>Found items</h2>\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 "<a href='$prefix".$address->get()."$suffix'>".encode( $address->fullPretty() )."</a>";
+                       } ], sub { 1; }, sub { ' class="item"'; } );
+                       genTableTail();
+                       genHtmlTail();
+                       return OK;
+               }
        }
        genHtmlHead( $req, 'No matches', undef );
        print "<div class='top'>\n";
        print '<h1>No matches</h1>';
-       my $address = PciIds::Address::new( $req->uri() );
        genMenu( $req, $address, $args, $auth, [ [ 'Help', 'help', 'jump' ] ] );
        print "<div class='clear'></div>\n";
        print "</div\n>";