소스 검색

Bulk Loader: Moved theme_tripal tpls into module

Lacey Sanderson 11 년 전
부모
커밋
32090a3863

+ 68 - 0
tripal_bulk_loader/theme/node-tripal_bulk_loader.tpl.php

@@ -0,0 +1,68 @@
+
+<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-info-box-desc tripal-info-box-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 ($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_get_form('tripal_bulk_loader_add_loader_job_form', $node); ?>
+
+  <?php if ($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('Chado Table', 'Number of Records Inserted'), $rows);
+  } ?>
+  <br>
+
+  <?php print drupal_get_form('tripal_bulk_loader_set_constants_form', $node); ?>
+
+	<?php print theme('tripal_bulk_loader_template', $node->template->template_id); ?>
+<?php } ?>

+ 83 - 0
tripal_bulk_loader/theme/tripal_bulk_loader_add_template_field_form.tpl.php

@@ -0,0 +1,83 @@
+
+<?php print $form['add_fields']['#prefix']; ?>
+<fieldset><legend> <?php print $form['add_fields']['#title']; ?> </legend>
+<?php
+  print drupal_render($form['template_name']);
+
+  // Foreach element in the form fieldset 'add_fields'
+  foreach ($form['add_fields'] as $key => $form_array) {
+    if (preg_match('/^#/',$key)) { continue; }
+    
+    // We only care about the additional fieldset
+    if (preg_match('/additional/', $key)) {
+      //print fieldset
+      if ($form_array['#collapsible']) { $class[] = 'collapsible'; }
+      if ($form_array['#collapsed']) { $class[] = 'collapsed'; }
+      if (sizeof($class)) { $class = ' class="'.implode(' ',$class).'"'; }
+      print '<fieldset'.$class.'><legend>'.$form_array['#title'].'</legend>';
+      
+      // Foreach element in the 'additional' fieldset
+      foreach ($form_array as $key => $sub_form_array) {
+        if (preg_match('/^#/',$key)) { continue; }
+        
+        // We only care about the 'regex_transform' fieldset
+        if (preg_match('/regex_transform/', $key)) {
+          
+          // print fieldset
+          if ($sub_form_array['#collapsible']) { $class[] = 'collapsible'; }
+          if ($sub_form_array['#collapsed']) { $class[] = 'collapsed'; }
+          if (sizeof($class)) { $class = ' class="'.implode(' ',$class).'"'; }
+          print '<fieldset'.$class.'><legend>'.$sub_form_array['#title'].'</legend>';
+          
+          // print description
+          print drupal_render($sub_form_array['regex_description']);
+          
+          // Render Draggable Table
+          drupal_add_tabledrag('draggable-table', 'order', 'sibling', 'transform-reorder');
+          $header = array('Match Pattern', 'Replacement Pattern', 'Order', '');
+          $rows = array();
+          foreach ($sub_form_array['regex-data'] as $key => $element) {
+            if (preg_match('/^#/',$key)) { continue; }
+            $element['new_index']['#attributes']['class'] = 'transform-reorder';
+            
+            $row = array();
+            $row[] = drupal_render($element['pattern']);
+            $row[] = drupal_render($element['replace']);
+            $row[] = drupal_render($element['new_index']) . drupal_render($element['id']);
+            $row[] = drupal_render($element['submit-delete']);
+            $rows[] = array('data' => $row, 'class' => 'draggable');
+          }
+          
+          print theme('table', $header, $rows, array('id' => 'draggable-table'));          
+          
+          // render remaining elements
+          foreach ($sub_form_array as $key => $s2_form_array) {
+            if (preg_match('/^#/',$key)) { continue; }
+            if (!preg_match('/regex-data/', $key)) {
+              print drupal_render($s2_form_array);
+            }
+          }
+          
+          print '</fieldset>';
+          
+        } else {
+          // render other elements  in additional fieldset
+          print drupal_render($sub_form_array);
+        }
+      }
+      print '</fieldset>';
+    } else {
+      // render other elements in add_fields fieldset
+      print drupal_render($form_array);
+    }
+  }
+  unset($form['add_fields']);
+?>
+
+</fieldset>
+</div>
+
+<?php
+  //Render remaining -Needed to submit
+  print drupal_render($form);
+?>

+ 83 - 0
tripal_bulk_loader/theme/tripal_bulk_loader_edit_template_field_form.tpl.php

@@ -0,0 +1,83 @@
+
+<?php print $form['edit_fields']['#prefix']; ?>
+<fieldset><legend> <?php print $form['edit_fields']['#title']; ?> </legend>
+<?php
+  print drupal_render($form['template_name']);
+
+  // Foreach element in the form fieldset 'edit_fields'
+  foreach ($form['edit_fields'] as $key => $form_array) {
+    if (preg_match('/^#/',$key)) { continue; }
+    
+    // We only care about the additional fieldset
+    if (preg_match('/additional/', $key)) {
+      //print fieldset
+      if ($form_array['#collapsible']) { $class[] = 'collapsible'; }
+      if ($form_array['#collapsed']) { $class[] = 'collapsed'; }
+      if (sizeof($class)) { $class = ' class="'.implode(' ',$class).'"'; }
+      print '<fieldset'.$class.'><legend>'.$form_array['#title'].'</legend>';
+      
+      // Foreach element in the 'additional' fieldset
+      foreach ($form_array as $key => $sub_form_array) {
+        if (preg_match('/^#/',$key)) { continue; }
+        
+        // We only care about the 'regex_transform' fieldset
+        if (preg_match('/regex_transform/', $key)) {
+          
+          // print fieldset
+          if ($sub_form_array['#collapsible']) { $class[] = 'collapsible'; }
+          if ($sub_form_array['#collapsed']) { $class[] = 'collapsed'; }
+          if (sizeof($class)) { $class = ' class="'.implode(' ',$class).'"'; }
+          print '<fieldset'.$class.'><legend>'.$sub_form_array['#title'].'</legend>';
+          
+          // print description
+          print drupal_render($sub_form_array['regex_description']);
+          
+          // Render Draggable Table
+          drupal_add_tabledrag('draggable-table', 'order', 'sibling', 'transform-reorder');
+          $header = array('Match Pattern', 'Replacement Pattern', 'Order', '');
+          $rows = array();
+          foreach ($sub_form_array['regex-data'] as $key => $element) {
+            if (preg_match('/^#/',$key)) { continue; }
+            $element['new_index']['#attributes']['class'] = 'transform-reorder';
+            
+            $row = array();
+            $row[] = drupal_render($element['pattern']);
+            $row[] = drupal_render($element['replace']);
+            $row[] = drupal_render($element['new_index']) . drupal_render($element['id']);
+            $row[] = drupal_render($element['submit-delete']);
+            $rows[] = array('data' => $row, 'class' => 'draggable');
+          }
+          
+          print theme('table', $header, $rows, array('id' => 'draggable-table'));          
+          
+          // render remaining elements
+          foreach ($sub_form_array as $key => $s2_form_array) {
+            if (preg_match('/^#/',$key)) { continue; }
+            if (!preg_match('/regex-data/', $key)) {
+              print drupal_render($s2_form_array);
+            }
+          }
+          
+          print '</fieldset>';
+          
+        } else {
+          // render other elements  in additional fieldset
+          print drupal_render($sub_form_array);
+        }
+      }
+      print '</fieldset>';
+    } else {
+      // render other elements in edit_fields fieldset
+      print drupal_render($form_array);
+    }
+  }
+  unset($form['edit_fields']);
+?>
+
+</fieldset>
+</div>
+
+<?php
+  //Render remaining -Needed to submit
+  print drupal_render($form);
+?>

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

@@ -0,0 +1,79 @@
+
+<style>
+tr.odd .form-item, tr.even .form-item {
+  white-space: normal;
+  word-wrap: break-word;
+}
+</style>
+
+<div id="tripal-bulk-loader-fields">
+<?php print drupal_render($form['template_name']); ?>
+
+<!-- For each table display details in a draggable table -->
+<?php if (!$form['records']['no_records']['#value']) { ?>
+  <fieldset><legend><?php print $form['records']['#title']; ?></legend>
+  <?php
+    print drupal_render($form['records']['description']);
+
+    // generate table
+    drupal_add_tabledrag('draggable-table', 'order', 'sibling', 'records-reorder');
+    $header = array('Record Name', 'Chado Table', 'Action', 'Order', '');
+    $rows = array();
+    foreach (element_children($form['records']['records-data']) as $key) {
+      $element = &$form['records']['records-data'][$key];
+      $element['new_priority']['#attributes']['class'] = 'records-reorder';
+
+      $row = array();
+      $row[] = drupal_render($element['title']);
+      $row[] = drupal_render($element['chado_table']);
+      $row[] = drupal_render($element['mode']);
+      $row[] = drupal_render($element['new_priority']) . drupal_render($element['id']);
+      $row[] = drupal_render($element['submit-edit_record']) . '<br>' . drupal_render($element['submit-duplicate_record']) . '<br>' . drupal_render($element['submit-add_field']);
+      $rows[] = array('data' => $row, 'class' => 'draggable');
+    }
+
+print theme('table', $header, $rows, array('id' => 'draggable-table', 'width' => '100%'));
+
+    // Render submit
+    print drupal_render($form['records']['submit-new_record']);
+    print drupal_render($form['records']['submit-reorder']);
+    unset($form['records']);
+  ?>
+  </fieldset>
+<?php } ?>
+
+<!-- For each field display details plus edit/delete buttons-->
+<?php if ($form['fields']['total_fields']['#value'] > 0) { ?>
+  <fieldset><legend><?php print $form['fields']['#title']; ?></legend>
+
+  <?php
+    // generate table
+  $header = array('','Record Name', 'Field Name', 'Chado Table', 'Chado Field', 'Data File Column', 'Constant Value', 'Foreign Record');
+    $rows = array();
+    foreach ($form['fields']['fields-data'] as $key => $element) {
+      if (preg_match('/^#/', $key)) { continue; }
+
+      $row = array();
+      $row[] = drupal_render($element['edit_submit']) . '<br>' . drupal_render($element['delete_submit']);
+      $row[] = drupal_render($element['record_id']);
+      $row[] = drupal_render($element['field_name']);
+      $row[] = drupal_render($element['chado_table_name']);
+      $row[] = drupal_render($element['chado_field_name']);
+      $row[] = drupal_render($element['column_num']);
+      $row[] = drupal_render($element['constant_value']);
+      $row[] = drupal_render($element['foreign_record_id']);
+
+      $rows[] = $row;
+    }
+print theme('table', $header, $rows, array('style'=>'table-layout: fixed; width: 100%'));
+
+    // Render other elements
+    print drupal_render($form['fields']['add_field']);
+    unset($form['fields']);
+  ?>
+  </fieldset>
+<?php } ?>
+
+<!-- Display Rest of form -->
+<?php print drupal_render($form); ?>
+</div>

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

@@ -0,0 +1,68 @@
+<?php
+	$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 = $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-info-box-desc tripal-info-box-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>

+ 17 - 8
tripal_bulk_loader/tripal_bulk_loader.module

@@ -174,29 +174,38 @@ function tripal_bulk_loader_menu() {
  */
 function tripal_bulk_loader_theme() {
   return array(
+    'node' => array(
+      'variables' => array('node' => NULL),
+      'path' => drupal_get_path('module', 'tripal_bulk_loader') . '/theme',
+    ),
     'tripal_bulk_loader_set_constants_form' => array(
-      'arguments' => array('form' => NULL),
+      'function' => 'theme_tripal_bulk_loader_set_constants_form',
+      'variables' => array('form' => NULL),
     ),
     'tripal_bulk_loader_template' => array(
-      'arguments' => array('template_id' => NULL),
-      'template' => 'tripal_bulk_loader_template'
+      'variables' => array('template_id' => NULL),
+      'template' => 'tripal_bulk_loader_template',
+      'path' => drupal_get_path('module', 'tripal_bulk_loader') . '/theme',
     ),
     'tripal_bulk_loader_modify_template_base_form' => array(
-      'arguments' => array('form' => NULL),
+      'variables' => array('form' => NULL),
       'template' => 'tripal_bulk_loader_modify_template_base_form',
+      'path' => drupal_get_path('module', 'tripal_bulk_loader') . '/theme',
     ),
     'tripal_bulk_loader_edit_template_field_form' => array(
-      'arguments' => array('form' => NULL),
+      'variables' => array('form' => NULL),
       'template' => 'tripal_bulk_loader_edit_template_field_form',
+      'path' => drupal_get_path('module', 'tripal_bulk_loader') . '/theme',
     ),
     'tripal_bulk_loader_add_template_field_form' => array(
-      'arguments' => array('form' => NULL),
+      'variables' => array('form' => NULL),
       'template' => 'tripal_bulk_loader_add_template_field_form',
+      'path' => drupal_get_path('module', 'tripal_bulk_loader') . '/theme',
     ),
     'tripal_bulk_loader_admin' => array(
       'template' => 'tripal_bulk_loader_admin',
-      'arguments' =>  array(NULL),
-      'path' => drupal_get_path('module', 'tripal_bulk_loader') . '/theme'
+      'variables' =>  array(NULL),
+      'path' => drupal_get_path('module', 'tripal_bulk_loader') . '/theme',
     ),
   );
 }