فهرست منبع

API: Added tripal_set_message and used it in chado node properties/dbxrefs/relationships api

Lacey Sanderson 11 سال پیش
والد
کامیت
522e717fa6

+ 18 - 0
tripal_core/api/tripal_core.chado_nodes.dbxrefs.api.inc

@@ -140,6 +140,19 @@ function chado_add_node_form_dbxrefs(&$form, &$form_state, $details) {
     }
     }
   }
   }
 
 
+  // Tell tripal administrators how to add terms to the property types drop down.
+  $importance = (empty($db_options)) ? TRIPAL_WARNING : TRIPAL_INFO;
+  $tripal_message = tripal_set_message(
+    t('To add databases to the drop down list, you need to <a href="@dblink">add
+      an external database reference</a>.',
+      array(
+        '@dblink' => url('admin/tripal/chado/tripal_db/add')
+      )
+    ),
+    $importance,
+    array('return_html' => TRUE)
+  );
+
   // the fieldset of the dbxref elements
   // the fieldset of the dbxref elements
   $form['addtl_dbxrefs'] = array(
   $form['addtl_dbxrefs'] = array(
     '#type' => 'fieldset',
     '#type' => 'fieldset',
@@ -153,6 +166,11 @@ function chado_add_node_form_dbxrefs(&$form, &$form_state, $details) {
     '#weight'      => 9
     '#weight'      => 9
   );
   );
 
 
+  $form['addtl_dbxrefs']['admin_message'] = array(
+    '#type' => 'markup',
+    '#markup' => $tripal_message
+  );
+
   // this form element is a tree, so that we don't puke all of the values into then node variable
   // this form element is a tree, so that we don't puke all of the values into then node variable
   // it is set as a tree, and keeps them in the $form_state['values']['dbxref_table'] heading.
   // it is set as a tree, and keeps them in the $form_state['values']['dbxref_table'] heading.
   $form['addtl_dbxrefs']['dbxref_table'] = array(
   $form['addtl_dbxrefs']['dbxref_table'] = array(

+ 48 - 4
tripal_core/api/tripal_core.chado_nodes.properties.api.inc

@@ -136,7 +136,7 @@ function chado_add_node_form_properties(&$form, &$form_state, $details) {
       $property_options = array();
       $property_options = array();
       $property_options[] = 'Select a Property';
       $property_options[] = 'Select a Property';
       $sql = "
       $sql = "
-        SELECT DISTINCT CVT.cvterm_id, CVT.name, CVT.definition
+        SELECT DISTINCT CVT.cvterm_id, CVT.name, CVT.definition, CV.cv_id as cv_id
         FROM  {cvterm} CVT
         FROM  {cvterm} CVT
           INNER JOIN {cv} CV ON CVT.cv_id = CV.cv_id
           INNER JOIN {cv} CV ON CVT.cv_id = CV.cv_id
         WHERE
         WHERE
@@ -147,12 +147,17 @@ function chado_add_node_form_properties(&$form, &$form_state, $details) {
       $prop_types = chado_query($sql, array(':cv_name' => $details['cv_name']));
       $prop_types = chado_query($sql, array(':cv_name' => $details['cv_name']));
       while ($prop = $prop_types->fetchObject()) {
       while ($prop = $prop_types->fetchObject()) {
         $property_options[$prop->cvterm_id] = $prop->name;
         $property_options[$prop->cvterm_id] = $prop->name;
+        $details['cv_id'] = $prop->cv_id;
+      }
+      if (!isset($details['cv_id'])) {
+        $result = chado_select_record('cv',array('cv_id'),array('name' => $details['cv_name']));
+        $details['cv_id'] = $result[0]->cv_id;
       }
       }
     } elseif (isset($details['cv_id'])) {
     } elseif (isset($details['cv_id'])) {
       $property_options = array();
       $property_options = array();
       $property_options[] = 'Select a Property';
       $property_options[] = 'Select a Property';
       $sql = "
       $sql = "
-        SELECT DISTINCT CVT.cvterm_id, CVT.name, CVT.definition
+        SELECT DISTINCT CVT.cvterm_id, CVT.name, CVT.definition, CV.name as cv_name
         FROM  {cvterm} CVT
         FROM  {cvterm} CVT
           INNER JOIN {cv} CV ON CVT.cv_id = CV.cv_id
           INNER JOIN {cv} CV ON CVT.cv_id = CV.cv_id
         WHERE
         WHERE
@@ -163,23 +168,62 @@ function chado_add_node_form_properties(&$form, &$form_state, $details) {
       $prop_types = chado_query($sql, array(':cv_id' => $details['cv_id']));
       $prop_types = chado_query($sql, array(':cv_id' => $details['cv_id']));
       while ($prop = $prop_types->fetchObject()) {
       while ($prop = $prop_types->fetchObject()) {
         $property_options[$prop->cvterm_id] = $prop->name;
         $property_options[$prop->cvterm_id] = $prop->name;
+        $details['cv_name'] = $prop->cv_name;
+      }
+      if (!isset($details['cv_name'])) {
+        $result = chado_select_record('cv',array('name'),array('cv_id' => $details['cv_id']));
+        $details['cv_name'] = $result[0]->name;
       }
       }
     }
     }
   }
   }
 
 
+  // Tell tripal administrators how to add terms to the property types drop down.
+  if (empty($property_options)) {
+    $tripal_message = tripal_set_message(
+      t('There are currently no proeprty types! To add additional properties to the drop
+        down list, you need to <a href="@cvtermlink">add a controlled vocabulary term</a>
+        to the %cv_name controlled vocabulary.',
+        array(
+          '%cv_name' => $details['cv_name'],
+          '@cvtermlink' => url('admin/tripal/chado/tripal_cv/cv/'.$details['cv_id'].'/cvterm/add')
+        )
+      ),
+      TRIPAL_WARNING,
+      array('return_html' => TRUE)
+    );
+  }
+  else {
+    $tripal_message = tripal_set_message(
+      t('To add additional properties to the drop down list, you need to <a href="@cvtermlink">add
+        a controlled vocabulary term</a> to the %cv_name controlled vocabulary.',
+        array(
+          '%cv_name' => $details['cv_name'],
+          '@cvtermlink' => url('admin/tripal/chado/tripal_cv/cv/'.$details['cv_id'].'/cvterm/add')
+        )
+      ),
+      TRIPAL_INFO,
+      array('return_html' => TRUE)
+    );
+  }
+
   // the fieldset of the property elements
   // the fieldset of the property elements
   $form['properties'] = array(
   $form['properties'] = array(
     '#type' => 'fieldset',
     '#type' => 'fieldset',
     '#title' => t($details['fieldset_title']),
     '#title' => t($details['fieldset_title']),
     '#description' => t('You may add additional properties by selecting a property type
     '#description' => t('You may add additional properties by selecting a property type
       from the dropdown and adding text. You may add as many properties as desired by
       from the dropdown and adding text. You may add as many properties as desired by
-      clicking the add button on the right. To remove a property, click the remove button.
-      To add additional properties to the drop down. ' . $details['additional_instructions']),
+      clicking the add button on the right. To remove a property, click the remove button.'
+      . $details['additional_instructions']),
     '#prefix' => "<div id='properties-fieldset'>",
     '#prefix' => "<div id='properties-fieldset'>",
     '#suffix' => '</div>',
     '#suffix' => '</div>',
     '#weight'      => 8
     '#weight'      => 8
   );
   );
 
 
+  $form['properties']['admin_message'] = array(
+    '#type' => 'markup',
+    '#markup' => $tripal_message
+  );
+
   // this form element is a tree, so that we don't puke all of the values into then node variable
   // this form element is a tree, so that we don't puke all of the values into then node variable
   // it is set as a tree, and keeps them in the $form_state['values']['property_table'] heading.
   // it is set as a tree, and keeps them in the $form_state['values']['property_table'] heading.
   $form['properties']['property_table'] = array(
   $form['properties']['property_table'] = array(

+ 46 - 2
tripal_core/api/tripal_core.chado_nodes.relationships.api.inc

@@ -150,7 +150,7 @@ function chado_add_node_form_relationships(&$form, &$form_state, $details) {
       $type_options = array();
       $type_options = array();
       $type_options[] = 'Select a Property';
       $type_options[] = 'Select a Property';
       $sql = "
       $sql = "
-        SELECT DISTINCT CVT.cvterm_id, CVT.name, CVT.definition
+        SELECT DISTINCT CVT.cvterm_id, CVT.name, CVT.definition, CV.cv_id as cv_id
         FROM  {cvterm} CVT
         FROM  {cvterm} CVT
           INNER JOIN {cv} CV ON CVT.cv_id = CV.cv_id
           INNER JOIN {cv} CV ON CVT.cv_id = CV.cv_id
         WHERE
         WHERE
@@ -161,12 +161,17 @@ function chado_add_node_form_relationships(&$form, &$form_state, $details) {
       $prop_types = chado_query($sql, array(':cv_name' => $details['cv_name']));
       $prop_types = chado_query($sql, array(':cv_name' => $details['cv_name']));
       while ($prop = $prop_types->fetchObject()) {
       while ($prop = $prop_types->fetchObject()) {
         $type_options[$prop->cvterm_id] = $prop->name;
         $type_options[$prop->cvterm_id] = $prop->name;
+        $details['cv_id'] = $prop->cv_id;
+      }
+      if (!isset($details['cv_id'])) {
+        $result = chado_select_record('cv',array('cv_id'),array('name' => $details['cv_name']));
+        $details['cv_id'] = $result[0]->cv_id;
       }
       }
     } elseif (isset($details['cv_id'])) {
     } elseif (isset($details['cv_id'])) {
       $type_options = array();
       $type_options = array();
       $type_options[] = 'Select a Property';
       $type_options[] = 'Select a Property';
       $sql = "
       $sql = "
-        SELECT DISTINCT CVT.cvterm_id, CVT.name, CVT.definition
+        SELECT DISTINCT CVT.cvterm_id, CVT.name, CVT.definition, CV.name AS cv_name
         FROM  {cvterm} CVT
         FROM  {cvterm} CVT
           INNER JOIN {cv} CV ON CVT.cv_id = CV.cv_id
           INNER JOIN {cv} CV ON CVT.cv_id = CV.cv_id
         WHERE
         WHERE
@@ -177,10 +182,44 @@ function chado_add_node_form_relationships(&$form, &$form_state, $details) {
       $prop_types = chado_query($sql, array(':cv_id' => $details['cv_id']));
       $prop_types = chado_query($sql, array(':cv_id' => $details['cv_id']));
       while ($prop = $prop_types->fetchObject()) {
       while ($prop = $prop_types->fetchObject()) {
         $type_options[$prop->cvterm_id] = $prop->name;
         $type_options[$prop->cvterm_id] = $prop->name;
+        $details['cv_name'] = $prop->cv_name;
+      }
+      if (!isset($details['cv_name'])) {
+        $result = chado_select_record('cv',array('name'),array('cv_id' => $details['cv_id']));
+        $details['cv_name'] = $result[0]->name;
       }
       }
     }
     }
   }
   }
 
 
+  // Tell tripal administrators how to add terms to the property types drop down.
+  if (empty($type_options)) {
+    $tripal_message = tripal_set_message(
+      t('There are currently no proeprty types! To add additional properties to the drop
+        down list, you need to <a href="@cvtermlink">add a controlled vocabulary term</a>
+        to the %cv_name controlled vocabulary.',
+        array(
+          '%cv_name' => $details['cv_name'],
+          '@cvtermlink' => url('admin/tripal/chado/tripal_cv/cv/'.$details['cv_id'].'/cvterm/add')
+        )
+      ),
+      TRIPAL_WARNING,
+      array('return_html' => TRUE)
+    );
+  }
+  else {
+    $tripal_message = tripal_set_message(
+      t('To add additional properties to the drop down list, you need to <a href="@cvtermlink">add
+        a controlled vocabulary term</a> to the %cv_name controlled vocabulary.',
+        array(
+          '%cv_name' => $details['cv_name'],
+          '@cvtermlink' => url('admin/tripal/chado/tripal_cv/cv/'.$details['cv_id'].'/cvterm/add')
+        )
+      ),
+      TRIPAL_INFO,
+      array('return_html' => TRUE)
+    );
+  }
+
   $form['relationships'] = array(
   $form['relationships'] = array(
     '#type' => 'fieldset',
     '#type' => 'fieldset',
     '#title' => t($details['fieldset_title']),
     '#title' => t($details['fieldset_title']),
@@ -194,6 +233,11 @@ function chado_add_node_form_relationships(&$form, &$form_state, $details) {
     '#weight'      => 10
     '#weight'      => 10
   );
   );
 
 
+  $form['relationships']['admin_message'] = array(
+    '#type' => 'markup',
+    '#markup' => $tripal_message
+  );
+
   // this form element is a tree, so that we don't puke all of the values into then node variable
   // this form element is a tree, so that we don't puke all of the values into then node variable
   // it is set as a tree, and keeps them in the $form_state['values']['relationship_table'] heading.
   // it is set as a tree, and keeps them in the $form_state['values']['relationship_table'] heading.
   $form['relationships']['relationship_table'] = array(
   $form['relationships']['relationship_table'] = array(

+ 67 - 0
tripal_core/api/tripal_core.tripal.api.inc

@@ -106,6 +106,73 @@ function tripal_report_error($type, $severity, $message, $variables = array(), $
   }
   }
 }
 }
 
 
+/**
+ * Display messages to tripal administrators. This can be used instead of
+ * drupal_set_message when you want to target tripal administrators.
+ *
+ * @param $message
+ *   The message to be displayed to the tripal administrators
+ * @param $importance
+ *   The level of importance for this message. In the future this will be used to allow
+ *   administrators to filter some of these messages. It can be one of the following:
+ *     - TRIPAL_CRITICAL: Critical conditions.
+ *     - TRIPAL_ERROR: Error conditions.
+ *     - TRIPAL_WARNING: Warning conditions.
+ *     - TRIPAL_NOTICE: Normal but significant conditions.
+ *     - TRIPAL_INFO: (default) Informational messages.
+ *     - TRIPAL_DEBUG: Debug-level messages.
+ * @param $options
+ *   Any options to apply to the current message. Supported options include:
+ *     - return_html: return HTML instead of setting a drupal message. This can be
+ *         used to place a tripal message in a particular place in the page.
+ *         The default is FALSE.
+ */
+function tripal_set_message($message, $importance = TRIPAL_INFO, $options = array()) {
+
+  // set defaults
+  $options['return_html'] = (isset($options['return_html'])) ? $options['return_html'] : FALSE;
+
+  // Get human-readable severity string
+  $importance_string = '';
+  switch ($importance) {
+    case TRIPAL_CRITICAL:
+      $importance_string = 'CRITICAL';
+      break;
+    case TRIPAL_ERROR:
+      $importance_string = 'ERROR';
+      break;
+    case TRIPAL_WARNING:
+      $importance_string = 'WARNING';
+      break;
+    case TRIPAL_NOTICE:
+      $importance_string = 'NOTICE';
+      break;
+    case TRIPAL_INFO:
+      $importance_string = 'INFO';
+      break;
+    case TRIPAL_DEBUG:
+      $importance_string = 'DEBUG';
+      break;
+  }
+
+  // Mark-up the Message
+  $full_message =
+     '<div class="tripal-site-admin-message">'
+       . '<span class="tripal-serverity-string ' . strtolower($importance_string) . '">' . $importance_string . ': </span>'
+       . $message
+   . '</div>';
+
+  // Handle whether to return the HTML & let the caller deal with it
+  // or to use drupal_set_message to put it near the top of the page  & let the theme deal with it
+  if ($options['return_html']) {
+    return '<div class="messages tripal-site-admin-only">' . $full_message . '</div>';
+  }
+  else {
+    drupal_set_message($full_message, 'tripal-site-admin-only');
+  }
+
+}
+
 /**
 /**
  * Use this function to encapsulate text intended to be
  * Use this function to encapsulate text intended to be
  * visible only by the site administrator. A small tripal logo
  * visible only by the site administrator. A small tripal logo

+ 35 - 23
tripal_core/theme/css/tripal.css

@@ -1,8 +1,8 @@
 /**
 /**
  * The Tripal generic node template (node--chado-generc.tpl.php)
  * The Tripal generic node template (node--chado-generc.tpl.php)
- * has an outer div box with class 'tripal-contents' and with an inner 
+ * has an outer div box with class 'tripal-contents' and with an inner
  * table with an id of 'tripal-contents-table'.  The table has a single
  * table with an id of 'tripal-contents-table'.  The table has a single
- * row with two columns.  The smaller left column houses the table of 
+ * row with two columns.  The smaller left column houses the table of
  * contents (TOC) for the node data.  The larger right column houses the data:
  * contents (TOC) for the node data.  The larger right column houses the data:
  *
  *
  * |-----------------------------------------------|
  * |-----------------------------------------------|
@@ -42,9 +42,9 @@
  * the table is meant for organizing the sidebar and contents so they don't
  * the table is meant for organizing the sidebar and contents so they don't
  * slip and slide around as would happen with div boxes that were floated.
  * slip and slide around as would happen with div boxes that were floated.
  * Therefore, we use !important to keep the default theme from overrideing
  * Therefore, we use !important to keep the default theme from overrideing
- * the table settings. 
+ * the table settings.
  */
  */
- 
+
 .tripal-contents-table tbody {
 .tripal-contents-table tbody {
   padding: 0px !important;
   padding: 0px !important;
   margin:  0px !important;
   margin:  0px !important;
@@ -57,7 +57,7 @@
   border:  none !important;
   border:  none !important;
   background-color: transparent !important;
   background-color: transparent !important;
 }
 }
-.tripal-contents-table-td-toc { 
+.tripal-contents-table-td-toc {
   border-right: 1px solid #CCCCCC !important;
   border-right: 1px solid #CCCCCC !important;
   margin:  0px !important;
   margin:  0px !important;
   padding: 0px !important;
   padding: 0px !important;
@@ -65,7 +65,7 @@
   text-align: left !important;
   text-align: left !important;
   vertical-align: top !important;
   vertical-align: top !important;
 }
 }
-.tripal-contents-table-td-data { 
+.tripal-contents-table-td-data {
   border: none !important;
   border: none !important;
   margin:  0px !important;
   margin:  0px !important;
   padding: 0px 0px 0px 20px !important;
   padding: 0px 0px 0px 20px !important;
@@ -76,7 +76,7 @@
 
 
 /**
 /**
  * The table of contents is an unordered list. The following can are used
  * The table of contents is an unordered list. The following can are used
- * to style the list 
+ * to style the list
  */
  */
 .tripal_toc_list {
 .tripal_toc_list {
 
 
@@ -93,11 +93,11 @@
  * Column. Initially, the JavaScript hids all "blocks" except for the "Details"
  * Column. Initially, the JavaScript hids all "blocks" except for the "Details"
  * block.  There will be as many blocks as there are TOC links.
  * block.  There will be as many blocks as there are TOC links.
  *
  *
- * By default, all blocks have the following layout that consists of a 
+ * By default, all blocks have the following layout that consists of a
  * container div box with the class 'tripal-info-box', a div box to house the
  * container div box with the class 'tripal-info-box', a div box to house the
  * block title with the class 'tripal-info-box-title', and a div box to
  * block title with the class 'tripal-info-box-title', and a div box to
- * house a brief description about the block with the class 
- * 'tripal-info-box-desc' 
+ * house a brief description about the block with the class
+ * 'tripal-info-box-desc'
  *
  *
  * |-----------------------------------------------|
  * |-----------------------------------------------|
  * |  .tripal-data-block                           |
  * |  .tripal-data-block                           |
@@ -129,7 +129,7 @@
 }
 }
 
 
 /**
 /**
- * Within the block data 
+ * Within the block data
  */
  */
  .tripal-data-table {
  .tripal-data-table {
    margin-top: 0px;
    margin-top: 0px;
@@ -139,7 +139,7 @@
 /******************************************************************************
 /******************************************************************************
  * The teaser appears anywhere that a small snippet of the content is required.
  * The teaser appears anywhere that a small snippet of the content is required.
  * When any node in Drupal is published to the home page a teaser is used.
  * When any node in Drupal is published to the home page a teaser is used.
- * Teasers can also be used in views to provide lists of content. The 
+ * Teasers can also be used in views to provide lists of content. The
  * teaser template is similar to the block but with the following sections and
  * teaser template is similar to the block but with the following sections and
  * classes
  * classes
  *
  *
@@ -168,35 +168,47 @@
 
 
 /**
 /**
  * some nodes such as the organism node may have images. This class
  * some nodes such as the organism node may have images. This class
- * is used to format any image that appears in the teaser 
+ * is used to format any image that appears in the teaser
  */
  */
 .tripal-teaser-img {
 .tripal-teaser-img {
-  width: 100px; 
-  float: left; 
-  padding-right: 10px; 
+  width: 100px;
+  float: left;
+  padding-right: 10px;
   padding-bottom: 5px;
   padding-bottom: 5px;
 }
 }
 
 
 /******************************************************************************
 /******************************************************************************
  * Administrative CSS classes
  * Administrative CSS classes
  *****************************************************************************/
  *****************************************************************************/
- 
+
  /**
  /**
-  * This class is used when providing hints or other instructions to the 
+  * This class is used when providing hints or other instructions to the
   * site administrator
   * site administrator
-  */ 
- 
-.tripal-site-admin-only {
+  */
+
+div.messages.tripal-site-admin-only{
   background-image: url("../images/TripalLogo-sm.png");
   background-image: url("../images/TripalLogo-sm.png");
   background-repeat: no-repeat;
   background-repeat: no-repeat;
   background-color: #cce3ff;
   background-color: #cce3ff;
   margin-top: 10px;
   margin-top: 10px;
   margin-bottom: 10px;
   margin-bottom: 10px;
-  border: 1px solid #888888;
+  border: 1px solid #7DA1D4;
   min-height: 50px;
   min-height: 50px;
   clear: both;
   clear: both;
 }
 }
 
 
+.tripal-serverity-string {
+  font-weight: bold;
+}
+
+.tripal-serverity-string.critical, .tripal-serverity-string.error {
+  color: #FF0000;
+}
+
+.tripal-serverity-string.warning {
+  color: #FF8000;
+}
+
 .tripal-site-admin-message {
 .tripal-site-admin-message {
    padding: 10px 10px 10px 55px;
    padding: 10px 10px 10px 55px;
    font-style: italic;
    font-style: italic;
@@ -204,6 +216,6 @@
 
 
 .tripal-site-admin-only-table-row {
 .tripal-site-admin-only-table-row {
   background-color: #cce3ff;
   background-color: #cce3ff;
-  border: 1px solid #888888;
+  border: 1px solid #7DA1D4;
   color: black;
   color: black;
 }
 }