tripal_jbrowse_mgmt.module 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php
  2. /**
  3. * @file
  4. * Create and manage JBrowse instances.
  5. */
  6. require_once 'includes/tripal_jbrowse_mgmt.api.inc';
  7. require_once 'includes/tripal_jbrowse_mgmt.jobs.inc';
  8. require_once 'includes/tripal_jbrowse_mgmt_commands.inc';
  9. /**
  10. * Implements hook_menu().
  11. */
  12. function tripal_jbrowse_mgmt_menu() {
  13. $items = [];
  14. // Admin forms.
  15. $items['admin/tripal/extension/tripal_jbrowse/management'] = [
  16. 'title' => 'Tripal JBrowse Management',
  17. 'description' => 'List JBrowse settings',
  18. 'page callback' => 'tripal_jbrowse_mgmt_instances_page',
  19. 'page arguments' => ['tripal_jbrowse_mgmt_configure_form'],
  20. 'access arguments' => ['administer tripal_jbrowse_mgmt'],
  21. 'file' => 'includes/tripal_jbrowse_mgmt_list.page.inc',
  22. 'type' => MENU_NORMAL_ITEM,
  23. ];
  24. $items['admin/tripal/extension/tripal_jbrowse/management/instances'] = [
  25. 'title' => 'List Instances',
  26. 'description' => 'List JBrowse settings',
  27. 'page callback' => 'tripal_jbrowse_mgmt_instances_page',
  28. 'page arguments' => ['tripal_jbrowse_mgmt_configure_form'],
  29. 'access arguments' => ['administer tripal_jbrowse_mgmt'],
  30. 'file' => 'includes/tripal_jbrowse_mgmt_list.page.inc',
  31. 'type' => MENU_DEFAULT_LOCAL_TASK,
  32. ];
  33. $items['admin/tripal/extension/tripal_jbrowse/management/configure'] = [
  34. 'title' => 'Settings',
  35. 'description' => 'List and create JBrowse instances.',
  36. 'page callback' => 'drupal_get_form',
  37. 'page arguments' => ['tripal_jbrowse_mgmt_configure_form'],
  38. 'access arguments' => ['configure tripal_jbrowse_mgmt'],
  39. 'file' => 'includes/tripal_jbrowse_mgmt_configure.form.inc',
  40. 'type' => MENU_LOCAL_TASK,
  41. ];
  42. $items['admin/tripal/extension/tripal_jbrowse/management/instances/register'] = [
  43. 'title' => 'Register Existing Instance',
  44. 'description' => 'Adds an existing JBrowse to the list of instances managed within Tripal.',
  45. 'page callback' => 'drupal_get_form',
  46. 'page arguments' => ['tripal_jbrowse_mgmt_register_form'],
  47. 'access arguments' => ['administer tripal_jbrowse_mgmt'],
  48. 'file' => 'includes/tripal_jbrowse_mgmt_register.form.inc',
  49. 'type' => MENU_LOCAL_ACTION,
  50. ];
  51. $items['admin/tripal/extension/tripal_jbrowse/management/instances/add'] = [
  52. 'title' => 'Create New Instance',
  53. 'description' => 'List and create JBrowse instances.',
  54. 'page callback' => 'drupal_get_form',
  55. 'page arguments' => ['tripal_jbrowse_mgmt_add_form'],
  56. 'access arguments' => ['administer tripal_jbrowse_mgmt'],
  57. 'file' => 'includes/tripal_jbrowse_mgmt_add.form.inc',
  58. 'type' => MENU_LOCAL_ACTION,
  59. ];
  60. $items['admin/tripal/extension/tripal_jbrowse/management/instances/%'] = [
  61. 'title' => 'Manage Instance',
  62. 'description' => 'View an instance and manage its tracks.',
  63. 'page callback' => 'tripal_jbrowse_mgmt_instance_page',
  64. 'page arguments' => [6],
  65. 'access arguments' => ['administer tripal_jbrowse_mgmt'],
  66. 'file' => 'includes/tripal_jbrowse_mgmt_instance.page.inc',
  67. 'type' => MENU_CALLBACK,
  68. ];
  69. $items['admin/tripal/extension/tripal_jbrowse/management/instances/%/edit'] = [
  70. 'title' => 'Edit Instance',
  71. 'description' => 'Edit metadata for existing JBrowse instances.',
  72. 'page callback' => 'drupal_get_form',
  73. 'page arguments' => ['tripal_jbrowse_mgmt_edit_form', 6],
  74. 'access arguments' => ['administer tripal_jbrowse_mgmt'],
  75. 'file' => 'includes/tripal_jbrowse_mgmt_edit.form.inc',
  76. 'type' => MENU_LOCAL_ACTION,
  77. ];
  78. $items['admin/tripal/extension/tripal_jbrowse/management/instances/%/delete'] = [
  79. 'title' => 'Delete Instance',
  80. 'description' => 'Confirm deleting an instance.',
  81. 'page callback' => 'drupal_get_form',
  82. 'page arguments' => ['tripal_jbrowse_mgmt_delete_instance_form', 6],
  83. 'access arguments' => ['administer tripal_jbrowse_mgmt'],
  84. 'file' => 'includes/tripal_jbrowse_mgmt_delete_instance.form.inc',
  85. 'type' => MENU_LOCAL_ACTION,
  86. ];
  87. $items['admin/tripal/extension/tripal_jbrowse/management/instances/%/add_track'] = [
  88. 'title' => 'Add New Track',
  89. 'description' => 'Add new track to a jbrowse instance.',
  90. 'page callback' => 'drupal_get_form',
  91. 'page arguments' => ['tripal_jbrowse_mgmt_add_track_form', 6],
  92. 'access arguments' => ['administer tripal_jbrowse_mgmt'],
  93. 'file' => 'includes/tripal_jbrowse_mgmt_tracks.form.inc',
  94. 'type' => MENU_LOCAL_ACTION,
  95. ];
  96. $items['admin/tripal/extension/tripal_jbrowse/management/tracks/%'] = [
  97. 'title' => 'Edit Track',
  98. 'description' => 'Edit tracks.',
  99. 'page callback' => 'drupal_get_form',
  100. 'page arguments' => ['tripal_jbrowse_mgmt_json_editor_form', 6],
  101. 'access arguments' => ['administer tripal_jbrowse_mgmt'],
  102. 'file' => 'includes/tripal_jbrowse_mgmt_json_editor.form.inc',
  103. 'type' => MENU_CALLBACK,
  104. ];
  105. $items['admin/tripal/extension/tripal_jbrowse/management/tracks/%/delete'] = [
  106. 'title' => 'Delete Track',
  107. 'page callback' => 'drupal_get_form',
  108. 'page arguments' => ['tripal_jbrowse_mgmt_delete_track_form', 6],
  109. 'access arguments' => ['administer tripal_jbrowse_mgmt'],
  110. 'file' => 'includes/tripal_jbrowse_mgmt_tracks.form.inc',
  111. 'type' => MENU_LOCAL_ACTION,
  112. ];
  113. $items['admin/tripal/extension/tripal_jbrowse/management/tracks/%/edit_json'] = [
  114. 'title' => 'Edit Json',
  115. 'page callback' => 'drupal_get_form',
  116. 'page arguments' => ['tripal_jbrowse_mgmt_json_editor_advance_form', 6],
  117. 'access arguments' => ['administer tripal_jbrowse_mgmt'],
  118. 'file' => 'includes/tripal_jbrowse_mgmt_tracks.form.inc',
  119. 'type' => MENU_LOCAL_ACTION,
  120. ];
  121. $items['admin/tripal/extension/tripal_jbrowse/management/instances/analysis/autocomplete'] = [
  122. 'title' => 'autocomplete for JBrowse instance analysis',
  123. 'page callback' => '_mgmt_add_analysis_autocomplete',
  124. 'access arguments' => ['administer tripal_jbrowse_mgmt'],
  125. 'type' => MENU_CALLBACK,
  126. ];
  127. return $items;
  128. }
  129. /**
  130. * Implements hook_permission().
  131. */
  132. function tripal_jbrowse_mgmt_permission() {
  133. $items = [];
  134. $items['configure tripal_jbrowse_mgmt'] = [
  135. 'title' => t('Configure Tripal JBrowse Management'),
  136. ];
  137. $items['administer tripal_jbrowse_mgmt'] = [
  138. 'title' => t('Create, edit and delete JBrowse instances'),
  139. ];
  140. return $items;
  141. }
  142. /**
  143. * autocomplete helper
  144. * $string = string for autocomplete search
  145. * to provide analysis names for form in tripal_jbrowse_mgmt_add.form.inc
  146. */
  147. function _mgmt_add_analysis_autocomplete($string){
  148. $analysis_4match =array();
  149. $analysis = db_select('chado.analysis', 'CA')
  150. ->fields('CA', ['analysis_id', 'name'])
  151. ->condition('name','%'.db_like($string).'%','LIKE')
  152. ->execute();
  153. foreach($analysis as $one_analysis){
  154. $key = $one_analysis->name . ' (' . $one_analysis->analysis_id . ')';
  155. $analysis_4match[$key] = $one_analysis->name;
  156. }
  157. drupal_json_output($analysis_4match);
  158. }