spficklin пре 14 година
родитељ
комит
6610387e7c

+ 82 - 16
tripal_core/jobs.php

@@ -95,26 +95,16 @@ function tripal_jobs_report () {
       if($i % 2 == 0 ){
          $class = 'tripal-table-even-row';
       }
-      $submit = format_date($job->submit_date);
-      if($job->start_time > 0){
-         $start = format_date($job->start_time);
-      } else {
-         if(strcmp($job->job_status,'Cancelled')==0){
-            $start = 'Cancelled';
-         } else {
-            $start = 'Not Yet Started';
-         }
-      }
-      if($job->end_time > 0){
-         $end = format_date($job->end_time);
-      } else {
-         $end = '';
-      }
+      $submit = tripal_jobs_get_submit_date($job);
+      $start = tripal_jobs_get_start_time($job);
+      $end = tripal_jobs_get_end_time($job);
+
       $cancel_link = '';
       if($job->start_time == 0 and $job->end_time == 0){
          $cancel_link = "<a href=\"".url("admin/tripal/tripal_jobs/cancel/".$job->job_id)."\">Cancel</a>";
       }
       $rerun_link = "<a href=\"".url("admin/tripal/tripal_jobs/rerun/".$job->job_id)."\">Re-run</a>";
+      $view_link ="<a href=\"".url("admin/tripal/tripal_jobs/view/".$job->job_id)."\">View</a>";
       $output .= "  <tr class=\"$class\">";
       $output .= "    <td>$job->job_id</td>".
                  "    <td>$job->username</td>".
@@ -125,7 +115,7 @@ function tripal_jobs_report () {
                  "    <td>$job->priority</td>".
 				     "    <td>$job->progress%</td>".
                  "    <td>$job->job_status</td>".
-                 "    <td>$cancel_link $rerun_link</td>".
+                 "    <td>$cancel_link $rerun_link $view_link</td>".
                  "  </tr>";
       $i++;
    }
@@ -135,6 +125,38 @@ function tripal_jobs_report () {
 }
 /**
 *
+*/
+function tripal_jobs_get_start_time($job){
+   if($job->start_time > 0){
+      $start = format_date($job->start_time);
+   } else {
+      if(strcmp($job->job_status,'Cancelled')==0){
+         $start = 'Cancelled';
+      } else {
+         $start = 'Not Yet Started';
+      }
+   }
+   return $start;
+}
+/**
+*
+*/
+function tripal_jobs_get_end_time($job){
+   if($job->end_time > 0){
+      $end = format_date($job->end_time);
+   } else {
+      $end = '';
+   }
+   return $end;
+}
+/**
+*
+*/
+function tripal_jobs_get_submit_date($job){
+   return format_date($job->submit_date);
+}
+/**
+*
 *
 * @ingroup tripal_core
 */
@@ -215,6 +237,50 @@ function tripal_jobs_check_running () {
    return 0;
 }
 
+/**
+*
+*/
+function tripal_jobs_view ($job_id){
+   return theme('tripal_core_job_view',$job_id);
+}
+/**
+*
+*/
+function tripal_core_preprocess_tripal_core_job_view (&$variables){
+   // get the job record
+   $job_id = $variables['job_id'];
+   $sql = 
+      "SELECT TJ.job_id,TJ.uid,TJ.job_name,TJ.modulename,TJ.progress,
+              TJ.status as job_status, TJ,submit_date,TJ.start_time,
+              TJ.end_time,TJ.priority,U.name as username,TJ.arguments,
+              TJ.callback,TJ.error_msg,TJ.pid
+       FROM {tripal_jobs} TJ 
+         INNER JOIN users U on TJ.uid = U.uid 
+       WHERE TJ.job_id = %d";
+   $job = db_fetch_object(db_query($sql,$job_id));
+
+   // we do not know what the arguments are for and we want to provide a 
+   // meaningful description to the end-user. So we use a callback function
+   // deinfed in the module that created the job to describe in an array
+   // the arguments provided.  If the callback fails then just use the 
+   // arguments as they are
+   $args = preg_split("/::/",$job->arguments);
+   $arg_hook = $job->modulename."_job_describe_args";
+   $new_args = call_user_func_array($arg_hook,array($job->callback,$args));
+   if(is_array($new_args) and count($new_args)){
+      $job->arguments = $new_args;
+   } else {
+      $job->arguments = $args;
+   }
+
+   // make our start and end times more legible
+   $job->submit_date = tripal_jobs_get_submit_date($job);
+   $job->start_time = tripal_jobs_get_start_time($job);
+   $job->end_time = tripal_jobs_get_end_time($job);
+
+   // add the job to the variables that get exported to the template
+   $variables['job'] = $job;
+}
 /**
 *
 * @ingroup tripal_core

+ 38 - 25
tripal_core/tripal_core.api.inc

@@ -365,7 +365,9 @@ function tripal_core_chado_update($table,$match,$values){
 * @param $columns
 *  An array of column names
 * @param $values
-*  An associative array containing the values for filtering the results.
+*  An associative array containing the values for filtering the results. In the 
+*  case where multiple values for the same time are to be selected an additional
+*  entry for the field should appear for each value
 * @param $has_record
 *  Set this argument to 'true' to have this function return a numeric 
 *  value for the number of recrods rather than the array of records.  this
@@ -381,7 +383,7 @@ function tripal_core_chado_update($table,$match,$values){
 *   $values =  array(
 *     'organism_id' => array(
 *         'genus' => 'Citrus',
-*         'species' => 'sinensis',
+*         'species' => array('sinensis','clementina'),
 *      ),
 *     'uniquename' => 'orange1.1g000034m.g',
 *     'type_id' => array (
@@ -399,11 +401,12 @@ function tripal_core_chado_update($table,$match,$values){
 * to select. The $values array is nested such that the organism is identified by 
 * way of the organism_id foreign key constraint by specifying the genus and 
 * species.  The cvterm is also specified using its foreign key and the cv_id 
-* for the cvterm is nested as well.
+* for the cvterm is nested as well.  In the example above, two different species
+* are allowed to match
 *
 * @ingroup tripal_api
 */
-function tripal_core_chado_select($table,$columns,$values,$has_record = 0){
+function tripal_core_chado_select($table,$columns,$values,$has_record = 0,$return_sql = 0){
 
    if (!is_array($columns)){
       watchdog('tripal_feature', 'the $columns argument for tripal_core_chado_select must be an array.');
@@ -425,29 +428,33 @@ function tripal_core_chado_select($table,$columns,$values,$has_record = 0){
    foreach($values as $field => $value){
       $select[] = $field;
       if(is_array($value)){
-         // select the value from the foreign key relationship for this value
-         $results = tripal_core_chado_get_foreign_key($table_desc,$field,$value);
-         if (sizeof($results) < 1) {
-           // foreign key records are required
-           // thus if none matched then return false and alert the admin through watchdog
-           watchdog('tripal_core', 
-            'tripal_core_chado_select: no record in the table referenced by the foreign key (!field)   exists. tripal_core_chado_select table=!table, columns=!columns, values=!values', 
-            array('!table' => $table, 
-              '!columns' => '<pre>' . print_r($columns, TRUE) . '</pre>', 
-              '!values' => '<pre>' . print_r($values, TRUE) . '</pre>',
-              '!field' => $field,
-            ), 
-            WATCHDOG_WARNING);
-           return false;
-           
-         } elseif (sizeof($results) == 1) {
-           $where[$field] = $results[0];
+         // if the user has specified multiple values for matching then this we
+         // want to catch that and save them in our $where array, otherwise
+         // we'll descend for a foreign key relationship
+         if(array_values($value) === $value){
+            $where[$field] = $value;
          } else {
-           $where[$field] = $results;
+            // select the value from the foreign key relationship for this value
+            $results = tripal_core_chado_get_foreign_key($table_desc,$field,$value);
+            if (sizeof($results) < 1) {
+              // foreign key records are required
+              // thus if none matched then return false and alert the admin through watchdog
+              watchdog('tripal_core', 
+               'tripal_core_chado_select: no record in the table referenced by the foreign key (!field)   exists. tripal_core_chado_select table=!table, columns=!columns, values=!values', 
+               array('!table' => $table, 
+                 '!columns' => '<pre>' . print_r($columns, TRUE) . '</pre>', 
+                 '!values' => '<pre>' . print_r($values, TRUE) . '</pre>',
+                 '!field' => $field,
+               ), 
+               WATCHDOG_WARNING);
+              return false;           
+            } else {
+              $where[$field] = $results;
+            }
          }
       } 
       else {
-         $where[$field] = $value;
+         $where[$field][] = $value;
       }
    }
 
@@ -461,17 +468,23 @@ function tripal_core_chado_select($table,$columns,$values,$has_record = 0){
      $sql .= "FROM {$table} ";
      $sql .= "WHERE ";
      foreach($where as $field => $value){
-       if (is_array($value)) {
+       if (count($value) > 1) {
          $sql .= "$field IN (".db_placeholders($value,'varchar').") AND ";
          foreach ($value as $v) { $args[] = $v; }
        } else {
          $sql .= "$field = '%s' AND ";
-         $args[] = $value;
+         $args[] = $value[0];
        }
      }
      $sql = substr($sql,0,-4);  // get rid of the trailing 'AND'
    }
 
+   // if the caller has requested the SQL rather than the results...
+   // which happens in the case of wanting to use the Drupal pager, then do so
+   if($return_sql){
+      return array('sql'=> $sql, 'args' => $args);
+   }
+
    $previous_db = tripal_db_set_active('chado');  // use chado database
    $resource = db_query($sql,$args);
    tripal_db_set_active($previous_db);  // now use drupal database   

+ 17 - 25
tripal_core/tripal_core.module

@@ -126,6 +126,14 @@ function tripal_core_menu() {
      'access arguments' => array('access administration pages'),
      'type' => MENU_CALLBACK,
    );
+   $items['admin/tripal/tripal_jobs/view/%'] = array(
+     'title' => 'Jobs Details',
+     'description' => 'View job details.',
+     'page callback' => 'tripal_jobs_view',
+     'page arguments' => array(4),
+     'access arguments' => array('access administration pages'),
+     'type' => MENU_CALLBACK,
+   );
    $items['admin/tripal/tripal_mview/%'] = array(
      'title' => 'Materialized View',
      'description' => 'Materialized views are used to improve speed of large or complex queries.',
@@ -209,31 +217,6 @@ function tripal_core_menu() {
   return $items;
 }
 
-/**
- * Provides the tripal box menu functionality
- *
- *  The typical display for information on feature, organism, library, etc
- *  pages is to use the Tripal expandable boxes.  However, some sites may
- *  prefer to use a menu system to keep the pages less cluttered.  This
- *  function provides a common interface for setting a Drupal variable
- *  that indicates whether or not the content is displayed in a box or as
- *  a menu item.  This function just reverses the setting each time it is
- *  called
- *
- * @ingroup tripal_core
- */
-function tripal_toggle_box_menu($module,$box_name,$nid){
-   // if the content is not in a menu then we wnat to turn on the
-   // menu. If the content is in a menu item then we want to turn
-   // on the box. 
-   if(strcmp(variable_get("$module-box-$box_name","menu_off"),"menu_off")==0){
-      variable_set("$module-box-$box_name","menu_on");
-   } else {
-      variable_set("$module-box-$box_name","menu_off");
-   }
-   drupal_goto("node/$nid");
-}
-
 /**
  *
  *
@@ -393,3 +376,12 @@ function tripal_get_max_chado_rank ($tablename, $where_options) {
 		return -1;
 	}
 }
+
+function tripal_core_theme () {
+   return array(      
+      'tripal_core_job_view' => array (
+         'arguments' => array('job_id'=> null),
+         'template' => 'tripal_core_job_view',
+      ),
+   );
+}

+ 80 - 0
tripal_core/tripal_core_job_view.tpl.php

@@ -0,0 +1,80 @@
+<?php
+$job = $variables['job'];
+
+$cancel_link = '';
+if($job->start_time == 0 and $job->end_time == 0){
+   $cancel_link = url("admin/tripal/tripal_jobs/cancel/".$job->job_id);
+}
+$rerun_link = url("admin/tripal/tripal_jobs/rerun/".$job->job_id);
+ 
+?>
+
+<div id="tripal_core-job_view-box" class="tripal_core-info-box tripal-info-box">
+  <div class="tripal_core-info-box-title tripal-info-box-title">Details for Job <?php print $job->job_id?></div>
+  <div class="tripal_core-info-box-desc tripal-info-box-desc"></div>
+   <a href="/admin/tripal/tripal_jobs/">Return to jobs list</a> | 
+   <a href="<?php print $rerun_link?>">Re-run this job</a> | 
+   <a href="<?php print $cancel_link?>">Cancel this Job</a><br>
+   <table id="tripal_core-job_view-table" class="tripal_core-table tripal-table tripal-table-vert">
+      <tr class="tripal_core-table-odd-row tripal-table-even-row tripal-table-first-row">
+         <th>Job Description</th>
+         <td><?php print $job->job_name?></td>
+      </tr>
+      <tr class="tripal_core-table-odd-row tripal-table-odd-row">
+         <th>Submitting Module</th>
+         <td><?php print $job->modulename?></td>
+      </tr>
+      <tr class="tripal_core-table-odd-row tripal-table-even-row">
+         <th>Callback function</th>
+         <td><?php print $job->callback?></td>
+      </tr>
+      <tr class="tripal_core-table-odd-row tripal-table-odd-row">
+         <th>Arguments</th>
+         <td>
+           <table>
+           <?php foreach($job->arguments as $key => $value){
+              print "<tr><td>$key</td><td>$value</td></tr>";
+           } ?>
+           </table>
+         </td>
+      </tr>
+      <tr class="tripal_core-table-odd-row tripal-table-even-row">
+         <th>Progress</th>
+         <td><?php print $job->progress?>%</td>
+      </tr>
+      <tr class="tripal_core-table-odd-row tripal-table-odd-row">
+         <th>Status</th>
+         <td><?php print $job->job_status?></td>
+      </tr>
+      <tr class="tripal_core-table-odd-row tripal-table-even-row">
+         <th>Process ID</th>
+         <td><?php print $job->pid?></td>
+      </tr>
+      <tr class="tripal_core-table-odd-row tripal-table-odd-row">
+         <th>Submit Date</th>
+         <td><?php print $job->submit_date?></td>
+      </tr>
+      <tr class="tripal_core-table-odd-row tripal-table-even-row">
+         <th>Start time</th>
+         <td><?php print $job->start_time?></td>
+      </tr>
+      <tr class="tripal_core-table-odd-row tripal-table-odd-row">
+         <th>End time</th>
+         <td><?php print $job->end_time?></td>
+      </tr>
+      <tr class="tripal_core-table-odd-row tripal-table-even-row">
+         <th>Error Message</th>
+         <td><?php print $job->error_msg?></td>
+      </tr>
+      <tr class="tripal_core-table-odd-row tripal-table-odd-row">
+         <th>Priority</th>
+         <td><?php print $job->priority?></td>
+      </tr>
+      <tr class="tripal_core-table-odd-row tripal-table-even-row tripal-table-last-row">
+         <th>Submitting User</th>
+         <td><?php print $job->username?></td>
+      </tr>
+   </table>
+</div>
+
+

+ 1 - 1
tripal_feature/fasta_loader.php

@@ -292,7 +292,7 @@ function tripal_feature_fasta_load_form_submit ($form, &$form_state){
    $args = array($dfile,$organism_id,$type,$library_id,$re_name,$re_uname,
             $re_accession,$db_id,$rel_type,$re_subject,$parent_type,$update,$user->uid);
 
-   tripal_add_job("Import FASTA file: $dfile",'tripal_core',
+   tripal_add_job("Import FASTA file: $dfile",'tripal_feature',
       'tripal_feature_load_fasta',$args,$user->uid);
 }
 

+ 1 - 1
tripal_feature/tripal_feature.api.inc

@@ -10,7 +10,7 @@
  *
  * @ingroup tripal_feature
  */
-function tripal_stock_chado_feature_schema() {
+function tripal_feature_chado_feature_schema() {
   $description = array();
 
   $description['foreign keys']['organism'] = array(

+ 34 - 1
tripal_feature/tripal_feature.module

@@ -2224,4 +2224,37 @@ function tripal_feature_return_fasta($feature,$desc){
    $fasta .= "\n\n";
    return $fasta;
 }
-
+/**
+ *
+ *
+ * @ingroup tripal_feature
+ */
+function tripal_feature_job_describe_args($callback,$args){
+
+   $new_args = array();
+   if($callback == 'tripal_feature_load_fasta'){
+      $new_args['FASTA file'] = $args[0];
+      $organism = tripal_core_chado_select('organism',array('genus','species'),array('organism_id' => $args[1]));
+      $new_args['Organism'] = $organism[0]->genus." ". $organism[0]->species;
+      $new_args['Sequence Type'] = $args[2];
+      $new_args['Name RE'] = $args[4];
+      $new_args['Unique Name RE'] = $args[5];
+
+      // add in the relationship arguments
+      $new_args['Relationship Type'] = $args[8];
+      $new_args['Relationship Subject RE'] = $args[9];
+      $new_args['Relationship Parent RE'] = $args[10];
+
+      // add in the database reference arguments
+      $db = tripal_core_chado_select('db',array('name'),array('db_id' => $args[7]));
+      $new_args['Database Reference'] = $db[0]->name;
+      $new_args['Accession RE'] = $args[6];
+      if($args[11]){
+         $new_args['Update and Insert'] = 'Yes';
+      }
+      else {
+         $new_args['Insert Only New Features'] = 'Yes';
+      }
+   }
+   return $new_args;
+}