Sfoglia il codice sorgente

Added download from on views displays that have a views data export display attached. Also made it so Chado tabes can work with views integration and not just materialized views

stephen 13 anni fa
parent
commit
143d4e2dca

+ 5 - 1
base/tripal_core/tripal_core.module

@@ -287,10 +287,14 @@ function tripal_core_theme () {
          'arguments' => array('job_id'=> null),
          'arguments' => array('job_id'=> null),
          'template' => 'tripal_core_job_view',
          'template' => 'tripal_core_job_view',
       ),
       ),
-	  'tripal_core_views_integration_form' => array(
+	   'tripal_core_views_integration_form' => array(
          'arguments' => array('form' => NULL),
          'arguments' => array('form' => NULL),
          'template'  => 'tripal_views_integration_fields_form',
          'template'  => 'tripal_views_integration_fields_form',
 	   ),
 	   ),
+	   'tripal_core_views_data_export_download_form' => array(
+         'arguments' => array('form' => NULL),
+         'template'  => 'tripal_core_views_data_export_download_form',
+	   ),
    );
    );
 }
 }
 /**
 /**

+ 86 - 4
base/tripal_core/tripal_core.views.inc

@@ -420,13 +420,16 @@ function tripal_core_views_data(){
       }
       }
       else {
       else {
          $type_prefix = 'Chado Table';
          $type_prefix = 'Chado Table';
-         // TODO: get the chado table info and populate these variables
-         //  1) $base_table
-         //  2) $base_fields (an array of just the table field names)
+         $base_table = $tvi_row->table_name;
+         $table_desc = module_invoke_all('chado_'.$base_table.'_schema');
+         $fields = $table_desc['fields'];
+         foreach($fields as $column => $attrs){
+            $base_fields[] = $column;
+         }
       }
       }
 
 
       // Setup the base table info in the data array
       // Setup the base table info in the data array
-      $data[$base_table]['table']['group'] = t($tvi_row->name);
+      $data[$base_table]['table']['group'] = t("$type_prefix: $tvi_row->name");
       $data[$base_table]['table']['base'] = array(
       $data[$base_table]['table']['base'] = array(
         'group' => "$type_prefix: $tvi_row->name",
         'group' => "$type_prefix: $tvi_row->name",
         'title' => "$type_prefix: $tvi_row->name",
         'title' => "$type_prefix: $tvi_row->name",
@@ -479,6 +482,7 @@ function tripal_core_views_data(){
         }
         }
       }
       }
     }
     }
+dpm($data);
     return $data;
     return $data;
 }
 }
 /**
 /**
@@ -582,3 +586,81 @@ function tripal_core_views_plugins() {
     ),
     ),
   );
   );
 }
 }
+/**
+ * Implementation of hook_views_pre_view().
+ */
+function tripal_core_views_pre_view(&$view,&$display_id,&$args){
+   $form = drupal_get_form('tripal_core_views_data_export_download_form',$view,$display_id,$args);
+   $view->attachment_after = $form;
+}
+/**
+ * 
+ */
+function tripal_core_views_data_export_download_form(&$form_state, $view,$display_id,$args){
+   $form = array();
+   $urls = array();
+
+   // get any export_data_export displays
+   $displays = $view->display;
+   $options = array();
+   $default = '';
+   foreach($displays as $name => $display){
+      if(preg_match("/^views_data_export/",$name)){
+         // set the first item as default
+         if(!$default){
+            $default = $display->id;
+         }
+         // add the data export URL to the URLs array
+         $query = $view->get_exposed_input();
+         $path = $display->display_options['path'];
+         $urls[$display->id]['path'] = $path;
+         $urls[$display->id]['query'] = $query;
+         // add the new item to the options array
+         $options[$display->id] = $display->display_title;
+      }
+   }
+   // only generate the form if we have views_data_export displays attached
+   // to this view
+   if(count($options) > 0){
+
+      $form_state['storage']['urls'] = $urls;
+      $form['#cache'] = TRUE;
+
+      // we want the form to redirect to a new window
+      $form['#attributes']['target'] = "_blank";
+
+      // now build the form elements
+      $form['downloads'] = array(
+        '#type' => 'fieldset',
+        '#title' => 'Download Results',
+        '#collapsible' => TRUE,
+        '#collapsed' => FALSE
+      );
+      $form['downloads']['file_type'] = array(
+         '#title' => t('File format'),
+         '#type' => 'radios',
+         '#options' => $options,
+         '#required' => TRUE,
+         '#default_value' => $default,
+         '#description' => t('Please select a file format to download'),
+      );
+      $form['downloads']['submit'] = array(
+         '#value' => t('Download Results'),
+         '#type' => 'submit',
+      );
+   }
+   
+   return $form;
+}
+/**
+ * 
+ */
+function tripal_core_views_data_export_download_form_submit($form, &$form_state){
+   $urls = $form_state['storage']['urls'];
+   $display_id = $form_state['values']['file_type'];
+   drupal_goto($urls[$display_id]['path'],$urls[$display_id]['query']);
+}
+
+
+
+

+ 39 - 15
base/tripal_core/tripal_views_integration.inc

@@ -82,7 +82,14 @@ function tripal_core_views_integration_setup_list(){
             l('Delete',"admin/tripal/views/integration/delete/".$tview->setup_id),
             l('Delete',"admin/tripal/views/integration/delete/".$tview->setup_id),
          );
          );
       } else {
       } else {
-         // TODO: customize for Chado tables
+         $rows[] = array(
+            l('Edit',"admin/tripal/views/integration/edit/".$tview->setup_id) ,
+            $tview->name, 
+            $tview->table_name, 
+            'No', 
+            $tview->comment,
+            l('Delete',"admin/tripal/views/integration/delete/".$tview->setup_id),
+         );         
       }
       }
    }
    }
    $rows[] = array(
    $rows[] = array(
@@ -128,6 +135,7 @@ function tripal_core_views_integration_form(&$form_state, $setup_id = NULL){
       $mview_id = $setup_obj->mview_id;
       $mview_id = $setup_obj->mview_id;
       $table_name = $setup_obj->table_name;
       $table_name = $setup_obj->table_name;
       $form_state['storage']['mview_id'] = $mview_id;
       $form_state['storage']['mview_id'] = $mview_id;
+      $form_state['storage']['table_name'] = $table_name;
 
 
       // get the default join settings and handlers
       // get the default join settings and handlers
       $sql = "SELECT * FROM {tripal_views_join} WHERE setup_id = %d";
       $sql = "SELECT * FROM {tripal_views_join} WHERE setup_id = %d";
@@ -261,12 +269,20 @@ function tripal_core_views_integration_form(&$form_state, $setup_id = NULL){
 
 
     // get the columns in this materialized view.  They are separated by commas
     // get the columns in this materialized view.  They are separated by commas
     // where the first word is the column name and the rest is the type
     // where the first word is the column name and the rest is the type
+    $columns = array();
     if($mview_id){
     if($mview_id){
        $sql = "SELECT mv_specs FROM {tripal_mviews} WHERE mview_id = %d";
        $sql = "SELECT mv_specs FROM {tripal_mviews} WHERE mview_id = %d";
        $mview = db_fetch_object(db_query($sql,$mview_id));
        $mview = db_fetch_object(db_query($sql,$mview_id));
        $columns = explode(",",$mview->mv_specs);
        $columns = explode(",",$mview->mv_specs);
     } else {
     } else {
-       // TODO: get chado table columns and add them to the $columns array
+       $table_desc = module_invoke_all('chado_'.$table_name.'_schema');
+       $fields = $table_desc['fields'];
+       // iterate through the columns and build the format
+       // compatible with the code below. The column name is first followed
+       // by the type with a separating space
+       foreach($fields as $column => $attrs){
+          $columns[] = "$column ".$attrs['type'];
+       }
     }
     }
 
 
     $i=1;
     $i=1;
@@ -583,24 +599,32 @@ function tripal_core_views_integration_form_submit($form, &$form_state){
        'name' => $name,
        'name' => $name,
        'comment' => $form_state['values']['row_description'],
        'comment' => $form_state['values']['row_description'],
       );
       );
-      if(!$setup_id){  // this is an insert
-         if(!drupal_write_record('tripal_views', $tripal_views_record)){
-            drupal_set_message("Failed to add record.");
-            return;
-         }
-      } else {  // this is an update
-         $tripal_views_record['setup_id'] = $setup_id;
-         if(!drupal_write_record('tripal_views', $tripal_views_record,array('setup_id'))){
-            drupal_set_message("Failed to update record.");
-            return;
-         }
-      }
    } 
    } 
    // if a chado table then...
    // if a chado table then...
    if($table_name){
    if($table_name){
-      // TODO: add code to update tables for Chado table
+            // build the record for insert/update
+      $tripal_views_record = array(
+       'table_name' => $table_name,
+       'name' => $name,
+       'comment' => $form_state['values']['row_description'],
+      );
    }
    }
 
 
+   // perform the insert or update
+   if(!$setup_id){  // this is an insert
+      if(!drupal_write_record('tripal_views', $tripal_views_record)){
+         drupal_set_message("Failed to add record.");
+         return;
+      }
+   } else {  // this is an update
+      $tripal_views_record['setup_id'] = $setup_id;
+      if(!drupal_write_record('tripal_views', $tripal_views_record,array('setup_id'))){
+         drupal_set_message("Failed to update record.");
+         return;
+      }
+   }
+   
+
    
    
    // if this is an update then clean out the existing joins and handlers so we can add new ones
    // if this is an update then clean out the existing joins and handlers so we can add new ones
    if($setup_id){  
    if($setup_id){  

+ 1 - 1
base/tripal_core/views_data_export/theme/tripal_core_views_data_export.theme.inc~

@@ -9,7 +9,7 @@ function template_preprocess_views_data_export_fasta_body(&$vars) {
    // to generate the definition line
    // to generate the definition line
    foreach ($vars['themed_rows'] as $i => $fields) {
    foreach ($vars['themed_rows'] as $i => $fields) {
       $defline = $defline_tpl;
       $defline = $defline_tpl;
-      foreach ($values as $key => $value) {
+      foreach ($fields as $key => $value) {
          $defline = preg_replace("/\[$key\]/",$value,$defline);
          $defline = preg_replace("/\[$key\]/",$value,$defline);
       }
       }
       $vars['themed_rows'][$i]['defline'] = $defline;
       $vars['themed_rows'][$i]['defline'] = $defline;