Browse Source

Add page integration configuration.

Lacey Sanderson 5 years ago
parent
commit
663fb673c6

+ 88 - 0
tripal_jbrowse_page/includes/tripal_jbrowse_page.admin.inc

@@ -0,0 +1,88 @@
+<?php
+/**
+ * @file
+ * Administration (settings) for this module.
+ */
+
+/**
+ * Settings Form for page integration.
+ */
+function tripal_jbrowse_page_settings_form($form, $form_state) {
+
+  $form['general'] = [
+    '#type' => 'fieldset',
+    '#title' => 'General Page Integration Settings'
+  ];
+
+  $form['general']['create_menu_items'] = [
+    '#type' => 'checkbox',
+    '#title' => 'Create Menu Items',
+    '#description' => 'Checking this box ensures that menu items under
+      "Navigation" will be created for each JBrowse instance. This only
+      applies to JBrowse Instances with a page.',
+    '#default_value' => variable_get('trpjbrowse_page_create_menu_items', 1),
+  ];
+
+  $form['exclude_fieldset'] = [
+    '#type' => 'fieldset',
+    '#title' => 'Exclude JBrowse Instances from Page Integration',
+    '#description' => 'To exclude a JBrowse instance from page integration (i.e. no embedded page will be shown and it won\'t show up in the listing), check the checkbox below.',
+  ];
+
+  // Get all instances as an option to be excluded.
+  $instances = tripal_jbrowse_mgmt_get_instances();
+  $options = [];
+  foreach ($instances as $instance) {
+    $key = $instance->id;
+    $options[$key] = [
+      'genus' => $instance->organism->genus,
+      'species' => $instance->organism->species,
+    ];
+  }
+  // Determine the default value.
+  $default_exclude = variable_get('trpjbrowse_page_exclude', []);
+  if (!is_array($default_exclude)) {
+    $default_exclude = unserialize($default_exclude);
+  }
+  // Now generate the table.
+  $form['exclude_fieldset']['exclude'] = [
+    '#type' => 'tableselect',
+    '#header' => [
+      'genus' => t('Genus'),
+      'species' => t('Species'),
+    ],
+    '#options' => $options,
+    '#empty' => t('No JBrowse Instances available. Please add one through the "List Instances" page.'),
+    '#default_value' => $default_exclude,
+  ];
+
+  $form['submit'] = [
+    '#type' => 'submit',
+    '#value' => 'Save Settings',
+  ];
+
+  return $form;
+}
+
+/**
+ * Settings Form for page integration.
+ */
+function tripal_jbrowse_page_settings_form_submit($form, $form_state) {
+  $values = $form_state['values'];
+
+  // General Settings.
+  variable_set(
+    'trpjbrowse_page_create_menu_items',
+    $values['create_menu_items']
+  );
+
+  // Exclude Instances.
+  variable_set(
+    'trpjbrowse_page_exclude',
+    serialize($values['exclude'])
+  );
+
+  // Ensure the menu is rebuilt.
+  variable_set('menu_rebuild_needed', TRUE);
+
+}

+ 22 - 0
tripal_jbrowse_page/includes/tripal_jbrowse_page.api.inc

@@ -29,3 +29,25 @@ function tripal_jbrowse_page_get_instance_id($conditions, $options) {
   }
 
 }
+
+/**
+ * Retrieve the instance id based on the organism.
+ */
+function tripal_jbrowse_page_is_instance_public($instance_id) {
+  $excluded_instances = variable_get('trpjbrowse_page_exclude', []);
+  if (!is_array($excluded_instances)) {
+    $excluded_instances = unserialize($excluded_instances);
+  }
+
+  if (isset($excluded_instances[$instance_id])) {
+    if ($excluded_instances[$instance_id] === $instance_id) {
+      return FALSE;
+    }
+    else {
+      return TRUE;
+    }
+  }
+  else {
+    return FALSE;
+  }
+}

+ 6 - 1
tripal_jbrowse_page/includes/tripal_jbrowse_page.listing.inc

@@ -17,7 +17,12 @@ function tripal_jbrowse_page_listing_page() {
 
   // Add the URL for each to link to.
   foreach($instances as $k => $instance) {
-    $instances[$k]->url = url('jbrowse/'.$instance->organism->genus . '/' . $instance->organism->species, ['absolute' => TRUE]);
+    if (tripal_jbrowse_page_is_instance_public($instance->id)) {
+      $instances[$k]->url = url('jbrowse/'.$instance->organism->genus . '/' . $instance->organism->species, ['absolute' => TRUE]);
+    }
+    else {
+      unset($instances[$k]);
+    }
   }
 
   // Use the template to render the page.

+ 18 - 0
tripal_jbrowse_page/theme/jbrowse-instance--public-listing.tpl.php

@@ -10,5 +10,23 @@
       <span class="jbrowse-launch-link"><?php print l('Launch JBrowse', $instance->url); ?></span>
     </div>
 
+  <?php }
+    if (empty($instances)) {?>
+
+      <div class="empty-list">
+        <p>There are currently no available JBrowse instances.</p>
+      </div>
   <?php } ?>
 </div>
+
+
+<div class="jbrowse-admin-message">
+  <?php
+    print tripal_set_message(
+      'You can create or register a JBrowse Instance at '
+      .l('Administration Toolbar > Tripal > Extensions > Tripal JBrowse Management', 'admin/tripal/extension/tripal_jbrowse/management'),
+      TRIPAL_INFO,
+      ['return_html' => TRUE]
+    );
+  ?>
+</div>

+ 4 - 0
tripal_jbrowse_page/theme/tripal_jbrowse_page.css

@@ -12,6 +12,10 @@
 .jbrowse-list .jbrowse-instance .jbrowse-launch-link {
   float: right;
 }
+.jbrowse-list .empty-list {
+  margin-top: 20px;
+  font-style: italic;
+}
 
 /** Embedded Page **/
 #JBrowseInstance iframe {

+ 35 - 13
tripal_jbrowse_page/tripal_jbrowse_page.module

@@ -3,38 +3,60 @@
 // API.
 require_once 'includes/tripal_jbrowse_page.api.inc';
 
-// Include files.
-require_once 'includes/tripal_jbrowse_page.listing.inc';
-require_once 'includes/tripal_jbrowse_page.page.inc';
-
 /**
  * Implements hook_menu().
  */
 function tripal_jbrowse_page_menu() {
   $items = [];
 
+  // Listing Page.
   $items['jbrowse'] = [
     'title' => 'JBrowse',
     'description' => 'A listing of available JBrowse instances.',
     'page callback' => 'tripal_jbrowse_page_listing_page',
     'access arguments' => ['access content'],
+    'file' => 'includes/tripal_jbrowse_page.listing.inc',
     'type' => MENU_NORMAL_ITEM,
   ];
 
+  // Pages for each JBrowse Instance.
   $instances = tripal_jbrowse_mgmt_get_instances();
   foreach ($instances as $instance) {
 
-    $path = 'jbrowse/'.$instance->organism->genus . '/' . $instance->organism->species;
-    $items[$path] = [
-      'title' => $instance->title,
-      'description' => $instance->description,
-      'page callback' => 'tripal_jbrowse_page_page',
-      'page arguments' => [1, 2],
-      'access arguments' => ['access content'],
-      'type' => MENU_NORMAL_ITEM,
-    ];
+    if (tripal_jbrowse_page_is_instance_public($instance->id)) {
+
+      // The type of menu needs to be determined.
+      $create_links = variable_get('trpjbrowse_page_create_menu_items', 1);
+      $menu_type = MENU_CALLBACK;
+      if ($create_links) {
+        $menu_type = MENU_NORMAL_ITEM;
+      }
+      // Create the menu item.
+      $path = 'jbrowse/'.$instance->organism->genus . '/' . $instance->organism->species;
+      $items[$path] = [
+        'title' => $instance->title,
+        'description' => $instance->description,
+        'page callback' => 'tripal_jbrowse_page_page',
+        'page arguments' => [1, 2],
+        'access arguments' => ['access content'],
+        'file' => 'includes/tripal_jbrowse_page.page.inc',
+        'type' => $menu_type,
+      ];
+    }
   }
 
+  // Administration.
+  $admin_path = 'admin/tripal/extension/tripal_jbrowse/management';
+  $items[$admin_path.'/page-integration'] = [
+    'title' => 'Page Integration',
+    'description' => 'A listing of available JBrowse instances.',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => ['tripal_jbrowse_page_settings_form'],
+    'access arguments' => ['access content'],
+    'file' => 'includes/tripal_jbrowse_page.admin.inc',
+    'type' => MENU_LOCAL_TASK,
+  ];
+
   return $items;
 }