Browse Source

Fixed some bugs releated to link-outs and added configuration for target upload.

Lacey Sanderson 10 years ago
parent
commit
4e5bdd9c2f

+ 24 - 0
includes/blast_ui.admin.inc

@@ -10,6 +10,28 @@
  */
 function blast_ui_admin_form($form, $form_state) {
 
+  $form['general'] = array(
+    '#type' => 'fieldset',
+    '#title' => 'General'
+  );
+
+  $form['general']['target_upload'] = array(
+    '#type' => 'checkbox',
+    '#title' => 'Enable Taget Sequence Upload',
+    '#default_value' => FALSE,
+    '#description' => 'When this option is checked, a file upload field will '
+      . 'show up on the various BLAST forms under the Database section. This '
+      . 'will allow users tp upload a FASTA file they want to BLAST against '
+      . '(database) as well as a FASTA file containing their query, providing '
+      . 'the ultimate in flexibility for your users. However, since this does '
+      . 'allow & in fact encourage the upload of large files which are then '
+      . 'processed into BLAST databases, this option is disabled by default.',
+    '#default_value' => variable_get(
+        'blast_ui_allow_target_upload',
+        FALSE
+      )
+  );
+
   $form['example_sequence'] = array(
     '#type' => 'fieldset',
     '#title' => 'Set Example Sequences',
@@ -85,6 +107,8 @@ KRSLEEGLKTTGEGLDWGVLFGFGPGLTIETVVLRSVAI';
  */
 function blast_ui_admin_form_submit($form, $form_state) {
 
+  variable_set('blast_ui_allow_target_upload', $form_state['values']['target_upload']);
+
   variable_set('blast_ui_nucleotide_example_sequence', $form_state['values']['nucleotide_example']);
   variable_set('blast_ui_protein_example_sequence', $form_state['values']['protein_example']);
 }

+ 38 - 24
includes/blast_ui.form_per_program.inc

@@ -150,25 +150,27 @@ attempting to submit your BLAST.</strong>',
     '#default_value' => 0,
   );
 
-  // Upload a file as an alternative to selecting an existing BLAST database
-  $form['#attributes']['enctype'] = 'multipart/form-data';
-  $form['DB']['DBUPLOAD'] = array(
-    '#title' => 'Or upload your own dataset:	',
-    '#type' => 'managed_file',
-    '#description' => t('The file should be a plain-text FASTA
-(.fasta, .fna, .fa) file. In other words, it cannot have formatting as is the
-case with MS Word (.doc, .docx) or Rich Text Format (.rtf). It cannot be greater
-than %max_size in size. <strong>Don\'t forget to press the Upload button before
-attempting to submit your BLAST.</strong>',
-      array(
-        '%max_size' => round(file_upload_max_size() / 1024 / 1024,1) . 'MB'
-      )
-    ),
-    '#upload_validators' => array(
-      'file_validate_extensions' => array('fasta fna fa'),
-      'file_validate_size' => array(file_upload_max_size()),
-    ),
-  );
+  if (variable_get('blast_ui_allow_target_upload', FALSE)) {
+    // Upload a file as an alternative to selecting an existing BLAST database
+    $form['#attributes']['enctype'] = 'multipart/form-data';
+    $form['DB']['DBUPLOAD'] = array(
+      '#title' => 'Or upload your own dataset:	',
+      '#type' => 'managed_file',
+      '#description' => t('The file should be a plain-text FASTA
+  (.fasta, .fna, .fa) file. In other words, it cannot have formatting as is the
+  case with MS Word (.doc, .docx) or Rich Text Format (.rtf). It cannot be greater
+  than %max_size in size. <strong>Don\'t forget to press the Upload button before
+  attempting to submit your BLAST.</strong>',
+        array(
+          '%max_size' => round(file_upload_max_size() / 1024 / 1024,1) . 'MB'
+        )
+      ),
+      '#upload_validators' => array(
+        'file_validate_extensions' => array('fasta fna fa'),
+        'file_validate_size' => array(file_upload_max_size()),
+      ),
+    );
+  }
 
   // Advanced Options
   //.........................
@@ -254,11 +256,23 @@ function blast_ui_per_blast_program_form_validate($form, &$form_state) {
   //-------------------
   // @todo: We are currently not validating uploaded files are valid FASTA.
   // First check to see if we have an upload & if so then validate it.
-  $file = file_load($form_state['values']['DBUPLOAD']);
-  // If the $file is populated then this is a newly uploaded, temporary file.
-  if (is_object($file)) {
-    $form_state['dbFlag'] = 'upDB';
-    $form_state['upDB_path'] = drupal_realpath($file->uri);
+  if (isset($form_state['values']['DBUPLOAD'])) {
+    $file = file_load($form_state['values']['DBUPLOAD']);
+    // If the $file is populated then this is a newly uploaded, temporary file.
+    if (is_object($file)) {
+      $form_state['dbFlag'] = 'upDB';
+      $form_state['upDB_path'] = drupal_realpath($file->uri);
+    }
+    // Otherwise there was no file uploaded
+    // Check if there was a database choosen from the list instead
+    elseif (!empty($form_state['values']['SELECT_DB'])) {
+      $form_state['dbFlag'] = 'blastdb';
+    }
+    // Otherwise they didn't select a database!!
+    else {
+      form_set_error('DB', t('No database selected. Either choose a database '
+      . 'from the list or upload one of your own.'));
+    }
   }
   // Otherwise there was no file uploaded
   // Check if there was a database choosen from the list instead

+ 14 - 12
includes/blast_ui.node.inc

@@ -137,7 +137,7 @@ function blastdb_form($node, &$form_state) {
       'swissprot' => '<span title="' . $description['swissprot'] . '">SWISS-PROT</span>',
       'custom' => '<span title="' . $description['custom'] . '">Custom Format</span>',
     ),
-    '#default_value' => ($node->linkout->regex_type) ? $node->linkout->regex_type : 'default',
+    '#default_value' => (isset($node->linkout->regex_type)) ? $node->linkout->regex_type : 'default',
     '#ajax' => array(
       'callback' => 'ajax_blast_ui_node_linkout_custom_callback',
       'wrapper' => 'link-regex',
@@ -163,7 +163,7 @@ function blastdb_form($node, &$form_state) {
     '#disabled' => $hide_regex,
     '#prefix' => '<div id="link-regex">',
     '#suffix' => '</div>',
-    '#default_value' => $node->linkout->regex
+    '#default_value' => (isset($node->linkout->regex)) ? $node->linkout->regex : ''
   );
 
   $db_options = tripal_get_db_select_options();
@@ -176,7 +176,7 @@ function blastdb_form($node, &$form_state) {
       . 'you would like to link-out to is not included you can add it '
       . '<a href="" target="_blank">Here</a>.',
     '#options' => $db_options,
-    '#default_value' => $node->linkout->db_id->db_id
+    '#default_value' => (isset($node->linkout->db_id->db_id)) ? $node->linkout->db_id->db_id : 0
   );
 
   return $form;
@@ -184,15 +184,17 @@ function blastdb_form($node, &$form_state) {
 
 function blastdb_form_validate($form, $form_state) {
 
-  // Check that any supplied regex includes //.
-  if (!preg_match('/\/.*\//', $form_state['values']['regex'])) {
-    form_set_error('regex', 'Regular Expressions require opening and closing slashes to delinate them. For example, <em>/^(\s+) .*/</em>');
-  }
-  // Check that the supplied regex is valid.
-  elseif (@preg_match($form_state['values']['regex'], NULL) === FALSE) {
-    form_set_error('regex', 'Regular Expression not valid. See '
-      . '<a href="http://php.net/manual/en/reference.pcre.pattern.syntax.php" target="_blank">PHP.net Regular '
-      . 'Expression Documentation</a> for more information.');
+  if (!empty($form_state['values']['regex'])) {
+    // Check that any supplied regex includes //.
+    if (!preg_match('/\/.*\//', $form_state['values']['regex'])) {
+      form_set_error('regex', 'Regular Expressions require opening and closing slashes to delinate them. For example, <em>/^(\s+) .*/</em>');
+    }
+    // Check that the supplied regex is valid.
+    elseif (@preg_match($form_state['values']['regex'], NULL) === FALSE) {
+      form_set_error('regex', 'Regular Expression not valid. See '
+        . '<a href="http://php.net/manual/en/reference.pcre.pattern.syntax.php" target="_blank">PHP.net Regular '
+        . 'Expression Documentation</a> for more information.');
+    }
   }
 
   // Check that the supplied db actually contains a URL prefix.

+ 6 - 1
theme/blast_report.tpl.php

@@ -12,7 +12,12 @@
 if ($blastdb->linkout->none === FALSE) {
   $linkout = TRUE;
   $linkout_regex = $blastdb->linkout->regex;
-  $linkout_urlprefix = $blastdb->linkout->db_id->urlprefix;
+  if (isset($blastdb->linkout->db_id->urlprefix) AND !empty($blastdb->linkout->db_id->urlprefix)) {
+    $linkout_urlprefix = $blastdb->linkout->db_id->urlprefix;
+  }
+  else {
+    $linkout = FALSE;
+  }
 }
 ?>