Selaa lähdekoodia

Added support for Excel & FASTA downloading of Views. Created a dependency for views_data_export module

stephen 13 vuotta sitten
vanhempi
commit
dbf191f6e8
19 muutettua tiedostoa jossa 352 lisäystä ja 20 poistoa
  1. 0 0
      base/tripal_core/patches/ahah_helper-submit-1231140-12.patch
  2. 41 0
      base/tripal_core/patches/views_data_export-postgresql-1293788-2.patch
  3. 1 0
      base/tripal_core/tripal_core.info
  4. 1 0
      base/tripal_core/tripal_core.module
  5. 42 0
      base/tripal_core/tripal_core.views.inc
  6. 1 1
      base/tripal_core/views/handlers/views_handler_filter_chado_select_string.inc
  7. 61 19
      base/tripal_core/views/handlers/views_handler_filter_file_upload.inc
  8. BIN
      base/tripal_core/views_data_export/images/fasta.png
  9. 56 0
      base/tripal_core/views_data_export/plugins/tripal_core_plugin_style_export_fasta.inc
  10. 56 0
      base/tripal_core/views_data_export/plugins/tripal_core_plugin_style_export_fasta.inc~
  11. 17 0
      base/tripal_core/views_data_export/theme/tripal_core_views_data_export.theme.inc
  12. 17 0
      base/tripal_core/views_data_export/theme/tripal_core_views_data_export.theme.inc~
  13. 19 0
      base/tripal_core/views_data_export/theme/views-data-export-fasta-body.tpl.php
  14. 19 0
      base/tripal_core/views_data_export/theme/views-data-export-fasta-body.tpl.php~
  15. 5 0
      base/tripal_core/views_data_export/theme/views-data-export-fasta-footer.tpl.php
  16. 5 0
      base/tripal_core/views_data_export/theme/views-data-export-fasta-footer.tpl.php~
  17. 5 0
      base/tripal_core/views_data_export/theme/views-data-export-fasta-header.tpl.php
  18. 6 0
      base/tripal_core/views_data_export/theme/views-data-export-fasta-header.tpl.php~
  19. 0 0
      views_exports/feature_for_search.view_export.txt

+ 0 - 0
base/ahah_helper-submit-1231140-12.patch → base/tripal_core/patches/ahah_helper-submit-1231140-12.patch


+ 41 - 0
base/tripal_core/patches/views_data_export-postgresql-1293788-2.patch

@@ -0,0 +1,41 @@
+diff --git a/plugins/views_data_export_plugin_display_export.inc b/plugins/views_data_export_plugin_display_export.inc
+index 3356a8c..bf6761a 100644
+--- a/plugins/views_data_export_plugin_display_export.inc
++++ b/plugins/views_data_export_plugin_display_export.inc
+@@ -544,7 +544,16 @@ class views_data_export_plugin_display_export extends views_plugin_display_feed
+         $select_aliases[] = "cl.$alias AS $hash";
+       }
+ 
+-      $insert_query = 'CREATE TABLE {' . $this->index_tablename() . '} SELECT @row := @row + 1 AS ' . $this->batched_execution_state->sandbox['weight_field_alias'] . ', ' . implode(', ', $select_aliases) . ' FROM (' . $query . ') AS cl, (SELECT @row := 0) AS r';
++      if ($this->_get_database_driver() == 'pgsql') {
++        // Create temporary sequence
++        $seq_name = $this->index_tablename() . '_seq';
++        $create_seq_query = 'CREATE TEMP sequence ' . $seq_name;
++        // query uses sequence to create row number
++        $insert_query = 'CREATE TABLE {' . $this->index_tablename() . "} AS SELECT nextval('".$seq_name."') AS " . $this->batched_execution_state->sandbox['weight_field_alias'] . ', ' . implode(', ', $select_aliases) . ' FROM (' . $query . ') AS cl';
++      }
++      else {
++        $insert_query = 'CREATE TABLE {' . $this->index_tablename() . '} SELECT @row := @row + 1 AS ' . $this->batched_execution_state->sandbox['weight_field_alias'] . ', ' . implode(', ', $select_aliases) . ' FROM (' . $query . ') AS cl, (SELECT @row := 0) AS r';
++      }
+ 
+       // Allow for a view to query an external database.
+       if (isset($view->base_database)) {
+@@ -552,6 +561,9 @@ class views_data_export_plugin_display_export extends views_plugin_display_feed
+         $external = TRUE;
+       }
+ 
++      if ($this->_get_database_driver() == 'pgsql') {
++        db_query($create_seq_query);
++      }
+       db_query($insert_query, $args);
+ 
+       // Now create an index for the weight field, otherwise the queries on the
+@@ -778,7 +790,7 @@ class views_data_export_plugin_display_export extends views_plugin_display_feed
+    */
+   function is_compatible() {
+     $incompatible_drivers = array (
+-      'pgsql',
++      //'pgsql',
+     );
+     $db_driver = $this->_get_database_driver();
+     return !in_array($db_driver, $incompatible_drivers);

+ 1 - 0
base/tripal_core/tripal_core.info

@@ -8,3 +8,4 @@ version = 6.x-0.3.1b
 
 dependencies[] = views
 dependencies[] = ahah_helper
+dependencies[] = views_data_export

+ 1 - 0
base/tripal_core/tripal_core.module

@@ -316,4 +316,5 @@ function tripal_core_load_gff3($gff_file, $organism_id,$analysis_id,$add_only =0
    tripal_feature_load_gff3($gff_file, $organism_id,$analysis_id,$add_only,
       $update, $refresh, $remove, $job);
 }
+ 
 

+ 42 - 0
base/tripal_core/tripal_core.views.inc

@@ -540,3 +540,45 @@ function tripal_core_views_data_alter(&$data) {
     }
     return $data;
 }
+/**
+ * Implementation of hook_views_plugins().
+ */
+function tripal_core_views_plugins() {
+  $tc_path = drupal_get_path('module', 'tripal_core');
+
+  $style_defaults = array(
+    'path' => $tc_path . '/views_data_export/plugins',
+    'parent' => 'views_data_export',
+    'theme' => 'views_data_export',
+    'theme path' => $tc_path . '/views_data_export/theme',
+    'theme file' => 'tripal_core_views_data_export.theme.inc',
+    'uses row plugin' => FALSE,
+    'uses fields' => TRUE,
+    'uses options' => TRUE,
+    'type' => 'data_export',
+  );
+
+  // add FASTA format as a new style for the existing views_export_data Display
+  return array( 
+    'style' => array(   
+      'views_data_export_fasta' => array(
+        'title' => t('FASTA file'),
+        'help' => t('Display results in FASTA format. All fields in results are on the definition line while the feature.residues field must be present .'),
+        'handler' => 'tripal_core_plugin_style_export_fasta',
+        // Views Data Export element that will be used to set additional headers when serving the feed.
+        'export headers' => array('Content-type: text/plain; charset=utf-8'),
+        // Views Data Export element mostly used for creating some additional classes and template names.
+        'export feed type' => 'fasta',
+        'export feed text' => 'FASTA',
+        'export feed file' => '%view.fna',
+        'export feed icon' => $tc_path . '/views_data_export/images/fasta.png',
+        'additional themes' => array(
+          'views_data_export_fasta_header' => 'style',
+          'views_data_export_fasta_body' => 'style',
+          'views_data_export_fasta_footer' => 'style',
+        ),
+        'additional themes base' => 'views_data_export_fasta',
+      ) + $style_defaults,      
+    ),
+  );
+}

+ 1 - 1
base/tripal_core/views/handlers/views_handler_filter_chado_select_string.inc

@@ -125,7 +125,7 @@ class views_handler_filter_chado_select_string extends views_handler_filter_stri
     $this->ensure_my_table();
     $field = "$this->table_alias.$this->real_field";
     $upper = $this->case_transform();
-      
+
     if ($this->options['multiple']) {
       // Remove any if it's there
       unset($this->value['All']);

+ 61 - 19
base/tripal_core/views/handlers/views_handler_filter_file_upload.inc

@@ -1,5 +1,6 @@
 <?php
 
+require_once "/var/www/sites/all/modules/views/handlers/views_handler_filter_string.inc";
 /**
  * Purpose: This Handler provides a file upload field.
  *
@@ -8,40 +9,64 @@
  */
 class views_handler_filter_file_upload extends views_handler_filter {
 
+  function init(&$view,$options){
+     parent::init($view,$options);
+
+  }
+
   function options_form(&$form, &$form_state) {
     parent::options_form($form, $form_state);
 
   }
   
- /**
+  /**
   * Defines the value field in both the views filter options form
   *   and the exposed form
   */
   function value_form(&$form, &$form_state) {
     parent::value_form($form, $form_state);
     
-    // add the file upload form element and set the encoding type for the
-    // form to be multipart/form-data
+    // we'll provide a single text area for this field.
+    // in the exposed_form function we'll add in the file upload button
     $form['value'] = array(
-      '#type' => 'file',
-      '#title' => $this->options['expose']['label'],
-    );
-    $form['#attributes']['enctype'] = 'multipart/form-data';
-    $form['#method'] = 'POST';
+       '#type' => 'textarea',
+       '#title' => $this->options['expose']['label'],
+       '#default_value' => $this->value,
+       '#multiple' => FALSE,
+       '#description' => t('Provide search values for ' . $this->options['expose']['label'] . 
+         '. Please place each search item on a separate line or separated by commas.'),
+    ); 
   }
 
- /**
+  /** 
+   *  Validates the input form
+   */
+  function exposed_validate(&$form, &$form_state) {
+    //dpm($form_state);
+
+  }
+  /**
   * Ensures the select list gets rendered when the filter is exposed
   */
   function exposed_form(&$form, &$form_state) {
+
     if (empty($this->options['exposed'])) {
       return;
     }
+
+    // rebuild the form elements 
     $value = $this->options['expose']['identifier'];
     $this->value_form($form, $form_state);
     $form[$value] = $form['value'];
     unset($form[$value]['#title']);
-
+    $form[$this->options['field'] . '_upload'] = array(
+      '#type' => 'file',
+      '#title' => '',
+      '#description' => t('Upload a file to provide search values for ' . $this->options['expose']['label'] . 
+         '. Please place each search item on a separate line.'),
+    );
+    $form['#attributes']['enctype'] = 'multipart/form-data';
+    $form['#method'] = 'POST';
     $this->exposed_translate($form[$value], 'value');
   }
 
@@ -49,23 +74,40 @@ class views_handler_filter_file_upload extends views_handler_filter {
   *
   */
   function query() {
-     $file = file_save_upload($this->field,array());
      $field = "$this->table.$this->real_field";
+     $holders = array();
+     $values = array();
 
+     // get the file upload info if one has been provided
+     $file = file_save_upload($this->field.'_upload',array());
      if($file){
         $fh = fopen($file->filepath,'r');
-        $holders = array();
-        $values = array();
+
         while($line = fgets($fh)){
           $line = trim($line);
-          if (preg_match('/^[\d\.]+$/',$v)) {
-            $holders[] = '%d';
-          } else {
-            $holders[] = "'%s'";
-          }
-          // don't include duplicates
           $values[] = $line;
         }
+     } 
+     // if a file upload has not been provided then use the value in the textarea
+     else {
+        $items = $this->value[0];
+        $items = preg_replace("/\s+,/",",",$items);
+        $items = preg_replace("/\s+\n/","\n",$items);
+        $items = preg_replace("/,\n/","\n",$items);
+        $values = preg_split("/[\n,]+/",$items);
+
+     }
+     for($i = 0 ; $i < count($values); $i++){
+        $values[$i] = trim($values[$i]);
+        if (preg_match('/^[\d\.]+$/',$values[$i])) {
+           $holders[] = '%d';
+        } else {
+           $holders[] = "'%s'";
+        }
+     }
+     // if we have any values supplied then update the where clause for
+     // the views query
+     if(count($holders) > 0){
         $where = "$field IN (".implode(", ",$holders).")";
         $this->query->add_where($this->options['group'], $where, $values);
      }

BIN
base/tripal_core/views_data_export/images/fasta.png


+ 56 - 0
base/tripal_core/views_data_export/plugins/tripal_core_plugin_style_export_fasta.inc

@@ -0,0 +1,56 @@
+<?php
+/**
+ * @file
+ * Plugin include file for export style plugin.
+ */
+
+/**
+ * Generalized style plugin for export plugins.
+ *
+ * @ingroup views_style_plugins
+ */
+class tripal_core_plugin_style_export_fasta extends views_data_export_plugin_style_export {
+
+  /**
+   * Set options fields and default values.
+   *
+   * @return
+   * An array of options information.
+   */
+  function option_definition() {
+    $options = parent::option_definition();
+
+  
+    return $options;
+  }
+
+  /**
+   * Options form mini callback.
+   *
+   * @param $form
+   * Form array to add additional fields to.
+   * @param $form_state
+   * State of the form.
+   * @return
+   * None.
+   */
+  function options_form(&$form, &$form_state) {
+    parent::options_form($form, $form_state);
+
+    $form['defline_fields'] = array(
+      '#prefix' => '<div><div id="edit-options-newline-replacement">',
+      '#suffix' => '</div></div>',
+      '#type' => 'textfield',
+      '#title' => t('Defenition line fields'),
+      '#default_value' => $this->options['defline_fields'],
+      '#description' => t("This field controls the information present in the definition ".
+         "line for each sequence. Any of the fields in the view can be used in the ".
+         "definition line.  To discover these fields, add the feature residues as the ".
+         "last field in the view.  Then edit the field and click the checkbox \"Rewrite ".
+         "the output of this field\".  In the replacement patterns section are the ".
+         "field replacement tokens that can be used in this field. You may include any ".
+         "additional text to separte or qualify these fields.  Only fields that have not ".
+         "been excluded from the display will appear."),
+    );
+  }
+}

+ 56 - 0
base/tripal_core/views_data_export/plugins/tripal_core_plugin_style_export_fasta.inc~

@@ -0,0 +1,56 @@
+<?php
+/**
+ * @file
+ * Plugin include file for export style plugin.
+ */
+
+/**
+ * Generalized style plugin for export plugins.
+ *
+ * @ingroup views_style_plugins
+ */
+class tripal_core_plugin_style_export_fasta extends views_data_export_plugin_style_export {
+
+  /**
+   * Set options fields and default values.
+   *
+   * @return
+   * An array of options information.
+   */
+  function option_definition() {
+    $options = parent::option_definition();
+
+  
+    return $options;
+  }
+
+  /**
+   * Options form mini callback.
+   *
+   * @param $form
+   * Form array to add additional fields to.
+   * @param $form_state
+   * State of the form.
+   * @return
+   * None.
+   */
+  function options_form(&$form, &$form_state) {
+    parent::options_form($form, $form_state);
+
+    $form['defline_fields'] = array(
+      '#prefix' => '<div><div id="edit-options-newline-replacement">',
+      '#suffix' => '</div></div>',
+      '#type' => 'textfield',
+      '#title' => t('Defenition line fields'),
+      '#default_value' => $this->options['defline_fields'],
+      '#description' => t("This field controls the information present in the definition ".
+         "line for each sequence. Any of the fields in the view can be used in the ".
+         "definition line.  To discover these fields, add the feature residues as the ".
+         "last field in the view.  Then edit the field and click the checkbox \"Rewrite ".
+         "the output of this field\".  In the replacement patterns section are the ".
+         "field replacement tokens that can be used in this field. You may include any ".
+         "additional text to separte or qualify these fields.  Only fields that have not ".
+         "been excluded from the display will appear"),
+    );
+  }
+}

+ 17 - 0
base/tripal_core/views_data_export/theme/tripal_core_views_data_export.theme.inc

@@ -0,0 +1,17 @@
+<?php
+
+function template_preprocess_views_data_export_fasta_body(&$vars) {
+   _views_data_export_header_shared_preprocess($vars);
+   _views_data_export_body_shared_preprocess($vars);
+   $defline_tpl = $vars['options']['defline_fields'];
+
+   // iterate through the rows and replace the field tokens with values
+   // to generate the definition line
+   foreach ($vars['themed_rows'] as $i => $fields) {
+      $defline = $defline_tpl;
+      foreach ($fields as $key => $value) {
+         $defline = preg_replace("/\[$key\]/",$value,$defline);
+      }
+      $vars['themed_rows'][$i]['defline'] = $defline;
+   }
+}

+ 17 - 0
base/tripal_core/views_data_export/theme/tripal_core_views_data_export.theme.inc~

@@ -0,0 +1,17 @@
+<?php
+
+function template_preprocess_views_data_export_fasta_body(&$vars) {
+   _views_data_export_header_shared_preprocess($vars);
+   _views_data_export_body_shared_preprocess($vars);
+   $defline_tpl = $vars['options']['defline_fields'];
+
+   // iterate through the rows and replace the field tokens with values
+   // to generate the definition line
+   foreach ($vars['themed_rows'] as $i => $fields) {
+      $defline = $defline_tpl;
+      foreach ($values as $key => $value) {
+         $defline = preg_replace("/\[$key\]/",$value,$defline);
+      }
+      $vars['themed_rows'][$i]['defline'] = $defline;
+   }
+}

+ 19 - 0
base/tripal_core/views_data_export/theme/views-data-export-fasta-body.tpl.php

@@ -0,0 +1,19 @@
+<?php
+//print_r($themed_rows);
+print $defline;
+foreach ($themed_rows as $index => $fields){
+   $defline = array();
+   $residues = '';
+   foreach ($fields as $key => $value){
+     if(strcmp($key,'residues')==0){
+        $residues = wordwrap($value, 60, "\r\n", true);
+     } 
+     if(strcmp($key,'defline')==0){
+        $defline = $value;
+     }
+   }
+   print ">$defline\r\n";
+   print "$residues\r\n";
+}
+
+

+ 19 - 0
base/tripal_core/views_data_export/theme/views-data-export-fasta-body.tpl.php~

@@ -0,0 +1,19 @@
+<?php
+//print_r($themed_rows);
+print $defline;
+foreach ($themed_rows as $index => $fields){
+   $defline = array();
+   $residues = '';
+   foreach ($fields as $key => $value){
+     if(strcmp($key,'residues')==0){
+        $residues = wordwrap($value, 60, "\r\n", true);
+     } 
+     if($strcmp($key,'defline')==0){
+        $defline = $value;
+     }
+   }
+   print ">$defline\r\n";
+   print "$residues\r\n";
+}
+
+

+ 5 - 0
base/tripal_core/views_data_export/theme/views-data-export-fasta-footer.tpl.php

@@ -0,0 +1,5 @@
+<?php
+
+/**
+ * FASTA files don't have a footer.
+ */

+ 5 - 0
base/tripal_core/views_data_export/theme/views-data-export-fasta-footer.tpl.php~

@@ -0,0 +1,5 @@
+<?php
+
+/**
+ * CSV files don't really have a footer.
+ */

+ 5 - 0
base/tripal_core/views_data_export/theme/views-data-export-fasta-header.tpl.php

@@ -0,0 +1,5 @@
+<?php
+
+/**
+ * FASTA files don't have a header.
+ */

+ 6 - 0
base/tripal_core/views_data_export/theme/views-data-export-fasta-header.tpl.php~

@@ -0,0 +1,6 @@
+<?php
+
+// Print out header row, if option was selected.
+if ($options['header']) {
+  print implode($separator, $header) . "\r\n";
+}

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 0 - 0
views_exports/feature_for_search.view_export.txt


Kaikkia tiedostoja ei voida näyttää, sillä liian monta tiedostoa muuttui tässä diffissä