tripal_jbrowse_mgmt_instance.page.inc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. /**
  3. * @param $instance_id
  4. *
  5. * @return mixed
  6. * @throws \Exception
  7. */
  8. function tripal_jbrowse_mgmt_instance_page($instance_id) {
  9. $instance = tripal_jbrowse_mgmt_get_instance($instance_id);
  10. if (empty($instance)) {
  11. drupal_not_found();
  12. return '';
  13. }
  14. $settings = tripal_jbrowse_mgmt_get_settings();
  15. drupal_set_title("Manage $instance->title JBrowse");
  16. $breadcrumb = array();
  17. $breadcrumb[] = l('Home', '');
  18. $breadcrumb[] = l('Administration', 'admin');
  19. $breadcrumb[] = l('Tripal', 'admin/tripal');
  20. $breadcrumb[] = l('Extensions', 'admin/tripal/extension');
  21. $breadcrumb[] = l('Tripal JBrowse', 'admin/tripal/extension/tripal_jbrowse/management');
  22. drupal_set_breadcrumb($breadcrumb);
  23. $content = [];
  24. $content['instance_table'] = [
  25. '#type' => 'markup',
  26. '#markup' => theme(
  27. 'table',
  28. [
  29. 'header' => ['Key', 'Value'],
  30. 'rows' => [
  31. ['Instance Name', $instance->title],
  32. ['Created At', date('m/d/Y', $instance->created_at)],
  33. [
  34. 'Organism',
  35. "{$instance->organism->genus} {$instance->organism->species}",
  36. ],
  37. ['Created By', $instance->user->name],
  38. [
  39. 'Launch',
  40. l(
  41. 'See ' . $instance->title . ' on JBrowse',
  42. $settings['link'],
  43. ['query' => tripal_jbrowse_mgmt_build_http_query($instance)]
  44. ),
  45. ],
  46. ],
  47. ]
  48. ),
  49. ];
  50. // First get tracks added by this module.
  51. $tracks = tripal_jbrowse_mgmt_get_tracks($instance, ['is_deleted' => 0]);
  52. $content['tracks_title'] = [
  53. '#type' => 'item',
  54. '#markup' => '<h4>Tracks</h4>',
  55. ];
  56. $managed_tracks = [];
  57. $rows = [];
  58. if (!empty($tracks)) {
  59. foreach ($tracks as $track) {
  60. // Keep track of managed tracks so they are not duplicated later.
  61. $managed_tracks[] = $track->label;
  62. // Add the current tracks to the table.
  63. $rows[] = [
  64. $track->label,
  65. $track->track_type,
  66. $track->file_type,
  67. $track->user->name,
  68. date('m/d/Y', $track->created_at),
  69. l('Manage Track', 'admin/tripal/extension/tripal_jbrowse/management/tracks/' . $track->id),
  70. l(
  71. 'Delete Track',
  72. 'admin/tripal/extension/tripal_jbrowse/management/tracks/' . $track->id . '/delete'
  73. ),
  74. ];
  75. }
  76. }
  77. // Second grab all tracks from the JSON.
  78. $trackList = tripal_jbrowse_mgmt_get_json($instance);
  79. if (!empty($trackList) and isset($trackList['tracks'])) {
  80. foreach ($trackList['tracks'] as $track) {
  81. // Make sure we only get the readable component for the type.
  82. $path_type = explode('/', $track['type']);
  83. $type = end($path_type);
  84. // Make sure this is not a managed track.
  85. if (in_array($track['key'], $managed_tracks)) {
  86. continue;
  87. }
  88. // Now compile our row.
  89. $rows[] = [
  90. $track['key'],
  91. $type,
  92. '',
  93. '',
  94. '',
  95. '',
  96. '',
  97. ];
  98. }
  99. }
  100. // Finally, if there are tracks, show them in a table.
  101. if (!empty($rows)) {
  102. $content['tracks_table'] = [
  103. '#type' => 'markup',
  104. '#markup' => theme(
  105. 'table',
  106. [
  107. 'header' => [
  108. 'Label',
  109. 'Track Type',
  110. 'File Type',
  111. 'Created By',
  112. 'Created At',
  113. 'Manage',
  114. 'Delete Track',
  115. ],
  116. 'rows' => $rows,
  117. ]
  118. ),
  119. ];
  120. }
  121. // Otherwise, prompt people to add tracks!
  122. else {
  123. $content['no_tracks'] = [
  124. '#type' => 'item',
  125. '#markup' => 'No tracks found for this instance. Please use the add tracks link above to add new tracks.',
  126. ];
  127. }
  128. return $content;
  129. }