Browse Source

Custom Tables: Added default admin view for new UI

Lacey Sanderson 11 years ago
parent
commit
9babfaab7c

+ 57 - 24
tripal_core/includes/custom_tables.inc

@@ -9,12 +9,45 @@
  */
 
 /**
- * 
+ * Provides a landing page for tripal jobs admin
+ */
+function tripal_custom_table_admin_view() {
+  $output = '';
+
+  // set the breadcrumb
+  $breadcrumb = array();
+  $breadcrumb[] = l('Home', '<front>');
+  $breadcrumb[] = l('Administration', 'admin');
+  $breadcrumb[] = l('Tripal', 'admin/tripal');
+  $breadcrumb[] = l('Chado Schema', 'admin/tripal/schema');
+  $breadcrumb[] = l('Custom Tables', 'admin/tripal/schema/custom_tables');
+  drupal_set_breadcrumb($breadcrumb);
+
+  // Add the view
+  $view = views_embed_view('tripal_core_admin_custom_table','default');
+  if (isset($view)) {
+    $output .= $view;
+  }
+  else {
+    $output .= '<p>The Tripal Custom Table management system uses primarily views to provide an '
+      . 'administrative interface. Currently one or more views needed for this '
+      . 'administrative interface are disabled. <strong>Click each of the following links to '
+      . 'enable the pertinent views</strong>:</p>';
+    $output .= '<ul>';
+      $output .= '<li>'.l('Custom Tables View', 'admin/tripal/schema/custom_tables/views/tables/enable').'</li>';
+    $output .= '</ul>';
+  }
+
+  return $output;
+}
+
+/**
+ *
  */
 function tripal_custom_table_new_page() {
   $output = drupal_render(drupal_get_form('tripal_custom_tables_form'));
-  return $output;     
-  
+  return $output;
+
 }
 /**
  * A template function which returns markup to display details for the custom table
@@ -76,7 +109,7 @@ function tripal_custom_tables_list() {
   $custom_tables = db_query("SELECT * FROM {tripal_custom_tables} ORDER BY table_name");
 
   foreach ($custom_tables as $custom_table) {
- 
+
     $rows[] = array(
       l(t('View'), "admin/tripal/custom_tables/view/$custom_table->table_id") . " | " .
       l(t('Edit'), "admin/tripal/custom_tables/edit/$custom_table->table_id") . " | " .
@@ -93,16 +126,16 @@ function tripal_custom_tables_list() {
     )
   );
   $table = array(
-    'header' => $header, 
-    'rows' => $rows, 
-    'attributes' => array(), 
+    'header' => $header,
+    'rows' => $rows,
+    'attributes' => array(),
     'sticky' => FALSE,
     'caption' => '',
-    'colgroups' => array(), 
-    'empty' => 'No custom tables have been added', 
+    'colgroups' => array(),
+    'empty' => 'No custom tables have been added',
   );
 
-  $page = theme_table($table);  
+  $page = theme_table($table);
   return $page;
 }
 
@@ -161,11 +194,11 @@ function tripal_custom_tables_form($form, &$form_state = NULL, $table_id = NULL)
     '#type' => 'value',
     '#value' => $table_id
   );
-  
+
   $form['instructions']= array(
     '#type'          => 'item',
-    '#description'         => t('At times it is necessary to add a custom table to the Chado schema.  
-       These are not offically sanctioned tables but may be necessary for local data requirements.  
+    '#description'         => t('At times it is necessary to add a custom table to the Chado schema.
+       These are not offically sanctioned tables but may be necessary for local data requirements.
        Avoid creating custom tables when possible as other GMOD tools may not recognize these tables
        nor the data in them.  Linker tables or property tables are often a good candidate for
        a custom table. For example a table to link stocks and libraries (e.g. library_stock) would be
@@ -202,7 +235,7 @@ function tripal_custom_tables_form($form, &$form_state = NULL, $table_id = NULL)
     '#executes_submit_callback' => TRUE,
   );
   $form['#redirect'] = 'admin/tripal/custom_tables';
-  
+
   $form['example']= array(
     '#type'          => 'item',
     '#description'         => "<br>Example library_stock table: <pre>
@@ -216,7 +249,7 @@ array (
     'library_id' => array(
       'type' => 'int',
       'not null' => TRUE,
-    ),      
+    ),
     'stock_id' => array(
       'type' => 'int',
       'not null' => TRUE,
@@ -248,7 +281,7 @@ array (
 )
     </pre>",
   );
-  
+
 
   return $form;
 }
@@ -279,7 +312,7 @@ function tripal_custom_tables_form_validate($form, &$form_state) {
         t("The schema array should begin with the word 'array'."));
     }
     else {
-      $success = eval("\$schema_array = $schema;");    
+      $success = eval("\$schema_array = $schema;");
       if ($success === FALSE) {
         $error = error_get_last();
         form_set_error($form_state['values']['schema'],
@@ -299,10 +332,10 @@ function tripal_custom_tables_form_validate($form, &$form_state) {
           $exists = db_table_exists('chado.' . $schema_array['table']);
           if ($exists) {
             form_set_error($form_state['values']['schema'],
-              t("The table name already exists, please choose a different name."));  
+              t("The table name already exists, please choose a different name."));
           }
         }
-      }     
+      }
     }
   }
 }
@@ -320,7 +353,7 @@ function tripal_custom_tables_form_submit($form, &$form_state) {
   $table_id = $form_state['values']['table_id'];
   $schema = $form_state['values']['schema'];
   $force_drop = $form_state['values']['force_drop'];
-  
+
   $skip_creation = 1;
   if ($force_drop) {
      $skip_creation = 0;
@@ -329,9 +362,9 @@ function tripal_custom_tables_form_submit($form, &$form_state) {
   // conver the schema into a PHP array
   $schema_arr = array();
   eval("\$schema_arr = $schema;");
-  
 
-  if (strcmp($action, 'Edit') == 0) {    
+
+  if (strcmp($action, 'Edit') == 0) {
     tripal_core_edit_custom_table($table_id, $schema_arr['table'], $schema_arr, $skip_creation);
   }
   elseif (strcmp($action, 'Add') == 0) {
@@ -369,12 +402,12 @@ function tripal_custom_tables_action($op, $table_id, $redirect = FALSE) {
   $custom_table = $results->fetchObject();
 
   if ($op == 'delete') {
-  
+
     // remove the entry from the tripal_custom tables table
     $sql = "DELETE FROM {tripal_custom_tables} " .
            "WHERE table_id = $table_id";
     db_query($sql);
-    
+
     // drop the table from chado if it exists
     if (db_table_exists($custom_table->table_name)) {
       $success = chado_query("DROP TABLE %s", $custom_table->table_name);

+ 3 - 0
tripal_core/theme/tripal_core_customtables_help.tpl.php

@@ -0,0 +1,3 @@
+<p>The Tripal Jobs Management System provides a framework for Biological jobs to be run
+via the command-line in order to eliminate the problems associated with long running
+jobs in the web browser (ie: timeout errors).</p>

+ 27 - 3
tripal_core/tripal_core.module

@@ -292,10 +292,21 @@ function tripal_core_menu() {
   $items['admin/tripal/schema/custom_tables'] = array(
     'title' => 'Custom Tables',
     'description' => 'Creation of custom tables that are added to Chado database.',
+    'page callback' => 'tripal_custom_table_admin_view',
     'access arguments' => array('access administration pages'),
     'type' => MENU_NORMAL_ITEM,
     'weight' => -10
   );
+  $items['admin/tripal/schema/custom_tables/help'] = array(
+    'title' => 'Help',
+    'description' => 'Help for the tripal job management system',
+    'page callback' => 'theme',
+    'page arguments' => array('tripal_core_job_help'),
+    'access arguments' => array('access administration pages'),
+    'type' => MENU_LOCAL_TASK,
+    'weight' => 10
+  );
+  /**
   $items['admin/tripal/schema/custom_tables/list'] = array(
     'title' => 'List of Custom Tables',
     'description' => 'Provides a list of all custom tables created by Tripal and allows for editing or removing existing custom tables.',
@@ -304,27 +315,28 @@ function tripal_core_menu() {
     'type' => MENU_NORMAL_ITEM,
     'weight' => -10
   );
+  */
   $items['admin/tripal/schema/custom_tables/view/%'] = array(
     'title' => 'Custom Tables',
     'description' => 'Custom tables are added to Chado.',
     'page callback' => 'tripal_custom_table_view',
     'page arguments' => array(4),
     'access arguments' => array('access administration pages'),
-    'type' => MENU_NORMAL_ITEM,
+    'type' => MENU_CALLBACK,
   );
   $items['admin/tripal/schema/custom_tables/new'] = array(
     'title' => 'Create Custom Table',
     'description' => 'An interface for creating your own custom tables.',
     'page callback' => 'tripal_custom_table_new_page',
     'access arguments' => array('access administration pages'),
-    'type' => MENU_NORMAL_ITEM,
+    'type' => MENU_CALLBACK,
   );
   $items['admin/tripal/schema/custom_tables/edit/%'] = array(
     'title' => 'Edit Custom Table',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('tripal_custom_tables_form', 4),
     'access arguments' => array('access administration pages'),
-    'type' => MENU_NORMAL_ITEM,
+    'type' => MENU_CALLBACK,
   );
   $items['admin/tripal/schema/custom_tables/action/%/%'] = array(
     'title' => 'Create Custom Table',
@@ -334,6 +346,13 @@ function tripal_core_menu() {
     'access arguments' => array('access administration pages'),
     'type' => MENU_CALLBACK,
   );
+  $items['admin/tripal/schema/custom_tables/views/tables/enable'] = array(
+    'title' => 'Enable Custom Tables Administrative View',
+    'page callback' => 'tripal_views_admin_enable_view',
+    'page arguments' => array('tripal_core_admin_custom_table', 'admin/tripal/schema/custom_tables'),
+    'access arguments' => array('access administration pages'),
+    'type' => MENU_CALLBACK,
+  );
 
   return $items;
 }
@@ -378,6 +397,11 @@ function tripal_core_theme() {
       'variables' =>  array(NULL),
       'path' => drupal_get_path('module', 'tripal_core') . '/theme'
     ),
+    'tripal_core_customtables_help' => array(
+      'template' => 'tripal_core_customtables_help',
+      'variables' =>  array(NULL),
+      'path' => drupal_get_path('module', 'tripal_core') . '/theme'
+    ),
   );
 }
 

+ 62 - 0
tripal_core/tripal_core.views.inc

@@ -287,5 +287,67 @@ function tripal_core_views_data_jobs($data) {
  */
 function tripal_core_views_data_custom_tables($data) {
 
+  $data['tripal_custom_tables']['table']['group'] = t('Tripal Custom Tables');
+  $data['tripal_custom_tables']['table']['base'] = array(
+    'field' => 'table_id', // This is the identifier field for the view.
+    'title' => t('Tripal Custom Tables'),
+    'help' => t('Custom Tables in Chado created by this Tripal Installation.'),
+    'weight' => -10,
+  );
+
+  // Table ID
+  $data['tripal_custom_tables']['table_id'] = array(
+    'title' => t('Custom Table ID'),
+    'help' => t('Custom table primary key.'),
+    'field' => array(
+      'handler' => 'views_handler_field_numeric',
+      'click sortable' => TRUE,
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_numeric',
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ),
+  );
+
+  // Table Name
+  $data['tripal_custom_tables']['table_name'] = array(
+    'title' => t('Table Name'),
+    'help' => t('The name of the table in the database.'),
+    'field' => array(
+      'handler' => 'views_handler_field',
+      'click sortable' => TRUE, // This is use by the table display plugin.
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_string',
+    ),
+    'argument' => array(
+      'handler' => 'views_handler_argument_string',
+    ),
+  );
+
+  // Schema
+  $data['tripal_custom_tables']['schema'] = array(
+    'title' => t('Table Schema'),
+    'help' => t('The schema definition of the table.'),
+    'field' => array(
+      'handler' => 'views_handler_field',
+      'click sortable' => TRUE, // This is use by the table display plugin.
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_string',
+    ),
+    'argument' => array(
+      'handler' => 'views_handler_argument_string',
+    ),
+  );
+
   return $data;
 }

+ 120 - 0
tripal_core/tripal_core.views_default.inc

@@ -10,6 +10,9 @@ function tripal_core_views_default_views() {
   $view = tripal_core_admin_defaultview_jobs();
   $views[$view->name] = $view;
 
+  $view = tripal_core_admin_defaultview_custom_tables();
+  $views[$view->name] = $view;
+
   return $views;
 }
 
@@ -282,5 +285,122 @@ function tripal_core_admin_defaultview_jobs() {
   $handler->display->display_options['menu']['context_only_inline'] = 0;
   $handler->display->display_options['tab_options']['weight'] = '0';
 
+  return $view;
+}
+
+function tripal_core_admin_defaultview_custom_tables() {
+
+  $view = new view();
+  $view->name = 'tripal_core_admin_custom_table';
+  $view->description = 'DO NOT DISABLE';
+  $view->tag = 'tripal admin';
+  $view->base_table = 'tripal_custom_tables';
+  $view->human_name = 'Tripal Custom Table Admin';
+  $view->core = 7;
+  $view->api_version = '3.0';
+  $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
+
+  /* Display: Master */
+  $handler = $view->new_display('default', 'Master', 'default');
+  $handler->display->display_options['title'] = 'Custom Tables';
+  $handler->display->display_options['use_more_always'] = FALSE;
+  $handler->display->display_options['access']['type'] = 'none';
+  $handler->display->display_options['cache']['type'] = 'none';
+  $handler->display->display_options['query']['type'] = 'views_query';
+  $handler->display->display_options['exposed_form']['type'] = 'basic';
+  $handler->display->display_options['exposed_form']['options']['submit_button'] = 'Filter';
+  $handler->display->display_options['pager']['type'] = 'full';
+  $handler->display->display_options['pager']['options']['items_per_page'] = '25';
+  $handler->display->display_options['style_plugin'] = 'table';
+  /* Header: Global: Action Links */
+  $handler->display->display_options['header']['action_links_area']['id'] = 'action_links_area';
+  $handler->display->display_options['header']['action_links_area']['table'] = 'views';
+  $handler->display->display_options['header']['action_links_area']['field'] = 'action_links_area';
+  $handler->display->display_options['header']['action_links_area']['label'] = 'Action Links';
+  $handler->display->display_options['header']['action_links_area']['empty'] = TRUE;
+  $handler->display->display_options['header']['action_links_area']['link-1'] = array(
+    'label-1' => 'Add Custom Table',
+    'path-1' => 'admin/tripal/schema/custom_tables/new',
+  );
+  $handler->display->display_options['header']['action_links_area']['link-2'] = array(
+    'label-2' => '',
+    'path-2' => '',
+  );
+  $handler->display->display_options['header']['action_links_area']['link-3'] = array(
+    'label-3' => '',
+    'path-3' => '',
+  );
+  $handler->display->display_options['header']['action_links_area']['link-4'] = array(
+    'label-4' => '',
+    'path-4' => '',
+  );
+  /* Field: Tripal Custom Tables: Custom Table ID */
+  $handler->display->display_options['fields']['table_id']['id'] = 'table_id';
+  $handler->display->display_options['fields']['table_id']['table'] = 'tripal_custom_tables';
+  $handler->display->display_options['fields']['table_id']['field'] = 'table_id';
+  $handler->display->display_options['fields']['table_id']['label'] = '';
+  $handler->display->display_options['fields']['table_id']['element_class'] = 'extra-short-column';
+  $handler->display->display_options['fields']['table_id']['element_label_class'] = 'extra-short-column';
+  $handler->display->display_options['fields']['table_id']['element_label_colon'] = FALSE;
+  $handler->display->display_options['fields']['table_id']['separator'] = '';
+  /* Field: Tripal Custom Tables: Table Name */
+  $handler->display->display_options['fields']['table_name']['id'] = 'table_name';
+  $handler->display->display_options['fields']['table_name']['table'] = 'tripal_custom_tables';
+  $handler->display->display_options['fields']['table_name']['field'] = 'table_name';
+  $handler->display->display_options['fields']['table_name']['label'] = 'Name';
+  $handler->display->display_options['fields']['table_name']['alter']['make_link'] = TRUE;
+  $handler->display->display_options['fields']['table_name']['alter']['path'] = 'admin/tripal/schema/custom_tables/view/[table_id]';
+  /* Field: Global: Custom text */
+  $handler->display->display_options['fields']['nothing']['id'] = 'nothing';
+  $handler->display->display_options['fields']['nothing']['table'] = 'views';
+  $handler->display->display_options['fields']['nothing']['field'] = 'nothing';
+  $handler->display->display_options['fields']['nothing']['label'] = 'Edit Link';
+  $handler->display->display_options['fields']['nothing']['exclude'] = TRUE;
+  $handler->display->display_options['fields']['nothing']['alter']['text'] = 'Edit';
+  $handler->display->display_options['fields']['nothing']['alter']['make_link'] = TRUE;
+  $handler->display->display_options['fields']['nothing']['alter']['path'] = 'admin/tripal/schema/custom_tables/edit/[table_id]';
+  /* Field: Global: Custom text */
+  $handler->display->display_options['fields']['nothing_1']['id'] = 'nothing_1';
+  $handler->display->display_options['fields']['nothing_1']['table'] = 'views';
+  $handler->display->display_options['fields']['nothing_1']['field'] = 'nothing';
+  $handler->display->display_options['fields']['nothing_1']['label'] = 'Delete Link';
+  $handler->display->display_options['fields']['nothing_1']['exclude'] = TRUE;
+  $handler->display->display_options['fields']['nothing_1']['alter']['text'] = 'Delete';
+  $handler->display->display_options['fields']['nothing_1']['alter']['make_link'] = TRUE;
+  $handler->display->display_options['fields']['nothing_1']['alter']['path'] = 'admin/tripal/schema/custom_tables/action/delete/[table_id]';
+  /* Field: Global: Custom text */
+  $handler->display->display_options['fields']['nothing_2']['id'] = 'nothing_2';
+  $handler->display->display_options['fields']['nothing_2']['table'] = 'views';
+  $handler->display->display_options['fields']['nothing_2']['field'] = 'nothing';
+  $handler->display->display_options['fields']['nothing_2']['label'] = '';
+  $handler->display->display_options['fields']['nothing_2']['alter']['text'] = '[nothing]   [nothing_1]';
+  $handler->display->display_options['fields']['nothing_2']['element_label_colon'] = FALSE;
+  /* Filter criterion: Tripal Custom Tables: Table Name */
+  $handler->display->display_options['filters']['table_name']['id'] = 'table_name';
+  $handler->display->display_options['filters']['table_name']['table'] = 'tripal_custom_tables';
+  $handler->display->display_options['filters']['table_name']['field'] = 'table_name';
+  $handler->display->display_options['filters']['table_name']['exposed'] = TRUE;
+  $handler->display->display_options['filters']['table_name']['expose']['operator_id'] = 'table_name_op';
+  $handler->display->display_options['filters']['table_name']['expose']['label'] = 'Table Name';
+  $handler->display->display_options['filters']['table_name']['expose']['operator'] = 'table_name_op';
+  $handler->display->display_options['filters']['table_name']['expose']['identifier'] = 'table_name';
+  $handler->display->display_options['filters']['table_name']['expose']['remember_roles'] = array(
+    2 => '2',
+    1 => 0,
+    3 => 0,
+  );
+
+  /* Display: Page */
+  $handler = $view->new_display('page', 'Page', 'page');
+  $handler->display->display_options['path'] = 'admin/tripal/schema/custom_tables/tables';
+  $handler->display->display_options['menu']['type'] = 'default tab';
+  $handler->display->display_options['menu']['title'] = 'Custom Tables';
+  $handler->display->display_options['menu']['description'] = 'A list of existing custom tables';
+  $handler->display->display_options['menu']['weight'] = '-10';
+  $handler->display->display_options['menu']['name'] = 'management';
+  $handler->display->display_options['menu']['context'] = 0;
+  $handler->display->display_options['menu']['context_only_inline'] = 0;
+  $handler->display->display_options['tab_options']['weight'] = '0';
+
   return $view;
 }