2 =head1 SGN::Controller::AJAX::HTMLSelect - a resource to dynamically obtain html selects for a number of widely used data types
8 get_breeding_program_select()
16 Lukas Mueller <lam87@cornell.edu>
20 package SGN
::Controller
::AJAX
::HTMLSelect
;
25 use CXGN
::BreedersToolbox
::Projects
;
26 use CXGN
::Page
::FormattingHelpers qw
| simple_selectbox_html
|;
28 use CXGN
::Trial
::Folder
;
29 use SGN
::Model
::Cvterm
;
31 BEGIN { extends
'Catalyst::Controller::REST' };
34 default => 'application/json',
36 map => { 'application/json' => 'JSON', 'text/html' => 'JSON' },
40 sub get_location_select
: Path
('/ajax/html/select/locations') Args
(0) {
44 my $id = $c->req->param("id") || "location_select";
45 my $name = $c->req->param("name") || "location_select";
46 my $empty = $c->req->param("empty") || "";
48 my $locations = CXGN
::BreedersToolbox
::Projects
->new( { schema
=> $c->dbic_schema("Bio::Chado::Schema") } )->get_all_locations();
50 if ($empty) { unshift @
$locations, [ "", "please select" ] }
52 my $default = $c->req->param("default") || @
$locations[0]->[0];
54 my $html = simple_selectbox_html
(
57 choices
=> $locations,
60 $c->stash->{rest
} = { select => $html };
63 sub get_breeding_program_select
: Path
('/ajax/html/select/breeding_programs') Args
(0) {
67 my $id = $c->req->param("id") || "breeding_program_select";
68 my $name = $c->req->param("name") || "breeding_program_select";
69 my $empty = $c->req->param("empty") || "";
71 my $breeding_programs = CXGN
::BreedersToolbox
::Projects
->new( { schema
=> $c->dbic_schema("Bio::Chado::Schema") } )->get_breeding_programs();
73 my $default = $c->req->param("default") || @
$breeding_programs[0]->[0];
74 if ($empty) { unshift @
$breeding_programs, [ "", "please select" ]; }
76 my $html = simple_selectbox_html
(
79 choices
=> $breeding_programs,
82 $c->stash->{rest
} = { select => $html };
85 sub get_year_select
: Path
('/ajax/html/select/years') Args
(0) {
89 my $id = $c->req->param("id") || "year_select";
90 my $name = $c->req->param("name") || "year_select";
91 my $empty = $c->req->param("empty") || "";
92 my $auto_generate = $c->req->param("auto_generate") || "";
96 my $next_year = 1901 + (localtime)[5];
97 my $oldest_year = $next_year - 30;
98 @years = sort { $b <=> $a } ($oldest_year..$next_year);
101 @years = sort { $b <=> $a } CXGN
::BreedersToolbox
::Projects
->new( { schema
=> $c->dbic_schema("Bio::Chado::Schema") } )->get_all_years();
104 my $default = $c->req->param("default") || @years[1];
106 my $html = simple_selectbox_html
(
112 $c->stash->{rest
} = { select => $html };
115 sub get_trial_folder_select
: Path
('/ajax/html/select/folders') Args
(0) {
119 my $breeding_program_id = $c->req->param("breeding_program_id");
121 my $id = $c->req->param("id") || "folder_select";
122 my $name = $c->req->param("name") || "folder_select";
123 my $empty = $c->req->param("empty") || ""; # set if an empty selection should be present
126 my @folders = CXGN
::Trial
::Folder
->list({
127 bcs_schema
=> $c->dbic_schema("Bio::Chado::Schema"),
128 breeding_program_id
=> $breeding_program_id
132 unshift @folders, [ 0, "None" ];
135 my $html = simple_selectbox_html
(
138 choices
=> \
@folders,
140 $c->stash->{rest
} = { select => $html };
143 sub get_trial_type_select
: Path
('/ajax/html/select/trial_types') Args
(0) {
147 my $id = $c->req->param("id") || "trial_type_select";
148 my $name = $c->req->param("name") || "trial_type_select";
150 my @types = CXGN
::Trial
::get_all_project_types
($c->dbic_schema("Bio::Chado::Schema"));
152 my $default = $c->req->param("default") || @types[0]->[0];
154 my $html = simple_selectbox_html
(
160 $c->stash->{rest
} = { select => $html };
163 sub get_trials_select
: Path
('/ajax/html/select/trials') Args
(0) {
167 my $p = CXGN
::BreedersToolbox
::Projects
->new( { schema
=> $c->dbic_schema("Bio::Chado::Schema") } );
169 my $breeding_program_id = $c->req->param("breeding_program_id");
171 if (!$breeding_program_id) {
172 $projects = $p->get_breeding_programs();
174 push @
$projects, [$breeding_program_id];
177 my $id = $c->req->param("id") || "html_trial_select";
178 my $name = $c->req->param("name") || "html_trial_select";
180 foreach my $project (@
$projects) {
181 my ($field_trials, $cross_trials, $genotyping_trials) = $p->get_trials_by_breeding_program($project->[0]);
182 foreach (@
$field_trials) {
187 my $html = simple_selectbox_html
(
193 $c->stash->{rest
} = { select => $html };
196 sub get_genotyping_protocols_select
: Path
('/ajax/html/select/genotyping_protocols') Args
(0) {
200 my $id = $c->req->param("id") || "gtp_select";
201 my $name = $c->req->param("name") || "genotyping_protocol_select";
202 my $empty = $c->req->param("empty") || "";
206 my $gt_protocols = CXGN
::BreedersToolbox
::Projects
->new( { schema
=> $c->dbic_schema("Bio::Chado::Schema") } )->get_gt_protocols();
208 if (@
$gt_protocols) {
209 $default_gtp = $c->config->{default_genotyping_protocol
};
210 %gtps = map { @
$_[1] => @
$_[0] } @
$gt_protocols;
212 if(!exists($gtps{$default_gtp}) && !($default_gtp =~ /^none$/)) {
213 die "The conf variable default_genotyping_protocol: \"$default_gtp\" does not match any protocols in the database. Set it in sgn_local.conf using a protocol name from the nd_protocol table, or set it to 'none' to silence this error.";
216 $gt_protocols = ["No genotyping protocols found"];
218 my $html = simple_selectbox_html
(
221 choices
=> $gt_protocols,
222 selected
=> $gtps{$default_gtp}
224 $c->stash->{rest
} = { select => $html };
228 sub ontology_children_select
: Path
('/ajax/html/select/ontology_children') Args
(0) {
230 my $parent_node_cvterm = $c->request->param("parent_node_cvterm");
231 my $rel_cvterm = $c->request->param("rel_cvterm");
232 my $rel_cv = $c->request->param("rel_cv");
234 my $select_name = $c->request->param("selectbox_name");
235 my $select_id = $c->request->param("selectbox_id");
237 my $empty = $c->request->param("empty") || '';
239 my $schema = $c->dbic_schema('Bio::Chado::Schema', 'sgn_chado');
240 my $parent_node_cvterm_id = SGN
::Model
::Cvterm
->get_cvterm_row_from_trait_name($schema, $parent_node_cvterm)->cvterm_id();
241 my $rel_cvterm_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, $rel_cvterm, $rel_cv)->cvterm_id();
243 my $ontology_children_ref = $schema->resultset("Cv::CvtermRelationship")->search({type_id
=> $rel_cvterm_id, object_id
=> $parent_node_cvterm_id})->search_related('subject');
244 my @ontology_children;
245 while (my $child = $ontology_children_ref->next() ) {
246 my $dbxref_info = $child->search_related('dbxref');
247 my $accession = $dbxref_info->first()->accession();
248 my $db_info = $dbxref_info->search_related('db');
249 my $db_name = $db_info->first()->name();
250 push @ontology_children, [$child->name."|".$db_name.":".$accession, $child->name."|".$db_name.":".$accession];
254 unshift @ontology_children, [ 0, "None" ];
257 my $html = simple_selectbox_html
(
258 name
=> $select_name,
260 choices
=> \
@ontology_children,
262 $c->stash->{rest
} = { select => $html };