tripal_jbrowse_mgmt_instance.page.inc 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. ['Sequence Assembly', $instance->analysis->name ?? 'Not provided'],
  33. ['Created At', date('m/d/Y', $instance->created_at)],
  34. [
  35. 'Organism',
  36. "{$instance->organism->genus} {$instance->organism->species}",
  37. ],
  38. ['Created By', $instance->user->name],
  39. [
  40. 'Launch',
  41. l(
  42. 'See ' . $instance->title . ' on JBrowse',
  43. $settings['link'],
  44. ['query' => tripal_jbrowse_mgmt_build_http_query($instance)]
  45. ),
  46. ],
  47. ],
  48. ]
  49. ),
  50. ];
  51. // First get tracks added by this module.
  52. $tracks = tripal_jbrowse_mgmt_get_tracks($instance, ['is_deleted' => 0]);
  53. $content['tracks_title'] = [
  54. '#type' => 'item',
  55. '#markup' => '<h4>Tracks</h4>',
  56. ];
  57. $managed_tracks = [];
  58. $rows = [];
  59. if (!empty($tracks)) {
  60. foreach ($tracks as $track) {
  61. // Keep track of managed tracks so they are not duplicated later.
  62. $managed_tracks[] = $track->label;
  63. // Add the current tracks to the table.
  64. $rows[] = [
  65. $track->label,
  66. $track->track_type,
  67. $track->file_type,
  68. $track->user->name,
  69. date('m/d/Y', $track->created_at),
  70. l('Manage Track', 'admin/tripal/extension/tripal_jbrowse/management/tracks/' . $track->id),
  71. l(
  72. 'Delete Track',
  73. 'admin/tripal/extension/tripal_jbrowse/management/tracks/' . $track->id . '/delete'
  74. ),
  75. ];
  76. }
  77. }
  78. // Second grab all tracks from the JSON.
  79. $trackList = tripal_jbrowse_mgmt_get_json($instance);
  80. if (!empty($trackList) and isset($trackList['tracks'])) {
  81. foreach ($trackList['tracks'] as $track) {
  82. // Make sure we only get the readable component for the type.
  83. $path_type = explode('/', $track['type']);
  84. $type = end($path_type);
  85. // Make sure this is not a managed track.
  86. if (in_array($track['key'], $managed_tracks)) {
  87. continue;
  88. }
  89. // Now compile our row.
  90. $rows[] = [
  91. $track['key'],
  92. $type,
  93. '',
  94. '',
  95. '',
  96. '',
  97. '',
  98. ];
  99. }
  100. }
  101. // Finally, if there are tracks, show them in a table.
  102. if (!empty($rows)) {
  103. $content['tracks_table'] = [
  104. '#type' => 'markup',
  105. '#markup' => theme(
  106. 'table',
  107. [
  108. 'header' => [
  109. 'Label',
  110. 'Track Type',
  111. 'File Type',
  112. 'Created By',
  113. 'Created At',
  114. 'Manage',
  115. 'Delete Track',
  116. ],
  117. 'rows' => $rows,
  118. ]
  119. ),
  120. ];
  121. }
  122. // Otherwise, prompt people to add tracks!
  123. else {
  124. $content['no_tracks'] = [
  125. '#type' => 'item',
  126. '#markup' => 'No tracks found for this instance. Please use the add tracks link above to add new tracks.',
  127. ];
  128. }
  129. return $content;
  130. }