| 1 | package Bio::Graphics::Browser2::Plugin::SimpleTrackFinder; | ||
| 2 | # $Id: SimpleTrackFinder.pm,v 1.2 2009-05-20 21:29:40 lstein Exp $ | ||
| 3 | use strict; | ||
| 4 | use CGI qw(:standard *table); | ||
| 5 | use base 'Bio::Graphics::Browser2::Plugin'; | ||
| 6 | our $VERSION = '0.25'; | ||
| 7 | |||
| 8 | sub name { "Simple Track Finder" } | ||
| 9 | |||
| 10 | sub description { | ||
| 11 | return p("The simple track finder filters the track table by the name of the track."); | ||
| 12 | } | ||
| 13 | |||
| 14 | sub type { 'trackfilter' } | ||
| 15 | |||
| 16 | sub init { } | ||
| 17 | |||
| 18 | sub config_defaults { | ||
| 19 | my $self = shift; | ||
| 20 | return { | ||
| 21 | track_name => undef, | ||
| 22 | }; | ||
| 23 | } | ||
| 24 | |||
| 25 | sub reconfigure { | ||
| 26 | my $self = shift; | ||
| 27 | my $current_config = $self->configuration; | ||
| 28 | $current_config->{track_name} = $self->config_param('track_name'); | ||
| 29 | } | ||
| 30 | |||
| 31 | sub configure_form { | ||
| 32 | my $self = shift; | ||
| 33 | my $current_config = $self->configuration; | ||
| 34 | my $name = $current_config->{track_name}; | ||
| 35 | return | ||
| 36 | b('Partial or full track name:'). | ||
| 37 | textfield(-id => 'track_name_filter', | ||
| 38 | -name => $self->config_name('track_name'), | ||
| 39 | -default => $name, | ||
| 40 | -override => 1, | ||
| 41 | -onKeyDown=>'if (event.keyCode==13) doPluginUpdate()', | ||
| 42 | ). | ||
| 43 | button(-value => 'Clear', | ||
| 44 | -onClick => "\$('track_name_filter').clear(); doPluginUpdate()"); | ||
| 45 | } | ||
| 46 | |||
| 47 | sub filter_tracks { | ||
| 48 | my $self = shift; | ||
| 49 | my $tracks = shift; | ||
| 50 | my $source = shift; | ||
| 51 | |||
| 52 | my $config = $self->configuration; | ||
| 53 | my $name = $config->{track_name} or return @$tracks; | ||
| 54 | |||
| 55 | my @filtered = grep { | ||
| 56 | my $key = $source->setting($_=>'key') || $_; | ||
| 57 | $key =~ m/$name/i | ||
| 58 | } @$tracks; | ||
| 59 | warn "name = $name, filtered = @filtered"; | ||
| 60 | return @filtered; | ||
| 61 | } | ||
| 62 | |||
| 63 | 1; | ||
| 64 | |||
| 65 | __END__ |