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
|;
27 use Scalar
::Util qw
| looks_like_number
|;
31 use CXGN
::Trial
::Folder
;
32 use SGN
::Model
::Cvterm
;
33 use CXGN
::Chado
::Stock
;
34 use CXGN
::Stock
::Search
;
35 use CXGN
::Stock
::Seedlot
;
38 BEGIN { extends
'Catalyst::Controller::REST' };
41 default => 'application/json',
43 map => { 'application/json' => 'JSON', 'text/html' => 'JSON' },
47 sub get_location_select
: Path
('/ajax/html/select/locations') Args
(0) {
51 my $id = $c->req->param("id") || "location_select";
52 my $name = $c->req->param("name") || "location_select";
53 my $empty = $c->req->param("empty") || "";
55 my $locations = CXGN
::BreedersToolbox
::Projects
->new( { schema
=> $c->dbic_schema("Bio::Chado::Schema") } )->get_all_locations();
57 if ($empty) { unshift @
$locations, [ "", "Select Location" ] }
59 my $default = $c->req->param("default") || @
$locations[0]->[0];
61 my $html = simple_selectbox_html
(
64 choices
=> $locations,
67 $c->stash->{rest
} = { select => $html };
70 sub get_breeding_program_select
: Path
('/ajax/html/select/breeding_programs') Args
(0) {
74 my $id = $c->req->param("id") || "breeding_program_select";
75 my $name = $c->req->param("name") || "breeding_program_select";
76 my $empty = $c->req->param("empty") || "";
78 my $breeding_programs = CXGN
::BreedersToolbox
::Projects
->new( { schema
=> $c->dbic_schema("Bio::Chado::Schema") } )->get_breeding_programs();
80 my $default = $c->req->param("default") || @
$breeding_programs[0]->[0];
81 if ($empty) { unshift @
$breeding_programs, [ "", "please select" ]; }
83 my $html = simple_selectbox_html
(
86 choices
=> $breeding_programs,
89 $c->stash->{rest
} = { select => $html };
92 sub get_year_select
: Path
('/ajax/html/select/years') Args
(0) {
96 my $id = $c->req->param("id") || "year_select";
97 my $name = $c->req->param("name") || "year_select";
98 my $empty = $c->req->param("empty") || "";
99 my $auto_generate = $c->req->param("auto_generate") || "";
102 if ($auto_generate) {
103 my $next_year = 1901 + (localtime)[5];
104 my $oldest_year = $next_year - 30;
105 @years = sort { $b <=> $a } ($oldest_year..$next_year);
108 @years = sort { $b <=> $a } CXGN
::BreedersToolbox
::Projects
->new( { schema
=> $c->dbic_schema("Bio::Chado::Schema") } )->get_all_years();
111 my $default = $c->req->param("default") || $years[1];
113 my $html = simple_selectbox_html
(
119 $c->stash->{rest
} = { select => $html };
122 sub get_trial_folder_select
: Path
('/ajax/html/select/folders') Args
(0) {
126 my $breeding_program_id = $c->req->param("breeding_program_id");
127 my $folder_for_trials = 1 ?
$c->req->param("folder_for_trials") eq 'true' : 0;
128 my $folder_for_crosses = 1 ?
$c->req->param("folder_for_crosses") eq 'true' : 0;
130 my $id = $c->req->param("id") || "folder_select";
131 my $name = $c->req->param("name") || "folder_select";
132 my $empty = $c->req->param("empty") || ""; # set if an empty selection should be present
135 my @folders = CXGN
::Trial
::Folder
->list({
136 bcs_schema
=> $c->dbic_schema("Bio::Chado::Schema"),
137 breeding_program_id
=> $breeding_program_id,
138 folder_for_trials
=> $folder_for_trials,
139 folder_for_crosses
=> $folder_for_crosses
143 unshift @folders, [ 0, "None" ];
146 my $html = simple_selectbox_html
(
149 choices
=> \
@folders,
151 $c->stash->{rest
} = { select => $html };
154 sub get_trial_type_select
: Path
('/ajax/html/select/trial_types') Args
(0) {
158 my $id = $c->req->param("id") || "trial_type_select";
159 my $name = $c->req->param("name") || "trial_type_select";
160 my $empty = $c->req->param("empty") || ""; # set if an empty selection should be present
162 my @types = CXGN
::Trial
::get_all_project_types
($c->dbic_schema("Bio::Chado::Schema"));
165 unshift @types, [ '', "None" ];
168 my $default = $c->req->param("default") || $types[0]->[0];
170 my $html = simple_selectbox_html
(
176 $c->stash->{rest
} = { select => $html };
179 sub get_treatments_select
: Path
('/ajax/html/select/treatments') Args
(0) {
182 my $schema = $c->dbic_schema("Bio::Chado::Schema");
183 my $trial_id = $c->req->param("trial_id");
185 my $id = $c->req->param("id") || "treatment_select";
186 my $name = $c->req->param("name") || "treatment_select";
187 my $empty = $c->req->param("empty") || ""; # set if an empty selection should be present
189 my $trial = CXGN
::Trial
->new({ bcs_schema
=> $schema, trial_id
=> $trial_id });
190 my $data = $trial->get_treatments();
193 unshift @
$data, [ 0, "None" ];
195 my $html = simple_selectbox_html
(
200 $c->stash->{rest
} = { select => $html };
203 sub get_trials_select
: Path
('/ajax/html/select/trials') Args
(0) {
206 my $p = CXGN
::BreedersToolbox
::Projects
->new( { schema
=> $c->dbic_schema("Bio::Chado::Schema") } );
207 my $breeding_program_id = $c->req->param("breeding_program_id");
210 if (!$breeding_program_id) {
211 $projects = $p->get_breeding_programs();
213 push @
$projects, [$breeding_program_id];
216 my $id = $c->req->param("id") || "html_trial_select";
217 my $name = $c->req->param("name") || "html_trial_select";
218 my $size = $c->req->param("size");
219 my $empty = $c->req->param("empty") || "";
220 my $multiple = $c->req->param("multiple") || 0;
221 my $live_search = $c->req->param("live_search") || 0;
224 foreach my $project (@
$projects) {
225 my ($field_trials, $cross_trials, $genotyping_trials) = $p->get_trials_by_breeding_program($project->[0]);
226 foreach (@
$field_trials) {
230 @trials = sort { $a->[1] cmp $b->[1] } @trials;
232 if ($empty) { unshift @trials, [ "", "Please select a trial" ]; }
234 my $html = simple_selectbox_html
(
235 multiple
=> $multiple,
236 live_search
=> $live_search,
242 $c->stash->{rest
} = { select => $html };
246 sub get_label_data_source_select
: Path
('/ajax/html/select/label_data_sources') Args
(0) {
249 print STDERR
"Retrieving list items . . .\n";
251 my $id = $c->req->param("id") || "label_data_sources_select";
252 my $name = $c->req->param("name") || "label_data_sources_select";
253 my $empty = $c->req->param("empty") || "";
254 my $live_search = $c->req->param("live_search") ?
'data-live-search="true"' : '';
255 my $default = $c->req->param("default") || 0;
257 my $user_id = $c->user()->get_sp_person_id();
258 my $lists = CXGN
::List
::available_lists
($c->dbc->dbh(), $user_id, 'plots');
259 my $public_lists = CXGN
::List
::available_public_lists
($c->dbc->dbh(), 'plots');
261 my $p = CXGN
::BreedersToolbox
::Projects
->new( { schema
=> $c->dbic_schema("Bio::Chado::Schema") } );
262 my $projects = $p->get_breeding_programs();
264 my (@field_trials, @cross_trials, @genotyping_trials) = [];
265 foreach my $project (@
$projects) {
266 my ($field_trials, $cross_trials, $genotyping_trials) = $p->get_trials_by_breeding_program($project->[0]);
267 foreach (@
$field_trials) {
268 push @field_trials, $_;
270 foreach (@
$cross_trials) {
271 push @cross_trials, $_;
273 foreach (@
$genotyping_trials) {
274 push @genotyping_trials, $_;
279 push @choices, '__Your Plot Lists';
280 foreach my $item (@
$lists) {
281 push @choices, [@
$item[0], @
$item[1]];
283 push @choices, '__Public Plot Lists';
284 foreach my $item (@
$public_lists) {
285 push @choices, [@
$item[0], @
$item[1]];
287 push @choices, '__Field Trials';
288 @field_trials = sort { $a->[1] cmp $b->[1] } @field_trials;
289 foreach my $trial (@field_trials) {
290 push @choices, $trial;
292 push @choices, '__Genotyping Trials';
293 @genotyping_trials = sort { $a->[1] cmp $b->[1] } @genotyping_trials;
294 foreach my $trial (@genotyping_trials) {
295 push @choices, $trial;
297 push @choices, '__Cross Trials';
298 @cross_trials = sort { $a->[1] cmp $b->[1] } @cross_trials;
299 foreach my $trial (@cross_trials) {
300 push @choices, $trial;
303 print STDERR
"Choices are:\n".Dumper
(@choices);
305 if ($default) { unshift @choices, [ '', $default ]; }
307 my $html = simple_selectbox_html
(
310 choices
=> \
@choices,
311 params
=> $live_search,
312 selected_params
=> 'hidden'
315 $c->stash->{rest
} = { select => $html };
317 # sub get_trials_select : Path('/ajax/html/select/trials') Args(0) {
321 # my $id = $c->req->param("id") || "label_data_sources_select";
322 # my $name = $c->req->param("name") || "label_data_sources_select";
323 # my $empty = $c->req->param("empty") || "";
324 # my $live_search = $c->req->param("live_search") ? 'data-live-search="true"' : '';
325 # my $default = $c->req->param("default") || 0;
327 # my $lists = CXGN::List::available_lists($c->dbc->dbh(), $c->user(), 'plots');
328 # my $public_lists = CXGN::List::available_public_lists($c->dbc->dbh(), 'plots');
330 # my $projects = CXGN::BreedersToolbox::Projects->new( { schema => $c->dbic_schema("Bio::Chado::Schema") } )->get_breeding_programs();
332 # foreach my $project (@$projects) {
333 # my ($field_trials, $cross_trials, $genotyping_trials) = $projects->get_trials_by_breeding_program($project->[0]);
334 # foreach (@$field_trials) {
338 # @trials = sort { $a->[1] cmp $b->[1] } @trials;
341 # push @choices, '__Your Plot Lists';
342 # foreach my $item (@$lists) {
343 # push @choices, $item;
345 # push @choices, '__Public Plot Lists';
346 # foreach my $item (@$public_lists) {
347 # push @choices, $item;
349 # push @choices, '__Trials';
350 # foreach my $trial (@trials) {
351 # push @choices, $trial;
354 # print STDERR "Choices are:\n".Dumper(@choices);
356 # if ($default) { unshift @trials, [ '', $default ]; }
358 # my $html = simple_selectbox_html(
361 # choices => \@choices,
362 # params => $live_search
365 # $c->stash->{rest} = { select => $html };
368 sub get_stocks_select
: Path
('/ajax/html/select/stocks') Args
(0) {
371 my $params = _clean_inputs
($c->req->params);
372 my $names_as_select = $params->{names_as_select
}->[0] || 0;
374 my %stockprops_values;
375 if ($params->{organization_list
} && scalar(@
{$params->{organization_list
}})>0){
376 $stockprops_values{'organization'} = $params->{organization_list
};
378 if ($params->{pui_list
} && scalar(@
{$params->{pui_list
}})>0){
379 $stockprops_values{'PUI'} = $params->{pui_list
};
381 if ($params->{accession_number_list
} && scalar(@
{$params->{accession_number_list
}})>0){
382 $stockprops_values{'accession number'} = $params->{accession_number_list
};
385 my $stock_search = CXGN
::Stock
::Search
->new({
386 bcs_schema
=>$c->dbic_schema("Bio::Chado::Schema", "sgn_chado"),
387 people_schema
=>$c->dbic_schema("CXGN::People::Schema"),
388 phenome_schema
=>$c->dbic_schema("CXGN::Phenome::Schema"),
389 match_type
=>$params->{match_type
}->[0],
390 match_name
=>$params->{match_type
}->[0],
391 uniquename_list
=>$params->{uniquename_list
},
392 genus_list
=>$params->{genus_list
},
393 species_list
=>$params->{species_list
},
394 stock_id_list
=>$params->{stock_id_list
},
395 organism_id
=>$params->{organism_id
}->[0],
396 stock_type_name
=>$params->{stock_type_name
}->[0],
397 stock_type_id
=>$params->{stock_type_id
}->[0],
398 owner_first_name
=>$params->{owner_first_name
}->[0],
399 owner_last_name
=>$params->{owner_last_name
}->[0],
400 trait_cvterm_name_list
=>$params->{trait_cvterm_name_list
},
401 minimum_phenotype_value
=>$params->{minimum_phenotype_value
}->[0],
402 maximum_phenotype_value
=>$params->{maximum_phenotype_value
}->[0],
403 trial_name_list
=>$params->{trial_name_list
},
404 trial_id_list
=>$params->{trial_id_list
},
405 breeding_program_id_list
=>$params->{breeding_program_id_list
},
406 location_name_list
=>$params->{location_name_list
},
407 year_list
=>$params->{year_list
},
408 stockprops_values
=>\
%stockprops_values,
409 limit
=>$params->{limit
}->[0],
410 offset
=>$params->{offset
}->[0],
414 my ($result, $records_total) = $stock_search->search();
415 #print STDERR Dumper $result;
416 my $id = $c->req->param("id") || "html_trial_select";
417 my $name = $c->req->param("name") || "html_trial_select";
418 my $multiple = defined($c->req->param("multiple")) ?
$c->req->param("multiple") : 1;
419 my $size = $c->req->param("size");
420 my $empty = $c->req->param("empty") || "";
421 my $data_related = $c->req->param("data-related") || "";
423 foreach my $r (@
$result) {
424 if ($names_as_select) {
425 push @stocks, [ $r->{uniquename
}, $r->{uniquename
} ];
427 push @stocks, [ $r->{stock_id
}, $r->{uniquename
} ];
430 @stocks = sort { $a->[1] cmp $b->[1] } @stocks;
432 if ($empty) { unshift @stocks, [ "", "Please select a stock" ]; }
434 my $html = simple_selectbox_html
(
435 multiple
=> $multiple,
440 data_related
=> $data_related
442 $c->stash->{rest
} = { select => $html };
445 sub get_seedlots_select
: Path
('/ajax/html/select/seedlots') Args
(0) {
448 my $accessions = $c->req->param('seedlot_content_accession_name') ?
[$c->req->param('seedlot_content_accession_name')] : [];
449 my $crosses = $c->req->param('seedlot_content_cross_name') ?
[$c->req->param('seedlot_content_cross_name')] : [];
450 my ($list, $records_total) = CXGN
::Stock
::Seedlot
->list_seedlots(
451 $c->dbic_schema("Bio::Chado::Schema", "sgn_chado"),
452 $c->dbic_schema("CXGN::People::Schema"),
453 $c->dbic_schema("CXGN::Phenome::Schema"),
454 $c->req->param('seedlot_offset'),
455 $c->req->param('seedlot_limit'),
456 $c->req->param('seedlot_name'),
457 $c->req->param('seedlot_breeding_program_name'),
458 $c->req->param('seedlot_location'),
459 $c->req->param('seedlot_amount'),
465 foreach my $sl (@
$list) {
467 breeding_program_id
=> $sl->{breeding_program_id
},
468 breeding_program_name
=> $sl->{breeding_program_name
},
469 seedlot_stock_id
=> $sl->{seedlot_stock_id
},
470 seedlot_stock_uniquename
=> $sl->{seedlot_stock_uniquename
},
471 location
=> $sl->{location
},
472 location_id
=> $sl->{location_id
},
473 count
=> $sl->{current_count
}
476 #print STDERR Dumper \@seedlots;
477 my $id = $c->req->param("id") || "html_trial_select";
478 my $name = $c->req->param("name") || "html_trial_select";
479 my $multiple = defined($c->req->param("multiple")) ?
$c->req->param("multiple") : 1;
480 my $size = $c->req->param("size");
481 my $empty = $c->req->param("empty") || "";
482 my $data_related = $c->req->param("data-related") || "";
484 foreach my $r (@seedlots) {
485 push @stocks, [ $r->{seedlot_stock_id
}, $r->{seedlot_stock_uniquename
} ];
487 @stocks = sort { $a->[1] cmp $b->[1] } @stocks;
489 if ($empty) { unshift @stocks, [ "", "Please select a stock" ]; }
491 my $html = simple_selectbox_html
(
492 multiple
=> $multiple,
497 data_related
=> $data_related
499 $c->stash->{rest
} = { select => $html };
502 sub get_traits_select
: Path
('/ajax/html/select/traits') Args
(0) {
505 my $trial_ids = $c->req->param('trial_ids') || 'all';
506 my $stock_id = $c->req->param('stock_id') || 'all';
507 my $stock_type = $c->req->param('stock_type') ?
$c->req->param('stock_type') . 's' : 'none';
508 my $data_level = $c->req->param('data_level') || 'all';
509 my $schema = $c->dbic_schema("Bio::Chado::Schema");
511 if ($data_level eq 'all') {
516 if (($trial_ids eq 'all') && ($stock_id eq 'all')) {
517 my $bs = CXGN
::BreederSearch
->new( { dbh
=> $c->dbc->dbh() } );
518 my $status = $bs->test_matviews($c->config->{dbhost
}, $c->config->{dbname
}, $c->config->{dbuser
}, $c->config->{dbpass
});
519 unless ($status->{'success'}) {
520 $c->stash->{rest
} = { select => '<center><p>Direct trait select is not currently available</p></center>'};
523 my $query = $bs->metadata_query([ 'traits' ], {}, {});
524 @traits = @
{$query->{results
}};
525 #print STDERR "Traits: ".Dumper(@traits)."\n";
526 } elsif (looks_like_number
($stock_id)) {
527 my $stock = CXGN
::Chado
::Stock
->new($schema, $stock_id);
528 my @trait_list = $stock->get_trait_list();
529 foreach (@trait_list){
530 my @val = ($_->[0], $_->[2]."|".$_->[1]);
533 } elsif ($trial_ids ne 'all') {
534 my @trial_ids = split ',', $trial_ids;
535 my %unique_traits_ids;
536 foreach (@trial_ids){
537 my $trial = CXGN
::Trial
->new({bcs_schema
=>$schema, trial_id
=>$_});
538 my $traits_assayed = $trial->get_traits_assayed($data_level);
539 foreach (@
$traits_assayed) {
540 $unique_traits_ids{$_->[0]} = [$_->[0], $_->[1]];
543 while ( my ($key, $value) = each %unique_traits_ids ){
544 push @traits, $value;
548 @traits = sort { $a->[1] cmp $b->[1] } @traits;
550 my $id = $c->req->param("id") || "html_trial_select";
551 my $name = $c->req->param("name") || "html_trial_select";
552 my $size = $c->req->param("size");
554 my $html = simple_selectbox_html
(
561 $c->stash->{rest
} = { select => $html };
564 sub get_phenotyped_trait_components_select
: Path
('/ajax/html/select/phenotyped_trait_components') Args
(0) {
567 my $trial_ids = $c->req->param('trial_ids');
568 #my $stock_id = $c->req->param('stock_id') || 'all';
569 #my $stock_type = $c->req->param('stock_type') . 's' || 'none';
570 my $data_level = $c->req->param('data_level') || 'all';
571 my $schema = $c->dbic_schema("Bio::Chado::Schema");
572 my $composable_cvterm_format = $c->config->{composable_cvterm_format
};
574 if ($data_level eq 'all') {
578 my @trial_ids = split ',', $trial_ids;
580 my @trait_components;
581 foreach (@trial_ids){
582 my $trial = CXGN
::Trial
->new({bcs_schema
=>$schema, trial_id
=>$_});
583 push @trait_components, @
{$trial->get_trait_components_assayed($data_level, $composable_cvterm_format)};
585 #print STDERR Dumper \@trait_components;
586 my %unique_trait_components = map {$_->[0] => $_->[1]} @trait_components;
587 my @unique_components;
588 foreach my $id (keys %unique_trait_components){
589 push @unique_components, [$id, $unique_trait_components{$id}];
591 #print STDERR Dumper \@unique_components;
593 my $id = $c->req->param("id") || "html_trait_component_select";
594 my $name = $c->req->param("name") || "html_trait_component_select";
596 my $html = simple_selectbox_html
(
600 choices
=> \
@unique_components,
602 $c->stash->{rest
} = { select => $html };
605 sub get_composable_cvs_allowed_combinations_select
: Path
('/ajax/html/select/composable_cvs_allowed_combinations') Args
(0) {
608 my $id = $c->req->param("id") || "html_composable_cvs_combinations_select";
609 my $name = $c->req->param("name") || "html_composable_cvs_combinations_select";
610 my $composable_cvs_allowed_combinations = $c->config->{composable_cvs_allowed_combinations
};
611 my @combinations = split ',', $composable_cvs_allowed_combinations;
613 foreach (@combinations){
614 my @parts = split /\|/, $_; #/#
615 push @select, [$parts[1], $parts[0]];
617 my $html = simple_selectbox_html
(
622 $c->stash->{rest
} = { select => $html };
625 sub get_crosses_select
: Path
('/ajax/html/select/crosses') Args
(0) {
629 my $p = CXGN
::BreedersToolbox
::Projects
->new( { schema
=> $c->dbic_schema("Bio::Chado::Schema") } );
631 my $breeding_program_id = $c->req->param("breeding_program_id");
633 if (!$breeding_program_id) {
634 $projects = $p->get_breeding_programs();
636 push @
$projects, [$breeding_program_id];
639 my $id = $c->req->param("id") || "html_trial_select";
640 my $name = $c->req->param("name") || "html_trial_select";
641 my $size = $c->req->param("size");
643 foreach my $project (@
$projects) {
644 my ($field_trials, $cross_trials, $genotyping_trials) = $p->get_trials_by_breeding_program($project->[0]);
645 foreach (@
$cross_trials) {
649 @crosses = sort @crosses;
651 my $html = simple_selectbox_html
(
656 choices
=> \
@crosses,
658 $c->stash->{rest
} = { select => $html };
661 sub get_genotyping_protocols_select
: Path
('/ajax/html/select/genotyping_protocols') Args
(0) {
665 my $id = $c->req->param("id") || "gtp_select";
666 my $name = $c->req->param("name") || "genotyping_protocol_select";
667 my $empty = $c->req->param("empty") || "";
671 my $gt_protocols = CXGN
::BreedersToolbox
::Projects
->new( { schema
=> $c->dbic_schema("Bio::Chado::Schema") } )->get_gt_protocols();
673 if (@
$gt_protocols) {
674 $default_gtp = $c->config->{default_genotyping_protocol
};
675 %gtps = map { @
$_[1] => @
$_[0] } @
$gt_protocols;
677 if(!exists($gtps{$default_gtp}) && !($default_gtp =~ /^none$/)) {
678 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.";
681 $gt_protocols = ["No genotyping protocols found"];
683 my $html = simple_selectbox_html
(
686 choices
=> $gt_protocols,
687 selected
=> $gtps{$default_gtp}
689 $c->stash->{rest
} = { select => $html };
692 sub get_trait_components_select
: Path
('/ajax/html/select/trait_components') Args
(0) {
697 my $cv_id = $c->req->param('cv_id');
698 #print STDERR "cv_id = $cv_id\n";
699 my $id = $c->req->param("id") || "component_select";
700 my $name = $c->req->param("name") || "component_select";
701 my $default = $c->req->param("default") || 0;
702 my $multiple = $c->req->param("multiple") || 0;
703 my $size = $c->req->param('size') || '5';
705 my $dbh = $c->dbc->dbh();
706 my $onto = CXGN
::Onto
->new( { schema
=> $c->dbic_schema('Bio::Chado::Schema', 'sgn_chado') } );
707 my @components = $onto->get_terms($cv_id);
708 #print STDERR Dumper \@components;
709 if ($default) { unshift @components, [ '', $default ]; }
711 my $html = simple_selectbox_html
(
713 multiple
=> $multiple,
715 choices
=> \
@components,
719 $c->stash->{rest
} = { select => $html };
724 sub ontology_children_select
: Path
('/ajax/html/select/ontology_children') Args
(0) {
726 my $parent_node_cvterm = $c->request->param("parent_node_cvterm");
727 my $rel_cvterm = $c->request->param("rel_cvterm");
728 my $rel_cv = $c->request->param("rel_cv");
729 my $size = $c->req->param('size') || '5';
730 my $value_format = $c->req->param('value_format') || 'ids';
731 print STDERR
"Parent Node $parent_node_cvterm\n";
733 my $select_name = $c->request->param("selectbox_name");
734 my $select_id = $c->request->param("selectbox_id");
736 my $empty = $c->request->param("empty") || '';
737 my $multiple = $c->req->param("multiple") || 0;
739 my $schema = $c->dbic_schema('Bio::Chado::Schema', 'sgn_chado');
740 my $parent_node_cvterm_row = SGN
::Model
::Cvterm
->get_cvterm_row_from_trait_name($schema, $parent_node_cvterm);
741 my $parent_node_cvterm_id;
742 if ($parent_node_cvterm_row){
743 $parent_node_cvterm_id = $parent_node_cvterm_row->cvterm_id();
745 my $rel_cvterm_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, $rel_cvterm, $rel_cv)->cvterm_id();
747 my $ontology_children_ref = $schema->resultset("Cv::CvtermRelationship")->search({type_id
=> $rel_cvterm_id, object_id
=> $parent_node_cvterm_id})->search_related('subject');
748 my @ontology_children;
749 while (my $child = $ontology_children_ref->next() ) {
750 my $cvterm_id = $child->cvterm_id();
751 my $dbxref_info = $child->search_related('dbxref');
752 my $accession = $dbxref_info->first()->accession();
753 my $db_info = $dbxref_info->search_related('db');
754 my $db_name = $db_info->first()->name();
755 if ($value_format eq 'ids'){
756 push @ontology_children, [$cvterm_id, $child->name."|".$db_name.":".$accession];
758 if ($value_format eq 'names'){
759 push @ontology_children, [$child->name."|".$db_name.":".$accession, $child->name."|".$db_name.":".$accession];
763 @ontology_children = sort { $a->[1] cmp $b->[1] } @ontology_children;
765 unshift @ontology_children, [ 0, "None" ];
767 #print STDERR Dumper \@ontology_children;
768 my $html = simple_selectbox_html
(
769 name
=> $select_name,
771 multiple
=> $multiple,
772 choices
=> \
@ontology_children,
774 $c->stash->{rest
} = { select => $html };
777 sub get_datasets_select
:Path
('/ajax/html/select/datasets') Args
(0) {
781 my $html = '<select><option disabled="1">None</option></select>';
784 if ($user_id = $c->user->get_object()->get_sp_person_id()) {
786 my $datasets = CXGN
::Dataset
->get_datasets_by_user(
787 $c->dbic_schema("CXGN::People::Schema"),
790 print STDERR
"Retrieved datasets: ".Dumper
($datasets);
792 $html = simple_selectbox_html
(
793 name
=> 'available_datasets',
794 id
=> 'available_datasets',
795 choices
=> $datasets,
800 $c->stash->{rest
} = { select => $html };
804 no warnings
'uninitialized';
806 foreach (keys %$params){
807 my $values = $params->{$_};
809 if (ref \
$values eq 'SCALAR'){
810 push @
$ret_val, $values;
811 } elsif (ref $values eq 'ARRAY'){
814 die "Input is not a scalar or an arrayref\n";
816 @
$ret_val = grep {$_ ne undef} @
$ret_val;
817 @
$ret_val = grep {$_ ne ''} @
$ret_val;
818 $_ =~ s/\[\]$//; #ajax POST with arrays adds [] to the end of the name e.g. germplasmName[]. since all inputs are arrays now we can remove the [].
819 $params->{$_} = $ret_val;