Skip to content

Commit

Permalink
Merge pull request #2229 from solgenomics/topic/fix_stock_buttons
Browse files Browse the repository at this point in the history
stock detail page buttons
  • Loading branch information
Guillaume Bauchet committed Oct 17, 2018
2 parents ce174e3 + 89451b2 commit 3e6a025
Show file tree
Hide file tree
Showing 4 changed files with 433 additions and 303 deletions.
102 changes: 102 additions & 0 deletions db/00103/FixTrialPluralTypes.pm
@@ -0,0 +1,102 @@
#!/usr/bin/env perl


=head1 NAME
FixTrialPluralTypes.pm
=head1 SYNOPSIS
mx-run FixTrialPluralTypes [options] -H hostname -D dbname -u username [-F]
this is a subclass of L<CXGN::Metadata::Dbpatch>
see the perldoc of parent class for more details.
=head1 DESCRIPTION
This patch fixes the odd "Preliminary Yield Trials" and "Advanced Yeld Trials" and "Advanced Yield Trials" terms that should be singular terms
This subclass uses L<Moose>. The parent class uses L<MooseX::Runnable>
=head1 AUTHOR
=head1 COPYRIGHT & LICENSE
Copyright 2010 Boyce Thompson Institute for Plant Research
This program is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut


package FixTrialPluralTypes;

use Moose;
use Bio::Chado::Schema;
use Try::Tiny;
use SGN::Model::Cvterm;
extends 'CXGN::Metadata::Dbpatch';


has '+description' => ( default => <<'' );
This patch fixes the odd "Preliminary Yield Trials" and "Advanced Yeld Trials" and "Advanced Yield Trials" terms that should be singular terms
has '+prereq' => (
default => sub {
[],
},

);

sub patch {
my $self=shift;

print STDOUT "Executing the patch:\n " . $self->name . ".\n\nDescription:\n ". $self->description . ".\n\nExecuted by:\n " . $self->username . " .";

print STDOUT "\nChecking if this db_patch was executed before or if previous db_patches have been executed.\n";

print STDOUT "\nExecuting the SQL commands.\n";
my $schema = Bio::Chado::Schema->connect( sub { $self->dbh->clone } );


print STDERR "INSERTING CV TERMS...\n";

my $correct_ayt_cvterm_id = SGN::Model::Cvterm->get_cvterm_row($schema, 'Advanced Yield Trial', 'project_type')->cvterm_id();
my $correct_pyt_cvterm_id = SGN::Model::Cvterm->get_cvterm_row($schema, 'Preliminary Yield Trial', 'project_type')->cvterm_id();

my $previously_saved_wrong_ayt_projectprops_sql = "SELECT projectprop_id FROM projectprop join cvterm on(type_id=cvterm_id) where name='Advanced Yeld Trials' OR name='Advanced Yield Trials';";
my $update_previously_saved_wrong_ayt_projectprops_sql = "UPDATE projectprop SET type_id = $correct_ayt_cvterm_id WHERE projectprop_id = ?;";

my $h1 = $schema->storage->dbh()->prepare($previously_saved_wrong_ayt_projectprops_sql);
my $h_update = $schema->storage->dbh()->prepare($update_previously_saved_wrong_ayt_projectprops_sql);

$h1->execute();
while (my ($projectprop_id) = $h1->fetchrow_array()) {
$h_update->execute($projectprop_id);
}

my $previously_saved_wrong_pyt_projectprops_sql = "SELECT projectprop_id FROM projectprop join cvterm on(type_id=cvterm_id) where name='Preliminary Yield Trials';";
my $update_previously_saved_wrong_pyt_projectprops_sql = "UPDATE projectprop SET type_id = $correct_pyt_cvterm_id WHERE projectprop_id = ?;";

my $h2 = $schema->storage->dbh()->prepare($previously_saved_wrong_pyt_projectprops_sql);
my $h2_update = $schema->storage->dbh()->prepare($update_previously_saved_wrong_pyt_projectprops_sql);

$h2->execute();
while (my ($projectprop_id) = $h2->fetchrow_array()) {
$h2_update->execute($projectprop_id);
}

my $wrong_trial_types_rs = $schema->resultset("Cv::Cvterm")->search({
name => {-in => ["Advanced Yeld Trials", "Advanced Yield Trials", "Preliminary Yield Trials"]}
});
while (my $r = $wrong_trial_types_rs->next){
$r->delete;
}

print "You're done!\n";
}


####
1; #
####
10 changes: 9 additions & 1 deletion mason/stock/index.mas
Expand Up @@ -205,7 +205,7 @@ function jqueryStuff() {
<& /page/page_title.mas, title=> join( ': ', grep $_, ucfirst($type_name), $uniquename ) || 'Create a new stock' &>


<&| /page/info_section.mas, title=>"Stock details" , collapsible=>1, collapsed=>0, subtitle => "<button class='btn btn-sm btn-default' style='margin:3px' href='/phenome/qtl_form.pl'>New QTL population</button> <button class='btn btn-sm btn-default' style='margin:3px' href='/search/stocks/'>Back to stock search</button>" &>
<&| /page/info_section.mas, title=>"Stock details" , collapsible=>1, collapsed=>0, subtitle => "<button class='btn btn-sm btn-default' style='margin:3px' name='stock_new_qtl_link'>New QTL population</button> <button class='btn btn-sm btn-default' style='margin:3px' name='stock_go_to_stock_search'>Back to stock search</button>" &>

<div class="panel panel-default">
<div class="panel-body">
Expand Down Expand Up @@ -348,6 +348,14 @@ function jqueryStuff() {
jQuery(document).ready(function() {
stock_detail_page_init_dialogs();

jQuery('[name="stock_new_qtl_link"]').click(function(){
window.location.href = '/phenome/qtl_form.pl';
});

jQuery('[name="stock_go_to_stock_search"]').click(function(){
window.location.href = '/search/stocks/';
});

jQuery('#stock_add_synonym').click(function(){
synonyms_addPropDialog();
});
Expand Down
2 changes: 0 additions & 2 deletions system_cvterms.txt
Expand Up @@ -114,11 +114,9 @@ project_relationship trial_treatment_relationship 00081
project_relationship field_trial_from_field_trial For linking field trials preceding other field trials 4/6/18 nm529 00093
project_relationship genotyping_trial_from_field_trial For linking genotyping plates to the source field trials 4/6/18 nm529 00093
project_relationship crossing_trial_from_field_trial For linking crossing trials to the source field trials 4/6/18 nm529 00093
project_type Advanced Yeld Trials 00052
project_type Advanced Yield Trial
project_type Clonal Evaluation
project_type Preliminary Yield Trial
project_type Preliminary Yield Trials 00052
project_type Regional Trials
project_type Seed Multiplication
project_type Seedling Nursery
Expand Down

0 comments on commit 3e6a025

Please sign in to comment.