fix json parsing in Seedlot controller.
[sgn.git] / lib / SGN / Controller / Seedlot.pm
blob195e3a9cb6dfea77d4cdb47d266ba8b70de6d1d6
2 package SGN::Controller::Seedlot;
4 use Moose;
6 BEGIN { extends 'Catalyst::Controller'; }
8 use CXGN::Stock::Seedlot;
9 use Data::Dumper;
10 use JSON::XS;
12 sub seedlots :Path('/breeders/seedlots') :Args(0) {
13 my $self = shift;
14 my $c = shift;
15 my $schema = $c->dbic_schema("Bio::Chado::Schema", "sgn_chado");
17 $c->stash->{preferred_species} = $c->config->{preferred_species};
18 $c->stash->{timestamp} = localtime;
20 my @editable_stock_props = split ',', $c->config->{editable_stock_props};
21 my %editable_stock_props = map { $_=>1 } @editable_stock_props;
22 $c->stash->{editable_stock_props} = \%editable_stock_props;
24 my $projects = CXGN::BreedersToolbox::Projects->new( { schema=> $schema } );
25 my $breeding_programs = $projects->get_breeding_programs();
26 $c->stash->{crossing_trials} = $projects->get_crossing_trials();
27 $c->stash->{locations} = JSON::XS->new->decode($projects->get_location_geojson());
28 $c->stash->{programs} = $breeding_programs;
29 $c->stash->{template} = '/breeders_toolbox/seedlots.mas';
32 sub seedlot_detail :Path('/breeders/seedlot') Args(1) {
33 my $self = shift;
34 my $c = shift;
35 my $seedlot_id = shift;
36 my $schema = $c->dbic_schema("Bio::Chado::Schema", "sgn_chado");
37 my $phenome_schema = $c->dbic_schema("CXGN::Phenome::Schema");
38 my $people_schema = $c->dbic_schema("CXGN::People::Schema");
40 my $sl = CXGN::Stock::Seedlot->new(
41 schema => $schema,
42 phenome_schema => $phenome_schema,
43 seedlot_id => $seedlot_id
45 my @content_accession_names;
46 my @content_cross_names;
47 my $accessions = $sl->accession();
48 my $accessions_html = '';
49 if ($accessions){
50 $accessions_html .= '<a href="/stock/'.$accessions->[0].'/view">'.$accessions->[1].'</a> (accession)';
51 push @content_accession_names, $accessions->[1];
53 my $crosses = $sl->cross();
54 my $crosses_html = '';
55 if ($crosses){
56 $crosses_html .= '<a href="/cross/'.$crosses->[0].'">'.$crosses->[1].'</a> (cross)';
57 push @content_cross_names, $crosses->[1];
59 my $populations = $sl->populations();
60 my $populations_html = '';
61 foreach (@$populations){
62 $populations_html .= '<a href="/stock/'.$_->[0].'/view">'.$_->[1].'</a> ';
64 my $owners = $sl->owners;
65 my $owners_string = '';
66 foreach (@$owners){
67 my $p = $people_schema->resultset("SpPerson")->find({sp_person_id=>$_});
68 $owners_string .= ' <a href="/solpeople/personal-info.pl?sp_person_id='.$p->sp_person_id.'">'.$p->username.'</a>';
70 $c->stash->{seedlot_id} = $seedlot_id;
71 $c->stash->{uniquename} = $sl->uniquename();
72 $c->stash->{organization_name} = $sl->organization_name();
73 $c->stash->{box_name} = $sl->box_name();
74 $c->stash->{population_name} = $populations_html;
75 $c->stash->{content_html} = $accessions_html ? $accessions_html : $crosses_html;
76 $c->stash->{content_accession_name} = $content_accession_names[0];
77 $c->stash->{content_cross_name} = $content_cross_names[0];
78 $c->stash->{current_count} = $sl->get_current_count_property();
79 $c->stash->{current_weight} = $sl->get_current_weight_property();
80 $c->stash->{owners_string} = $owners_string;
81 $c->stash->{timestamp} = localtime();
82 $c->stash->{template} = '/breeders_toolbox/seedlot_details.mas';