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

Issue #27 - Search new stock name, ignore column and email support. #30

Merged
Show file tree
Hide file tree
Changes from 5 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
45 changes: 45 additions & 0 deletions include/rawpheno.function.measurements.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1176,6 +1176,51 @@ function rawpheno_function_plot_exists($plot, $project_id) {


/**
* Function to get stock_id number of a stock name in chado.stock.
* NOTE: AGL applies only to when saving data. Validation (germplasm exists)
* is based on stock w/o this token.
*
* @param $stock_name
* A string, the name of the stock.
* @param $project_name
* A string, the name of the project.
*
* @return
* An integer, the stock id number.
*/
function rawpheno_function_getstockid($stock_name, $project_name) {
// Calling all modules implementing hook_rawpheno_AGILE_stock_name_alter():
drupal_alter('rawpheno_AGILE_stock_name', $stock_name, $project_name);

// Limit the search to project organism.
$result = chado_query(
"SELECT stock_id FROM {stock} WHERE name = :name LIMIT 1",
array(':name' => $stock_name)
);

return ($result) ? $result->fetchField() : 0;
}


/**
* Function: get project name.
*
* @param $project_id
* An integer value, the project id number.
*
* @return
* A string value, the name for the project from chado.project table.
*/
function rawpheno_function_getproject($project_id) {
$result = chado_query("SELECT name FROM {project} WHERE project_id = :project_id LIMIT 1", array(
':project_id' => $project_id,
));

return ($result) ? $result->fetchField() : 0;
}


/**
* Function to get environment data files.
*
* @param $project
Expand Down
43 changes: 40 additions & 3 deletions include/rawpheno.upload.excel.inc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ function rawpheno_load_spreadsheet($project_id, $arr_newheaders, $fid, $plantpro
$plantprop_headers = unserialize($plantprop_headers);
$arr_newheaders = unserialize($arr_newheaders);

// Project name.
$project_name = rawpheno_function_getproject($project_id);

// First we load the file.
$file = file_load($fid);

Expand Down Expand Up @@ -85,6 +88,13 @@ function rawpheno_load_spreadsheet($project_id, $arr_newheaders, $fid, $plantpro
// print "\nNow parsing each row and saving it to the database...\nNumber of rows saved: \n";
$i = 0;

// Skip columns.
$skip = array();
// Project name.
$project_name = rawpheno_function_getproject($project_id);
// Calling all modules implementing hook_rawpheno_ignorecols_valsave_alter():
drupal_alter('rawpheno_ignorecols_valsave', $skip, $project_name);

// Each row in the spreadsheet.
foreach ($xls_obj as $row) {
// Create progress update by computing the number of rows saved in percent.
Expand Down Expand Up @@ -134,9 +144,9 @@ function rawpheno_load_spreadsheet($project_id, $arr_newheaders, $fid, $plantpro
// Process the name column first since we need a plant_id before we can insert any more data.
// Name column header goes into pheno_plant.
// Check if stock name exists.
$stock_id = NULL;
$r = chado_query('SELECT stock_id FROM {stock} WHERE name=:name', array(':name' => trim($row[$name_index])));
if ($r) $stock_id = $r->fetchField();
unset($stock_id);
$stock_id = rawpheno_function_getstockid(trim($row[$name_index]), $project_name);
// print $stock_id . ' -- ' . $row[$name_index] . "\n";

// Determine if name has a stock id number.
if (isset($stock_id) && $stock_id > 0) {
Expand Down Expand Up @@ -226,6 +236,14 @@ function rawpheno_load_spreadsheet($project_id, $arr_newheaders, $fid, $plantpro
// Read each row and each cell.
// Each row will be an array where name is always the first element.
foreach($row as $cell_index => $cell_entry) {
// Skip this cell when col from durpal_alter hook matches the col.
$h = rawpheno_function_delformat($header[$cell_index]);

if (count($skip) > 0 && in_array($h, $skip)) {
// print 'skipping value : ' . $h . '=' . $cell_entry . "\n";
continue;
}

// For consistency, convert all variations of not applicable to NA.
if (is_string($cell_entry) && in_array(strtolower($cell_entry), $not_applicable)) {
$cell_entry = 'NA';
Expand Down Expand Up @@ -312,6 +330,11 @@ function rawpheno_load_spreadsheet($project_id, $arr_newheaders, $fid, $plantpro
// THE REST OF THE COLUMN HEADERS
// Everything else into pheno_measurements.
elseif (!empty($cell_colheader) && $cell_entry != 'NA') {
if (in_array($cell_colheader, $skip)) {
// print 'skipping header : ' . $cell_colheader . "\n";
continue;
}

// Get the cvterm_id for the trait measurement.
$type_id = rawpheno_get_trait_id($cell_colheader);

Expand Down Expand Up @@ -535,6 +558,13 @@ function rawpheno_validate_excel_file($file, $project_id, $source) {
// Variations of Not Applicable.
$not_applicable = array('na', 'n/a', 'n.a.');

// Skip columns.
$skip = array();
// Project name.
$project_name = rawpheno_function_getproject($project_id);
// Calling all modules implementing hook_rawpheno_ignorecols_valsave_alter():
drupal_alter('rawpheno_ignorecols_valsave', $skip, $project_name);

// Iterate though each row.
$num_errored_rows = 0;
$storage = array();
Expand All @@ -557,12 +587,18 @@ function rawpheno_validate_excel_file($file, $project_id, $source) {
$o = 0;
foreach ($row as $r) {
$without_format = rawpheno_function_delformat($r);

// To maintain index of both cells and header, tag either to skip or process
// based on headers in drupal_alter hook.
$s = (in_array($without_format, $skip)) ? 1 : 0;

$no_units = rawpheno_get_trait_name($r);
$header[] = array(
'no format' => $without_format,
'original' => $r,
'units' => rawpheno_function_unit($without_format),
'no units' => $no_units,
'skip' => $s,
);

// Store index number of Plot trait requirements.
Expand Down Expand Up @@ -596,6 +632,7 @@ function rawpheno_validate_excel_file($file, $project_id, $source) {

$row_has_error = FALSE;
foreach ($row as $column_index => $cell) {
if ($header[$column_index]['skip'] == 1) continue;

$column_name = $header[$column_index]['no units'];
if (empty($column_name)) continue;
Expand Down
5 changes: 5 additions & 0 deletions include/rawpheno.upload.form.inc
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ function rawpheno_upload_form_stage_review(&$form, &$form_state) {

// The project id number the spreadsheet and column headers are specific to.
$project_id = $form_state['values']['sel_project'];
$project_name = rawpheno_function_getproject($project_id);

// FIND NEW HEADERS.
// First step, determine which headers/traits need to be described.
Expand All @@ -230,6 +231,10 @@ function rawpheno_upload_form_stage_review(&$form, &$form_state) {
// when no project id is selected, user will be stopped and is requested to retry the process.
if ($file AND !empty($project_id)) {
$new_header = rawpheno_indicate_new_headers($file, $project_id);

// Calling all modules implementing hook_rawpheno_AGILE_stock_name_alter():
drupal_alter('rawpheno_ignorecols_newcolumn', $new_header, $project_name);

$form_state['multistep_values']['new_headers'] = $new_header;
}
else {
Expand Down
4 changes: 4 additions & 0 deletions include/rawpheno.validation.inc
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ function validator_column_exists_validate_header($header, $project_id) {
$nospace_header = array();

foreach ($header as $h) {
if ($h['skip'] == 1) continue;

$delformat_header[] = $h['no units'];
$nospace_header[] = str_replace(' ','', $h['no format']);
}
Expand Down Expand Up @@ -265,6 +267,8 @@ function validator_column_exists_validate_header($header, $project_id) {
// or closing paren.
$invalid_format = array();
foreach($header as $f) {
if ($f['skip'] == 1) continue;

$h = trim(str_replace(array("\n", "\r", " "), ' ', $f['original']));

$is_valid = rawpheno_valid_trait_format($h);
Expand Down
11 changes: 10 additions & 1 deletion rawpheno.module
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,10 @@ function rawpheno_preprocess_rawpheno_upload_form_master(&$variables, $hook) {
$variables['rel_url'] = url('phenotypes/raw/instructions');
// Page Title
$variables['page_title'] = variable_get('rawpheno_upload_title');
// Support Email.
$support_email = '';
drupal_alter('rawpheno_support_email', $support_email);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be an API function for retrieving the support email. Furthermore, the code in kp_nodes determining the default support email (https://github.com/UofS-Pulse-Binfo/kp_nodes/pull/7/files#diff-ea83b3e1886aaaeac403bd6114856bd6R553) should be in this rawphenotypes API function --otherwise only we are given a default ;-)

$variables['support_email'] = $support_email;

// Needs url in help window and links in stage 3.
$variables['page_url'] =
Expand All @@ -334,7 +338,8 @@ function rawpheno_preprocess_rawpheno_upload_form_master(&$variables, $hook) {
'rawpheno_download' => url('phenotypes/raw/download'),
'rawpheno_instructions' => url('phenotypes/raw/instructions'),
'rawpheno_upload' => url('phenotypes/raw/upload'),
'rawpheno_backup' => url('phenotypes/raw/backup')
'rawpheno_backup' => url('phenotypes/raw/backup'),
'rawpheno_demo' => url('phenotypes/raw/videos'),
);

// Stages in upload page.
Expand Down Expand Up @@ -1106,11 +1111,15 @@ function rawpheno_block_view($delta = '') {
$u = explode('.', $url);
$hostname = (empty($u[0])) ? $url : ucfirst($u[0]);

$support_email = '';
drupal_alter('rawpheno_support_email', $support_email);

$content = theme('rawpheno_notification_block', array(
'alert' => $alert,
'username' => $user,
'hostname' => $hostname,
'file_count' => $file_count,
'support_email' => $support_email,
'path_module' => base_path() . $path . '/',
'path_phenotypes_raw' => $GLOBALS['base_url'] . '/phenotypes/raw/',
'path_phenotypes_video' => file_create_url('public://') . 'tutorial_files/rawpheno_videos/',
Expand Down
7 changes: 7 additions & 0 deletions theme/css/rawpheno.notification.block.style.css
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,13 @@
font-size: 1em;
}

#rawpheno-notification-helptopic-select {
font-size: 1em;
margin: 2px 0 10px 0;
padding: 5px;
width: 90%;
}

/* Media query - apply stype when viewport is 1500px */
@media(max-width: 1500px) {
#rawpheno-notification-block-wrapper {
Expand Down
12 changes: 12 additions & 0 deletions theme/js/rawpheno.notification.block.script.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@

whyBackupInfo.slideUp().hide();
});

// Convert help topic select box to a jump menu.
if ($('#rawpheno-notification-helptopic-select').length) {
$('#rawpheno-notification-helptopic-select').change(function() {
var url = $(this).attr('value');

if (url) {
window.open(url, '_blank');
}
});
}

}
};
}(jQuery));
6 changes: 6 additions & 0 deletions theme/js/rawpheno.upload.script.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
collapseLink.once(function() {
$(this).click(function(event) {
event.preventDefault();

// Check if select project message is on.
if (!$('#float-text').is(':hidden')) {
$('#float-text').hide();
}

if (helpWindow.is(':hidden')) {
helpWindow.slideDown(speed, function() {
collapseLink.text('Close window');
Expand Down
19 changes: 13 additions & 6 deletions theme/rawpheno_notification_block.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,19 @@
<div class="rawpheno-notification-item rawpheno-item-c" title="Raw Phenotypes Help Topics">
<div class="rawpheno-item-wrapper">
<h3>Need Help? Select a topic below.</h3>
<ul>
<li><a href="<?php print $path_phenotypes_video . 'rawpheno_backup.mp4'; ?>" target="_blank" class="rawpheno-notification-arrow-right">How to Backup Data Collection Spreadsheet File</a></li>
<li><a href="<?php print $path_phenotypes_video . 'rawpheno_upload.mp4'; ?>" target="_blank" class="rawpheno-notification-arrow-right">How to Upload Data to <?php print $hostname; ?></a></li>
<li><a href="<?php print $path_phenotypes_raw . 'instructions'; ?>" target="_blank" class="rawpheno-notification-arrow-right">Standard Phenotyping Procedure</a></li>
<li><a href="<?php print $path_phenotypes_raw . 'videos'; ?>" target="_blank" class="rawpheno-notification-arrow-right">Other Video Demonstrations</a></li>
</ul>

<select id="rawpheno-notification-helptopic-select">
<option value="">---</option>
<option value="<?php print $path_phenotypes_video . 'rawpheno_backup.mp4'; ?>">How to Backup Spreadsheet File</option>
<option value="<?php print $path_phenotypes_video . 'rawpheno_upload.mp4'; ?>">How to Upload Data to <?php print $hostname; ?></option>
<option value="<?php print $path_phenotypes_raw . 'instructions'; ?>">Standard Phenotyping Procedure</option>
<option value="<?php print $path_phenotypes_raw . 'videos'; ?>">Other Video Demonstrations</option>
</select>

<?php if (isset($support_email) && !empty($support_email)) { ?>
<h3>Still need a help? Send us an email.</h3>
<span class="rawpheno-notification-arrow-right">Email: <a href="mailto:<?php print $support_email; ?>">KnowPulse Support</a></span>
<?php } ?>
</div>
</div>
</div>
10 changes: 10 additions & 0 deletions theme/rawpheno_pages.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,16 @@
<a href="<?php print $page_url['rawpheno_download'] ?>" target="_blank">downloads</a></em>.
</li>
</ul>

<br />
<div>
<h3>&bull; Still Need Help?</h3>
<a href="<?php print $page_url['rawpheno_demo'] ?>" title="This link opens a new window" target="_blank">Watch Raw Phenotypes Video Demonstrations</a>

<?php if (isset($support_email) && !empty($support_email)) { ?>
or Send Us an Email: <a href="mailto:<?php print $support_email; ?>" title="Right click to copy email address">KnowPulse Support</a></span>
<?php } ?>
</div>
</div>

<div>
Expand Down