tripal_jbrowse_mgmt_instance.page.inc 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. $content = [];
  17. $content['instance_table'] = [
  18. '#type' => 'markup',
  19. '#markup' => theme(
  20. 'table',
  21. [
  22. 'header' => ['Key', 'Value'],
  23. 'rows' => [
  24. ['Instance Name', $instance->title],
  25. ['Created At', date('m/d/Y', $instance->created_at)],
  26. [
  27. 'Organism',
  28. "{$instance->organism->genus} {$instance->organism->species}",
  29. ],
  30. ['Created By', $instance->user->name],
  31. [
  32. 'Launch',
  33. l(
  34. 'See ' . $instance->title . ' on JBrowse',
  35. $settings['link'],
  36. ['query' => tripal_jbrowse_mgmt_build_http_query($instance)]
  37. ),
  38. ],
  39. ],
  40. ]
  41. ),
  42. ];
  43. $tracks = tripal_jbrowse_mgmt_get_tracks($instance, ['is_deleted' => 0]);
  44. $content['tracks_title'] = [
  45. '#type' => 'item',
  46. '#markup' => '<h4>Tracks</h4>',
  47. ];
  48. if (empty($tracks)) {
  49. $content['no_tracks'] = [
  50. '#type' => 'item',
  51. '#markup' => 'No tracks found for this instance. Please use the add tracks link above to add new tracks.',
  52. ];
  53. }
  54. else {
  55. $rows = array_map(
  56. function ($track) {
  57. return [
  58. $track->label,
  59. $track->track_type,
  60. $track->file_type,
  61. $track->user->name,
  62. date('m/d/Y', $track->created_at),
  63. l('Manage Track', 'admin/tripal_jbrowse_mgmt/tracks/' . $track->id),
  64. l(
  65. 'Delete Track',
  66. 'admin/tripal_jbrowse_mgmt/tracks/' . $track->id . '/delete'
  67. ),
  68. ];
  69. },
  70. $tracks
  71. );
  72. $content['tracks_table'] = [
  73. '#type' => 'markup',
  74. '#markup' => theme(
  75. 'table',
  76. [
  77. 'header' => [
  78. 'Label',
  79. 'Track Type',
  80. 'File Type',
  81. 'Created By',
  82. 'Created At',
  83. 'Manage',
  84. 'Delete Track',
  85. ],
  86. 'rows' => $rows,
  87. ]
  88. ),
  89. ];
  90. }
  91. return $content;
  92. }