Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select display image for accession #5275

Merged
merged 9 commits into from
Feb 10, 2025
84 changes: 84 additions & 0 deletions db/00188/AddSelectedDisplayImageCvterm.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/usr/bin/env perl


=head1 NAME

AddSelectedDisplayImageCvterm.pm

=head1 SYNOPSIS

mx-run ThisPackageName [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 adds selected_display_image stock_property cvterm
This subclass uses L<Moose>. The parent class uses L<MooseX::Runnable>

=head1 AUTHOR

Benjamin Maza<[email protected]>

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

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


has '+description' => ( default => <<'' );
This patch adds the selected_display_image stock_property cvterm.

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 $terms = {
'stock_property' => [
'selected_display_image',
]
};

foreach my $t (keys %$terms){
foreach (@{$terms->{$t}}){
$schema->resultset("Cv::Cvterm")->create_with({
name => $_,
cv => $t
});
}
}

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


####
1; #
####
54 changes: 54 additions & 0 deletions lib/SGN/Controller/AJAX/Stock.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2636,5 +2636,59 @@ sub get_vector_related_stocks:Chained('/stock/get_stock') PathPart('datatables/v
$c->stash->{rest}={data=>\@related_stocks};
}

=head2 set_display_image

Usage: /stock/set_display_image
Desc: Updates stockprop with selected image_id
Ret: Success or error string
Args:
Side Effects:
Example:

=cut

sub set_display_image : Path('/ajax/stock/set_display_image') : ActionClass('REST') { }

sub set_display_image_POST : Args(0) {
my ($self, $c) = @_;

my $stock_id = $c->req->param('stock_id');
my $image_id = $c->req->param('image_id');

if (!$stock_id) {
$c->stash->{rest} = { error_string=> 'Missing stock_id' };
return;
}

if (!$image_id) {
$c->stash->{rest} = { error_string=> 'Missing image_id' };
return;
}

my $schema = $c->dbic_schema('Bio::Chado::Schema', 'sgn_chado');
my $dbh = $c->dbc->dbh;

my $display_image_cvterm_id = SGN::Model::Cvterm->get_cvterm_row($schema, 'selected_display_image', 'stock_property')->cvterm_id();

my $stock = $schema->resultset('Stock::Stock')->find({ stock_id => $stock_id });
if (!$stock) {
$c->stash->{rest} = { error_string => 'Stock not found' };
return;
}

my $stockprop = $schema->resultset('Stock::Stockprop')->find_or_create({
stock_id => $stock_id,
type_id => $display_image_cvterm_id,
});
$stockprop->update({ value => $image_id });

if ($stockprop->value != $image_id) {
$c->stash->{rest} = { error_string => 'Error setting display image' };
return;
}

$c->stash->{rest} = { success => 1 };

}

1;
80 changes: 76 additions & 4 deletions mason/image/print_images.mas
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ $additional_image_button_id => 'Images'
$images => undef
$dbh => undef
$image_objects => undef
$selected_image_id => undef
$stock_id => undef
$stock_image_flag => undef
$curator => undef

</%args>

Expand All @@ -68,7 +72,12 @@ if ($images && !$image_objects) {
###print qq{ <script src="jquery.colorbox-min.js"></script> };

if ($image_objects) { # don't display anything for empty list of images
$image_html .= qq|<table class="table table-bordered"><thead><tr><th><button class="btn btn-sm btn-default" id="print_images_multi_image_view">View Selected</button></th><th>Image</th><th>Description</th><th>Type</th></tr></thead><tbody>|;
if ($curator && $stock_image_flag == '1') { # Only include 'Set as Display Image' column for images of this stock, not for images of related stock table
$image_html .= qq|<table class="table table-bordered"><thead><tr><th><button class="btn btn-sm btn-default" id="print_images_multi_image_view">View Selected</button></th><th>Image</th><th>Description</th><th>Type</th><th>Set as Display Image</th></tr></thead><tbody>|;
} else {
$image_html .= qq|<table class="table table-bordered"><thead><tr><th><button class="btn btn-sm btn-default" id="print_images_multi_image_view">View Selected</button></th><th>Image</th><th>Description</th><th>Type</th></tr></thead><tbody>|;
}

my $i = 0;
foreach my $image_ob (@$image_objects) {
$count++;
Expand All @@ -85,6 +94,8 @@ if ($image_objects) { # don't display anything for empty list of images
my $colorbox =
qq|<a href="$image_img" title="<a href=$image_page>Go to image page ($image_name)</a>" class="stock_image_group" rel="gallery-figures"><img src="$small_image" alt="$image_description" /></a> |;
my $multi_open_colorbox = qq|<a href="$image_img" title="<a href=$image_page>Go to image page ($image_name)</a>" class="stock_image_group" rel="gallery-figures"><img src="$original_img" alt="$image_description" /></a> |;

my $set_button = "<button class='btn btn-sm btn-default' onclick='setDisplayImage($image_id, $stock_id)'>Set</button";
my $fhtml =
qq|<tr><td><input type="checkbox" name="print_images_checkbox" data-html_text='$multi_open_colorbox'></td><td>|
. $colorbox
Expand All @@ -93,7 +104,9 @@ if ($image_objects) { # don't display anything for empty list of images
. $image_description
. "</td><td>"
. $images->[$i]->[1]
. "</td></tr>";
. "</td>"
. ($curator == 1 ? "<td>$set_button</td>" : "")
. "</tr>";
if ( $count < 3 ) { $image_html .= $fhtml; }
else {
push @more_is, $fhtml;
Expand All @@ -118,8 +131,11 @@ if ($image_objects) { # don't display anything for empty list of images
}); </script>\n";

}
$m_image_html .=
"<table class='table table-bordered'><thead><tr><th><button class='btn btn-sm btn-default' id='print_images_multi_image_view'>View Selected</button></th><th>Image</th><th>Description</th><th>Type</th></tr></thead><tbody>"; #open table tag for the hidden figures #4 and on
if ($curator && $stock_image_flag == '1') { # Only include 'Set as Display Image' column for images of this stock, not for images of related stock table
$m_image_html .= qq|<table class="table table-bordered"><thead><tr><th><button class="btn btn-sm btn-default" id="print_images_multi_image_view">View Selected</button></th><th>Image</th><th>Description</th><th>Type</th><th>Set as Display Image</th></tr></thead><tbody>|; #open table tag for the hidden figures #4 and on
} else {
$m_image_html .= qq|<table class="table table-bordered"><thead><tr><th><button class="btn btn-sm btn-default" id="print_images_multi_image_view">View Selected</button></th><th>Image</th><th>Description</th><th>Type</th></tr></thead><tbody>|;
}
my $more = scalar(@more_is);
foreach (@more_is) { $m_image_html .= $_; }

Expand All @@ -137,5 +153,61 @@ if (@more_is) { #html_optional_show if there are more than 3 figures

</%perl>

<div class="modal fade" id="set_display_image_message_dialog" name="set_display_image_message_dialog" tabindex="-1" role="dialog" aria-labelledby="setDisplayMessageDialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="setDisplayMessageDialog">Success</h4>
</div>
<div class="modal-body">
<div class="container-fluid">
<p>
<span class="ui-icon ui-icon-circle-check" style="float: left; margin: 0 7px 50px 0;"></span>
The display image was set successfully.
</p>
</div>
</div>
<div class="modal-footer">
<button id="dismiss_set_display_image_message_dialog" type="button" class="btn btn-default" data-dismiss="modal">Close & Reload</button>
</div>
</div>
</div>
</div>

<script>
function setDisplayImage(image_id, stock_id) {
jQuery.ajax({
url: '/ajax/stock/set_display_image',
dataType: 'json',
type: 'POST',
data: {
'image_id': image_id,
'stock_id': stock_id
},
beforeSend: function(response) {
jQuery('#working_modal').modal('show');
},
success: function(response) {
jQuery('#working_modal').modal('hide');
if (response.success == 1) {
jQuery('#set_display_image_message_dialog').modal('show');
}
if (response.error_string) {
alert(response.error_string);
}
},
error: function() {
jQuery('#working_modal').modal('hide');
alert('An error occured while setting the display image');
}
});

jQuery("#dismiss_set_display_image_message_dialog").click(function(){
location.reload();
});

}
</script>

<% $image_html %>
5 changes: 3 additions & 2 deletions mason/page/detail_page_2_col_section.mas
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ $info_section_title => "A title"
$info_section_subtitle => "A subtitle"
$buttons_html => undef
$locations_by_program_json => undef
$curator => undef

#Trying to find the right one
$project_id => undef
Expand Down Expand Up @@ -322,11 +323,11 @@ $field_headers => ()
<& /image/compare_images.mas, stock_id => $stock_id &>

<&| /page/info_section.mas, title=>"Images of This Stock(" . scalar(@$image_ids) . ")", collapsible=>1, collapsed=>0 &>
<& /image/print_images.mas , images=>$image_ids , dbh=>$dbh, additional_image_button_id=>'stock_images' &>
<& /image/print_images.mas , stock_id=>$stock_id , images=>$image_ids , dbh=>$dbh, additional_image_button_id=>'stock_images', stock_image_flag=>'1' , curator=>$curator &>
</&>

<&| /page/info_section.mas, title=>"Images of Related Stock(s) (" . scalar(@$related_image_ids) . ")", collapsible=>1, collapsed=>0 &>
<& /image/print_images.mas , images=>$related_image_ids , dbh=>$dbh, additional_image_button_id=>'related_stock_images' &>
<& /image/print_images.mas , images=>$related_image_ids , dbh=>$dbh, additional_image_button_id=>'related_stock_images', stock_image_flag=>'0' &>
</&>
% } #End stock_images_section
% if ($info_section_id eq 'stock_sequencing_status_section'){
Expand Down
25 changes: 20 additions & 5 deletions mason/stock/index.mas
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ $barcode_tempdir => undef
$barcode_tempuri => undef
$identifier_prefix => 'SGN'
$organism_autocomplete_uri => '/ajax/organism/autocomplete/'
$image => undef
$image_url => undef
</%args>


Expand Down Expand Up @@ -268,9 +270,22 @@ function jqueryStuff() {
<div style="display: flex; justify-content: center; align-items; height: 100%; margin-top: 20px;">
<%perl>
use SGN::Image;
my $image_id = $stockref->{image_ids}->[0]->[0];
my $image = SGN::Image->new($schema->storage->dbh, $image_id, $c);
my $image_url = $image->get_image_url('small');
my $schema = $stockref->{schema};
my $stock_id = $stockref->{stock_id};

my $display_image_cvterm_id = SGN::Model::Cvterm->get_cvterm_row($schema, 'selected_display_image', 'stock_property')->cvterm_id();
my $stockprop = $schema->resultset('Stock::Stockprop')->find({ stock_id => $stock_id, type_id => $display_image_cvterm_id });

if ($stockprop) {
my $image_id = $stockprop->value;
my $image = SGN::Image->new($schema->storage->dbh, $image_id, $c);
$image_url = $image->get_image_url('small');
} else {
my $image_id = $stockref->{image_ids}->[0]->[0];
my $image = SGN::Image->new($schema->storage->dbh, $image_id, $c);
$image_url = $image->get_image_url('small');
}

</%perl>

<img src="<% $image_url %>" alt="No accession image to display" class="img-responsive" style="max-width: 100%; height: auto;" />
Expand Down Expand Up @@ -376,8 +391,8 @@ function jqueryStuff() {
<& /page/detail_page_2_col_section.mas, stock_id => $stock_id, info_section_title => "<h4 style='display:inline'>Related Stocks</h4>", info_section_subtitle => 'View any plots, plants, tissue_sample, and/or accessions that are linked to this stock.', icon_class => "glyphicon glyphicon-retweet", info_section_id => "stock_related_stock_section", stock_uniquename => $uniquename, type_name => $type_name &>

% }

<& /page/detail_page_2_col_section.mas, stock_id => $stock_id, info_section_title => "<h4 style='display:inline'>Images</h4>", info_section_subtitle => 'View and add images of this stock and of related stocks.', icon_class => "glyphicon glyphicon-camera", info_section_id => "stock_images_section", image_ids => $image_ids, related_image_ids => $related_image_ids, dbh => $dbh, buttons_html => qq|<a id="add_new_image_button" class="btn btn-sm btn-default" style="margin:3px" href="/image/add?type_id=$stock_id&action=new&type=stock&refering_page=$this_page">Add new image</a><a class="btn btn-sm btn-default" style="margin:3px" id="stock_images_section_compare_images_button">Compare Images</a>| &>
<& /page/detail_page_2_col_section.mas, stock_id => $stock_id, info_section_title => "<h4 style='display:inline'>Images</h4>", info_section_subtitle => 'View and add images of this stock and of related stocks.', icon_class => "glyphicon glyphicon-camera", info_section_id => "stock_images_section", image_ids => $image_ids, related_image_ids => $related_image_ids, dbh => $dbh, curator =>$curator, buttons_html => qq|<a id="add_new_image_button" class="btn btn-sm btn-default" style="margin:3px" href="/image/add?type_id=$stock_id&action=new&type=stock&refering_page=$this_page">Add new image</a><a class="btn btn-sm btn-default" style="margin:3px" id="stock_images_section_compare_images_button">Compare Images</a>| &>

<& /page/detail_page_2_col_section.mas, stock_id => $stock_id, info_section_title => "<h4 style='display:inline'>Upload Data Files</h4>", info_section_subtitle => 'Upload any additional files for this Accession.', icon_class => "glyphicon glyphicon-cloud-upload", info_section_id => "stock_upload_files" &>

Expand Down