Browse Source

adding the spinner to the relationships pager and the permissions for new bundles

Shawna Spoor 8 years ago
parent
commit
cf6a12d0cc

+ 41 - 11
tripal/api/tripal.entities.api.inc

@@ -325,17 +325,6 @@ function tripal_create_bundle($args, &$error = '') {
       $function = $module . '_bundle_postcreate';
       $function($bundle);
     }
-
-    // Finally set admin perimssions for the content type:
-//     $roles = user_roles();
-//     $admin_rid = variable_get('user_admin_role');
-//     $perms = user_role_permissions(array($admin_rid));
-//     dpm($perms);
-//     foreach ($perms[$admin_rid] as $perm => $value) {
-//       $perms[$admin_rid][$perm] = TRUE;
-//     }
-//     user_role_change_permissions($admin_rid, $perms[$admin_rid]);
-
   }
   catch (Exception $e) {
     $transaction->rollback();
@@ -348,6 +337,47 @@ function tripal_create_bundle($args, &$error = '') {
   return $bundle;
 }
 
+/*
+ * Checks access permissions for a given entity.
+ *
+ * This function is set for TripalEntity access checking in the
+ * tripal_entity_info() under the 'access callback' element.
+ *
+ *
+ * @param $entity
+ *   The entity to check access for.
+
+function tripal_entity_permissions($entity) {
+
+  if ($entity) {
+    $bundle_name = $entity->bundle;
+  }
+  else {
+    return FALSE;
+  }
+
+  // Get the bundle object.
+  $bundle = tripal_load_bundle_entity(array('name' => $bundle_name));
+
+  // Identify the administrative user roles.
+  $admin_role = user_role_load_by_name('administrator');
+  $roles = array($admin_role->rid => $admin_role->name);
+  // Define the permissions.
+  $permission_for_role = array(
+    'create ' . $bundle->label => TRUE,
+    'view ' . $bundle->label => TRUE,
+    'edit ' . $bundle->label => TRUE,
+    'delete ' . $bundle->label => TRUE,
+  );
+  // Assign the permissions
+  foreach($roles as $role => $value){
+    user_role_grant_permissions($role, $permission_for_role);
+    watchdog('debug', '<pre>tripal_entity_permissions  $role: '. print_r($role, TRUE) .'</pre>');
+  }
+
+  return TRUE;
+}
+ */
 /**
  * Retrieves a list of the content types.
  *

+ 34 - 1
tripal/includes/TripalBundleUIController.inc

@@ -942,6 +942,7 @@ function tripal_admin_add_type_form_submit($form, &$form_state) {
       }
       else {
         drupal_set_message('New data type created.');
+        tripal_admin_access($bundle);
         $form_state['redirect'] = "admin/structure/bio_data";
       }
 
@@ -953,4 +954,36 @@ function tripal_admin_add_type_form_submit($form, &$form_state) {
       drupal_set_message("The term '$accession' already exists as a content type.", 'warning');
     }
   }
-}
+}
+
+/**
+ * Checks access permissions for a given entity.
+ */
+function tripal_admin_access($entity) {
+  if ($entity) {
+    $bundle_name = $entity->name;
+  }
+  else {
+    return FALSE;
+  }
+
+  // Get the bundle object.
+  $bundle = tripal_load_bundle_entity(array('name' => $bundle_name));
+
+  // Identify the administrative user roles.
+  $admin_role = user_role_load_by_name('administrator');
+  $roles = array($admin_role->rid => $admin_role->name);
+  // Define the permissions.
+  $permission_for_role = array(
+    'create ' . $bundle->name => TRUE,
+    'view ' . $bundle->name => TRUE,
+    'edit ' . $bundle->name => TRUE,
+    'delete ' . $bundle->name => TRUE,
+  );
+
+  // Assign the permissions
+  foreach($roles as $role => $value){
+    user_role_change_permissions($role, $permission_for_role);
+  }
+  return TRUE;
+}

+ 12 - 1
tripal/theme/css/tripal.css

@@ -66,4 +66,15 @@ div.messages.tripal-site-admin-only{
   float: left;
 }
 .tripal-dl dd {
-}
+}
+
+
+ /******************************************************************************
+  * Spinner for paginated elements
+  *****************************************************************************/
+ #spinner {
+   position: absolute;
+   display: none;
+   left: 24%;
+   bottom: 7%;
+ }

+ 7 - 1
tripal/theme/js/tripal.js

@@ -24,7 +24,13 @@
 })(jQuery);
 
 function tripal_navigate_field_pager(id, page) {
-  jQuery.ajax({
+    jQuery(document).ajaxStart(function () {
+        jQuery('#spinner').show();
+    }).ajaxComplete(function () {
+        jQuery('#spinner').hide();
+    });
+
+    jQuery.ajax({
     type: "GET",
     url: Drupal.settings["basePath"] + "bio_data/ajax/field_attach/" + id,
     data: { 'page' : page },

+ 40 - 31
tripal_chado/api/tripal_chado.api.inc

@@ -154,6 +154,11 @@ function tripal_chado_publish_records($values, $job_id = NULL) {
   $result = chado_query($sql, $args);
   $count = $result->fetchField();
 
+  //If this is the publication table remove one record, record_id = 1
+  // which is the null publication.
+  if($table == 'pub'){
+    $count = $count - 1;
+  }
 
   // calculate the interval for updates
   $interval = intval($count / 1000);
@@ -174,42 +179,46 @@ function tripal_chado_publish_records($values, $job_id = NULL) {
   try {
     $i = 0;
     while($record = $records->fetchObject()) {
-
-      // update the job status every interval
-      //if ($jobid and $i % $interval == 0) {
+      if($table == 'pub' && $record->record_id == 1){
+        // Do not create the chado entity.
+      }
+      else {
+        // update the job status every interval
+        //if ($jobid and $i % $interval == 0) {
         $complete = ($i / $count) * 33.33333333;
         //tripal_set_job_progress($jobid, intval($complete + 33.33333333));
         printf("%d of %d records. (%0.2f%%) Memory: %s bytes\r", $i, $count, $complete * 3, number_format(memory_get_usage()));
-      //}
-
-      // First save the tripal_entity record.
-      $record_id = $record->record_id;
-      $ec = entity_get_controller('TripalEntity');
-      $entity = $ec->create(array(
-        'bundle' => $bundle_name,
-        'term_id' => $bundle->term_id,
-        'chado_record' => chado_generate_var($table, array($pkey_field => $record_id)),
-        'chado_record_id' => $record_id,
-      ));
-      $entity = $entity->save();
-      if (!$entity) {
-        throw new Exception('Could not create entity.');
-      }
+        //}
+
+        // First save the tripal_entity record.
+        $record_id = $record->record_id;
+        $ec = entity_get_controller('TripalEntity');
+        $entity = $ec->create(array(
+          'bundle' => $bundle_name,
+          'term_id' => $bundle->term_id,
+          'chado_record' => chado_generate_var($table, array($pkey_field => $record_id)),
+          'chado_record_id' => $record_id,
+        ));
+
+        $entity = $entity->save();
+        if (!$entity) {
+          throw new Exception('Could not create entity.');
+        }
 
-      // Next save the chado_entity record.
-      $entity_record = array(
-        'entity_id' => $entity->id,
-        'record_id' => $record_id,
-        'data_table' => $table,
-      );
-
-      // For the Tv2 to Tv3 migration we want to add the nid to the
-      // entity so we can associate the node with the entity.
-      if (property_exists($record, 'nid')) {
-        $entity_record['nid'] = $record->nid;
+        // Next save the chado_entity record.
+        $entity_record = array(
+          'entity_id' => $entity->id,
+          'record_id' => $record_id,
+          'data_table' => $table,
+        );
+
+        // For the Tv2 to Tv3 migration we want to add the nid to the
+        // entity so we can associate the node with the entity.
+        if (property_exists($record, 'nid')) {
+          $entity_record['nid'] = $record->nid;
+        }
+        $success = drupal_write_record('chado_entity', $entity_record);
       }
-      $success = drupal_write_record('chado_entity', $entity_record);
-
       $i++;
     }
   }

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

@@ -96,7 +96,7 @@ class sbo__relationship_formatter extends ChadoFieldFormatter {
 
     //$pager = $this->generate_pager(count($rows), $per_page);
 
-    $per_page = 2;
+    $per_page = 10;
     // Initialize the pager
     $current_page = pager_default_initialize(count($rows), $per_page);
     // Split your list into page sized chunks
@@ -135,8 +135,7 @@ class sbo__relationship_formatter extends ChadoFieldFormatter {
       $element[0] = array(
         '#type' => 'markup',
         '#markup' => theme_table($table),
-        '#prefix' => '<div id="ajax-target">',
-        '#suffix' => $pager . '</div>',
+        '#suffix' => '<img src=\'/sites/all/modules/tripal-7.x-3.x/tripal/theme/images/ajax-loader.gif\' id=\'spinner\'/>' . $pager,
       );
     }
   }