Forráskód Böngészése

Changed bulk loader theming to match new Tripal style

Stephen Ficklin 10 éve
szülő
commit
0e4a26e1fc

+ 0 - 2
tripal_bulk_loader/includes/tripal_bulk_loader.admin.templates.inc

@@ -1435,8 +1435,6 @@ function tripal_bulk_loader_template_field_form_default_values($mode, &$form_sta
   
   // mode can be 'create' or 'edit'
   $v['mode'] = $mode;
-  
-  dpm($mode);
 
   // the template_id is the ID of the template if this is an edit, or FALSE if this is a create
   $v['template_id'] = (isset($form_state['build_info']['args'][1])) ? $form_state['build_info']['args'][1] : FALSE;

+ 37 - 0
tripal_bulk_loader/includes/tripal_bulk_loader.chado_node.inc

@@ -363,3 +363,40 @@ function tripal_bulk_loader_node_access($node, $op, $account) {
     return NODE_ACCESS_IGNORE;
   }
 }
+
+
+/**
+ * Implements hook_node_view().
+ * Acts on all content types.
+ *
+ * @ingroup tripal_feature
+ */
+function tripal_bulk_loader_node_view($node, $view_mode, $langcode) {
+  switch ($node->type) {
+    case 'tripal_bulk_loader':
+      // Show feature browser and counts
+      if ($view_mode == 'full') {
+        
+        // we want to use the Tripal generic node template
+        $node->content['#tripal_generic_node_template'] = TRUE;
+        
+        $node->content['tripal_bulk_loader_base'] = array(
+          '#markup' => theme('tripal_bulk_loader_base', array('node' => $node)),
+          '#tripal_toc_id'    => 'base',
+          '#tripal_toc_title' => 'Overview',
+          '#weight' => -100,
+        );
+        $node->content['tripal_bulk_loader_fields'] = array(
+          '#markup' => theme('tripal_bulk_loader_fields', array('node' => $node)),
+          '#tripal_toc_id'    => 'fields',
+          '#tripal_toc_title' => 'Data Fields',
+        );
+      }
+      if ($view_mode == 'teaser') {
+        $node->content['tripal_bulk_loader_teaser'] = array(
+          '#markup' => theme('tripal_bulk_loader_teaser', array('node' => $node)),
+        );
+      }
+      break;
+  }
+}

+ 0 - 67
tripal_bulk_loader/theme/node--tripal-bulk-loader.tpl.php

@@ -1,67 +0,0 @@
-<div id="tripal_bulk_loader-base-box" class="tripal_bulk_loader-info-box tripal-info-box">
-  <div class="tripal_bulk_loader-info-box-title tripal-info-box-title">
-    <?php if ($teaser) { print l($node->title, 'node/'.$node->nid); } ?>
-  </div>
-  <div class="tripal_bulk_loader-data-block-desc tripal-data-block-desc"></div>
-
-  <table id="tripal_bulk_loader-base-table" class="tripal_bulk_loader-table tripal-table tripal-table-vert">
-    <tr class="tripal_bulk_loader-table-odd-row tripal-table-odd-row">
-      <th>Job Name</th>
-      <td><?php print $node->loader_name;?></td>
-    </tr>
-    <tr class="tripal_bulk_loader-table-even-row tripal-table-even-row">
-      <th>Submitted By</th>
-      <td><span class="author"><?php //print theme('username', $node); ?></span></td>
-    </tr>
-    <tr class="tripal_bulk_loader-table-odd-row tripal-table-odd-row">
-      <th>Job Creation Date</th>
-      <td><?php print format_date($node->created, 'custom', "F j, Y, g:i a"); ?></td>
-    </tr>
-    <tr class="tripal_bulk_loader-table-even-row tripal-table-even-row">
-      <th>Last Updated</th>
-      <td><?php print format_date($node->changed, 'custom', "F j, Y, g:i a"); ?></td>
-    </tr>
-    <tr class="tripal_bulk_loader-table-odd-row tripal-table-odd-row">
-      <th>Template Name</th>
-      <td><?php print $node->template->name; ?></td>
-    </tr>
-    <tr class="tripal_bulk_loader-table-even-row tripal-table-even-row">
-      <th>Data File</th>
-      <td><?php print $node->file;?></td>
-    </tr>
-    <tr class="tripal_bulk_loader-table-odd-row tripal-table-odd-row">
-      <th>Job Status</th>
-      <td><?php print $node->job_status;?></td>
-    </tr>
-    <?php if (isset($node->job)) { if (isset($node->job->progress)) { ?>
-    <tr class="tripal_bulk_loader-table-even-row tripal-table-even-row">
-      <th>Job Progress</th>
-      <td><?php print $node->job->progress . '% (' . l('view job', 'admin/tripal/tripal_jobs/view/' . $node->job_id) . ')';?></td>
-    </tr>
-    <?php }} ?>
-  </table>
-</div>
-
-<?php if (!$teaser) { ?>
-<?php print drupal_render(drupal_get_form('tripal_bulk_loader_add_loader_job_form', $node)); ?>
-
-  <?php if (!empty($node->inserted_records)) {
-    print '<h3>Loading Summary</h3>';
-    $rows = array();
-    $total = 0;
-    foreach ($node->inserted_records as $r) {
-      $row = array();
-      $row[] = $r->table_inserted_into;
-      $row[] = $r->num_inserted;
-      $rows[] = $row;
-      $total = $total + $r->num_inserted;
-    }
-    $rows[] = array('<b>TOTAL</b>','<b>'.$total.'</b>');
-    print theme('table',array('header'=>array('Chado Table', 'Number of Records Inserted'), 'rows'=>$rows));
-  } ?>
-  <br>
-
-  <?php print drupal_render(drupal_get_form('tripal_bulk_loader_set_constants_form', $node)); ?>
-
-<?php print theme('tripal_bulk_loader_template', $node->template->template_id); ?>
-<?php } ?>

+ 0 - 0
tripal_bulk_loader/theme/tripal_bulk_loader_admin.tpl.php → tripal_bulk_loader/theme/templates/tripal_bulk_loader_admin.tpl.php


+ 166 - 0
tripal_bulk_loader/theme/templates/tripal_bulk_loader_base.tpl.php

@@ -0,0 +1,166 @@
+<?php
+$node  = $variables['node']; ?>
+
+<div class="tripal_bulk_loader-data-block-desc tripal-data-block-desc"></div> <?php 
+
+// the $headers array is an array of fields to use as the colum headers. 
+// additional documentation can be found here 
+// https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+// This table for the analysis has a vertical header (down the first column)
+// so we do not provide headers here, but specify them in the $rows array below.
+$headers = array();
+
+// the $rows array contains an array of rows where each row is an array
+// of values for each column of the table in that row.  Additional documentation
+// can be found here:
+// https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7 
+$rows = array();
+
+// Name row
+$rows[] = array(
+  array(
+    'data' => 'Job Name',
+    'header' => TRUE,
+    'width' => '20%',
+  ),
+  $node->loader_name
+);
+// Submitted By
+$rows[] = array(
+  array(
+    'data' => 'Submitted By',
+    'header' => TRUE
+  ),
+  $node->uid
+);
+// Job Creation Date
+$rows[] = array(
+  array(
+    'data' => 'Job Creation Date',
+    'header' => TRUE
+  ),
+  format_date($node->created, 'custom', "F j, Y, g:i a")
+);
+// Last Updated
+$rows[] = array(
+  array(
+    'data' => 'Last Updated',
+    'header' => TRUE
+  ),
+  format_date($node->changed, 'custom', "F j, Y, g:i a")
+);
+// Template Name
+$rows[] = array(
+  array(
+    'data' => 'Template Name',
+    'header' => TRUE
+  ),
+  $node->template->name
+);
+// Data File
+$rows[] = array(
+  array(
+    'data' => 'Data File',
+    'header' => TRUE
+  ),
+  $node->file
+);
+// Job Status
+$rows[] = array(
+  array(
+    'data' => 'Job Status',
+    'header' => TRUE
+  ),
+  $node->job_status
+);  
+//Job Progress
+if (isset($node->job)) {
+  if (isset($node->job->progress)) { 
+    $rows[] = array(
+      array(
+        'data' => 'Job Progress',
+        'header' => TRUE
+      ),
+      $node->job->progress . '% (' . l('view job', 'admin/tripal/tripal_jobs/view/' . $node->job_id) . ')'
+    );
+  }
+} 
+
+// the $table array contains the headers and rows array as well as other
+// options for controlling the display of the table.  Additional
+// documentation can be found here:
+// https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+$table = array(
+  'header' => $headers,
+  'rows' => $rows,
+  'attributes' => array(
+    'id' => 'tripal_bulk_loader-table-base',
+    'class' => 'tripal-data-table'
+  ),
+  'sticky' => FALSE,
+  'caption' => '',
+  'colgroups' => array(),
+  'empty' => '',
+);
+
+// once we have our table array structure defined, we call Drupal's theme_table()
+// function to generate the table.
+print theme_table($table);
+
+
+// add the "submit" button for adding a loading job to the Tripal jobs management system
+$form = drupal_get_form('tripal_bulk_loader_add_loader_job_form', $node);
+print drupal_render($form); 
+
+
+// if we have inserted records then load the summary:
+if (!empty($node->inserted_records)) {
+ 
+  print '<h3>Loading Summary</h3>';
+  // the $headers array is an array of fields to use as the colum headers.
+  // additional documentation can be found here
+  // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+  $headers = array('Chado Table', 'Number of Records Inserted');
+  
+  // the $rows array contains an array of rows where each row is an array
+  // of values for each column of the table in that row.  Additional documentation
+  // can be found here:
+  // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+  $rows = array();
+  $total = 0;
+  
+  foreach ($node->inserted_records as $r) {
+    $row = array();
+    $row[] = $r->table_inserted_into;
+    $row[] = $r->num_inserted;
+    $rows[] = $row;
+    $total = $total + $r->num_inserted;
+  }
+  $rows[] = array('<b>TOTAL</b>','<b>'.$total.'</b>');
+  
+  // the $table array contains the headers and rows array as well as other
+  // options for controlling the display of the table.  Additional
+  // documentation can be found here:
+  // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+  $table = array(
+    'header' => $headers,
+    'rows' => $rows,
+    'attributes' => array(),
+    'sticky' => FALSE,
+    'caption' => '',
+    'colgroups' => array(),
+    'empty' => '',
+  );
+  
+  // once we have our table array structure defined, we call Drupal's theme_table()
+  // function to generate the table.
+  print theme_table($table);
+} ?>
+<br> <?php
+
+// add the form for setting any constants values
+$form =  drupal_get_form('tripal_bulk_loader_set_constants_form', $node);
+print drupal_render($form); 
+
+// add in the constant details
+print theme('tripal_bulk_loader_template', array('template_id' => $node->template->template_id));

+ 104 - 0
tripal_bulk_loader/theme/templates/tripal_bulk_loader_fields.tpl.php

@@ -0,0 +1,104 @@
+<?php
+$node  = $variables['node']; 
+
+// Retrieve Template
+$template = db_select('tripal_bulk_loader_template', 't')
+  ->fields('t')
+  ->condition('template_id', $node->template->template_id, '=')
+  ->execute()
+  ->fetchObject();
+
+$template->template_array = unserialize($template->template_array);
+
+// Summarize Template
+$fields = array();
+$constants = array();
+foreach ($template->template_array as $priority => $table_array) {
+  if (!is_array($table_array)) {
+    continue;
+  }
+
+  $table = $table_array['table'];
+  $record = $table_array['record_id'];
+  foreach ($table_array['fields'] as $field) {
+    if (preg_match('/table field/', $field['type'])) {
+      $field['table'] = $table;
+      $field['record'] = $record;
+      $sheet = 0;//$field['spreadsheet sheet'];
+      $column = $field['spreadsheet column'];
+      $fields[$sheet.'-'.$column][] = $field;
+    } 
+    elseif ($field['type'] == 'constant') {
+      $field['table'] = $table;
+      $field['record'] = $record;
+      $constants[] = $field;
+    }
+  }
+} ?>
+
+<p><b>Constants</b></p> <?php 
+
+// add a table describing the constants specified in the file
+if (sizeof($constants)) { 
+  $headers = array('Record Name', 'Field Name', 'Value', 'Chado Table', 'Chado Field');
+  $rows = array(); 
+  
+  // iterate through the fields and add rows to the table
+  foreach ($constants as $field) {
+    $rows[] = array($field['record'], $field['title'], $field['constant value'], $field['table'], $field['field']);
+  }
+  
+  // theme the table
+  $table = array(
+    'header' => $headers,
+    'rows' => $rows,
+    'attributes' => array(
+      'id' => 'tripal_bulk_loader-table-constants',
+      'class' => 'tripal-data-table'
+    ),
+    'sticky' => FALSE,
+    'caption' => '',
+    'colgroups' => array(),
+    'empty' => '',
+  );
+  print theme_table($table);
+
+} 
+?>
+
+<br><p><b>Data Columns</b></p> <?php 
+
+// add a table specifying the data file columns
+if (sizeof($fields)) { 
+
+  $headers = array('Record Name', 'Field Name', 'Data File Column', 'Chado Table', 'Chado Field');
+  $rows = array();
+  
+  // iterate through the fields and add rows to the table
+  foreach ($fields as $column) {
+    foreach ($column as $field) {
+      $rows[] = array(
+        $field['record'],
+        $field['title'],
+        $field['spreadsheet column'],
+        $field['table'],
+        $field['field']
+      );
+    }
+  }
+  
+  // theme the table
+  $table = array(
+    'header' => $headers,
+    'rows' => $rows,
+    'attributes' => array(
+      'id' => 'tripal_bulk_loader-table-columns',
+      'class' => 'tripal-data-table'
+    ),
+    'sticky' => FALSE,
+    'caption' => '',
+    'colgroups' => array(),
+    'empty' => '',
+  );
+  print theme_table($table);
+}

+ 0 - 0
tripal_bulk_loader/theme/tripal_bulk_loader_modify_template_base_form.tpl.php → tripal_bulk_loader/theme/templates/tripal_bulk_loader_modify_template_base_form.tpl.php


+ 9 - 0
tripal_bulk_loader/theme/templates/tripal_bulk_loader_teaser.tpl.php

@@ -0,0 +1,9 @@
+<div class="tripal_bulk_loader-teaser tripal-teaser">
+<div class="tripal-bulk_loader-teaser-title tripal-teaser-title"><?php
+    print l($node->title, "node/$node->nid", array('html' => TRUE));?>
+  </div>
+  <div class="tripal-bulk_loader-teaser-text tripal-teaser-text"><?php 
+    print $node->title;
+    print "... " . l("[more]", "node/$node->nid"); ?>
+  </div>
+</div> <?php 

+ 0 - 79
tripal_bulk_loader/theme/tripal_bulk_loader_template.tpl.php

@@ -1,79 +0,0 @@
-<?php
-
-  // Retrieve Template
-  $template = db_select('tripal_bulk_loader_template', 't')
-    ->fields('t')
-    ->condition('template_id', $variables['template_id'], '=')
-    ->execute()
-    ->fetchObject();
-
-  $template->template_array = unserialize($template->template_array);
-
-  // Summarize Template
-  $fields = array();
-  $constants = array();
-  foreach ($template->template_array as $priority => $table_array) {
-    if (!is_array($table_array)) {
-      continue;
-    }
-
-    $table = $table_array['table'];
-    $record = $table_array['record_id'];
-    foreach ($table_array['fields'] as $field) {
-      if (preg_match('/table field/', $field['type'])) {
-        $field['table'] = $table;
-        $field['record'] = $record;
-        $sheet = 0;//$field['spreadsheet sheet'];
-        $column = $field['spreadsheet column'];
-        $fields[$sheet.'-'.$column][] = $field;
-      } elseif ($field['type'] == 'constant') {
-        $field['table'] = $table;
-        $field['record'] = $record;
-        $constants[] = $field;
-      }
-    }
-  }
-?>
-
-<div id="tripal_bulk_loader-base-box" class="tripal_bulk_loader-info-box tripal-info-box">
-  <div class="tripal_bulk_loader-info-box-title tripal-info-box-title">Template Description</div>
-  <div class="tripal_bulk_loader-data-block-desc tripal-data-block-desc"></div>
-
-<?php if (sizeof($constants)) { ?>
-  <table id="tripal_bulk_loader-template_constant-table" class="tripal_bulk_loader-table tripal-table tripal-table-vert">
-  <caption><b>Constants</b> -These values are applied to all records in the Data File</caption>
-    <tr><th rowspan="2">Record Name</th><th rowspan="2">Field Name</th><th rowspan="2">Value</th><th colspan="2">Chado Database</th></tr>
-    <tr><th>Table</th><th>Field</th></tr>
-    <?php $row = 'even' ?>
-    <?php foreach ($constants as $field) {?>
-      <tr class="tripal_bulk_loader-table-<?php print $row; ?>-row tripal-table-<?php print $row; ?>-row">
-        <td><?php print $field['record'];?></td>
-        <td><?php print $field['title'];?></td>
-        <td><?php print $field['constant value']; ?></td>
-        <td><?php print $field['table'];?></td>
-        <td><?php print $field['field'];?></td>
-      </tr>
-      <?php $row = ($row == 'odd') ? 'even':'odd' ; ?>
-    <?php } ?>
-  </table>
-
-<?php } if (sizeof($fields)) { ?>
-  <table id="tripal_bulk_loader-template_fields-table" class="tripal_bulk_loader-table tripal-table tripal-table-vert">
-  <caption><b>Fields</b> -Below is a mapping between Data File columns and the Chado Database</caption>
-  <tr><th rowspan="2">Record Name</th><th rowspan="2">Field Name</th><th rowspan="2">Data File Column</th><th colspan="2">Chado Datbase</th></tr>
-  <tr><th>Table</th><th>Field</th></tr>
-  <?php $row = 'even' ?>
-  <?php foreach ($fields as $column) {?>
-    <?php foreach ($column as $field) {?>
-    <tr class="tripal_bulk_loader-table-<?php print $row; ?>-row tripal-table-<?php print $row; ?>-row">
-      <td><?php print $field['record'];?></td>
-      <td><?php print $field['title'];?></td>
-      <td><?php print $field['spreadsheet column'];?></td>
-      <td><?php print $field['table'];?></td>
-      <td><?php print $field['field'];?></td>
-    <tr>
-    <?php $row = ($row == 'odd') ? 'even':'odd' ; ?>
-  <?php }} ?>
-  </table>
-<?php } ?>
-</div>

+ 28 - 9
tripal_bulk_loader/tripal_bulk_loader.module

@@ -283,22 +283,31 @@ function tripal_bulk_loader_views_api() {
  *
  * @ingroup tripal_bulk_loader
  */
-function tripal_bulk_loader_theme() {
+function tripal_bulk_loader_theme($existing, $type, $theme, $path) {
+  $core_path = drupal_get_path('module', 'tripal_core');
+  
   return array(
     'node__tripal_bulk_loader' => array(
-      'template' => 'node--tripal-bulk-loader',
-      'path' => drupal_get_path('module', 'tripal_bulk_loader') . '/theme',
+      'template' => 'node--chado-generic',
       'render element' => 'node',
       'base hook' => 'node',
+      'path' => "$core_path/theme/templates",
     ),
-    'tripal_bulk_loader_template' => array(
-      'variables' => array('template_id' => NULL),
-      'template' => 'tripal_bulk_loader_template',
-      'path' => drupal_get_path('module', 'tripal_bulk_loader') . '/theme',
+    'tripal_bulk_loader_base' => array(
+      'variables' => array('node' => NULL),
+      'template' => 'tripal_bulk_loader_base',
+      'path' => "$path/theme/templates",
     ),
+    'tripal_bulk_loader_fields' => array(
+      'variables' => array('node' => NULL),
+      'template' => 'tripal_bulk_loader_fields',
+      'path' => "$path/theme/templates",
+    ),
+    
+    // form element themes
     'tripal_bulk_loader_modify_template_base_form' => array(
       'template' => 'tripal_bulk_loader_modify_template_base_form',
-      'path' => drupal_get_path('module', 'tripal_bulk_loader') . '/theme',
+      'path' => "$path/theme/templates",
       'render element' => 'form'
     ),
     'tripal_bulk_loader_field_regex_fieldset' => array(
@@ -306,9 +315,19 @@ function tripal_bulk_loader_theme() {
       'function' => 'tripal_bulk_loader_field_regex_fieldset',
       'render element' => 'element'
     ),
+    
+    // admin theme
     'tripal_bulk_loader_admin' => array(
       'template' => 'tripal_bulk_loader_admin',
-      'path' => drupal_get_path('module', 'tripal_bulk_loader') . '/theme',
+      'path' => "$path/theme/templates",
+    ),
+    
+
+    // themed teaser
+    'tripal_bulk_loader_teaser' => array(
+      'variables' => array('node' => NULL),
+      'template' => 'tripal_bulk_loader_teaser',
+      'path' => "$path/theme/templates",
     ),
   );
 }

+ 10 - 8
tripal_core/theme/templates/node--chado-generic.tpl.php

@@ -44,15 +44,17 @@ else {
         <td nowrap class="tripal-contents-table-td tripal-contents-table-td-toc"  align="left"><?php
         
           // print the table of contents. It's found in the content array 
-          print $content['tripal_toc']['#markup'];
+          if (array_key_exists('tripal_toc', $content)) {
+            print $content['tripal_toc']['#markup'];
           
-          // we may want to add the links portion of the contents to the sidebar
-          //print render($content['links']);
-          
-          // remove the table of contents and links so thye doent show up in the 
-          // data section when the rest of the $content array is rendered
-          unset($content['tripal_toc']);
-          unset($content['links']); ?>
+            // we may want to add the links portion of the contents to the sidebar
+            //print render($content['links']);
+            
+            // remove the table of contents and links so thye doent show up in the 
+            // data section when the rest of the $content array is rendered
+            unset($content['tripal_toc']);
+            unset($content['links']); 
+          } ?>
 
         </td>
         <td class="tripal-contents-table-td-data" align="left" width="100%"> <?php