Explorar el Código

Moved drupal_add_js/css() into preprocess hook.

Lacey Sanderson hace 7 años
padre
commit
54a7353b5e
Se han modificado 2 ficheros con 40 adiciones y 33 borrados
  1. 7 31
      theme/blast_report.tpl.php
  2. 33 2
      theme/blast_ui.theme.inc

+ 7 - 31
theme/blast_report.tpl.php

@@ -72,13 +72,13 @@ $no_hits = TRUE;
         <a href="<?php print '../../' . $blast_job->files->result->gff; ?>">GFF3</a>
       </div>
       <br />
-      <div class="blast-query-info"><strong>Query Information</strong>: 
+      <div class="blast-query-info"><strong>Query Information</strong>:
         <?php print $blast_job->files->query;?></div>
-      <div class="blast-target-info"><strong>Search Target</strong>: 
+      <div class="blast-target-info"><strong>Search Target</strong>:
         <?php print $blast_job->blastdb->db_name;?></div>
-      <div class="blast-date-info"><strong>Submission Date</strong>: 
+      <div class="blast-date-info"><strong>Submission Date</strong>:
         <?php print format_date($blast_job->date_submitted, 'medium');?></div>
-      <div class="blast-cmd-info"><strong>BLAST Command executed</strong>: 
+      <div class="blast-cmd-info"><strong>BLAST Command executed</strong>:
         <?php print $blast_job->blast_cmd;?></div>
       <br />
       <div class="num-results">
@@ -87,38 +87,14 @@ $no_hits = TRUE;
     </div>
 
     <?php
-      if (variable_get('blast_ui_cvitjs_enabled', false)
-            && isset($blast_job->blastdb->cvitjs_enabled)
-            && $blast_job->blastdb->cvitjs_enabled == '1') {
-        $cvitjs_location = variable_get('blast_ui_cvitjs_location', '');
+      if ($show_cvit_diagram) {
     ?>
       <!-- CViTjs image of BLAST hits, if enabled -->
       <div class="cvitjs">
         <div id="title-div"></div>
         <div id="cvit-div"></div>
       </div>
-      <?php
-        drupal_add_js(array(
-          'blast_ui'=> array(
-            'dataset' => $blast_job->blastdb->db_name)
-          ),
-          'setting'
-        );
-        drupal_add_js(array(
-          'blast_ui'=> array(
-            'gff' => '../../' . $blast_job->files->result->gff)),'setting'
-        );    
-        $base = drupal_get_path('module','blast_ui') 
-                . DIRECTORY_SEPARATOR . $cvitjs_location
-                . DIRECTORY_SEPARATOR . 'js'
-                . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR;
-        drupal_add_css($base.'bootstrap/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'));
-      ?>
-    <?php  
+    <?php
       }
     ?>
 
@@ -243,7 +219,7 @@ $no_hits = TRUE;
                               ';';
                 $Hsp_bit_score .=   $hsp_xml->{'Hsp_bit-score'} .';';
               }
-              
+
               // Finally record the range.
               // @todo figure out why we arbitrarily subtract 50,000 here...
               // @more removing the 50,000 and using track start/end appears to cause no change...

+ 33 - 2
theme/blast_ui.theme.inc

@@ -30,6 +30,37 @@ function blast_ui_preprocess_show_blast_report(&$vars) {
       $vars['blast_job']->blast_cmd .= ' -' . $key. ' ' . $value ;
   }
 
+  // CViTjs
+  $vars['show_cvit_diagram'] = FALSE;
+  if (variable_get('blast_ui_cvitjs_enabled', false)
+    && isset($vars['blast_job']->blastdb->cvitjs_enabled)
+    && $vars['blast_job']->blastdb->cvitjs_enabled == '1') {
+
+    // Set a clean var so we don't have to do this long check again ;-).
+    $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/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'));
+
+    // Add the JS settings.
+    global $base_url;
+    drupal_add_js(array('blast_ui'=> array(
+            'dataset' => $vars['blast_job']->blastdb->db_name,
+            'gff' => $base_url . '/' . $vars['blast_job']->files->result->gff
+      )),
+      'setting'
+    );
+  }
+
   // Determine the URL of the blast form.
   $vars['blast_form_url'] = 'blast/nucleotide/nucleotide';
   switch($vars['blast_job']->program) {
@@ -129,7 +160,7 @@ function blast_ui_reveal_secret($secret) {
   // Check that the job_id exists if it is an integer.
   if (is_numeric($job_id)) {
 
-    $exists = db_query('SELECT job_id FROM {tripal_jobs} WHERE job_id=:id', 
+    $exists = db_query('SELECT job_id FROM {tripal_jobs} WHERE job_id=:id',
                        array(':id' => $job_id))->fetchField();
     if (!$exists) {
       tripal_report_error(
@@ -148,7 +179,7 @@ function blast_ui_reveal_secret($secret) {
 
     $job_id = base64_decode($secret);
     if (is_numeric($job_id)) {
-      $exists = db_query('SELECT job_id FROM {tripal_jobs} WHERE job_id=:id', 
+      $exists = db_query('SELECT job_id FROM {tripal_jobs} WHERE job_id=:id',
                          array(':id' => $job_id))->fetchField();
       if (!$exists) {
         tripal_report_error(