Browse Source

Continued theme updates

Stephen Ficklin 11 years ago
parent
commit
ed6f2cf2ea

+ 2 - 3
tripal_core/theme/css/tripal.css

@@ -147,9 +147,8 @@ table.tripal-table-horz .tripal-table-odd-row {
   border-width:1px;
 }
 .tripal_toc ul {
- margin-left: 0px;
- margin-top: 5px;
- padding-left: 15px;
+  margin: 0 !important;
+  padding: 0 0 0.25em 1em !important;
 }
 .tripal_toc_title {
   font-size: 1.5em;

+ 154 - 0
tripal_core/theme/node--chado-generic.tpl.php

@@ -0,0 +1,154 @@
+<?php
+// Purpose: This template provides a generic layout for all Tripal nodes (page)
+
+// get the template type of node (e.g. if type == chado_organism then template type == organism)
+$ttype = $variables['type'];
+$ttype = preg_replace('/chado_/','', $ttype);
+
+// get the template settings
+$template_settings = theme_get_setting('tripal');
+
+// toggle the sidebar if desired
+$no_sidebar = 0;
+if (is_array($template_settings['tripal_no_sidebar']) and 
+   $template_settings['tripal_no_sidebar'][$ttype]) {
+  $no_sidebar = 1;
+}
+
+if ($teaser) { 
+  print theme('tripal_' . $ttype . '_teaser', $variables); 
+} 
+else { ?>
+
+<script type="text/javascript">
+(function ($) {
+  Drupal.behaviors.<?php print $ttype?>Behavior = {
+    attach: function (context, settings){ <?php
+      // hide the resource sidbar if requested and strech the details section
+      if ($no_sidebar) { ?>    
+        $(".tripal_toc").hide();
+        $(".tripal_details").addClass("tripal_details_full");
+        $(".tripal_details_full").removeClass("tripal_details"); <?php
+      } 
+      // use default resource sidebar
+      else { ?>        
+        $(".tripal-info-box").hide();
+
+        // set the widths of the details and sidebar sections so they can work 
+        // seemlessly with any theme.
+        total_width = $(".tripal_contents").width();
+        details_width = (total_width * 0.70) - 52; // 52 == 20  x 2 left/right padding + 10 right margin + 2pt border
+        toc_width = (total_width * 0.30) - 42;  // 42 == 20 x 2 left/right padding + 2pt border
+        // don't let sidebar get wider than 200px
+        if (toc_width > 200) {
+          details_width += toc_width - 200;
+          toc_width = 200;
+        }
+        $('#tripal_<?php print $ttype?>_toc').width(toc_width);
+        $('#tripal_<?php print $ttype?>_details').width(details_width);
+        <?php
+      } ?>
+ 
+      // iterate through all of the info boxes and add their titles
+      // to the table of contents
+      $(".tripal-info-box-title").each(function(){
+        var parent = $(this).parent();
+        var id = $(parent).attr('id');
+        var title = $(this).text();
+        $('#tripal_<?php print $ttype?>_toc_list').append('<li><a href="#'+id+'" class="tripal_<?php print $ttype?>_toc_item">'+title+'</a></li>');
+      });
+
+      // when a title in the table of contents is clicked, then
+      // show the corresponding item in the details box
+      $(".tripal_<?php print $ttype?>_toc_item").click(function(){
+        $(".tripal-info-box").hide();
+        href = $(this).attr('href');
+        if(href.match(/^#/)){
+           //alert("correct: " + href);
+        }
+        else{
+          tmp = href.replace(/^.*?#/, "#");
+          href = tmp;
+          //alert("fixed: " + href);
+        }
+        $(href).fadeIn('slow');
+        // we want to make sure our table of contents and the details
+        // box stay the same height
+        $("#tripal_<?php print $ttype?>_toc").height($(href).parent().height());
+        return false;
+      }); 
+
+      // we want the base details to show up when the page is first shown 
+      // unless we're using the feature browser then we want that page to show
+      var block = window.location.href.match(/[\?|\&]block=(.+?)\&/)
+      if(block == null){
+        block = window.location.href.match(/[\?|\&]block=(.+)/)
+      }
+      if(block != null){
+        $("#tripal_<?php print $ttype?>-"+block[1]+"-box").show();
+      }
+      else {
+        $("#tripal_<?php print $ttype?>-base-box").show();
+      }
+
+      // make sure the sidebar and details sections are the same hieght
+      base_height = $("#tripal_<?php print $ttype?>_details").height();
+      toc_height = $("#tripal_<?php print $ttype?>_toc").height();
+      if (toc_height > base_height) {
+        $("#tripal_<?php print $ttype?>_details").height(toc_height);
+      }
+      else {
+        $("#tripal_<?php print $ttype?>_toc").height(base_height);
+      }
+    }
+  };
+})(jQuery);
+</script>
+
+<div id="tripal_<?php print $ttype?>_content" class="tripal_contents">
+  <div id="tripal_<?php print $ttype?>_details" class="tripal_details">
+  
+     <!-- Resource Blocks CCK elements --> <?php
+     if (property_exists($node, 'field_resource_titles')) {
+       for ($i = 0; $i < count($node->field_resource_titles); $i++){
+         if ($node->field_resource_titles[$i]['value']){ ?>
+           <div id="tripal_<?php print $ttype?>-resource_<?php print $i?>-box" class="tripal_<?php print $ttype?>-info-box tripal-info-box">
+             <div class="tripal_<?php print $ttype?>-info-box-title tripal-info-box-title"><?php print $node->field_resource_titles[$i]['value'] ?></div>
+             <?php print $node->field_resource_blocks[$i]['value']; ?>
+           </div> <?php
+         }
+       } 
+     }?>
+     <!-- Let modules add more content -->
+     <?php
+       foreach ($content as $key => $values) {
+         if (array_key_exists('#value', $values)) {
+           print $content[$key]['#value'];
+         }
+       }
+     ?>
+     
+  </div>
+  
+  <!-- Table of contents -->
+  <div id="tripal_<?php print $ttype?>_toc" class="tripal_toc">
+     <div id="tripal_<?php print $ttype?>_toc_title" class="tripal_toc_title">Resources</i></div>
+     <span id="tripal_<?php print $ttype?>_toc_desc" class="tripal_toc_desc"></span>
+     <ul id="tripal_<?php print $ttype?>_toc_list" class="tripal_toc_list">
+     
+       <!-- Resource Links CCK elements --><?php
+       if(property_exists($node, 'field_resource_links')) {
+         for($i = 0; $i < count($node->field_resource_links); $i++){
+           if($node->field_resource_links[$i]['value']){
+             $matches = preg_split("/\|/",$node->field_resource_links[$i]['value']);?>
+             <li><a href="<?php print $matches[1] ?>" target="_blank"><?php print $matches[0] ?></a></li><?php
+           }
+         }
+       }
+       ?> 
+     </ul>
+  </div>
+</div> 
+<?php 
+} ?>
+

+ 0 - 173
tripal_feature/theme/node--chado-feature.tpl.php

@@ -1,173 +0,0 @@
-<?php
-// Purpose: This template provides the layout of the feature node (page)
-//   using the same templates used for the various feature content blocks.
-//
-// To Customize the Featture Node Page:
-//   - This Template: customize basic layout and which elements are included
-//   - Using Panels: Override the node page using Panels3 and place the blocks
-//       of content as you please. This method requires no programming. See
-//       the Tripal User Guide for more details
-//   - Block Templates: customize the content/layout of each block of stock 
-//       content. These templates are found in the tripal_stock subdirectory
-//
-// Variables Available:
-//   - $node: a standard object which contains all the fields associated with
-//       nodes including nid, type, title, taxonomy. It also includes stock
-//       specific fields such as stock_name, uniquename, stock_type, synonyms,
-//       properties, db_references, object_relationships, subject_relationships,
-//       organism, etc.
-//   NOTE: For a full listing of fields available in the node object the
-//       print_r $node line below or install the Drupal Devel module which 
-//       provides an extra tab at the top of the node page labelled Devel
-
-$feature  = $variables['node']->feature;
-
-// get the template settings
-$template_settings = theme_get_setting('tripal');
-
-// toggle the sidebar if desired
-$no_sidebar = 0;
-if (is_array($template_settings['tripal_no_sidebar']) and 
-   $template_settings['tripal_no_sidebar']['feature']) {
-  $no_sidebar = 1;
-}
-$feature_no_sidebar = preg_split('/\n/', $template_settings['tripal_feature_no_sidebar']);
-
-if ($teaser) { 
-  print theme('tripal_feature_teaser', $variables); 
-} 
-else { ?>
-
-<script type="text/javascript">
-(function ($) {
-  Drupal.behaviors.featureBehavior = {
-    attach: function (context, settings){ <?php 
-      if ($no_sidebar or in_array($feature->type_id->name, $feature_no_sidebar)) { ?>    
-        // hide the resource side bar and strech the details section    
-        $(".tripal_toc").hide();
-        $(".tripal_details").addClass("tripal_details_full");
-        $(".tripal_details_full").removeClass("tripal_details"); <?php
-      } else { ?>
-        // use default resource sidebar
-        $(".tripal-info-box").hide(); <?php
-      } ?>
- 
-      // iterate through all of the info boxes and add their titles
-      // to the table of contents
-      $(".tripal-info-box-title").each(function(){
-        var parent = $(this).parent();
-        var id = $(parent).attr('id');
-        var title = $(this).text();
-        $('#tripal_feature_toc_list').append('<li><a href="#'+id+'" class="tripal_feature_toc_item">'+title+'</a></li>');
-      });
-
-      // when a title in the table of contents is clicked, then
-      // show the corresponding item in the details box
-      $(".tripal_feature_toc_item").click(function(){
-         $(".tripal-info-box").hide();
-         href = $(this).attr('href');
-         $(href).fadeIn('slow');
-         // we want to make sure our table of contents and the details
-         // box stay the same height
-         $("#tripal_feature_toc").height($(href).parent().height());
-         return false;
-      }); 
-
-      // we want the base details to show up when the page is first shown 
-      // unless the user specified a specific block
-      var block = window.location.href.match(/[\?|\&]block=(.+?)\&/)
-      if(block == null){
-         block = window.location.href.match(/[\?|\&]block=(.+)/)
-      }
-      if(block != null){
-         $("#tripal_feature-"+block[1]+"-box").show();
-      } else {
-         $("#tripal_feature-base-box").show();
-      }
-
-      $("#tripal_organism_toc").height($("#tripal_feature-base-box").parent().height());
-    }     
-  };
-})(jQuery);
-</script>
-
-<div id="tripal_feature_details" class="tripal_details">
-
-   <!-- Basic Details Theme -->
-   <?php print theme('tripal_feature_base',$node); ?>
-
-   <!-- Database References -->
-   <?php print theme('tripal_feature_references', $node); ?>
-
-   <!-- Properties -->
-   <?php print theme('tripal_feature_properties', $node); ?>
-
-   <!-- Annotated Terms -->
-   <?php print theme('tripal_feature_terms', $node); ?>
-
-   <!-- Synonyms -->
-   <?php print theme('tripal_feature_synonyms', $node); ?>
-   
-   <!-- Phenotypes -->
-   <?php print theme('tripal_feature_phenotypes', $node); ?>
-   
-   <!-- Maps -->   
-   <?php print theme('tripal_feature_featurepos', $node); ?>
-
-   <!-- Sequence --> <?php 
-   if(strcmp($feature->type_id->name,'scaffold')!=0 and 
-      strcmp($feature->type_id->name,'chromosome')!=0 and
-      strcmp($feature->type_id->name,'supercontig')!=0 and
-      strcmp($feature->type_id->name,'pseudomolecule')!=0)
-   {
-      print theme('tripal_feature_sequence', $node); 
-   } ?>
-
-   <!-- Formatted Sequences -->
-   <?php print theme('tripal_feature_featureloc_sequences', $node); ?>
-
-   <!-- Relationships -->
-   <?php print theme('tripal_feature_relationships', $node); ?>
-   
-   <!-- Feature locations --> <?php 
-   if(strcmp($feature->type_id->name,'scaffold')!=0 and 
-      strcmp($feature->type_id->name,'chromosome')!=0 and
-      strcmp($feature->type_id->name,'supercontig')!=0 and
-      strcmp($feature->type_id->name,'pseudomolecule')!=0)
-   {
-      print theme('tripal_feature_alignments', $node); 
-   } ?>
-     
-  
-   <!-- Resource Blocks CCK elements --><?php
-   for($i = 0; $i < count($node->field_resource_titles); $i++){
-     if($node->field_resource_titles[$i]['value']){ ?>
-       <div id="tripal_feature-resource_<?php print $i?>-box" class="tripal_feature-info-box tripal-info-box">
-         <div class="tripal_feature-info-box-title tripal-info-box-title"><?php print $node->field_resource_titles[$i]['value'] ?></div>
-         <?php print $node->field_resource_blocks[$i]['value']; ?>
-       </div><?php
-     }
-   }?>
-   
-   <!-- Let modules add more content -->
-   <?php print $content ?>
-</div>
-
-<!-- Table of contents -->
-<div id="tripal_feature_toc" class="tripal_toc">
-   <div id="tripal_feature_toc_title" class="tripal_toc_title">Resources</div>
-   <ul id="tripal_feature_toc_list" class="tripal_toc_list">
-   
-     <!-- Resource Links CCK elements --><?php
-     for($i = 0; $i < count($node->field_resource_links); $i++){
-       if($node->field_resource_links[$i]['value']){
-         $matches = preg_split("/\|/",$node->field_resource_links[$i]['value']);?>
-         <li><a href="<?php print $matches[1] ?>" target="_blank"><?php print $matches[0] ?></a></li><?php
-       }
-     }?>
-     
-     <?php // ADD CUSTOMIZED <li> LINKS HERE ?>
-   </ul>
-</div>
-
-<?php } ?>

+ 8 - 3
tripal_feature/theme/tripal_organism/tripal_organism_feature_browser.tpl.php

@@ -1,9 +1,14 @@
 <?php
 
 $organism = $variables['node']->organism;
-$features = $organism->feature_browser['features'];
-$pager    = $organism->feature_browser['pager'];
-$enabled  = $organism->feature_browser['enabled'];
+$enabled = 1;
+$features = array();
+
+if(property_exists($organism, 'feature_browser')) {
+  $features = $organism->feature_browser['features'];
+  $pager    = $organism->feature_browser['pager'];
+  $enabled  = $organism->feature_browser['enabled'];
+}
 
 // only show this block if it is enabled
 if ($enabled) { 

+ 8 - 3
tripal_feature/theme/tripal_organism/tripal_organism_feature_counts.tpl.php

@@ -1,9 +1,14 @@
 <?php
 
 $organism = $variables['node']->organism;
-$types    = $organism->feature_counts['types'];
-$names    = $organism->feature_counts['names'];
-$enabled  = $organism->feature_counts['enabled'];
+$enabled = 1;
+$types = array();
+
+if(property_exists($organism, 'feature_counts')) {
+  $types    = $organism->feature_counts['types'];
+  $names    = $organism->feature_counts['names'];
+  $enabled  = $organism->feature_counts['enabled'];
+}
 
 // only show this block if it is enabled
 if ($enabled) { 

+ 212 - 0
tripal_organism/includes/organism_sync.inc

@@ -0,0 +1,212 @@
+<?php 
+
+/**
+ * 
+ */
+function tripal_organism_sync () {
+  $form = array();
+  
+  get_tripal_organism_admin_form_sync_set($form);
+  get_tripal_organism_admin_form_cleanup_set($form);
+  
+  return $form;
+}
+
+/**
+ *
+ *
+ * @ingroup tripal_organism
+ */
+function get_tripal_organism_admin_form_cleanup_set(&$form) {
+  $form['cleanup'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Clean Up'),
+    '#description' => t("With Drupal and chado residing in different databases or database schemas " .
+        "it is possible that nodes in Drupal and organisms in Chado become " .
+        "\"orphaned\".  This can occur if an organism node in Drupal is " .
+        "deleted but the corresponding chado organism is not and/or vice " .
+        "versa. Click the button below to resolve these discrepancies."),
+  );
+  $form['cleanup']['button'] = array(
+    '#type' => 'submit',
+    '#value' => t('Clean up orphaned organisms'),
+  );
+}
+/**
+ *
+ * @ingroup tripal_organism
+ */
+function get_tripal_organism_admin_form_sync_set(&$form) {
+  // define the fieldsets
+  $form['sync'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Sync Organisms')
+  );
+
+  // get the list of organisms
+  $sql = "SELECT * FROM {Organism} ORDER BY genus,species";
+  $org_rset = chado_query($sql);
+
+  // if we've added any organisms to the list that can be synced
+  // then we want to build the form components to allow the user
+  // to select one or all of them.  Otherwise, just present
+  // a message stating that all organisms are currently synced.
+  $org_boxes = array();
+  $added = 0;
+  foreach ($org_rset as $organism) {
+    // check to see if the organism is already present as a node in drupal.
+    // if so, then skip it.
+    $sql = "SELECT * FROM {chado_organism} WHERE organism_id = :organism_id";
+    if (!db_query($sql, array(':organism_id' => $organism->organism_id))->fetchObject()) {
+      $org_boxes[$organism->organism_id] = "$organism->genus $organism->species ($organism->common_name)";
+      $added++;
+    }
+  }
+
+  // if we have organisms we need to add to the checkbox then
+  // build that form element
+  if ($added > 0) {
+    $org_boxes['all'] = "All Organisms";
+
+    $form['sync']['organisms'] = array(
+      '#title'       => t('Available Organisms'),
+      '#type'        => t('checkboxes'),
+      '#description' => t("Check the organisms you want to sync.  Drupal content will be created for each of the organisms listed above.  Select 'All Organisms' to sync all of them."),
+      '#required'    => FALSE,
+      '#prefix'      => '<div id="org_boxes">',
+      '#suffix'      => '</div>',
+      '#options'     => $org_boxes,
+    );
+    $form['sync']['button'] = array(
+      '#type' => 'submit',
+      '#value' => t('Submit Sync Job')
+    );
+  }
+  // we don't have any organisms to select from
+  else {
+    $form['sync']['value'] = array(
+      '#markup' => t('All organisms in Chado are currently synced with Drupal.')
+    );
+  }
+}
+
+/**
+ *
+ * @ingroup tripal_organism
+ */
+function tripal_organism_sync_submit($form, &$form_state) {
+  global $user;  // we need access to the user info
+  $job_args = array();
+
+  if ($form_state['values']['op'] == t('Submit Sync Job')) {
+
+    // check to see if the user wants to sync chado and drupal.  If
+    // so then we need to register a job to do so with tripal
+    $organisms = $form_state['values']['organisms'];
+    $do_all = FALSE;
+    $to_sync = array();
+
+    foreach ($organisms as $organism_id) {
+      if (preg_match("/^all$/i" , $organism_id)) {
+        $do_all = TRUE;
+      }
+      if ($organism_id and preg_match("/^\d+$/i" , $organism_id)) {
+        // get the list of organisms
+        $sql = "SELECT * FROM {organism} WHERE organism_id = :organism_id";
+        $organism = chado_query($sql, array(':organism_id' => $organism_id))->fetchObject();
+        $to_sync[$organism_id] = "$organism->genus $organism->species";
+      }
+    }
+
+    // submit the job the tripal job manager
+    if ($do_all) {
+      tripal_add_job('Sync all organisms' , 'tripal_organism',
+      'tripal_organism_sync_organisms' , $job_args , $user->uid);
+    }
+    else{
+      foreach ($to_sync as $organism_id => $name) {
+        $job_args[0] = $organism_id;
+        tripal_add_job("Sync organism: $name" , 'tripal_organism',
+        'tripal_organism_sync_organisms' , $job_args , $user->uid);
+      }
+    }
+  }
+
+  // -------------------------------------
+  // Submit the Cleanup Job if selected
+  if ($form_state['values']['op'] == t('Clean up orphaned organisms')) {
+    tripal_add_job('Cleanup orphaned organisms', 'tripal_organism',
+    'tripal_organism_cleanup', $job_args, $user->uid);
+  }
+}
+/**
+ * Synchronize organisms from chado to drupal
+ *
+ * @ingroup tripal_organism
+ */
+function tripal_organism_sync_organisms($organism_id = NULL, $job_id = NULL) {
+  global $user;
+  $page_content = '';
+
+  if (!$organism_id) {
+    $sql = "SELECT * FROM {Organism} O";
+    $results = chado_query($sql);
+  }
+  else {
+    $sql = "SELECT * FROM {organism} WHERE organism_id = :organism_id";
+    $results = chado_query($sql, array(':organism_id' => $organism_id));
+  }
+
+  // We'll use the following SQL statement for checking if the organism
+  // already exists as a drupal node.
+  $sql = "SELECT * FROM {chado_organism} " .
+      "WHERE organism_id = :organism_id";
+
+  foreach ($results as $organism) {
+
+    // check if this organism already exists in the drupal database. if it
+    // does then skip this organism and go to the next one.
+    if (!db_query($sql, array(':organism_id' => $organism->organism_id))->fetchObject()) {
+
+      $new_node = new stdClass();
+      $new_node->type = 'chado_organism';
+      $new_node->uid = $user->uid;
+      $new_node->title = "$organism->genus $organism->species";
+      $new_node->organism_id = $organism->organism_id;
+      $new_node->genus = $organism->genus;
+      $new_node->species = $organism->species;
+      $new_node->description = '';
+      $form = array(); // dummy variable
+      $form_state = array(); // dummy variable
+      node_validate($new_node, $form, $form_state);
+      if (!form_get_errors()) {
+        $node = node_submit($new_node);
+        node_save($node);
+        if ($node->nid) {
+          print "Added $organism->common_name\n";
+        }
+      }
+      else {
+        print "Failed to insert organism $organism->common_name\n";
+      }
+    }
+    else {
+      print "Skipped $organism->common_name\n";
+    }
+  }
+  return $page_content;
+}
+/**
+ * Remove orphaned drupal nodes
+ *
+ * @param $dummy
+ *   Not Used -kept for backwards compatibility
+ * @param $job_id
+ *   The id of the tripal job executing this function
+ *
+ * @ingroup tripal_organism
+ */
+function tripal_organism_cleanup($dummy = NULL, $job_id = NULL) {
+
+  return tripal_core_clean_orphaned_nodes('organism', $job_id);
+}

+ 1 - 0
tripal_organism/theme/node--chado-organism.tpl.php

@@ -19,6 +19,7 @@
 //   NOTE: For a full listing of fields available in the node object the
 //       print_r $node line below or install the Drupal Devel module which 
 //       provides an extra tab at the top of the node page labelled Devel
+dpm($variables);
 
 $organism  = $variables['node']->organism;
 

+ 4 - 2
tripal_organism/tripal_organism.module

@@ -153,12 +153,14 @@ function tripal_organism_help ($path, $arg) {
  * @ingroup tripal_organism
  */
 function tripal_organism_theme($existing, $type, $theme, $path) {
+  $core_path = drupal_get_path('module', 'tripal_core');
+  
   $items = array(
     'node__chado_organism' => array(
-      'template' => 'node--chado-organism',
+      'template' => 'node--chado-generic',
       'render element' => 'node',
       'base hook' => 'node',
-      'path' => "$path/theme",
+      'path' => "$core_path/theme",
     ),
     'tripal_organism_base' => array(
       'variables' => array('node' => NULL),