Browse Source

move tripal dashboard to drupal dashabord and add content type barchart with vertical listing and add warning message on tripal_ds disable

Shawna 7 years ago
parent
commit
0667aceca2

+ 8 - 22
tripal/includes/tripal_admin_usage_page.inc → tripal/includes/tripal.admin_blocks.inc

@@ -1,32 +1,18 @@
 <?php
 
 /**
- * Create the admin page for the dashboard.
  *
- */
-function tripal_admin_usage_page() {
-  // set the breadcrumb
-  $breadcrumb = array();
-  $breadcrumb[] = l('Home', '<front>');
-  $breadcrumb[] = l('Administration', 'admin');
-  $breadcrumb[] = l('Tripal', 'admin/tripal');
-  drupal_set_breadcrumb($breadcrumb);
-  tripal_add_d3js();
-  drupal_add_css(drupal_get_path ('module', 'tripal') . '/theme/css/tripal.dashboard.css');
-  drupal_add_library('system', 'drupal.collapse');
-  $output = '<h2>Tripal Administrative Notifications and Info</h2>';
-  return $output;
-}
-
-/**
  * Import the field from the admin notification table on the dashboard.
  *
- * @param $field_name
+ * @param $field_or_instance
  *   The name of the field to be imported.
- *
  *  * @param $bundle_id
  *   The ID of the bundle associated with that field.
+ * @param $field_name_note
+ * @param $module
+ *
  *
+ * @return bool
  */
 function tripal_admin_notification_import_field($field_name_note, $bundle_id, $module, $field_or_instance) {
   // Get the bundle object.
@@ -34,7 +20,7 @@ function tripal_admin_notification_import_field($field_name_note, $bundle_id, $m
   if (!$bundle) {
     tripal_report_error('tripal', TRIPAL_ERROR, "Unrecognized bundle name '%bundle'.",
       array('%bundle' => $bundle_id));
-    drupal_goto("admin/tripal/dashboard");
+    drupal_goto("admin/dashboard");
     return FALSE;
   }
 
@@ -83,7 +69,7 @@ function tripal_admin_notification_import_field($field_name_note, $bundle_id, $m
     drupal_set_message(t("There was a problem creating: %field", array('%field' => $info[ $field_name ]['label'])));
   }
 
-  drupal_goto("admin/tripal/dashboard");
+  drupal_goto("admin/dashboard");
 }
 
 /**
@@ -106,5 +92,5 @@ function tripal_disable_admin_notification($note_id) {
   else {
     drupal_set_message("Could not dismiss notification.", 'error');
   }
-  drupal_goto("admin/tripal/dashboard");
+  drupal_goto("admin/dashboard");
 }

+ 25 - 0
tripal/theme/css/tripal.css

@@ -77,3 +77,28 @@ div.messages.tripal-site-admin-only{
    display: none;
    float: left;
  }
+
+
+ /******************************************************************************
+  * Format for tripal dashbaord chart
+  *****************************************************************************/
+ .bar text.value {
+   fill: white;
+ }
+
+ .axis {
+   shape-rendering: crispEdges;
+ }
+
+ .axis path {
+   fill: none;
+ }
+
+ .x.axis line {
+   stroke: #fff;
+   stroke-opacity: .8;
+ }
+
+ .y.axis path {
+   stroke: black;
+ }

+ 75 - 0
tripal/theme/js/tripal.dashboard.js

@@ -0,0 +1,75 @@
+Drupal.behaviors.tripalDashboard = {
+  attach: function (context, settings) {
+
+
+    /**
+     * Renders the graphs for the Admin Dashboard.
+     *
+     * id: the element id into which the charts will be drawn.
+     * fData: The data to be rendered in graphs.
+     */
+
+    function barchart2(id, data) {
+        // Set aside 10 colors
+        var c10 = d3.scale.category10();
+
+        var m = [30, 100, 10, 120],
+            w = 960 - m[1] - m[3],
+            h = 930 - m[0] - m[2];
+
+        var format = d3.format(",.0f");
+
+        var x = d3.scale.linear().range([0, w]),
+            y = d3.scale.ordinal().rangeRoundBands([0, h], .1);
+
+        var xAxis = d3.svg.axis().scale(x).orient("top").tickSize(-h),
+            yAxis = d3.svg.axis().scale(y).orient("left").tickSize(0);
+
+        var svg = d3.select(id).append("svg")
+            .attr("width", w + m[1] + m[3])
+            .attr("height", h + m[0] + m[2])
+            .append("g")
+            .attr("transform", "translate(" + m[3] + "," + m[0] + ")");
+
+
+
+            // Parse numbers, and sort by count.
+            data.forEach(function(d) { d.count = +d.count; });
+            data.sort(function(a, b) { return b.count - a.count; });
+
+            // Set the scale domain.
+            x.domain([0, d3.max(data, function(d) { return d.count; })]);
+            y.domain(data.map(function(d) { return d.name; }));
+
+            var bar = svg.selectAll("g.bar")
+                .data(data)
+                .enter().append("g")
+                .attr("class", "bar")
+                .attr("transform", function(d) { return "translate(0," + y(d.name) + ")"; });
+
+            bar.append("rect")
+                .attr("width", function(d) { return x(d.count); })
+                .attr("height", y.rangeBand())
+                .attr('fill', function(d, i) { return c10(i); });
+
+            bar.append("text")
+                .attr("class", "count")
+                .attr("x", function(d) { return x(d.count); })
+                .attr("y", y.rangeBand() / 2)
+                .attr("dx", 35)
+                .attr("dy", ".35em")
+                .attr("text-anchor", "end")
+                .text(function(d) { return format(d.count); });
+
+            svg.append("g")
+                .attr("class", "x axis")
+                .call(xAxis);
+
+            svg.append("g")
+                .attr("class", "y axis")
+                .call(yAxis);
+    }
+
+    barchart2('#tripal-entity-type-chart', entityCountListing);
+  }
+};

+ 54 - 16
tripal/tripal.module

@@ -110,17 +110,6 @@ function tripal_menu() {
     'access arguments' => array('administer tripal'),
   );
 
-  $items['admin/tripal/dashboard'] = array(
-    'title' => 'Dashboard',
-    'description' => t("A dashboard view of Tripal including new fields for entities."),
-    'weight' => 0,
-    'page callback' => 'tripal_admin_usage_page',
-    'access arguments' => array('administer tripal'),
-    'type' => MENU_NORMAL_ITEM,
-    'file' => 'includes/tripal_admin_usage_page.inc',
-    'file path' => drupal_get_path('module', 'tripal'),
-  );
-
   $items['admin/tripal/extension'] = array(
     'title' => 'Extensions',
     'description' => t("Configuration and management pages for Tripal extension modules."),
@@ -247,7 +236,7 @@ function tripal_menu() {
     'page arguments' => array(3),
     'access arguments' => array('access content'),
     'type' => MENU_CALLBACK,
-    'file' => 'includes/tripal_admin_usage_page.inc',
+    'file' => 'includes/tripal.admin_blocks.inc',
     'file path' => drupal_get_path('module', 'tripal'),
   );
 
@@ -256,7 +245,7 @@ function tripal_menu() {
     'page arguments' => array(3, 4, 5, 6),
     'access arguments' => array('access content'),
     'type' => MENU_CALLBACK,
-    'file' => 'includes/tripal_admin_usage_page.inc',
+    'file' => 'includes/tripal.admin_blocks.inc',
     'file path' => drupal_get_path('module', 'tripal'),
   );
 
@@ -668,18 +657,30 @@ function tripal_check_new_fields($bundle_name) {
  */
 function tripal_block_info() {
   $blocks = array();
+  $admin_theme = 'seven';
 
   $blocks['notifications_block'] = array(
     'info' => t('Dashboard Notifications'),
     'visibility' => BLOCK_VISIBILITY_LISTED,
-    'pages' => 'admin/tripal/dashboard',
+    'pages' => 'admin/dashboard',
     'status' => TRUE,
-    'region' => 'content',
+    'theme' => $admin_theme,
+    'region' => 'dashboard_main',
+    'properties' => array(
+      'administrative' => TRUE,
+    ),
+  );
+  $blocks['content_type_barchart'] = array(
+    'info' => t('Tripal Content Type Count'),
+    'visibility' => BLOCK_VISIBILITY_LISTED,
+    'pages' => 'admin/dashboard',
+    'status' => TRUE,
+    'theme' => $admin_theme,
+    'region' => 'dashboard_main',
     'properties' => array(
       'administrative' => TRUE,
     ),
   );
-
   $blocks['powered_by_tripal'] = array(
     'info' => t('Powered by Tripal'),
     'cache' => DRUPAL_NO_CACHE,
@@ -715,6 +716,42 @@ function tripal_block_view($delta = ''){
         '#markup' => '<a href="http://tripal.info"><img border="0" src="' . $base_path . drupal_get_path('module', 'tripal') . '/theme/images/' . $image . '"></a>',
       );
       break;
+    case 'content_type_barchart':
+      // The number of content types
+      $entity_types = db_select('tripal_bundle', 'tb')
+        ->fields('tb')
+        ->execute()
+        ->fetchAll();
+
+      $entity_count_listing = array();
+      // The number of entities per content type.
+      foreach($entity_types as $entity_types => $entity_type){
+        $result = db_select('chado_'.$entity_type->name, 'et')
+          ->fields('et')
+          ->execute();
+        $number_of_entities = $result->rowCount();
+        $entity_count_listing[$entity_types] = array(
+          'name' => $entity_type->label,
+          'count' => $number_of_entities,
+        );
+
+      }
+      tripal_add_d3js();
+      drupal_add_js(drupal_get_path ('module', 'tripal') . '/theme/js/tripal.dashboard.js');
+      drupal_add_css(drupal_get_path ('module', 'tripal') . '/theme/css/tripal.dashboard.css');
+      drupal_add_library('system', 'drupal.collapse');
+      drupal_add_js("var entityCountListing = " . json_encode($entity_count_listing) . ";", array('type' => 'inline'));
+
+      $output = "<div id=\"tripal-entity-types\" class=\"tripal-entity-types-pane\">
+            <p>A list of the Tripal Content Types and the number of each.</p>
+            <div id=\"tripal-entity-type-chart\"></div>
+          </div>";
+
+      $block['title'] = '';
+      $block['content'] = array(
+        '#markup' => $output,
+      );
+      break;
 
     case 'notifications_block':
       // Create your block content here
@@ -788,6 +825,7 @@ function tripal_block_view($delta = ''){
       else {
         $block['content'] = 'There are no notifications at this time.';
       }
+      $block['title'] = 'Tripal Administrative Notifications';
       break;
   }
   return $block;

+ 34 - 0
tripal_ds/tripal_ds.install

@@ -49,6 +49,40 @@ function tripal_ds_schema() {
   return $schema;
 }
 
+
+/**
+ * Implements hook_disable().
+ */
+function tripal_ds_disable(){
+  //Check if any tripal panes currently exist.
+  //Grab all the bundles to cycle through them.
+  $entities_with_tripal_panes = array();
+  $bundles = db_select('tripal_bundle', 'tb')
+    ->fields('tb')
+    ->execute()
+    ->fetchAll();
+  foreach($bundles as $bundles => $bundle){
+    $field_groups = field_group_info_groups('TripalEntity', $bundle->name);
+    foreach($field_groups['default'] as $field_names => $field_name){
+      if($field_name->format_type == 'tripalpane'){
+        array_push($entities_with_tripal_panes, $bundle->label);
+        continue 2;
+      }
+    }
+  }
+
+  $output = 'You have disabled the Tripal DS module but Tripal Panes were found in the following Content Types: ';
+  $output .= '<ul>';
+  foreach ($entities_with_tripal_panes as $item) {
+    $output .= '<li> ' . $item . '</li>';
+  }
+  $output .= '</ul>';
+  if(!empty($entities_with_tripal_panes)){
+    drupal_set_message($output, 'warning');
+
+  }
+}
+
 /**
  * Add a weight column to the tripal_ds table.
  */