Skip to content

Commit

Permalink
Merge pull request #5205 from solgenomics/topic/generic_trial_upload
Browse files Browse the repository at this point in the history
Generic Multi-Trial Upload
  • Loading branch information
lukasmueller authored Nov 21, 2024
2 parents 27870e9 + 90f9049 commit 09e0554
Show file tree
Hide file tree
Showing 10 changed files with 1,023 additions and 691 deletions.
653 changes: 192 additions & 461 deletions bin/upload_multiple_trial_design.pl

Large diffs are not rendered by default.

127 changes: 56 additions & 71 deletions js/source/legacy/CXGN/BreedersToolbox/UploadTrial.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,62 @@ jQuery(document).ready(function ($) {
jQuery("#upload_multiple_trials_warning_messages").html('');
jQuery("#upload_multiple_trials_error_messages").html('');
jQuery("#upload_multiple_trials_success_messages").html('');
jQuery('#upload_multiple_trial_designs_form').attr("action", "/ajax/trial/upload_multiple_trial_designs_file");
jQuery("#upload_multiple_trial_designs_form").submit();

var uploadedTrialLayoutFile = jQuery("#multiple_trial_designs_upload_file").val();
if ( !uploadedTrialLayoutFile || uploadedTrialLayoutFile === '' ) {
alert("No file selected");
return;
}

jQuery("#working_modal").modal("show");
jQuery.ajax({
url: '/ajax/trial/upload_multiple_trial_designs_file',
type: 'POST',
data: new FormData(jQuery("#upload_multiple_trial_designs_form")[0]),
processData: false,
contentType: false,
success : function(response) {
jQuery("#working_modal").modal("hide");
if (response.warnings) {
warnings = response.warnings;
warning_html = "<li>"+warnings.join("</li><li>")+"</li>"
jQuery("#upload_multiple_trials_warning_messages").show();
jQuery("#upload_multiple_trials_warning_messages").html('<b>Warnings. Fix or ignore the following warnings and try again.</b><br><br>'+warning_html);
return;
}
if (response.errors) {
errors = response.errors;
if (Array.isArray(errors)) {
error_html = "<li>"+errors.join("</li><li>")+"</li>";
} else {
error_html = "<li>"+errors+"</li>";
}
jQuery("#upload_multiple_trials_error_messages").show();
jQuery("#upload_multiple_trials_error_messages").html('<b>Errors found. Fix the following problems and try again.</b><br><br>'+error_html);
return;
}
if (response.success) {
refreshTrailJsTree(0);
jQuery("#upload_multiple_trials_success_messages").show();
jQuery("#upload_multiple_trials_success_messages").html("Success! All trials successfully loaded.");
jQuery("#multiple_trial_designs_upload_submit").hide();
jQuery("#upload_multiple_trials_success_button").show();
return;
}
if (response.background) {
jQuery("#upload_multiple_trials_success_messages").show();
jQuery("#upload_multiple_trials_success_messages").html("Your file has been uploaded. You will receive an email once the process is complete.");
jQuery("#multiple_trial_designs_upload_submit").hide();
jQuery("#upload_multiple_trials_success_button").show();
return;
}
},
error: function() {
jQuery("#working_modal").modal("hide");
jQuery("#upload_multiple_trials_error_messages").html("An error occurred while trying to upload this file. Please check the formatting and try again");
return;
}
});
}


Expand Down Expand Up @@ -198,7 +252,6 @@ jQuery(document).ready(function ($) {
});

jQuery('#multiple_trial_designs_upload_submit').click(function () {
console.log("Registered click on multiple_trial_designs_upload_submit button");
upload_multiple_trial_designs_file();
});

Expand Down Expand Up @@ -313,74 +366,6 @@ jQuery(document).ready(function ($) {
// Call the function initially in case the checkbox is already checked
toggleEmailField();

jQuery('#upload_multiple_trial_designs_form').iframePostForm({
json: true,
post: function () {
var uploadedTrialLayoutFile = jQuery("#multiple_trial_designs_upload_file").val();
var email_option_enabled = jQuery('#email_option_to_recieve_trial_upload_status').is(':checked') ? 1 : 0;

// Clear existing messages
jQuery("#upload_multiple_trials_warning_messages").html('');
jQuery("#upload_multiple_trials_error_messages").html('');
jQuery("#upload_multiple_trials_success_messages").html('');

if (uploadedTrialLayoutFile === '') {
alert("No file selected");
return;
}

if (email_option_enabled === 1) {
if (confirm('You will receive an email once the process is complete. Do you want to continue?')) {
jQuery("#upload_trial_dialog").modal('hide');
} else {
return;
}
}
else {
jQuery('#working_modal').modal("show");
}
},
complete: function(response) {
// console.log(response);
jQuery('#working_modal').modal("hide");
if (response.warnings) {
warnings = response.warnings;
warning_html = "<li>"+warnings.join("</li><li>")+"</li>"
jQuery("#upload_multiple_trials_warning_messages").show();
jQuery("#upload_multiple_trials_warning_messages").html('<b>Warnings. Fix or ignore the following warnings and try again.</b><br><br>'+warning_html);
return;
}
if (response.errors) {
errors = response.errors;
if (Array.isArray(errors)) {
error_html = "<li>"+errors.join("</li><li>")+"</li>";
} else {
error_html = "<li>"+errors+"</li>";
}
jQuery("#upload_multiple_trials_error_messages").show();
jQuery("#upload_multiple_trials_error_messages").html('<b>Errors found. Fix the following problems and try again.</b><br><br>'+error_html);
console.log("check the errors: ", response.errors);
return;
}
if (response.success) {
console.log("Success!!");
refreshTrailJsTree(0);
jQuery("#upload_multiple_trials_success_messages").show();
jQuery("#upload_multiple_trials_success_messages").html("Success! All trials successfully loaded.");
jQuery("#multiple_trial_designs_upload_submit").hide();
jQuery("#upload_multiple_trials_success_button").show();
return;
}
},
error: function(response) {
if (!jQuery('#email_option_to_recieve_trial_upload_status').is(':checked')) {
jQuery("#working_modal").modal("hide");
jQuery("#upload_multiple_trials_error_messages").html("An error occurred while trying to upload this file. Please check the formatting and try again");
return;
}
}
});

jQuery('#upload_multiple_trials_success_button').on('click', function(){
//alert('Trial was saved in the database');
jQuery('#upload_trial_dialog').modal('hide');
Expand Down
2 changes: 1 addition & 1 deletion lib/CXGN/Trial/Folder.pm
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ sub _jstree_li_html {
my $type = shift;
my $id = shift;
my $name = shift;
print STDERR "TYPE =".Dumper($type)."\n";
# print STDERR "TYPE =".Dumper($type)."\n";

my $url = '#';
if ($type eq 'trial' || $type eq 'genotyping_trial' || $type eq 'sampling_trial') {
Expand Down
9 changes: 9 additions & 0 deletions lib/CXGN/Trial/ParseUpload.pm
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ has '_parsed_data' => (
predicate => '_has_parsed_data'
);

has '_validated_data' => (
is => 'ro',
isa => 'HashRef',
writer => '_set_validated_data',
reader => '_get_validated_data',
predicate => '_has_validated_data',
required => 0
);

has '_location_code_map' => (
is => 'ro',
isa => 'HashRef',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ use CXGN::Stock::Seedlot;
use CXGN::Calendar;
use CXGN::Trial;

#
# DEPRECATED: This plugin has been replaced by the MultipleTrialDesignGeneric plugin
#

my @REQUIRED_COLUMNS = qw|trial_name breeding_program location year design_type description accession_name plot_number block_number|;
my @OPTIONAL_COLUMNS = qw|plot_name trial_type plot_width plot_length field_size planting_date transplanting_date harvest_date is_a_control rep_number range_number row_number col_number seedlot_name num_seed_per_plot weight_gram_seed_per_plot entry_number|;
# Any additional columns that are not required or optional will be used as a treatment
Expand Down
Loading

0 comments on commit 09e0554

Please sign in to comment.