Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions db/00204/AddFillerPlotStockprop.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/usr/bin/env perl


=head1 NAME

AddFillerPlotStockprop.pm

=head1 SYNOPSIS

mx-run AddFillerPlotStockprop [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 is a test dummy patch.
This subclass uses L<Moose>. The parent class uses L<MooseX::Runnable>

=head1 AUTHOR

Ben Maza <bm743@cornell.edu>

=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 AddFillerPlotStockprop;

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


has '+description' => ( default => <<'' );
This patch will find_or_create a cvterm for plots

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 } );

my $coderef = sub {

my $plot_stockprop_filler_plot_cvterm = $schema->resultset("Cv::Cvterm")->create_with({
name => 'filler_plot',
cv => 'stock_property',
});
};

try {
$schema->txn_do($coderef);

} catch {
die "Load failed! " . $_ . "\n" ;
};

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


####
1; #
####
1 change: 1 addition & 0 deletions js/source/entries/fieldmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export function init() {
for (let plot of this.plot_arr.filter((plot) => plot.type == "filler")) {
brapi_post_plots.push({
additionalInfo: {
filler_plot: 1,
invert_row_checkmark: document.getElementById(
"invert_row_checkmark"
).checked,
Expand Down
7 changes: 7 additions & 0 deletions lib/CXGN/Trial/TrialDesignStore/AbstractTrial.pm
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ sub store {
my $stock_rel_type_id = $self->get_stock_relationship_type_id();
my $additional_info_type_id = SGN::Model::Cvterm->get_cvterm_row($chado_schema, 'stock_additional_info', 'stock_property')->cvterm_id();
my $intercrop_rel_type_id = SGN::Model::Cvterm->get_cvterm_row($chado_schema, 'intercrop_plot_of', 'stock_relationship')->cvterm_id();
my $filler_plot_cvterm_id = SGN::Model::Cvterm->get_cvterm_row( $chado_schema, 'filler_plot', 'stock_property' )->cvterm_id();

my @source_stock_types = @{$self->get_source_stock_types()};

Expand Down Expand Up @@ -630,6 +631,8 @@ sub store {
}
my $additional_info = $design{$key}->{additional_info} ? encode_json $design{$key}->{additional_info} : undef;

my $is_filler = $design{$key}->{additional_info}->{filler_plot};

my $facility_identifier;
if ($design{$key}->{facility_identifier}) {
$facility_identifier = $design{$key}->{facility_identifier};
Expand Down Expand Up @@ -721,6 +724,10 @@ sub store {
push @plot_stock_props, { type_id => $self->get_facility_identifier_cvterm_id, value => $facility_identifier };
}

if ($is_filler) {
push @plot_stock_props, { type_id => $filler_plot_cvterm_id, value => $is_filler };
}

my @plot_subjects;
my @plot_objects;

Expand Down
65 changes: 65 additions & 0 deletions lib/SGN/Controller/AJAX/TrialMetadata.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2528,6 +2528,71 @@ sub trial_plots : Chained('trial') PathPart('plots') Args(0) {
$c->stash->{rest} = { plots => \@data };
}

sub remove_filler_plots : Chained('trial') PathPart('remove_fillers') Args(0) {
my $self = shift;
my $c = shift;
my $sp_person_id = $c->user() ? $c->user->get_object()->get_sp_person_id() : undef;
my $schema = $c->dbic_schema("Bio::Chado::Schema", undef, $sp_person_id);
my $trial = $c->stash->{trial};
my $trial_id = $c->stash->{trial_id};

my $stocks_rs = $schema->resultset('Stock::Stock')->search(
{
'project.project_id' => $trial_id,
'stockprops.type_id' => SGN::Model::Cvterm->get_cvterm_row(
$schema,
'filler_plot',
'stock_property'
)->cvterm_id(),
},
{
join => [
{
nd_experiment_stocks => {
nd_experiment => {
nd_experiment_projects => 'project'
}
}
},
'stockprops'
],
distinct => 1,
}
);

my @stock_ids = $stocks_rs->get_column('stock_id')->all;

my $trial_layout_cvterm_id = SGN::Model::Cvterm->get_cvterm_row($schema, 'trial_layout_json', 'project_property')->cvterm_id();

if (@stock_ids) {
$schema->resultset('Stock::Stock')->search({
stock_id => { -in => \@stock_ids }
})->delete;

my $pp_rs = $schema->resultset('Project::Projectprop')->search({
project_id => $trial_id,
type_id => $trial_layout_cvterm_id,
});

while (my $row = $pp_rs->next) {
my $layout = decode_json($row->value);

# Remove filler plot numbers from projectprop.value json
my %filler_ids = map { $_ => 1 } @stock_ids;

foreach my $plot_number (keys %$layout) {
if ($filler_ids{ $layout->{$plot_number}->{plot_id} }) {
delete $layout->{$plot_number};
}
}

$row->value(encode_json($layout));
$row->update;
}
}
$c->stash->{rest} = { success => 1, deleted => scalar(@stock_ids) };
}

sub trial_has_data_levels : Chained('trial') PathPart('has_data_levels') Args(0) {
my $self = shift;
my $c = shift;
Expand Down
55 changes: 55 additions & 0 deletions mason/breeders_toolbox/trial/phenotype_heatmap.mas
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ $trial_stock_type => undef
<div class="interactive_fieldmap_buttons">
<button type="button" class="btn btn-primary fieldmap_edit" id="transpose_fieldmap">Transpose</button>
<button type="button" class="btn btn-primary fieldmap_edit" id="change_dimensions_button">Change Dimensions</button>
<button type="button" class="btn btn-primary fieldmap_edit" id ="remove_fillers">Remove Filler Plots</button>
<button type="button" id="print_fieldmap" name="print_fieldmap" class="btn btn-primary fieldmap_edit">Print Fieldmap</button>
<button type="button" id="submit_fieldmap" name="submit_fieldmap" class="btn btn-success fieldmap_edit">Submit Field Layout</button>
</div>
Expand Down Expand Up @@ -703,6 +704,28 @@ $trial_stock_type => undef
</div>
</div>

<div class="modal fade" id="delete_filler_plots_confirm_message" name="delete_filler_dialog_confirm_message" tabindex="-1" role="dialog" aria-labelledby="DeleteFillerPlotsDialog">
<div class="modal-dialog " role="document">
<div class="modal-content">
<div class="modal-header" style="text-align: center">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="DeleteFillerPlotsDialog">Remove Filler Plots</h4>
</div>
<div class="modal-body">
<div class="container-fluid">

<p3>This will remove all filler plots in this trial. Do you want to continue?</p3> </br></br>

</div>
</div>
<div class="modal-footer">
<button id="close_delete_filler_dialog" type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary" name="delete_filler_plots_dialog_submit" id="remove_filler_plots_dialog_submit">Remove Fillers</button>
</div>
</div>
</div>
</div>

<%perl>
my $dbh = $stockref->{dbh};
my $image_ids = $stockref->{image_ids} || [] ;
Expand Down Expand Up @@ -1053,6 +1076,38 @@ jQuery(document).ready( function() {
}
})

jQuery("#remove_fillers").click(function() {
jQuery('#delete_filler_plots_confirm_message').modal("show");
});

jQuery("#remove_filler_plots_dialog_submit").click(function() {
remove_fillers();
});

function remove_fillers() {
jQuery.ajax({
url: '/ajax/breeders/trial/<% $trial_id %>/remove_fillers',
type: "POST",
dataType: "json",
beforeSend: function(){
jQuery('#delete_filler_plots_confirm_message').modal("hide");
jQuery("#working_modal").modal("show");
},
success: function(response) {
if (response.success) {
alert(`Removed ${response.deleted} filler plot(s)`);
location.reload();
} else {
alert("Failed to remove filler plots");
}
},
error: function(err) {
console.error(err);
alert("Error removing filler plots");
}
});
}

jQuery("#border_accession_form").submit( function() {
event.preventDefault();
});
Expand Down
Loading