Pārlūkot izejas kodu

ajax pagination for relationships

Shawna Spoor 8 gadi atpakaļ
vecāks
revīzija
a40041947a

+ 91 - 0
tripal/api/tripal.DEPRECATED.api.inc

@@ -0,0 +1,91 @@
+<?php
+/**
+ * Returns the end time for a given job
+ *
+ * @param $job
+ *   An object describing the job
+ *
+ * @return
+ *   The end time of the job if it was already run and empty otherwise
+ *
+ * @ingroup tripal_jobs_api
+ */
+function tripal_get_job_end($job) {
+  tripal_report_error('tripal_deprecated', TRIPAL_NOTICE,
+    "DEPRECATED: %function has been removed from the API the end date " .
+    "is now accessible via the %property property. Please update your code.",
+    array(
+      '%old_function' => 'tripal_jobs_get_end_time',
+      '%property' => '\$job->end_time_string',
+    )
+  );
+
+  if ($job->end_time > 0) {
+    $end = format_date($job->end_time);
+  }
+  else {
+    $end = '';
+  }
+
+  return $end;
+}
+
+/**
+ * Returns the start time for a given job
+ *
+ * @param $job
+ *   An object describing the job
+ *
+ * @return
+ *   The start time of the job if it was already run and either "Cancelled" or "Not Yet Started" otherwise
+ *
+ * @ingroup tripal_jobs_api
+ */
+function tripal_get_job_start($job) {
+
+  tripal_report_error('tripal_deprecated', TRIPAL_NOTICE,
+    "DEPRECATED: %function has been removed from the API the end date " .
+    "is now accessible via the %property property. Please update your code.",
+    array(
+      '%old_function' => 'tripal_get_job_start',
+      '%property' => '\$job->start_time_string',
+    )
+  );
+
+  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;
+}
+
+/**
+ * Returns the date the job was added to the queue
+ *
+ * @param $job
+ *   An object describing the job
+ *
+ * @return
+ *   The date teh job was submitted
+ *
+ * @ingroup tripal_jobs_api
+ */
+function tripal_get_job_submit_date($job) {
+
+  tripal_report_error('tripal_deprecated', TRIPAL_NOTICE,
+      "DEPRECATED: %function has been removed from the API the end date " .
+      "is now accessible via the %property property. Please update your code.",
+      array(
+        '%old_function' => 'tripal_get_job_submit_date',
+        '%property' => '\$job->submit_date_string',
+      )
+  );
+  return format_date($job->submit_date);
+}

+ 16 - 65
tripal/api/tripal.jobs.api.inc

@@ -160,23 +160,35 @@ function tripal_add_job($job_name, $modulename, $callback, $arguments, $uid,
  *   The unique identifier of the job
  *
  * @return
- *   An object describing the job
+ *   An object describing the job if a job is found or FALSE on failure.
  *
  * @ingroup tripal_jobs_api
  */
 function tripal_get_job($job_id) {
+  if (!$job_id or !is_numeric($job_id)) {
+    watchdog('tripal', "Must provide a numeric \$job_id to the tripal_cancel_job() function.");
+    return FALSE;
+  }
 
   $job = db_query('SELECT j.* FROM {tripal_jobs} j WHERE j.job_id=:job_id', array(':job_id' => $job_id))
     ->fetchObject();
 
+  $job->submit_date_string = format_date($job->submit_date);
+  $job->start_time_string = format_date($job->start_time);
+  $job->end_time_string = format_date($job->end_time);
+
   return $job;
 }
 
 /**
- * Returns a list of running tripal jobs
+ * Indicates if any jobs are running.
+ *
+ * This function will check the system to see if a job has a process ID
+ * and if that process ID is still running. It will update the job status
+ * accordingly before returning.
  *
  * @return
- *    and array of objects where each object describes a running job or FALSE if no jobs are running
+ *   Returns TRUE if any job is running or FALSE otherwise.
  *
  * @ingroup tripal_jobs_api
  */
@@ -211,55 +223,7 @@ function tripal_is_job_running() {
   return FALSE;
 }
 
-/**
- * Returns the start time for a given job
- *
- * @param $job
- *   An object describing the job
- *
- * @return
- *   The start time of the job if it was already run and either "Cancelled" or "Not Yet Started" otherwise
- *
- * @ingroup tripal_jobs_api
- */
-function tripal_get_job_start($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;
-}
 
-/**
- * Returns the end time for a given job
- *
- * @param $job
- *   An object describing the job
- *
- * @return
- *   The end time of the job if it was already run and empty otherwise
- *
- * @ingroup tripal_jobs_api
- */
-function tripal_get_job_end($job) {
-
-  if ($job->end_time > 0) {
-    $end = format_date($job->end_time);
-  }
-  else {
-    $end = '';
-  }
-
-  return $end;
-}
 /**
  * Set a job to be re-ran (ie: add it back into the job queue)
  *
@@ -510,17 +474,4 @@ function tripal_get_active_jobs($modulename = NULL) {
   return $jobs;
 }
 
-/**
- * Returns the date the job was added to the queue
- *
- * @param $job
- *   An object describing the job
- *
- * @return
- *   The date teh job was submitted
- *
- * @ingroup tripal_jobs_api
- */
-function tripal_get_job_submit_date($job) {
-  return format_date($job->submit_date);
-}
+

+ 1 - 1
tripal/includes/tripal.jobs.inc

@@ -120,7 +120,7 @@ function tripal_jobs_report() {
 
   // run the following function which will
   // change the status of jobs that have errored out
-  tripal_is_job_running();
+  tripal_get_running_jobs();
 
   $job_status = '';
   $job_name = '';

+ 2 - 0
tripal/theme/js/tripal.js

@@ -18,6 +18,8 @@
           }
         });
       });
+
     }
   }
+
 })(jQuery);

+ 1 - 0
tripal/tripal.module

@@ -566,6 +566,7 @@ function tripal_import_api() {
   module_load_include('inc', 'tripal', 'api/tripal.jobs.api');
   module_load_include('inc', 'tripal', 'api/tripal.notice.api');
   module_load_include('inc', 'tripal', 'api/tripal.variables.api');
+  module_load_include('inc', 'tripal', 'api/tripal.DEPRECATED.api');
 }
 
 /**

+ 123 - 26
tripal_chado/api/modules/tripal_chado.cv.api.inc

@@ -425,7 +425,108 @@ function tripal_update_cvtermpath_root_loop($rootid, $cvid){
  * @param $depth
  * @return multitype:
  */
-function tripal_update_cvtermpath_loop($origin, $subject_id, $cv_id, $type_id, $depth){
+function tripal_update_cvtermpath_loop($origin, $child_id, $cv_id, $type_id, $depth){
+  chado_set_active('chado');
+  $count =  db_query(
+    'SELECT *
+     FROM cvtermpath
+     WHERE cv_id = :cvid 
+      AND object_id = :origin
+      AND subject_id = :child_id
+      AND pathdistance = :depth
+    ',
+    array(':cvid' => $cv_id, ':origin' => $origin, ':child_id' => $child_id, ':depth' => $depth)
+  );
+  $count_total = $count->rowCount();
+
+  //Loop check
+  chado_set_active('chado');
+  $loop = db_query(
+    'SELECT *
+     FROM cvtermpath
+     WHERE cv_id = :cvid 
+      AND object_id = :origin
+      AND subject_id = :child_id 
+      AND type_id = :type_id
+    ',
+    array(':cvid' => $cv_id, ':origin' => $origin, ':child_id' => $child_id, ':type_id' => $type_id,)
+  );
+  $loop_check = $loop->rowCount();
+
+  //watchdog('debug', '<pre>tripal_ds_preprocess_TripalEntity $rows ' . print_r($rows, TRUE) . '</pre>');
+  /*if(!empty($rows)){
+    foreach($rows as $row){
+      tripal_update_cvtermpath_loop_check($origin, $child_id, $cv_id, $type_id, $depth, $row->cvtermpath_id, 0);
+    }
+  }
+  else {*/
+    //If no loop proceed.
+  try{
+    if($count_total == 0) {
+      chado_set_active('chado');
+
+      $query = db_insert('cvtermpath')
+        ->fields(array(
+          'object_id' => $origin,
+          'subject_id' => $child_id,
+          'cv_id' => $cv_id,
+          'type_id' => $type_id,
+          'pathdistance' => $depth,
+        ));
+      $rows = $query->execute();
+    }
+    if ($loop_check == 0) {
+      chado_set_active('chado');
+
+      $query = db_select('cvterm_relationship', 'cvtr')
+        ->fields('cvtr')
+        ->condition('cvtr.object_id', $child_id, '=')
+        ->execute();
+      $cterm = $query->fetchAll();
+
+      foreach ($cterm as $item) {
+        //watchdog('debug', '<pre>tripal_ds_preprocess_TripalEntity $item ' . print_r($item, TRUE) . '</pre>');
+        tripal_update_cvtermpath_loop($origin, $item->subject_id, $cv_id, $item->type_id, $depth + 1);
+      };
+      //}
+    }
+  }
+  catch(Exception $e){
+    watchdog_exception('tripal_ds', $e);
+    return FALSE;
+  }
+
+  return 1;
+
+}
+
+/**
+ *
+ * @param $origin
+ * @param $subject_id
+ * @param $cv_id
+ * @param $type_id
+ * @param $depth
+ * @return multitype:
+
+function tripal_update_cvtermpath_loop_check($origin, $child_id, $cv_id, $type_id, $depth, $cvtermpath_id, $loop_count, $loop_check, $object_id){
+  //Store the
+
+  //Check if the passed parameters match any of the items in the loop_check array.
+  if(!empty($loop_check)){
+    foreach($loop_check as $item){
+        if ($item['type_id'] = $type_id){
+          if($item['subject_id'] = $child_id){
+            if($item['object_id'] = $object_id){
+              //Loop found, roll back all rows until $cvtermpath_id-1 (last correct entry)
+              // and step into the next loop
+            }
+          }
+        }
+    }
+  }
+  $loop_count + 1;
+
   chado_set_active('chado');
   $count =  db_query(
     'SELECT *
@@ -434,43 +535,39 @@ function tripal_update_cvtermpath_loop($origin, $subject_id, $cv_id, $type_id, $
        AND subject_id = :child_id
        AND pathdistance = :depth
     ',
-    array(':cvid' => $cv_id, ':origin' => $origin, ':child_id' => $subject_id, ':depth' => $depth)
+    array(':cvid' => $cv_id, ':origin' => $origin, ':child_id' => $child_id, ':depth' => $depth)
   );
   $count_total = $count->rowCount();
-  chado_set_active('chado');
-  watchdog('debug', '<pre>tripal_update_cvtermpath_loop  $count_total: ' . print_r($count_total, TRUE) . '</pre>');
 
   if ($count_total == 0) {
-    watchdog('debug', '<pre>tripal_update_cvtermpath_loop inside if count total $origin: ' . print_r($origin, TRUE) . '</pre>');
     chado_set_active('chado');
-
-    db_update("cvtermpath")
+    $query = db_insert('cvtermpath')
       ->fields(array(
-        "object_id" => $origin,
-        "subject_id" => $subject_id,
-        "cv_id" => $cv_id,
-        "type_id" => $type_id,
-        "pathdistance" => $depth
-      ))
+        'object_id' => $origin,
+        'subject_id' => $child_id,
+        'cv_id' => $cv_id,
+        'type_id' => $type_id,
+        'pathdistance' => $depth,
+      ));
+    $rows = $query->execute();
+    $cterm = array();
+    $query = db_select('cvterm_relationship', 'cvtr')
+      ->fields('cvtr')
+      ->condition('cvtr.object_id', $child_id, '=' )
       ->execute();
-  }
-  $cterm = array();
+    $cterm = $query->fetchAll();
 
-  $query = db_select('cvterm_relationship', 'cvtr')
-          ->fields('cvtr')
-          ->condition('cvtr.object_id', $subject_id, '=' )
-          ->execute();
+    foreach ($cterm as $item) {
+      $loop_check[$loop_count]= $item;
+      tripal_update_cvtermpath_loop_check($origin, $item->subject_id, $cv_id, $item->type_id, $depth + 1, $loop_count, $loop_check, $item->object_id);
+    };
+  }
 
-  while($loop_item = $query->fetchAssoc()){
-    watchdog('debug', '<pre>tripal_update_cvtermpath_loop  $loop_item: ' . print_r($loop_item, TRUE) . '</pre>');
-    tripal_update_cvtermpath_loop($origin, $loop_item['subject_id'], $cv_id, $loop_item['type_id'], $depth + 1);
-  };
 
-  return $cterm;
+  return 1;
 
 }
-
-
+ */
 
 /**
  * Adds a controlled vocabular to the CV table of Chado.

+ 14 - 2
tripal_chado/includes/TripalFields/sbo__relationship/sbo__relationship_formatter.inc

@@ -92,9 +92,19 @@ class sbo__relationship_formatter extends ChadoFieldFormatter {
         }
       }
 
-      $rows[] = array($phrase);
+      $rows[][] = array('data' => $phrase, 'class' => array('tripal-entity-unattached field-items'));
     }
 
+    $per_page = 10;
+    // Initialize the pager
+    $current_page = pager_default_initialize(count($rows), $per_page);
+    // Split your list into page sized chunks
+    $chunks = array_chunk($rows, '10', TRUE);
+    //format pager
+    $pager = theme('pager', array('quantity', count($rows)));
+
+    //$pager = preg_replace("/href=\"(.*)\"/", 'href="javascript:void(0)" onclick="tripal_navigate_field_pager()"', $pager);
+    //$pager = preg_replace("/href=\"" . $tmp_base_path . "gensas\/load_job_view_panel\/" . $job_id . "\/\d\"/", 'href="javascript:void(0)" onclick="gensas.show_job_view_panel(\'' . $job_id . '\', \'' . $job->getName() . '\')"', $pager);
     // 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:
@@ -102,7 +112,7 @@ class sbo__relationship_formatter extends ChadoFieldFormatter {
 
     $table = array(
       'header' => $headers,
-      'rows' => $rows,
+      'rows' => $chunks[$current_page],
       'attributes' => array(
         'id' => 'sbo--relationship-table',
       ),
@@ -118,6 +128,8 @@ class sbo__relationship_formatter extends ChadoFieldFormatter {
       $element[0] = array(
         '#type' => 'markup',
         '#markup' => theme_table($table),
+        '#prefix' => '<div id="ajax-target">',
+        '#suffix' => $pager . '</div>',
       );
     }
   }

+ 13 - 0
tripal_chado/includes/loaders/tripal_chado.obo_loader.inc

@@ -511,6 +511,7 @@ function tripal_chado_load_update_cvtermpath($newcvs, $jobid) {
 function tripal_chado_load_obo_v1_2($file, $jobid = NULL, &$newcvs) {
 
   //$transaction = db_transaction();
+
   print "\nNOTE: Loading of this OBO file is performed using a database transaction. \n" .
       "If the load fails or is terminated prematurely then the entire set of \n" .
       "insertions/updates is rolled back and will not be found in the database\n\n";
@@ -900,6 +901,18 @@ function tripal_cv_obo_process_term($term, $defaultcv, $is_relationship = 0, &$n
     foreach ($term['relationship'] as $value) {
       $rel = preg_replace('/^(.+?)\s.+?$/', '\1', $value);
       $object = preg_replace('/^.+?\s(.+?)$/', '\1', $value);
+      // The Gene Ontology uses 'has_part' for transitive relationships, but
+      // it specifically indicates that 'has_part' should not be used for
+      // grouping annotations.  Unfortunately, this means that when we
+      // try to popoulate the cvtermpath table a 'has_part' relationships
+      // will be used for exactly that purpose: to group annotations.  This
+      // doesn't seem to the be the case for other vocabularies such as the
+      // sequence ontology that uses has_part as primary relationship between
+      // terms. So, when loading the GO, we'll not include has_part
+      // relationships.
+      if ($rel == 'has_part' and $cvterm->dbxref_id->db_id->name == 'GO') {
+        continue;
+      }
       if (!tripal_cv_obo_add_relationship($cvterm, $defaultcv, $rel, $object, $is_relationship, $default_db)) {
         tripal_cv_obo_quiterror("Cannot add relationship $rel: $object");
       }

+ 5 - 0
tripal_chado/theme/js/tripal_chado_fields.js

@@ -0,0 +1,5 @@
+
+function tripal_navigate_field_pager($page) {
+    console.log($page);
+    jQuery("#ajax-target").load("bio_data/ajax/field_attach/"+$page);
+}

+ 1 - 0
tripal_chado/tripal_chado.info

@@ -11,6 +11,7 @@ files[] = views_handlers/chado_views_handler_sort.inc
 files[] = views_handlers/chado_views_handler_field_chado_base__organism_id.inc
 
 stylesheets[all][] = theme/css/tripal_chado.css
+scripts[]          = theme/js/tripal_chado_fields.js
 
 dependencies[] = tripal
 dependencies[] = date

+ 1 - 14
tripal_chado/tripal_chado.module

@@ -838,17 +838,4 @@ function tripal_chado_form_field_ui_field_edit_form_alter(&$form, &$form_state,
   }
 
   // TODO: don't the the maximum length be larger than the field size.
-}
-
-/**
- * Implements hook_form_alter().
- */
-function tripal_chado_form_alter(&$form, $form_state, $form_id) {
-  // If this is the field_ui_field_edit_form (i.e. the form that appears
-  // when editing a field that is attached to an entity). Then we want
-  // to add term settings for any field attached to a TripalEntity
-  // content type.
-  if ($form_id == 'field_ui_field_edit_form' and $form['#instance']['entity_type'] == 'TripalEntity') {
-    tripal_chado_field_instance_settings_form_alter($form, $form_state);
-  }
-}
+}