| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 | <?php/** * @param $instance_id * * @return mixed * @throws \Exception */function tripal_jbrowse_mgmt_instance_page($instance_id) {  $instance = tripal_jbrowse_mgmt_get_instance($instance_id);  if (empty($instance)) {    drupal_not_found();    return '';  }  $settings = tripal_jbrowse_mgmt_get_settings();  drupal_set_title("Manage $instance->title JBrowse");  $breadcrumb = array();  $breadcrumb[] = l('Home', '');  $breadcrumb[] = l('Administration', 'admin');  $breadcrumb[] = l('Tripal', 'admin/tripal');  $breadcrumb[] = l('Extensions', 'admin/tripal/extension');  $breadcrumb[] = l('Tripal JBrowse', 'admin/tripal/extension/tripal_jbrowse/management');  drupal_set_breadcrumb($breadcrumb);  $content = [];  $content['instance_table'] = [    '#type' => 'markup',    '#markup' => theme(      'table',      [        'header' => ['Key', 'Value'],        'rows' => [          ['Instance Name', $instance->title],          ['Sequence Assembly', $instance->analysis->name ?? 'Not provided'],          ['Created At', date('m/d/Y', $instance->created_at)],          [            'Organism',            "{$instance->organism->genus} {$instance->organism->species}",          ],          ['Created By', $instance->user->name],          [            'Launch',            l(              'See ' . $instance->title . ' on JBrowse',              $settings['link'],              ['query' => tripal_jbrowse_mgmt_build_http_query($instance)]            ),          ],        ],      ]    ),  ];  // First get tracks added by this module.  $tracks = tripal_jbrowse_mgmt_get_tracks($instance, ['is_deleted' => 0]);  $content['tracks_title'] = [    '#type' => 'item',    '#markup' => '<h4>Tracks</h4>',  ];  $managed_tracks = [];  $rows = [];  if (!empty($tracks)) {    foreach ($tracks as $track) {      // Keep track of managed tracks so they are not duplicated later.      $managed_tracks[] = $track->label;      // Add the current tracks to the table.      $rows[] = [        $track->label,        $track->track_type,        $track->file_type,        $track->user->name,        date('m/d/Y', $track->created_at),        l('Manage Track', 'admin/tripal/extension/tripal_jbrowse/management/tracks/' . $track->id),        l(          'Delete Track',          'admin/tripal/extension/tripal_jbrowse/management/tracks/' . $track->id . '/delete'        ),      ];    }  }  // Second grab all tracks from the JSON.  $trackList = tripal_jbrowse_mgmt_get_json($instance);  if (!empty($trackList) and isset($trackList['tracks'])) {    foreach ($trackList['tracks'] as $track) {      // Make sure we only get the readable component for the type.      $path_type = explode('/', $track['type']);      $type = end($path_type);      // Make sure this is not a managed track.      if (in_array($track['key'], $managed_tracks)) {        continue;      }      // Now compile our row.      $rows[] = [        $track['key'],        $type,        '',        '',        '',        '',        '',      ];    }  }  // Finally, if there are tracks, show them in a table.  if (!empty($rows)) {    $content['tracks_table'] = [      '#type' => 'markup',      '#markup' => theme(        'table',        [          'header' => [            'Label',            'Track Type',            'File Type',            'Created By',            'Created At',            'Manage',            'Delete Track',          ],          'rows' => $rows,        ]      ),    ];  }  // Otherwise, prompt people to add tracks!  else {    $content['no_tracks'] = [      '#type' => 'item',      '#markup' => 'No tracks found for this instance. Please use the add tracks link above to add new tracks.',    ];  }  return $content;}
 |