Browse Source

Bulk Loader fix to default views so exposed filters work correctly

Lacey Sanderson 11 years ago
parent
commit
5cdd1a1a79

+ 33 - 92
tripal_bulk_loader/includes/tripal_bulk_loader.admin.inc

@@ -8,114 +8,55 @@
 function tripal_bulk_loader_admin_jobs_listing() {
   $output = '';
 
+  // set the breadcrumb
+  $breadcrumb = array();
+  $breadcrumb[] = l('Home', '<front>');
+  $breadcrumb[] = l('Administration', 'admin');
+  $breadcrumb[] = l('Tripal', 'admin/tripal');
+  $breadcrumb[] = l('Chado Data Loaders', 'admin/tripal/loaders');
+  $breadcrumb[] = l('Bulk Loader', 'admin/tripal/loaders/bulk');
+  drupal_set_breadcrumb($breadcrumb);
+
   // Add Tripal Admin View CSS
   $tripal_admin_view_css = drupal_get_path('module', 'tripal_views') . '/theme/tripal_views_admin_views.css';
   drupal_add_css($tripal_admin_view_css);
 
   // Add the view
-  $view = views_get_view('tripal_bulk_loading_jobs');
-  if (isset($view)) {
-    $view->set_display('default');
-    $output .= '<h2>' . $view->get_title() . '</h2>';
-    $output .= $view->preview('page');
+  $jobs_view = views_embed_view('tripal_bulk_loading_jobs','default');
+  $template_view = views_embed_view('tripal_bulk_loader_templates','default');
+  if (isset($jobs_view) && isset($template_view)) {
+    $output .= $jobs_view;
   }
   else {
-    $output .= '<p>The "Tripal Bulk Loading Jobs" View should be displayed here. If you '
-      . 'have disabled, please re-enable it in order to administrate this module.</p>';
+    $output .= '<p>The Tripal Bulk Loader 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>';
+    if (!isset($jobs_view)) {
+      $output .= '<li>'.l('Tripal Bulk Loading Jobs', 'admin/tripal/loaders/bulk/views/jobs/enable').'</li>';
+    }
+    if (!isset($template_view)) {
+      $output .= '<li>'.l('Tripal Bulk Loader Templates', 'admin/tripal/loaders/bulk/views/templates/enable').'</li>';
+    }
+    $output .= '</ul>';
   }
 
   return $output;
 }
 
-function tripal_bulk_loader_admin_template_listing() {
-  $output = '';
+function tripal_bulk_loader_admin_enable_view($view_name) {
 
-  // Add Tripal Admin View CSS
-  $tripal_admin_view_css = drupal_get_path('module', 'tripal_views') . '/theme/tripal_views_admin_views.css';
-  drupal_add_css($tripal_admin_view_css);
-
-  $view = views_get_view('tripal_bulk_loader_templates');
-  if (isset($view)) {
-    $view->set_display('default');
-    $output .= '<h2>' . $view->get_title() . '</h2>';
-    $output .= $view->preview('page');
+  $status = variable_get('views_defaults', array());
+  if (isset($status[$view_name])) {
+    $status[$view_name] = FALSE;
+    variable_set('views_defaults', $status);
+    drupal_set_message("Successfully Enabled $view_name");
   }
   else {
-    $output .= '<p>The "Tripal Bulk Loader Templates" View should be displayed here. If you '
-      . 'have disabled, please re-enable it in order to administrate this module.</p>';
-  }
-
-  return $output;
-}
-
-/**
- * Provides a description page and quick links for template management
- *
- * @ingroup tripal_bulk_loader
- */
-function tripal_bulk_loader_admin_manage_templates() {
-  $output = '';
-  $output .= '<p>' . t('Templates, as the term is used for this module, refer to plans
-  describing how the columns in the data file supplied to a bulk loading job map to tables
-  and fields in chado. Templates are created independently of bulk loading jobs so that
-  they can be re-used. Thus you only need one template to load any number of files of the
-  same format.') . '</p>';
-
-  return $output;
-}
-
-/**
- * Provides a listing of bulk loader jobs and links for administration
- *
- * @ingroup tripal_bulk_loader
- */
-function tripal_bulk_loader_admin_jobs() {
-  $output = '';
-  $num_jobs_per_page = 50;
-
-  $output .= '<p>' . t('Jobs are not automatically submitted to the tripal jobs management
-  system when they are first created. Any jobs listed below with a status of "Initialized"
-  will not have a Job ID until you go to the bulk loader page and submit the job.') . '</p>';
-
-  $header = array(
-    array('data' => 'Job ID', 'field' => 'job_id', 'sort' => 'DESC'),
-    array('data' => 'Name', 'field' => 'loader_name'),
-    array('data' =>  'Template', 'field' => 'template_name'),
-    array('data' =>  'Status', 'field' => 'job_status'),
-    array('data' => 'Progress', 'field' => 'progress'),
-    '');
-  $rows = array();
-  $query = db_select('tripal_bulk_loader', 'n')->extend('TableSort');
-  $query->join('tripal_bulk_loader_template', 't', 'cast(n.template_id as integer) = t.template_id');
-  $query->join('tripal_jobs', 'j', 'n.job_id = j.job_id');
-  $query->fields('n')
-    ->fields('t', array('name'))
-    ->fields('j', array('progress'))
-    ->orderByHeader($header);
-  $result = $query->execute();
-  /**
-  $resource = pager_query("SELECT n.*, t.name as template_name, j.progress
-    FROM {tripal_bulk_loader} n
-    LEFT JOIN {tripal_bulk_loader_template} t ON cast(n.template_id as integer) = t.template_id
-    LEFT JOIN {tripal_jobs} j ON n.job_id = j.job_id"
-    . tablesort_sql($header),
-    $num_jobs_per_page);
-    */
-  foreach ($result as $n) {
-    $rows[] = array(
-      l($n->job_id, 'admin/tripal/tripal_jobs/view/' . $n->job_id),
-      l($n->loader_name, 'node/' . $n->nid),
-      l($n->template_name, 'admin/tripal/loaders/bulk/template/'.$n->template_id.'/edit'),
-      $n->job_status,
-      ($n->progress) ? $n->progress . '%' : '',
-      l('View', 'node/' . $n->nid) . ' | ' .  l('Edit', 'node/' . $n->nid . '/edit')
-    );
+    drupal_set_message("Unable to find a view by the name of '$view_name'",'error');
   }
-  $output .= theme_table(array('header' => $header, 'rows' => $rows));
-
-  $output .= theme('pager');
-
-  return $output;
+  drupal_goto('admin/tripal/loaders/bulk');
 }
 
 /**

+ 96 - 1
tripal_bulk_loader/includes/tripal_bulk_loader.admin.templates.inc

@@ -19,6 +19,16 @@
  */
 function tripal_bulk_loader_modify_template_base_form($form, $form_state = NULL, $mode) {
 
+  // set the breadcrumb
+  $breadcrumb = array();
+  $breadcrumb[] = l('Home', '<front>');
+  $breadcrumb[] = l('Administration', 'admin');
+  $breadcrumb[] = l('Tripal', 'admin/tripal');
+  $breadcrumb[] = l('Chado Data Loaders', 'admin/tripal/loaders');
+  $breadcrumb[] = l('Bulk Loader', 'admin/tripal/loaders/bulk');
+  $breadcrumb[] = l('Templates', 'admin/tripal/loaders/bulk/templates');
+  drupal_set_breadcrumb($breadcrumb);
+
    // get template id from path and rebuild form
   if (isset($form_state['build_info']['args'][1])) {
     $mode = 'edit';
@@ -533,6 +543,16 @@ function tripal_bulk_loader_modify_template_base_form_submit($form, &$form_state
 function tripal_bulk_loader_delete_template_base_form($form, $form_state) {
   $form = array();
 
+  // set the breadcrumb
+  $breadcrumb = array();
+  $breadcrumb[] = l('Home', '<front>');
+  $breadcrumb[] = l('Administration', 'admin');
+  $breadcrumb[] = l('Tripal', 'admin/tripal');
+  $breadcrumb[] = l('Chado Data Loaders', 'admin/tripal/loaders');
+  $breadcrumb[] = l('Bulk Loader', 'admin/tripal/loaders/bulk');
+  $breadcrumb[] = l('Templates', 'admin/tripal/loaders/bulk/templates');
+  drupal_set_breadcrumb($breadcrumb);
+
   $template_id = $form_state['build_info']['args'][0];
   $form_state['storage']['template_id'] = $template_id;
 
@@ -624,6 +644,16 @@ function tripal_bulk_loader_delete_template_base_form_submit($form, &$form_state
 function tripal_bulk_loader_import_template_form($form, $form_state) {
   $form = array();
 
+  // set the breadcrumb
+  $breadcrumb = array();
+  $breadcrumb[] = l('Home', '<front>');
+  $breadcrumb[] = l('Administration', 'admin');
+  $breadcrumb[] = l('Tripal', 'admin/tripal');
+  $breadcrumb[] = l('Chado Data Loaders', 'admin/tripal/loaders');
+  $breadcrumb[] = l('Bulk Loader', 'admin/tripal/loaders/bulk');
+  $breadcrumb[] = l('Templates', 'admin/tripal/loaders/bulk/templates');
+  drupal_set_breadcrumb($breadcrumb);
+
   $form['new_template_name'] = array(
     '#type' => 'textfield',
     '#title' => 'Template Name',
@@ -694,6 +724,16 @@ function tripal_bulk_loader_import_template_form_submit($form, &$form_state) {
  */
 function tripal_bulk_loader_export_template_form($form, $form_state) {
 
+  // set the breadcrumb
+  $breadcrumb = array();
+  $breadcrumb[] = l('Home', '<front>');
+  $breadcrumb[] = l('Administration', 'admin');
+  $breadcrumb[] = l('Tripal', 'admin/tripal');
+  $breadcrumb[] = l('Chado Data Loaders', 'admin/tripal/loaders');
+  $breadcrumb[] = l('Bulk Loader', 'admin/tripal/loaders/bulk');
+  $breadcrumb[] = l('Templates', 'admin/tripal/loaders/bulk/templates');
+  drupal_set_breadcrumb($breadcrumb);
+
   $template_id = $form_state['build_info']['args'][0];
   $form_state['storage']['template_id'] = $template_id;
   if ($template_id > 0) {
@@ -763,6 +803,17 @@ function tripal_bulk_loader_edit_template_record_form($form, $form_state) {
     return $form;
   }
 
+  // set the breadcrumb
+  $breadcrumb = array();
+  $breadcrumb[] = l('Home', '<front>');
+  $breadcrumb[] = l('Administration', 'admin');
+  $breadcrumb[] = l('Tripal', 'admin/tripal');
+  $breadcrumb[] = l('Chado Data Loaders', 'admin/tripal/loaders');
+  $breadcrumb[] = l('Bulk Loader', 'admin/tripal/loaders/bulk');
+  $breadcrumb[] = l('Templates', 'admin/tripal/loaders/bulk/templates');
+  $breadcrumb[] = l('Edit Template', 'admin/tripal/loaders/bulk/template/' . $template_id . '/edit');
+  drupal_set_breadcrumb($breadcrumb);
+
   // Pre-process values/defaults ---------------------------
 
   // If this is the first load of the form (no form state) we need to initialize some variables
@@ -1115,6 +1166,17 @@ function tripal_bulk_loader_delete_template_record_form($form, $form_state) {
     return $form;
   }
 
+  // set the breadcrumb
+  $breadcrumb = array();
+  $breadcrumb[] = l('Home', '<front>');
+  $breadcrumb[] = l('Administration', 'admin');
+  $breadcrumb[] = l('Tripal', 'admin/tripal');
+  $breadcrumb[] = l('Chado Data Loaders', 'admin/tripal/loaders');
+  $breadcrumb[] = l('Bulk Loader', 'admin/tripal/loaders/bulk');
+  $breadcrumb[] = l('Templates', 'admin/tripal/loaders/bulk/templates');
+  $breadcrumb[] = l('Edit Template', 'admin/tripal/loaders/bulk/template/' . $template_id . '/edit');
+  drupal_set_breadcrumb($breadcrumb);
+
   $_GET['record_name'] = (isset($_GET['record_name'])) ?  $_GET['record_name'] : '';
   $_GET['chado_table'] = (isset($_GET['chado_table'])) ?  $_GET['chado_table'] : '';
   $_GET['record_mode'] = (isset($_GET['record_mode'])) ?  $_GET['record_mode'] : '';
@@ -1221,7 +1283,18 @@ function tripal_bulk_loader_duplicate_template_record_form($form, &$form_state)
     return $form;
   }
 
-    $_GET['record_name'] = (isset($_GET['record_name'])) ?  $_GET['record_name'] : '';
+  // set the breadcrumb
+  $breadcrumb = array();
+  $breadcrumb[] = l('Home', '<front>');
+  $breadcrumb[] = l('Administration', 'admin');
+  $breadcrumb[] = l('Tripal', 'admin/tripal');
+  $breadcrumb[] = l('Chado Data Loaders', 'admin/tripal/loaders');
+  $breadcrumb[] = l('Bulk Loader', 'admin/tripal/loaders/bulk');
+  $breadcrumb[] = l('Templates', 'admin/tripal/loaders/bulk/templates');
+  $breadcrumb[] = l('Edit Template', 'admin/tripal/loaders/bulk/template/' . $template_id . '/edit');
+  drupal_set_breadcrumb($breadcrumb);
+
+  $_GET['record_name'] = (isset($_GET['record_name'])) ?  $_GET['record_name'] : '';
   $_GET['chado_table'] = (isset($_GET['chado_table'])) ?  $_GET['chado_table'] : '';
   $_GET['record_mode'] = (isset($_GET['record_mode'])) ?  $_GET['record_mode'] : '';
 
@@ -1647,6 +1720,17 @@ function tripal_bulk_loader_template_field_form($form, $form_state = NULL) {
 
   $values = tripal_bulk_loader_template_field_form_default_values($mode, $form_state);
 
+  // set the breadcrumb
+  $breadcrumb = array();
+  $breadcrumb[] = l('Home', '<front>');
+  $breadcrumb[] = l('Administration', 'admin');
+  $breadcrumb[] = l('Tripal', 'admin/tripal');
+  $breadcrumb[] = l('Chado Data Loaders', 'admin/tripal/loaders');
+  $breadcrumb[] = l('Bulk Loader', 'admin/tripal/loaders/bulk');
+  $breadcrumb[] = l('Templates', 'admin/tripal/loaders/bulk/templates');
+  $breadcrumb[] = l('Edit Template', 'admin/tripal/loaders/bulk/template/' . $values['template_id'] . '/edit');
+  drupal_set_breadcrumb($breadcrumb);
+
   $form['template_name'] = array(
     '#type' => 'item',
     '#title' => 'Template',
@@ -2202,6 +2286,17 @@ function tripal_bulk_loader_delete_template_field_form($form, $form_state) {
     return $form;
   }
 
+  // set the breadcrumb
+  $breadcrumb = array();
+  $breadcrumb[] = l('Home', '<front>');
+  $breadcrumb[] = l('Administration', 'admin');
+  $breadcrumb[] = l('Tripal', 'admin/tripal');
+  $breadcrumb[] = l('Chado Data Loaders', 'admin/tripal/loaders');
+  $breadcrumb[] = l('Bulk Loader', 'admin/tripal/loaders/bulk');
+  $breadcrumb[] = l('Templates', 'admin/tripal/loaders/bulk/templates');
+  $breadcrumb[] = l('Edit Template', 'admin/tripal/loaders/bulk/template/' . $template_id . '/edit');
+  drupal_set_breadcrumb($breadcrumb);
+
   $_GET['record_name'] = (isset($_GET['record_name'])) ?  $_GET['record_name'] : '';
   $_GET['field_name'] = (isset($_GET['field_name'])) ?  $_GET['field_name'] : '';
   $_GET['chado_table'] = (isset($_GET['chado_table'])) ?  $_GET['chado_table'] : '';

+ 18 - 16
tripal_bulk_loader/tripal_bulk_loader.module

@@ -62,22 +62,6 @@ function tripal_bulk_loader_menu() {
     'access arguments' => array('administer tripal_bulk_loader'),
     'type' => MENU_NORMAL_ITEM,
   );
-  $items['admin/tripal/loaders/bulk/jobs'] = array(
-    'title' => 'Jobs',
-    'description' => 'Listing of Bulk Loading Jobs',
-    'page callback' => 'tripal_bulk_loader_admin_jobs_listing',
-    'access arguments' => array('administer tripal_bulk_loader'),
-    'weight' => 4,
-    'type' => MENU_DEFAULT_LOCAL_TASK,
-  );
-  $items['admin/tripal/loaders/bulk/templates'] = array(
-    'title' => 'Templates',
-    'description' => 'Listing of Bulk Loading Templates',
-    'page callback' => 'tripal_bulk_loader_admin_template_listing',
-    'access arguments' => array('administer tripal_bulk_loader'),
-    'weight' => 6,
-    'type' => MENU_LOCAL_TASK,
-  );
   $items['admin/tripal/loaders/bulk/configure'] = array(
     'title' => 'Configure',
     'description' => 'Configuration of global options related to bulk loading jobs',
@@ -96,6 +80,24 @@ function tripal_bulk_loader_menu() {
     'type' => MENU_LOCAL_TASK,
   );
 
+  // Enable View Callbacks
+  $items['admin/tripal/loaders/bulk/views/jobs/enable'] = array(
+    'title' => 'Enable Jobs Administrative View',
+    'description' => 'Enable Jobs Administrative View',
+    'page callback' => 'tripal_bulk_loader_admin_enable_view',
+    'page arguments' => array('tripal_bulk_loading_jobs'),
+    'access arguments' => array('administer tripal_bulk_loader'),
+    'type' => MENU_CALLBACK,
+  );
+  $items['admin/tripal/loaders/bulk/views/templates/enable'] = array(
+    'title' => 'Enable Templates Administrative View',
+    'description' => 'Enable Templates Administrative View',
+    'page callback' => 'tripal_bulk_loader_admin_enable_view',
+    'page arguments' => array('tripal_bulk_loader_templates'),
+    'access arguments' => array('administer tripal_bulk_loader'),
+    'type' => MENU_CALLBACK,
+  );
+
   // Create/Edit Template --------
   $items['admin/tripal/loaders/bulk/template/create'] = array(
     'title' => 'Create Template',

+ 20 - 1
tripal_bulk_loader/tripal_bulk_loader.views_default.inc

@@ -241,6 +241,16 @@ function tripal_bulk_loader_defaultview_admin_job_listing() {
     3 => 0,
   );
 
+  /* Display: Page */
+  $handler = $view->new_display('page', 'Page', 'page_1');
+  $handler->display->display_options['path'] = 'admin/tripal/loaders/bulk/jobs';
+  $handler->display->display_options['menu']['type'] = 'default tab';
+  $handler->display->display_options['menu']['title'] = 'Jobs';
+  $handler->display->display_options['menu']['weight'] = '0';
+  $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;
 }
 
@@ -341,7 +351,7 @@ function tripal_bulk_loader_defaultview_admin_template_listing() {
   $handler->display->display_options['fields']['nothing_3']['exclude'] = TRUE;
   $handler->display->display_options['fields']['nothing_3']['alter']['text'] = 'View Jobs';
   $handler->display->display_options['fields']['nothing_3']['alter']['make_link'] = TRUE;
-  $handler->display->display_options['fields']['nothing_3']['alter']['path'] = 'admin/tripal/loaders/bulk/jobs';
+  $handler->display->display_options['fields']['nothing_3']['alter']['path'] = 'admin/tripal/loaders/bulk/jobs?name=[name]';
   /* Field: Global: Custom text */
   $handler->display->display_options['fields']['nothing_4']['id'] = 'nothing_4';
   $handler->display->display_options['fields']['nothing_4']['table'] = 'views';
@@ -383,6 +393,15 @@ function tripal_bulk_loader_defaultview_admin_template_listing() {
     3 => 0,
   );
 
+  /* Display: Page */
+  $handler = $view->new_display('page', 'Page', 'page_1');
+  $handler->display->display_options['path'] = 'admin/tripal/loaders/bulk/templates';
+  $handler->display->display_options['menu']['type'] = 'tab';
+  $handler->display->display_options['menu']['title'] = 'Templates';
+  $handler->display->display_options['menu']['weight'] = '0';
+  $handler->display->display_options['menu']['name'] = 'management';
+  $handler->display->display_options['menu']['context'] = 0;
+  $handler->display->display_options['menu']['context_only_inline'] = 0;
 
   return $view;
 }