|
@@ -27,7 +27,19 @@ function tripal_vocabulary_lookup_form_submit($form, $form_state) {
|
|
|
|
|
|
function tripal_vocabulary_lookup_page($vocabulary) {
|
|
|
|
|
|
+ // set the breadcrumb
|
|
|
+ $breadcrumb = array();
|
|
|
+ $breadcrumb[] = l('Home', '<front>');
|
|
|
+ $breadcrumb[] = l('Controlled Vocabularies', 'cv/lookup');
|
|
|
+ drupal_set_breadcrumb($breadcrumb);
|
|
|
+
|
|
|
$vocab = tripal_get_vocabulary_details($vocabulary);
|
|
|
+ if ($vocab['description']) {
|
|
|
+ drupal_set_title($vocab['description']);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ drupal_set_title($vocabulary);
|
|
|
+ }
|
|
|
|
|
|
// If we can't find the term then just return a message.
|
|
|
if (!$vocab) {
|
|
@@ -41,11 +53,12 @@ function tripal_vocabulary_lookup_page($vocabulary) {
|
|
|
if ($vocab['url']) {
|
|
|
$vocab_name = l($vocab['name'], $vocab['url'], array('attributes' => array('target' => '_blank')));
|
|
|
}
|
|
|
+
|
|
|
$short_name = $vocab['short_name'];
|
|
|
$vocab_desc = $vocab['description'];
|
|
|
$rows[] = array(
|
|
|
array(
|
|
|
- 'data' => 'Name',
|
|
|
+ 'data' => 'Vocabulary Name(s)',
|
|
|
'header' => TRUE,
|
|
|
'width' => '20%',
|
|
|
),
|
|
@@ -73,13 +86,99 @@ function tripal_vocabulary_lookup_page($vocabulary) {
|
|
|
'rows' => $rows,
|
|
|
'attributes' => array(),
|
|
|
'sticky' => FALSE,
|
|
|
- 'caption' => 'Vocabulary details',
|
|
|
+ 'caption' => '',
|
|
|
'colgroups' => array(),
|
|
|
'empty' => '',
|
|
|
);
|
|
|
- $content = theme_table($table);
|
|
|
+
|
|
|
+ $root_terms = tripal_get_vocabulary_root_terms($vocabulary);
|
|
|
+ $items = tripal_vocabulary_lookup_term_children_format($root_terms);
|
|
|
+
|
|
|
+ drupal_add_js(array(
|
|
|
+ 'tripal' => array(
|
|
|
+ 'cv_lookup' => array(
|
|
|
+ 'vocabulary' => $vocabulary,
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ), 'setting');
|
|
|
+
|
|
|
+ $content = array(
|
|
|
+ 'vocab_table' => array(
|
|
|
+ '#type' => 'item',
|
|
|
+ '#title' => 'Details',
|
|
|
+ '#markup' => theme_table($table),
|
|
|
+ ),
|
|
|
+ 'vocab_browser' => array(
|
|
|
+ '#type' => 'item',
|
|
|
+ '#title' => 'Term Browser',
|
|
|
+ '#markup' => $items,
|
|
|
+ ),
|
|
|
+ );
|
|
|
+
|
|
|
+ // Add support for our custom tree viewer
|
|
|
+ drupal_add_css(drupal_get_path('module', 'tripal') . '/theme/css/tripal.cv_lookup.css');
|
|
|
+ drupal_add_js(drupal_get_path('module', 'tripal') . '/theme/js/tripal.cv_lookup.js', 'file');
|
|
|
+
|
|
|
return $content;
|
|
|
}
|
|
|
+
|
|
|
+/**
|
|
|
+ * A helper function to format an array of terms into a list for the web page.
|
|
|
+ *
|
|
|
+ * @param $children
|
|
|
+ * A list of children terms.
|
|
|
+ */
|
|
|
+function tripal_vocabulary_lookup_term_children_format($children) {
|
|
|
+ $items = '<ul id="tripal-cv-lookup-tree">';
|
|
|
+ foreach ($children as $child) {
|
|
|
+ $grand = tripal_get_term_children($child['vocabulary']['short_name'], $child['accession']);
|
|
|
+ $num_grand = count($grand);
|
|
|
+ $items .= '<li vocabulary = "' . $child['vocabulary']['short_name'] . '" ' .
|
|
|
+ 'accession = "' . $child['accession'] . '" ' .
|
|
|
+ 'children = "' . $num_grand . '" ' .
|
|
|
+ 'state = "closed" '.
|
|
|
+ 'class = "cv-lookup-tree-node">';
|
|
|
+ $class = 'tree-node-closed';
|
|
|
+ if ($num_grand == 0) {
|
|
|
+ $class = 'tree-node-single';
|
|
|
+ }
|
|
|
+ $items .= '<i class = "tree-node-icon ' . $class . '"></i>';
|
|
|
+ $items .= l($child['name'], 'cv/lookup/' . $child['vocabulary']['short_name'] . '/' . $child['accession'], array('attributes' => array('target' => '_blank'))) . ' (' . $num_grand . ')';
|
|
|
+ $items .= '</li>';
|
|
|
+ }
|
|
|
+ $items .= '</ul>';
|
|
|
+
|
|
|
+ if (count($children)== 0) {
|
|
|
+ $items ='';
|
|
|
+ }
|
|
|
+
|
|
|
+ return $items;
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * An ajax callback to get the children of a term.
|
|
|
+ *
|
|
|
+ * @param $vocabulary
|
|
|
+ * The short name of the vocabulary (e.g. SO, GO, etc.)
|
|
|
+ * @param $accession
|
|
|
+ * The term accession.
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ * A JSON array compatible with the JSTree library.
|
|
|
+ * https://www.jstree.com/docs/json/
|
|
|
+ */
|
|
|
+function tripal_vocabulary_lookup_term_children_ajax($vocabulary, $accession) {
|
|
|
+
|
|
|
+ $term = tripal_get_term_details($vocabulary, $accession);
|
|
|
+ $children = tripal_get_term_children($vocabulary, $accession);
|
|
|
+ $response = array(
|
|
|
+ 'vocabulary' => $vocabulary,
|
|
|
+ 'accession' => $accession,
|
|
|
+ 'content' => tripal_vocabulary_lookup_term_children_format($children)
|
|
|
+ );
|
|
|
+ drupal_json_output($response);
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
*
|
|
|
* @param $vocabulary
|
|
@@ -88,7 +187,17 @@ function tripal_vocabulary_lookup_page($vocabulary) {
|
|
|
* @return
|
|
|
*/
|
|
|
function tripal_vocabulary_lookup_term_page($vocabulary, $accession) {
|
|
|
+
|
|
|
+ // set the breadcrumb
|
|
|
+ $breadcrumb = array();
|
|
|
+ $breadcrumb[] = l('Home', '<front>');
|
|
|
+ $breadcrumb[] = l('Controlled Vocabularies', 'cv/lookup');
|
|
|
+ $breadcrumb[] = l($vocabulary, 'cv/lookup/' . $vocabulary);
|
|
|
+ drupal_set_breadcrumb($breadcrumb);
|
|
|
+
|
|
|
$term = tripal_get_term_details($vocabulary, $accession);
|
|
|
+ drupal_set_title($term['name']);
|
|
|
+
|
|
|
|
|
|
// If we can't find the term then just return a message.
|
|
|
if (!$term) {
|
|
@@ -184,5 +293,15 @@ function tripal_vocabulary_lookup_term_page($vocabulary, $accession) {
|
|
|
'empty' => '',
|
|
|
);
|
|
|
$content .= theme_table($table);
|
|
|
+
|
|
|
+ drupal_add_js(array(
|
|
|
+ 'tripal' => array(
|
|
|
+ 'cv_lookup' => array(
|
|
|
+ 'vocabulary' => $vocabulary,
|
|
|
+ 'accession' => $accession,
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ), 'setting');
|
|
|
+
|
|
|
return $content;
|
|
|
}
|