Browse Source

Added missing files to example module. Working on default CV form

Stephen Ficklin 11 years ago
parent
commit
ddf18ece9e

+ 1 - 1
tripal_cv/api/tripal_cv.api.inc

@@ -127,7 +127,7 @@ function tripal_get_cv($identifiers, $options = array()) {
  */
  */
 function tripal_get_cv_select_options() {
 function tripal_get_cv_select_options() {
 
 
-  $results = chado_select_record('cv', array('cv_id', 'name'), array());
+  $results = chado_select_record('cv', array('cv_id', 'name'), array(), array('order_by' => array('name' => 'ASC')));
 
 
   $options = array();
   $options = array();
   foreach ($results as $r) {
   foreach ($results as $r) {

+ 116 - 1
tripal_cv/includes/tripal_cv.admin.inc

@@ -52,8 +52,123 @@ function tripal_cv_admin_set_defaults_form() {
   $form = array();
   $form = array();
   
   
   $form['instructions'] = array(
   $form['instructions'] = array(
-    '#markup' => 'use the following...'
+    '#markup' => t('Much of the data housed in Chado is typed, meaning that a ' .
+        'controlled vocabulary describes what type of data the record is. For example, '.
+        'a feature must have a "type" which is typically a term from ' .
+        'the Sequence Ontology. Record properties typically have a type as well. '.
+        'Tripal allows the administrator to set a default type for each table in '.
+        'Chado that requires a type from a vocabulary. By default, autocomplete fields, '.
+        'type select boxes and type validation occur using the default vocabularies set below. '),
   );
   );
   
   
+  // get the list of all tables that use the cvterm table as an FK
+  $cvterm_schema = chado_get_schema('cvterm');
+  $referring_tables = $cvterm_schema['referring_tables'];
+  
+  // get the list of tables that already have default set
+  $cv_defaults = db_select('tripal_cv_defaults', 'TCD')
+    ->fields('TCD', array('cv_default_id', 'table_name', 'field_name', 'cv_id'))
+    ->orderBy('table_name', 'ASC')
+    ->execute();
+  
+  // get the list of vocabularies
+  $cvs = tripal_get_cv_select_options();
+  
+  $form['settings'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Configured Defaults'),
+    '#description' => t('The following tables have a default vocabulary'),
+    '#tree' => TRUE,
+  );
+  foreach ($cv_defaults as $cv_default) {
+    $cv_default_id = $cv_default->cv_default_id;
+    $cv = tripal_get_cv(array('cv_id' => $cv_default->cv_id));
+    $form['settings']['existing'][$cv_default_id]["id"] = array(
+      '#type' => 'hidden',
+      '#value' => $cv_default_id,
+    );
+    $form['settings']['existing'][$cv_default_id]["table_name"] = array(
+      '#type' => 'markup',
+      '#markup' => $cv_default->table_name
+    );
+    $form['settings']['existing'][$cv_default_id]["field_name"] = array(
+      '#type' => 'markup',
+      '#markup' => $cv_default->field_name
+    );
+    $form['settings']['existing'][$cv_default_id]["vocabulary"] = array(
+      '#type' => 'select',
+      '#options' => $cvs,
+      '#default_value' => $cv_default->cv_id,
+      '#suffix' => '<a target="_blank" href="'. url('admin/tripal/chado/tripal_cv/cvterms') . '?cv=' . $cv->name . '">View terms</a>'
+    );
+    // remove button
+    $form['settings']['existing'][$cv_default_id]['remove'] = array(
+      '#type' => 'submit',
+      '#value' => t('Remove'),
+      '#name' => "cv_remove-$cv_default_id",
+      '#ajax' => array(
+        'callback' => "tripal_cv_admin_set_defaults_ajax_update",
+        'wrapper' => 'tripal-generic-edit-properties-table',
+        'effect'   => 'fade',
+        'method'   => 'replace',
+        'prevent'  => 'click'
+      ),
+      // When this button is clicked, the form will be validated and submitted.
+      // Therefore, we set custom submit and validate functions to override the
+      // default node form submit.  In the validate function we validate only the
+      // property fields and in the submit we remove the indicated property
+      // from the chado_properties array. In order to keep validate errors
+      // from the node form validate and Drupal required errors for non-property fields
+      // preventing the user from removing properties we set the #limit_validation_errors below
+      '#validate' => array('chado_add_node_form_properties_remove_button_validate'),
+      '#submit' => array('chado_add_node_form_properties_remove_button_submit'),
+      // Limit the validation of the form upon clicking this button to the property_table tree
+      // No other fields will be validated (ie: no fields from the main form or any other api
+      // added form).
+      '#limit_validation_errors' => array(
+        array('property_table')  // Validate all fields within $form_state['values']['property_table']
+      )
+    );
+  }
+  
   return $form;
   return $form;
+}
+
+/**
+ * 
+ * @param unknown $variables
+ */
+function theme_tripal_cv_admin_set_defaults_form($variables) {
+  $element = $variables['element'];
+
+  $header = array(
+    'table_name'      => array('data' => t('Table Name'),      'width' => '20%'),
+    'field_name'      => array('data' => t('Field Name'),      'width' => '20%'),
+    'vocabulary'      => array('data' => t('Default Vocabulary'), 'width' => '40%'),
+    'property_action' => array('data' => t('Actions'),    'width' => '20%'),
+  );
+
+  $rows = array();
+  
+  foreach ($element['settings']['existing'] as $key => $value) {
+    if (is_numeric($key)) {
+      $rows[] = array(
+        drupal_render($value['table_name']),
+        drupal_render($value['field_name']),
+        drupal_render($value['vocabulary']),
+        drupal_render($value['remove']),
+      );
+    }
+  } 
+  $settings_table = theme('table', array(
+    'header' => $header,
+    'rows' => $rows
+  ));
+  $element['settings']['existing'] = array(
+    '#type' => 'markup',
+    '#markup' => $settings_table,
+  );
+  
+  return drupal_render_children($element);
+  
 }
 }

+ 6 - 1
tripal_cv/tripal_cv.module

@@ -326,7 +326,12 @@ function tripal_cv_theme($existing, $type, $theme, $path) {
       'template' => 'tripal_cv_help',
       'template' => 'tripal_cv_help',
       'variables' =>  array(NULL),
       'variables' =>  array(NULL),
       'path' => "$path/theme/templates"
       'path' => "$path/theme/templates"
-    )
+    ),
+    // Default CV form
+    'tripal_cv_admin_set_defaults_form' => array(
+      'function' => 'theme_tripal_cv_admin_set_defaults_form',
+      'render element' => 'element',
+    ),
   );
   );
 
 
   return $items;
   return $items;

+ 0 - 0
tripal_example/theme/css/tripal_example.css


+ 9 - 0
tripal_example/theme/js/tripal_example.js

@@ -0,0 +1,9 @@
+(function($) {
+  Drupal.behaviors.tripal_exampleBehavior = {
+    attach: function (context, settings){
+
+      // Place JavaScript code here
+
+    }
+  };
+})(jQuery);

+ 14 - 0
tripal_example/theme/templates/tripal_example_teaser.tpl.php

@@ -0,0 +1,14 @@
+<?php
+$example  = $variables['node']->example; ?>
+
+<div class="tripal_example-teaser tripal-teaser"> 
+  <div class="tripal-example-teaser-title tripal-teaser-title"><?php 
+    print l("<i>$example->uniquename", "node/$node->nid", array('html' => TRUE));?>
+  </div>
+  <div class="tripal-example-teaser-text tripal-teaser-text"> <?php
+    print substr($example->description, 0, 650);
+    if (strlen($example->description) > 650) {
+      print "... " . l("[more]", "node/$node->nid");
+    } ?>
+  </div>
+</div>

+ 1 - 0
tripal_feature/api/tripal_feature.api.inc

@@ -370,6 +370,7 @@ function tripal_get_sequence($feature, $options) {
 
 
       // get the reverse compliment if feature is on the reverse strand
       // get the reverse compliment if feature is on the reverse strand
       $dir = 'forward';
       $dir = 'forward';
+      $notes = '';
       if ($parent->strand < 0) {
       if ($parent->strand < 0) {
         $seq = tripal_feature_reverse_complement($seq);
         $seq = tripal_feature_reverse_complement($seq);
         $dir = 'reverse';
         $dir = 'reverse';

+ 16 - 14
tripal_feature/theme/templates/tripal_feature_sequence.tpl.php

@@ -164,16 +164,18 @@ if ($residues or count($featureloc_sequences) > 0) {
         )
         )
     );
     );
     if (count($cds_sequence) > 0) {
     if (count($cds_sequence) > 0) {
-      $list_items[] = '<a href="#coding_' . $attrs['id'] . '">coding sequnece from alignment at  ' . $attrs['location'] . "</a>";
-      $sequences_html .= '<a name="ccoding_' . $attrs['id'] . '"></a>';
-      $sequences_html .= '<div id="coding_' . $attrs['id'] . '" class="tripal_feature-sequence-item">';
-      $sequences_html .= '<p><b>Coding sequence (CDS) from alignment at  ' . $attrs['location'] . '</b></p>';
-      $sequences_html .= '<pre class="tripal_feature-sequence">';
-      $sequences_html .= '>' . tripal_get_fasta_defline($feature, $attrs['featureloc'], 'CDS') . "\n";
-      $sequences_html .= $cds_sequence[0]['residues'];
-      $sequences_html .= '</pre>';
-      $sequences_html .= '<a href="#sequences-top">back to top</a>';
-      $sequences_html .= '</div>';
+      if ($cds_sequence[0]['residues']) {
+        $list_items[] = '<a href="#coding_' . $attrs['id'] . '">coding sequnece from alignment at  ' . $attrs['location'] . "</a>";
+        $sequences_html .= '<a name="ccoding_' . $attrs['id'] . '"></a>';
+        $sequences_html .= '<div id="coding_' . $attrs['id'] . '" class="tripal_feature-sequence-item">';
+        $sequences_html .= '<p><b>Coding sequence (CDS) from alignment at  ' . $attrs['location'] . '</b></p>';
+        $sequences_html .= '<pre class="tripal_feature-sequence">';
+        $sequences_html .= '>' . tripal_get_fasta_defline($feature, $attrs['featureloc'], 'CDS') . "\n";
+        $sequences_html .= $cds_sequence[0]['residues'];
+        $sequences_html .= '</pre>';
+        $sequences_html .= '<a href="#sequences-top">back to top</a>';
+        $sequences_html .= '</div>';
+      }
     }
     }
   } 
   } 
   ?>
   ?>
@@ -199,13 +201,13 @@ if ($residues or count($featureloc_sequences) > 0) {
       <li>This feature has residues stored in the "residues" field of the feature table of Chado.</li>
       <li>This feature has residues stored in the "residues" field of the feature table of Chado.</li>
       <li>This feature has a protein feature associated via the "feature_relationship" table of Chado with a
       <li>This feature has a protein feature associated via the "feature_relationship" table of Chado with a
           relationship of type "derives from" and the protein feature has residues.</li>
           relationship of type "derives from" and the protein feature has residues.</li>
-      <li>This feature has one or more CDS feature associated via the "feature_relationship" table of Chado with a
+      <li>This feature has one or more CDS features associated via the "feature_relationship" table of Chado with a
           relationship of type "part of". If the CDS features have residues then those will be concatenated
           relationship of type "part of". If the CDS features have residues then those will be concatenated
-          and presented as a feature.</li>
+          and presented as a sequence.</li>
       <li>This feature is aligned to another feature (e.g. scaffold, or chromosome). In this case, the
       <li>This feature is aligned to another feature (e.g. scaffold, or chromosome). In this case, the
-          sequence underlying the alignment will be shown</li>
+          sequence underlying the alignment will be shown.</li>
       <li>This feature is aligned to another feature (e.g. scaffold, or chromosome) and this feature has
       <li>This feature is aligned to another feature (e.g. scaffold, or chromosome) and this feature has
-          one ore more CDS features associated.  The CDS sequenes underlying the alignment will be
+          one or more CDS features associated.  The CDS sequenes underlying the alignment will be
           shown.</li>
           shown.</li>
     </ul>
     </ul>
     </p>';
     </p>';