blib/conf/plugins/TrackFinder.pm untested

filter: Statementstmt 0.0% 0 / 66 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 6 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 16 Podpod 0.0% 0 / 12 totaltotal 0.0% 0 / 108 CC 5 SCAR 22.0
CC
5
Cov
0%
filter_tracks
30.0
name
2.0
description
2.0
CRAP 9.0
1 package Bio::Graphics::Browser2::Plugin::TrackFinder;
2 # $Id: SourceTrackFinder.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 use Bio::Graphics::Browser2::Util 'shellwords';
7 our $VERSION = '0.25';
8  
9 sub name { "Track Finder" }
10  
11 sub description {
12 return p("The track finder filters the track table by the contents of its key, comments and select fields.");
13 }
14  
15 sub type { 'trackfilter' }
16  
17 sub init { }
18  
19 sub config_defaults {
20 my $self = shift;
21  
22 # this line gets all the options defined in the "[TrackFinder:plugin]" stanza
23 my %fields = map {$_=>undef} $self->get_fields;
24 return \%fields;
25 }
26  
27  
28 # this method gets all the options defined in the "[SourceTrackFinder:plugin]" stanza
29 sub get_fields {
30 my $self = shift;
31 return $self->browser_config->plugin_setting;
32 }
33  
34 sub reconfigure {
35 my $self = shift;
36 my $current_config = $self->configuration;
37 $current_config->{keywords} = $self->config_param('keywords');
38 }
39  
40 sub configure_form {
41 my $self = shift;
42 my $current_config = $self->configuration;
43 my $source = $self->browser_config;
44 my $html = '';
45  
46 $html .= div({-class=>'searchbody'},
47 b('Search: ').textfield(-id => 'plugin_TrackFinderKeywords',
48 -name => $self->config_name('keywords'),
49 -onKeyDown => "Controller.busy();if (typeof(timeOutID) != 'undefined') clearTimeout(timeOutID);timeOutID= setTimeout('Controller.idle();doPluginUpdate()',500)",
50 -override => 1,
51 -value => $current_config->{keywords},
52 -onBlur => 'clearTimeout(timeOutID)',
53 ),
54 input({-type => 'checkbox',
55 -id => 'stickySearch',
56 -value => 'Stick to top when scrolled'
57 }
58 ),
59 label({-for => 'stickySearch'}, 'Stick to top when scrolled')
60 );
61 $html .= button(-value => 'Clear',
62 -onClick => "\$('plugin_TrackFinderKeywords').clear();doPluginUpdate()",
63 );
64  
65 return $html;
66 }
67  
68 sub filter_tracks {
69 my $self = shift;
70 my $track_labels = shift;
71 my $source = shift;
72  
73 my $config = $self->configuration;
74 my @keywords = map {quotemeta($_)} shellwords $config->{keywords};
75 my @searches = get_fields($self);
76 my @result;
77 LABEL:
78 for my $l (@$track_labels) {
79 do {push @result,$l; next LABEL} if $l =~ /^(plugin|file|http|das)/;
80
81 my @searched_fields = @searches ? @searches :(qw(key keywords select),"subtrack select labels");
82 my $aggregate_text = join ' ',map {$source->code_setting($l=>$_)} @searched_fields;
83 $aggregate_text ||= $l;
84 my $labels = $source->subtrack_scan_list($l);
85 $aggregate_text .= " @$labels" if $labels && @$labels;
86  
87 for my $k (@keywords) {
88 next LABEL unless $aggregate_text =~ /$k/i;
89 }
90 push @result,$l;
91 }
92 return @result;
93 }
94  
95 sub hilite_terms {
96 my $self = shift;
97 my $config = $self->configuration;
98 my @keywords = map {quotemeta($_)} shellwords $config->{keywords};
99 return @keywords;
100 }
101  
102 # Scripts required by the plugin.
103 sub scripts {
104 return qw(scrollfix.js);
105 }
106  
107 # Functions to run once the content has been loaded.
108 sub onLoads {
109 my %loads = (track_page => "scrollfix.setup();");
110 return %loads;
111 }
112  
113 1;
114  
115 __END__