Browse Source

Switch cvitjs to use the libraries api.

Lacey Sanderson 6 years ago
parent
commit
408cacb63f
4 changed files with 32 additions and 34 deletions
  1. 4 8
      api/blast_ui.api.inc
  2. 20 4
      blast_ui.module
  3. 2 12
      includes/blast_ui.admin.inc
  4. 6 10
      theme/blast_ui.theme.inc

+ 4 - 8
api/blast_ui.api.inc

@@ -884,7 +884,7 @@ function printGFF_parent_children ($gff,$blast_feature_array){
 function blast_ui_get_cvit_conf_text($genome_target = FALSE) {
 
   // Retrieve the full path and filename of the conf.
-  $cvit_conf = blast_ui_get_cvit_conf(variable_get('blast_ui_cvitjs_location', false));
+  $cvit_conf = blast_ui_get_cvit_conf();
   if ($cvit_conf) {
 
     // Retrieve the contents of the file.
@@ -931,19 +931,15 @@ function blast_ui_get_cvit_conf_text($genome_target = FALSE) {
 /**
  * Get path to cvitjs conf file.
  *
- * ASSUMPTION: Assumes the code is contained within the blast ui module.
- *
  * @return
  *  The path to the CViTjs codebase.
  */
-function blast_ui_get_cvit_conf($cvitjs_location) {
+function blast_ui_get_cvit_conf($cvitjs_location = NULL) {
   if (!$cvitjs_location) {
-    return false;
+    $cvitjs_location = libraries_get_path('cvitjs') . DIRECTORY_SEPARATOR;
   }
 
-  $cvit_conf_path = drupal_get_path('module','blast_ui')
-                  . DIRECTORY_SEPARATOR . $cvitjs_location
-                  . DIRECTORY_SEPARATOR . 'cvit.conf';
+  $cvit_conf_path = $cvitjs_location . 'cvit.conf';
 
   return $cvit_conf_path;
 }

+ 20 - 4
blast_ui.module

@@ -168,14 +168,14 @@ function blast_ui_theme() {
     'variables' => array('hsps' => NULL),
     'path' => "$path/theme",
   );
-  
+
   // Lists the recent blast jobs for a given user/session.
   $items['blast_recent_jobs'] = array(
     'template' => 'blast_recent_jobs',
     'variables' => array('programs' => NULL),
     'path' => "$path/theme",
   );
-  
+
   // Module Help
   $items['blast_help'] = array(
     'template' => 'blast_help',
@@ -210,6 +210,22 @@ function blast_ui_help($path, $arg) {
   }
 }
 
+/**
+ * Implements hook_libraries_info().
+ */
+function blast_ui_libraries_info() {
+
+  // Tell the libraries API about CViTjs
+  $libraries['cvitjs'] = array(
+    'name' => 'CViTjs',
+    'vendor url' => 'https://github.com/awilkey/cvitjs',
+    'version' => '0.0.1',
+    'download url' => 'https://github.com/awilkey/cvitjs/archive/master.zip',
+  );
+
+  return $libraries;
+}
+
 /**
  * Facilitate presenting the result of the blast search
  *
@@ -259,11 +275,11 @@ function show_blast_output($job_string) {
  * Enable web services API
  *
  * @param $owner
- *   
+ *
  * @param $api
  *
  * @return $result
- *  
+ *
  */
 function blast_ui_ctools_plugin_api($owner, $api) {
   if ($owner == 'services' && $api == 'services') {

+ 2 - 12
includes/blast_ui.admin.inc

@@ -153,7 +153,6 @@ KRSLEEGLKTTGEGLDWGVLFGFGPGLTIETVVLRSVAI';
 
   // CVITJS
   $cvitjs_enabled = variable_get('blast_ui_cvitjs_enabled', FALSE);
-  $cvitjs_location = variable_get('blast_ui_cvitjs_location', '');
   $description = 'The JavaScript program CViTjs enables users to see BLAST hits on an '
                . 'entire genome assembly. See the help tab for information on how to '
                . 'download and set up CViTjs.';
@@ -166,7 +165,7 @@ KRSLEEGLKTTGEGLDWGVLFGFGPGLTIETVVLRSVAI';
     '#description' => $description,
   );
 
-  $absolute_cvitjs_data_path = DRUPAL_ROOT . '/' . drupal_get_path('module','blast_ui') . '/' . $cvitjs_location . '/data';
+  $absolute_cvitjs_data_path = DRUPAL_ROOT . '/sites/all/libraries/cvitjs/data';
   $description = '<div class ="messages warning">CViTjs is only applicable for genome BLAST targets. After it is '
                . 'enabled here, CViTjs will need to be enabled for each applicable BLAST '
               . 'target node.</div>'
@@ -186,14 +185,6 @@ KRSLEEGLKTTGEGLDWGVLFGFGPGLTIETVVLRSVAI';
     '#default_value' => $cvitjs_enabled,
   );
 
-  $form['cvitjs']['cvitjs_location'] = array(
-    '#type' => 'textfield',
-    '#title' => 'Path to CViTjs code',
-    '#description' => 'Path is relative to the location of this module. Example: js/cvitjs',
-    '#default_value' => $cvitjs_location,
-    '#disabled' => !$cvitjs_enabled,
-  );
-
   // Get CViTjs confuration text, if possible.
   if (!$default_value = blast_ui_get_cvit_conf_text()) {
     $default_value = 'Unable to get CViTjs configuration information. '
@@ -268,7 +259,7 @@ function blast_ui_admin_form_validate($form, &$form_state) {
 
   // Check path to CViTjs executable and make sure cvit.conf is writable
   if ($form_state['values']['cvitjs_enabled']) {
-    $cvit_path = blast_ui_get_cvit_conf($form_state['values']['cvitjs_location']);
+    $cvit_path = blast_ui_get_cvit_conf();
     if (!$cvit_path || !file_exists($cvit_path)) {
       $msg = "The CViTjs configuration file, cvit.conf, does not exist at the path given ("
            . $form_state['values']['cvitjs_location']
@@ -332,7 +323,6 @@ function blast_ui_admin_form_submit($form, $form_state) {
 
   // Whole genome visualization - CViTjs
   variable_set('blast_ui_cvitjs_enabled', $form_state['values']['cvitjs_enabled']);
-  variable_set('blast_ui_cvitjs_location', $form_state['values']['cvitjs_location']);
   if ($form_state['values']['cvitjs_enabled'] && $form_state['values']['cvitjs_config']) {
     // Need absolute path to conf file to write
     $cvit_conf_path = getcwd() . DIRECTORY_SEPARATOR

+ 6 - 10
theme/blast_ui.theme.inc

@@ -40,16 +40,12 @@ function blast_ui_preprocess_show_blast_report(&$vars) {
     $vars['show_cvit_diagram'] = TRUE;
 
     // Add the CSS/JS.
-    $cvitjs_location = variable_get('blast_ui_cvitjs_location', '');
-    $base = drupal_get_path('module','blast_ui')
-           . DIRECTORY_SEPARATOR . $cvitjs_location
-           . DIRECTORY_SEPARATOR . 'js'
-           . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR;
-    drupal_add_css($base.'bootstrap_embed/css/bootstrap.min.css',array('preprocess'=>FALSE));
-    drupal_add_css($base.'hopscotch/css/hopscotch.min.css',array('preprocess'=>FALSE));
-    drupal_add_css($base.'../../css/cvit.css',array('preprocess'=> FALSE));
-    drupal_add_js($base.'require/require.js',array('group'=>'JS_LIBRARY','type'=>'file'));
-    drupal_add_js($base.'require/blast_ui-config.js',array('group'=>'JS_THEME'));
+    $cvitjs_lib_path = libraries_get_path('cvitjs') . DIRECTORY_SEPARATOR;
+    drupal_add_css($cvitjs_lib_path . 'js/lib/bootstrap_embed/css/bootstrap.min.css',array('preprocess'=>FALSE));
+    drupal_add_css($cvitjs_lib_path . 'js/lib/hopscotch/css/hopscotch.min.css',array('preprocess'=>FALSE));
+    drupal_add_css($cvitjs_lib_path . 'css/cvit.css',array('preprocess'=> FALSE));
+    drupal_add_js($cvitjs_lib_path . 'js/lib/require/require.js',array('group'=>'JS_LIBRARY','type'=>'file'));
+    drupal_add_js($cvitjs_lib_path . 'js/lib/require/blast_ui-config.js',array('group'=>'JS_THEME'));
 
     // Add the JS settings.
     global $base_url;