Browse Source

updates requested by stephen to the notifications table

Shawna Spoor 8 years ago
parent
commit
371dce019d
3 changed files with 149 additions and 89 deletions
  1. 9 7
      tripal/api/tripal.entities.api.inc
  2. 35 80
      tripal/includes/tripal_admin_usage_page.inc
  3. 105 2
      tripal/tripal.module

+ 9 - 7
tripal/api/tripal.entities.api.inc

@@ -236,7 +236,7 @@ function tripal_add_notifcation($title, $details, $type, $actions, $submitter_id
       $record->actions = serialize($actions);
       $record->enabled = 1;
       $record->type = $type;
-      drupal_write_record('tripal_admin_notfications', $record);
+      $success = drupal_write_record('tripal_admin_notfications', $record);
     }
     catch (Exception $e) {
       $transaction->rollback();
@@ -488,6 +488,7 @@ function tripal_tripal_cron_notification() {
       $function = $module . '_bundle_create_fields';
       $info = $function('TripalEntity', $bundle);
       foreach ($info as $field_name => $details) {
+
         // If the field already exists then skip it.
         $field = field_info_field($details['field_name']);
         if ($field) {
@@ -495,9 +496,9 @@ function tripal_tripal_cron_notification() {
         }
 
         // Create notification that new fields exist.
-        $detail_info = ' Tripal has detected a field named ' . $details['field_name'] . ' is available for the ' . $bundle->label. ' content type.';
-        $title = 'New field available';
-        $actions['import'] = 'admin/import/field/' . $details['field_name'] . '/' . $bundle_name->name . '/' . $module;
+        $detail_info = ' Tripal has detected a new field ' . $details['field_name'] .' for ' . $bundle->label. ' content type is available for import.';
+        $title = 'New field available for import';
+        $actions['Import'] = 'admin/import/field/' . $details['field_name'] . '/' . $bundle_name->name . '/' . $module . '/field';
         $type = 'Field';
         $submitter_id = $details['field_name'] . '-' . $bundle_name->name . '-' . $module;
 
@@ -512,6 +513,7 @@ function tripal_tripal_cron_notification() {
       $function = $module . '_bundle_create_instances';
       $info = $function('TripalEntity', $bundle);
       foreach ($info as $field_name => $details) {
+
         // If the field is already attached to this bundle then skip it.
         $field = field_info_field($details['field_name']);
         if ($field and array_key_exists('bundles', $field) and
@@ -521,9 +523,9 @@ function tripal_tripal_cron_notification() {
         }
 
         // Create notification that new fields exist.
-        $detail_info = ' Tripal has detected a field named ' . $details['field_name'] . ' is available for the ' . $bundle->name. ' content type.';
-        $title = 'New field available';
-        $actions['import'] = 'admin/import/field/' . $details['field_name'] . '/' . $bundle->label . '/' . $module;
+        $detail_info = ' Tripal has detected a new field ' . $details['field_name'] .' for ' . $bundle->label. ' content type is available for import.';
+        $title = 'New field available for import';
+        $actions['Import'] = 'admin/import/field/' . $details['field_name'] . '/' . $bundle->name . '/' . $module . '/instance';
         $type = 'Field';
         $submitter_id = $details['field_name'] . '-' . $bundle_name->name . '-' . $module;
 

+ 35 - 80
tripal/includes/tripal_admin_usage_page.inc

@@ -14,67 +14,9 @@ function tripal_admin_usage_page() {
   tripal_add_d3js();
   //drupal_add_js(drupal_get_path ('module', 'tripal') . '/theme/js/tripal_galaxy.dashboard.js');
   drupal_add_css(drupal_get_path ('module', 'tripal') . '/theme/css/tripal.dashboard.css');
-
-  // Prepare table header
-  $header = array(
-    'title' => array('data' => t('Title')),
-    'details' => array('data' => t('Details')),
-    'type' => array('data' => t('Type'), 'field' => 'tan.type'),
-    'operations' => array('date' => t('Operations'))
-  );
-
-  $query = db_select('tripal_admin_notfications', 'tan')
-    ->extend('TableSort');
-
-  $results = $query->fields('tan')
-    ->condition('enabled', 1, '=')
-    ->orderByHeader($header)
-    ->execute()->fetchAll();
-  $rows = array();
-
-  foreach($results as $result){
-    $data['operation'] = ' | ';
-    $data['operation'] .= l(t('Dismiss Notification'), 'admin/disable/notification/' . $result->note_id);
-
-    $actions = unserialize($result->actions);
-    foreach($actions as $action){
-      $label = key($actions);
-      $link = $action;
-    }
-
-    $rows[] = array(
-      'Title' => $result->title,
-      'Details' => $result->details,
-      'Type' => $result->type,
-      'Operations' => l(t($label), $link) . $data['operation'],
-      );
-  }
-  if(!empty($rows)) {
-    //Number of records shown in per page
-    $per_page = 20;
-    $current_page = pager_default_initialize(count($rows), $per_page);
-    $chunks = array_chunk($rows, $per_page, TRUE);
-
-    // Output of table with the paging
-    $output = '<h2>Notifications</h2>';
-    $output .= theme('table',
-      array(
-        "header" => $header,
-        "rows" => $chunks[ $current_page ],
-        "attributes" => array(),
-        "sticky" => TRUE,
-        "caption" => "",
-        "colgroups" => array(),
-        "empty" => t("No notifications.")
-      )
-    );
-    //return pager with limited number of records.
-    return $output .= theme('pager', array('quantity', count($rows)));
-  }
-  else {
-    $output = 'There are no notifications at this time.';
-    return $output;
-  }
+  drupal_add_library('system', 'drupal.collapse');
+  $output = '<h2>Tripal Administrative Notifications and Info</h2>';
+  return $output;
 }
 
 /**
@@ -88,36 +30,49 @@ function tripal_admin_usage_page() {
  *   The ID of the bundle associated with that field.
  *
  */
-function tripal_admin_notification_import_field($field_name_note, $bundle_id, $module) {
+function tripal_admin_notification_import_field($field_name_note, $bundle_id, $module, $field_or_instance) {
   // Get the bundle object.
   $bundle = tripal_load_bundle_entity(array('name' => $bundle_id));
   if (!$bundle) {
     tripal_report_error('tripal', TRIPAL_ERROR, "Unrecognized bundle name '%bundle'.",
       array('%bundle' => $bundle_id));
+    drupal_goto("admin/tripal/dashboard");
     return FALSE;
   }
 
-  $function = $module . '_bundle_create_fields';
-  $info = $function('TripalEntity', $bundle);
-  foreach ($info as $field_name => $details) {
-    if($details['field_name'] == $field_name_note) {
-      // Create the field.
-      $field = field_create_field($details);
-      if (!$field) {
-        tripal_set_message(t("Could not create new field: %field.",
-          array('%field' =>  $field_name_note)), TRIPAL_ERROR);
+  if($field_or_instance == 'field'){
+    $function = $module . '_bundle_create_fields';
+    $info = $function('TripalEntity', $bundle);
+    foreach ($info as $field_name => $details) {
+      if($details['field_name'] == $field_name_note) {
+        // Create the field.
+        $instance = field_create_field($details);
+        drupal_set_message(t("Created field: %field", array('%field' => $info[ $field_name ]['label'])));
+
+        if (!$instance) {
+          tripal_set_message(t("Could not create new field: %field.",
+            array('%field' =>  $field_name_note)), TRIPAL_ERROR);
+        }
       }
     }
   }
-  $function = $module . '_bundle_create_instances';
-  $info = $function('TripalEntity', $bundle);
-  foreach ($info as $field_name => $details) {
-    if($details['field_name'] == $field_name_note) {
-      // Create the field instance.
-      $instance = field_create_instance($details);
-      drupal_set_message(t("Created field: %field", array('%field' => $info[ $field_name ]['label'])));
+  else if($field_or_instance == 'instance'){
+    $function = $module . '_bundle_create_instances';
+    $info = $function('TripalEntity', $bundle);
+    foreach ($info as $field_name => $details) {
+      if($details['field_name'] == $field_name_note) {
+        // Create the field instance.
+        $instance = field_create_instance($details);
+        drupal_set_message(t("Created field: %field", array('%field' => $info[ $field_name ]['label'])));
+
+        if (!$instance) {
+          tripal_set_message(t("Could not create new field: %field.",
+            array('%field' =>  $field_name_note)), TRIPAL_ERROR);
+        }
+      }
     }
   }
+
   $submitter_id = $field_name_note . '-' . $bundle_id . '-' . $module;
   if($instance){
     // Delete the notification table entry.
@@ -125,10 +80,10 @@ function tripal_admin_notification_import_field($field_name_note, $bundle_id, $m
       ->condition('submitter_id', $submitter_id, '=')
       ->execute();
   }
-  else{
+  else {
     drupal_set_message(t("There was a problem creating: %field", array('%field' => $info[ $field_name ]['label'])));
-
   }
+
   drupal_goto("admin/tripal/dashboard");
 }
 

+ 105 - 2
tripal/tripal.module

@@ -271,9 +271,9 @@ function tripal_menu() {
     'file path' => drupal_get_path('module', 'tripal'),
   );
 
-  $items['admin/import/field/%/%'] = array(
+  $items['admin/import/field/%/%/%/%'] = array(
     'page callback' => 'tripal_admin_notification_import_field',
-    'page arguments' => array(3, 4),
+    'page arguments' => array(3, 4, 5, 6),
     'access arguments' => array('access content'),
     'type' => MENU_CALLBACK,
     'file' => 'includes/tripal_admin_usage_page.inc',
@@ -636,3 +636,106 @@ function tripal_check_new_fields($bundle_name) {
   tripal_refresh_bundle_fields($bundle_name);
   drupal_goto("admin/structure/bio_data/manage/$bundle_name/fields");
 }
+
+
+/**
+ * Implements hook_block_info().
+ */
+function tripal_block_info() {
+  $blocks = array();
+
+  $blocks['notifications_block'] = array(
+    'info' => t('Dashboard Notifications'),
+    'visibility' => BLOCK_VISIBILITY_LISTED,
+    'pages' => 'admin/tripal/dashboard',
+    'status' => TRUE,
+    'region' => 'content',
+    'properties' => array(
+      'administrative' => TRUE,
+    ),
+  );
+  return $blocks;
+}
+
+/**
+ * Implements hook_block_view().
+ */
+function tripal_block_view($delta = ''){
+  // The $delta parameter tells us which block is being requested.
+  switch ($delta) {
+    case 'notifications_block':
+      // Create your block content here
+      $block['content'] = '';
+
+      // Prepare table header
+      $header = array(
+        'title' => array('data' => t('Title')),
+        'details' => array('data' => t('Details')),
+        'type' => array('data' => t('Type'), 'field' => 'tan.type'),
+        'actions' => array('data' => t('Actions'))
+      );
+
+      $query = db_select('tripal_admin_notfications', 'tan')
+        ->extend('TableSort');
+
+      $results = $query->fields('tan')
+        ->condition('enabled', 1, '=')
+        ->orderByHeader($header)
+        ->execute()->fetchAll();
+      $rows = array();
+
+      foreach($results as $result){
+        $data['operation'] = ' | ';
+        $data['operation'] .= l(t('Dismiss Notification'), 'admin/disable/notification/' . $result->note_id);
+
+        $actions = unserialize($result->actions);
+        foreach($actions as $action){
+          $label = key($actions);
+          $link = $action;
+        }
+
+        $rows[] = array(
+          'Title' => $result->title,
+          'Details' => $result->details,
+          'Type' => $result->type,
+          'Actions' => l(t($label), $link) . $data['operation'],
+        );
+      }
+      if(!empty($rows)) {
+        //Number of records shown in per page
+        $per_page = 10;
+        $current_page = pager_default_initialize(count($rows), $per_page);
+        $chunks = array_chunk($rows, $per_page, TRUE);
+
+        // Output of table with the paging
+        $table = theme('table',
+          array(
+            "header" => $header,
+            "rows" => $chunks[ $current_page ],
+            "attributes" => array(),
+            "sticky" => TRUE,
+            "caption" => "",
+            "colgroups" => array(),
+            "empty" => t("No notifications.")
+          )
+        );
+        $table .= theme('pager', array('quantity', count($rows)));
+
+        $fieldset_table = array(
+          '#title' => t('Notifications'),
+          '#collapsed' => FALSE,
+          '#collapsible' => TRUE,
+          '#attributes' => array('class' => array('collapsible')),
+          '#children' => $table,
+        );
+
+        //return pager with limited number of records.
+        $block['content'] = theme('fieldset', array('element' => $fieldset_table));
+      }
+      else {
+        $block['content'] = 'There are no notifications at this time.';
+      }
+      break;
+  }
+  return $block;
+}