[Bio] / Sprout / SearchHelper.pm Repository:
ViewVC logotype

Diff of /Sprout/SearchHelper.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.18, Sat Nov 18 20:36:49 2006 UTC revision 1.23, Wed Dec 6 03:35:42 2006 UTC
# Line 257  Line 257 
257    
258  =over 4  =over 4
259    
260  =item query  =item cgi
261    
262  The CGI query object for the current script.  The CGI query object for the current script.
263    
# Line 267  Line 267 
267    
268  sub new {  sub new {
269      # Get the parameters.      # Get the parameters.
270      my ($class, $query) = @_;      my ($class, $cgi) = @_;
271      # Check for a session ID.      # Check for a session ID.
272      my $session_id = $query->param("SessionID");      my $session_id = $cgi->param("SessionID");
273      my $type = "old";      my $type = "old";
274      if (! $session_id) {      if (! $session_id) {
275          # Here we're starting a new session. We create the session ID and          # Here we're starting a new session. We create the session ID and
276          # store it in the query object.          # store it in the query object.
277          $session_id = NewSessionID();          $session_id = NewSessionID();
278          $type = "new";          $type = "new";
279          $query->param(-name => 'SessionID', -value => $session_id);          $cgi->param(-name => 'SessionID', -value => $session_id);
280      }      }
281      # Compute the subclass name.      # Compute the subclass name.
282      $class =~ /SH(.+)$/;      my $subClass;
283      my $subClass = $1;      if ($class =~ /SH(.+)$/) {
284            # Here we have a real search class.
285            $subClass = $1;
286        } else {
287            # Here we have a bare class. The bare class cannot search, but it can
288            # process search results.
289            $subClass = 'SearchHelper';
290        }
291      # Insure everybody knows we're in Sprout mode.      # Insure everybody knows we're in Sprout mode.
292      $query->param(-name => 'SPROUT', -value => 1);      $cgi->param(-name => 'SPROUT', -value => 1);
293      # Generate the form name.      # Generate the form name.
294      my $formName = "$class$formCount";      my $formName = "$class$formCount";
295      $formCount++;      $formCount++;
# Line 290  Line 297 
297      # as well as an indicator as to whether or not the session is new, plus the      # as well as an indicator as to whether or not the session is new, plus the
298      # class name and a placeholder for the Sprout object.      # class name and a placeholder for the Sprout object.
299      my $retVal = {      my $retVal = {
300                    query => $query,                    query => $cgi,
301                    type => $type,                    type => $type,
302                    class => $subClass,                    class => $subClass,
303                    sprout => undef,                    sprout => undef,
# Line 672  Line 679 
679          push @colNames, $self->DefaultFeatureColumns();          push @colNames, $self->DefaultFeatureColumns();
680          # Add any additional columns requested by the feature filter.          # Add any additional columns requested by the feature filter.
681          push @colNames, FeatureQuery::AdditionalColumns($self);          push @colNames, FeatureQuery::AdditionalColumns($self);
682            Trace("Full column list determined.") if T(3);
683          # Save the full list.          # Save the full list.
684          $self->{cols} = \@colNames;          $self->{cols} = \@colNames;
685          # Write out the column headers. This also prepares the cache file to receive          # Write out the column headers. This also prepares the cache file to receive
686          # output.          # output.
687            Trace("Writing column headers.") if T(3);
688          $self->WriteColumnHeaders(map { $self->FeatureColumnTitle($_) } @{$self->{cols}});          $self->WriteColumnHeaders(map { $self->FeatureColumnTitle($_) } @{$self->{cols}});
689            Trace("Column headers written.") if T(3);
690      }      }
691      # Get the feature ID.      # Get the feature ID.
692      my $fid = $fd->FID();      my $fid = $fd->FID();
# Line 979  Line 989 
989    
990  sub ComputeFASTA {  sub ComputeFASTA {
991      # Get the parameters.      # Get the parameters.
992      my ($self, $incomingType, $desiredType, $sequence) = @_;      my ($self, $desiredType, $sequence) = @_;
993      # Declare the return variable. If an error occurs, it will remain undefined.      # Declare the return variable. If an error occurs, it will remain undefined.
994      my $retVal;      my $retVal;
995      # This variable will be cleared if an error is detected.      # This variable will be cleared if an error is detected.
# Line 1515  Line 1525 
1525                                                      -default => $pageSize) . " " .                                                      -default => $pageSize) . " " .
1526                                     $cgi->checkbox(-name => 'ShowURL',                                     $cgi->checkbox(-name => 'ShowURL',
1527                                                    -value => 1,                                                    -value => 1,
1528                                                    -label => 'Show URL')),                                                    -label => 'Show URL',
1529                                                      -checked => 1)),
1530                            $cgi->td($cgi->submit(-class => 'goButton',                            $cgi->td($cgi->submit(-class => 'goButton',
1531                                                  -name => 'Search',                                                  -name => 'Search',
1532                                                  -value => $realCaption)));                                                  -value => $realCaption)));
# Line 1705  Line 1716 
1716    
1717  =head3 ComputeSearchURL  =head3 ComputeSearchURL
1718    
1719  C<< my $url = $shelp->ComputeSearchURL(); >>  C<< my $url = $shelp->ComputeSearchURL(%overrides); >>
1720    
1721  Compute the GET-style URL for the current search. In order for this to work, there  Compute the GET-style URL for the current search. In order for this to work, there
1722  must be a copy of the search form on the current page. This will always be the  must be a copy of the search form on the current page. This will always be the
# Line 1715  Line 1726 
1726  main complication is that if the user specified all genomes, we'll want to  main complication is that if the user specified all genomes, we'll want to
1727  remove the parameter entirely from a get-style URL.  remove the parameter entirely from a get-style URL.
1728    
1729    =over 4
1730    
1731    =item overrides
1732    
1733    Hash containing override values for the parameters, where the parameter name is
1734    the key and the parameter value is the override value. If the override value is
1735    C<undef>, the parameter will be deleted from the result.
1736    
1737    =item RETURN
1738    
1739    Returns a GET-style URL for invoking the search with the specified overrides.
1740    
1741    =back
1742    
1743  =cut  =cut
1744    
1745  sub ComputeSearchURL {  sub ComputeSearchURL {
1746      # Get the parameters.      # Get the parameters.
1747      my ($self) = @_;      my ($self, %overrides) = @_;
1748      # Get the database and CGI query object.      # Get the database and CGI query object.
1749      my $cgi = $self->Q();      my $cgi = $self->Q();
1750      my $sprout = $self->DB();      my $sprout = $self->DB();
# Line 1760  Line 1785 
1785              if ($allFlag) {              if ($allFlag) {
1786                  @values = ();                  @values = ();
1787              }              }
1788            } elsif (exists $overrides{$parmKey}) {
1789                # Here the value is being overridden, so we skip it for now.
1790                @values = ();
1791          }          }
1792          # If we still have values, create the URL parameters.          # If we still have values, create the URL parameters.
1793          if (@values) {          if (@values) {
1794              push @urlList, map { "$parmKey=" . uri_escape($_) } @values;              push @urlList, map { "$parmKey=" . uri_escape($_) } @values;
1795          }          }
1796      }      }
1797        # Now do the overrides.
1798        for my $overKey (keys %overrides) {
1799            # Only use this override if it's not a delete marker.
1800            if (defined $overrides{$overKey}) {
1801                push @urlList, "$overKey=" . uri_escape($overrides{$overKey});
1802            }
1803        }
1804      # Add the parameters to the URL.      # Add the parameters to the URL.
1805      $retVal .= "?" . join(";", @urlList);      $retVal .= "?" . join(";", @urlList);
1806      # Return the result.      # Return the result.
# Line 2197  Line 2232 
2232    
2233  =head2 Feature Column Methods  =head2 Feature Column Methods
2234    
2235  The methods in this column manage feature column data. If you want to provide the  The methods in this section manage feature column data. If you want to provide the
2236  capability to include new types of data in feature columns, then all the changes  capability to include new types of data in feature columns, then all the changes
2237  are made to this section of the source file. Technically, this should be implemented  are made to this section of the source file. Technically, this should be implemented
2238  using object-oriented methods, but this is simpler for non-programmers to maintain.  using object-oriented methods, but this is simpler for non-programmers to maintain.
# Line 2272  Line 2307 
2307      } elsif ($colName =~ /^keyword:(.+)$/) {      } elsif ($colName =~ /^keyword:(.+)$/) {
2308          $retVal = ucfirst $1;          $retVal = ucfirst $1;
2309      } elsif ($colName eq 'orgName') {      } elsif ($colName eq 'orgName') {
2310          $retVal = "Gene Name";          $retVal = "Organism and Gene ID";
2311      } elsif ($colName eq 'protlink') {      } elsif ($colName eq 'protlink') {
2312          $retVal = "NMPDR Protein Page";          $retVal = "NMPDR Protein Page";
2313      } elsif ($colName eq 'subsystem') {      } elsif ($colName eq 'subsystem') {
# Line 2345  Line 2380 
2380          ($retVal) = $record->Value('Feature(assignment)');          ($retVal) = $record->Value('Feature(assignment)');
2381      } elsif ($colName eq 'gblink') {      } elsif ($colName eq 'gblink') {
2382          # Here we want a link to the GBrowse page using the official GBrowse button.          # Here we want a link to the GBrowse page using the official GBrowse button.
2383          $retVal = Formlet('GBrowse', "GetGBrowse.cgi", undef,          $retVal = FakeButton('GBrowse', "GetGBrowse.cgi", undef,
2384                            fid => $fid);                            fid => $fid);
2385      } elsif ($colName eq 'group') {      } elsif ($colName eq 'group') {
2386          # Get the NMPDR group name.          # Get the NMPDR group name.
# Line 2363  Line 2398 
2398          $retVal = $self->FeatureName($fid);          $retVal = $self->FeatureName($fid);
2399      } elsif ($colName eq 'protlink') {      } elsif ($colName eq 'protlink') {
2400          # Here we want a link to the protein page using the official NMPDR button.          # Here we want a link to the protein page using the official NMPDR button.
2401          $retVal = Formlet('NMPDR', "protein.cgi", undef,          $retVal = FakeButton('NMPDR', "protein.cgi", undef,
2402                            prot => $fid, SPROUT => 1, new_framework => 0,                            prot => $fid, SPROUT => 1, new_framework => 0,
2403                            user => '');                            user => '');
2404      }elsif ($colName eq 'subsystem') {      }elsif ($colName eq 'subsystem') {
# Line 2432  Line 2467 
2467          # Get the subsystems.          # Get the subsystems.
2468          Trace("Generating subsystems for feature $fid.") if T(4);          Trace("Generating subsystems for feature $fid.") if T(4);
2469          my %subs = $sprout->SubsystemsOf($fid);          my %subs = $sprout->SubsystemsOf($fid);
2470          # Convert them to links.          # Extract the subsystem names.
2471          my @links = map { HTML::sub_link($cgi, $_) } sort keys %subs;          my @names = map { HTML::sub_link($cgi, $_) } sort keys %subs;
2472          # String them into a list.          # String them into a list.
2473          $retVal = join(", ", @links);          $retVal = join(", ", @names);
2474      } elsif ($type =~ /^keyword:(.+)$/) {      } elsif ($type =~ /^keyword:(.+)$/) {
2475          # Here the caller wants the value of the named keyword. The text is the          # Here the caller wants the value of the named keyword. The text is the
2476          # feature ID.          # feature ID.
# Line 2557  Line 2592 
2592      if (! @wordList) {      if (! @wordList) {
2593          if ($required) {          if ($required) {
2594              $self->SetMessage("No search words specified.");              $self->SetMessage("No search words specified.");
2595            } else {
2596                $retVal = 1;
2597          }          }
2598      } elsif (! @plusWords) {      } elsif (! @plusWords) {
2599          $self->SetMessage("At least one keyword must be positive. All the keywords entered are preceded by minus signs.");          $self->SetMessage("At least one keyword must be positive. All the keywords entered are preceded by minus signs.");
# Line 2567  Line 2604 
2604      return $retVal;      return $retVal;
2605  }  }
2606    
2607    =head3 FakeButton
2608    
2609    C<< my $html = SearchHelper::FakeButton($caption, $url, $target, %parms); >>
2610    
2611    Create a fake button that hyperlinks to the specified URL with the specified parameters.
2612    Unlike a real button, this one won't visibly click, but it will take the user to the
2613    correct place.
2614    
2615    The parameters of this method are deliberately identical to L</Formlet> so that we
2616    can switch easily from real buttons to fake ones in the code.
2617    
2618    =over 4
2619    
2620    =item caption
2621    
2622    Caption to be put on the button.
2623    
2624    =item url
2625    
2626    URL for the target page or script.
2627    
2628    =item target
2629    
2630    Frame or target in which the new page should appear. If C<undef> is specified,
2631    the default target will be used.
2632    
2633    =item parms
2634    
2635    Hash containing the parameter names as keys and the parameter values as values.
2636    These will be appended to the URL.
2637    
2638    =back
2639    
2640    =cut
2641    
2642    sub FakeButton {
2643        # Get the parameters.
2644        my ($caption, $url, $target, %parms) = @_;
2645        # Declare the return variable.
2646        my $retVal;
2647        # Compute the target URL.
2648        my $targetUrl = "$url?" . join(";", map { "$_=" . uri_escape($parms{$_}) } keys %parms);
2649        # Compute the target-frame HTML.
2650        my $targetHtml = ($target ? " target=\"$target\"" : "");
2651        # Assemble the result.
2652        return "<a href=\"$targetUrl\" $targetHtml><div class=\"button2 button\">$caption</div></a>";
2653    }
2654    
2655  =head3 Formlet  =head3 Formlet
2656    
2657  C<< my $html = SearchHelper::Formlet($caption, $url, $target, %parms); >>  C<< my $html = SearchHelper::Formlet($caption, $url, $target, %parms); >>

Legend:
Removed from v.1.18  
changed lines
  Added in v.1.23

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3