From bf3a95e197cac500838e12033000208a5a24196d Mon Sep 17 00:00:00 2001 From: Stephen Ficklin Date: Sun, 10 Nov 2019 01:51:14 -0800 Subject: [PATCH] Simplified results pages, and fixed bug with file usage not being set properly --- includes/tripal_galaxy.admin_files.inc | 1 + theme/css/tripal_galaxy.css | 10 + tripal_galaxy.module | 272 ++++++++++++------------- 3 files changed, 136 insertions(+), 147 deletions(-) diff --git a/includes/tripal_galaxy.admin_files.inc b/includes/tripal_galaxy.admin_files.inc index a354bd6..ace6f4a 100644 --- a/includes/tripal_galaxy.admin_files.inc +++ b/includes/tripal_galaxy.admin_files.inc @@ -247,6 +247,7 @@ function tripal_galaxy_admin_add_file_form_submit($form, &$form_state) { $file = file_load($file_upload); $filename = $file->filename; $fields['filename'] = $filename; + file_usage_add($file, 'tripal_galaxy', 'site-wide', 0); // Move the file out of the user upload directory that the Tripal // upload tool uses and into a new directory that is site-specific // rather than user-specific. diff --git a/theme/css/tripal_galaxy.css b/theme/css/tripal_galaxy.css index ce4fbee..a0038bc 100644 --- a/theme/css/tripal_galaxy.css +++ b/theme/css/tripal_galaxy.css @@ -29,4 +29,14 @@ .tripal-galaxy-fieldset .fieldset-description { color: #0099ff; +} + +.tripal-galaxy-file-peek { + overflow: auto; + max-width: 500px; +} + +.tripal-galaxy-submission-table tr.odd .form-item, +.tripal-galaxy-submission-table tr.even .form-item { + white-space: normal; } \ No newline at end of file diff --git a/tripal_galaxy.module b/tripal_galaxy.module index 50cfff5..743c97c 100755 --- a/tripal_galaxy.module +++ b/tripal_galaxy.module @@ -532,13 +532,6 @@ function tripal_galaxy_menu_alter(&$items) { ]; } -/** - * Implements hook_admin_paths_alter(). - */ -function tripal_galaxy_admin_paths_alter(&$paths) { - $paths['galaxy/viewer*'] = TRUE; -} - /** * Implements hook_views_api(). * @@ -659,10 +652,23 @@ function tripal_galaxy_webform_client_form_submit($form, &$form_state) { // For any files that were uploaded we want to set the usage for those // so that they are mapped to the correct submission. foreach ($form_state['values']['submitted'] as $cid => $component) { - if (is_array($component) and array_key_exists('html5_file_fid', $component) and $component['html5_file_fid']) { - $file = file_load($component['html5_file_fid']); - $form_key = $component['html5_file_table_key']; - file_usage_add($file, 'tripal_galaxy', $form_key, $tg_workflow); + if (is_array($component)){ + $fids = []; + if(array_key_exists('existing', $component) and $component['existing']) { + $fids = explode('|', $component['existing']); + } + if(array_key_exists('site_wide', $component) and $component['site_wide']) { + $fids = explode('|', $component['site_wide']); + } + if(array_key_exists('data_collection', $component) and $component['data_collection']) { + $fids = explode('|', $component['data_collection']); + } + if ($fids) { + foreach ($fids as $fid) { + $file = file_load($fid); + file_usage_add($file, 'tripal_galaxy', 'submission', $tg_workflow); + } + } } } @@ -796,7 +802,7 @@ function tripal_galaxy_webform_component_info() { */ function tripal_galaxy_webform_submission_presave($node, &$submission) { - // Itereate through the components being submitted and remove non + // Iterate through the components being submitted and remove non // needed elements added by our galaxy form elements. foreach ($submission->data as $cid => $data) { $component = db_select('webform_component', 'wc')->fields('wc', [ @@ -828,7 +834,6 @@ function tripal_galaxy_webform_submission_presave($node, &$submission) { } else { $submission->data[$cid]['data_collection'] = $file->fid; - file_usage_add($file, 'tripal_galaxy', $component->form_key, 0); } } } @@ -895,7 +900,8 @@ function tripal_galaxy_workflow_report(int $sid) { } // Get the galaxy server. - $galaxy = db_select('tripal_galaxy', 'tg')->fields('tg') + $galaxy = db_select('tripal_galaxy', 'tg') + ->fields('tg') ->condition('galaxy_id', $submission->galaxy_id) ->execute() ->fetchObject(); @@ -920,6 +926,15 @@ function tripal_galaxy_workflow_report(int $sid) { return $content; } + // Get the list of input files so we can exclude them from the results + $files_query = db_select('file_usage', 'fu'); + $files_query->join('file_managed', 'fm', 'fu.fid = fm.fid'); + $files_query->fields('fm', ['filename']); + $files_query->condition('fu.id', $sid); + $files_query->condition('fu.module', 'tripal_galaxy'); + $files_query->condition('fu.type', 'submission'); + $input_files = $files_query->execute()->fetchCol(); + $headers = []; $rows = []; @@ -1033,46 +1048,18 @@ function tripal_galaxy_workflow_report(int $sid) { ], ]; - $content['submission_details']['table'] = [ - '#type' => 'markup', - '#markup' => theme_table([ - 'header' => $headers, - 'rows' => $rows, - 'attributes' => [], - 'sticky' => FALSE, - 'caption' => '', - 'colgroups' => [], - 'empty' => '', - ]), - ]; // Get details about the galaxy server and the connection to Galaxy. $galaxy_server = tripal_galaxy_get_galaxy($submission->galaxy_id); $galaxy = tripal_galaxy_get_connection($submission->galaxy_id); + // This is just a placeholder for the results text. It will get fully + // set below. $content['results'] = [ '#type' => 'item', - '#title' => t('Results'), - '#description' => t('Each step in the workflow may have results of its own. Click the step name below to view its results.'), - ]; - $content['result_tabs'] = [ - '#type' => 'vertical_tabs', - '#theme_wrappers' => [ - 'vertical_tabs', - ], - '#attached' => [ - 'js' => [ - 'misc/form.js', - 'misc/collapse.js', - 'misc/vertical-tabs.js', - ], - 'css' => [ - 'misc/vertical-tabs.css', - ], - ], - '#children' => '', ]; + $file_errors = []; $has_any_results = FALSE; if (is_array($submission->errors)) { @@ -1097,20 +1084,33 @@ function tripal_galaxy_workflow_report(int $sid) { $has_step_results = TRUE; $has_any_results = TRUE; + if ($history_content['state'] == 'error') { + $file_errors[] = [ + '#type' => 'item', + '#title' => $history_content['name'], + '#markup' => $history_content['misc_info'] + ]; + } + // Skip history content items that should be hidden. if ($history_content['visible'] != TRUE) { continue; } + // Don't show input files. + if (in_array($history_content['name'], $input_files)) { + continue; + } + $step_content = []; $step_content['history_content_' . $history_content['id'] . '_' . $index] = [ '#type' => 'fieldset', '#title' => $history_content['name'], - '#collapsed' => FALSE, + '#collapsed' => TRUE, '#collapsible' => TRUE, - // '#attributes' => [ - // 'class' => ['collapsible', 'collapsed'], - // ],. + '#attributes' => [ + 'class' => ['collapsible', 'collapsed'], + ], '#attached' => [ 'js' => [ 'misc/collapse.js', @@ -1119,34 +1119,40 @@ function tripal_galaxy_workflow_report(int $sid) { ], ]; - switch ($history_content['type']) { - case 'file': - if (!isset($history_content['content_link'])) { - break; - } - $link = $history_content['content_link']; - // SPF: originally this was $history_content['dataset_id'] but for - // some reason that value seems off for v17.09 as it does not - // point to the correct dataset. Rather the 'id' does. However, - // in v18.01 it seems fixed and both 'id' and 'dataset_id' are the - // same. - $dataset_id = $history_content['id']; - $dataset = tripal_galaxy_get_dataset($submission, $dataset_id); - $proxy_url = tripal_galaxy_get_proxy_url($submission, $dataset, $node->uid, 'download'); - $file_size = tripal_format_bytes($history_content['file_size']); - $step_content['history_content_' . $history_content['id'] . '_' . $index]['download_link'] = [ - '#type' => 'item', - '#title' => t('Download Results'), - '#markup' => l($history_content['name'], $proxy_url) . ' (' . $file_size . ')', - ]; - break; - - default: + // If this is a file add in a downloadlink. + if ($history_content['type'] == 'file') { + if (!isset($history_content['content_link'])) { break; + } + $link = $history_content['content_link']; + $dataset_id = $history_content['id']; + $dataset = tripal_galaxy_get_dataset($submission, $dataset_id); + $proxy_url = tripal_galaxy_get_proxy_url($submission, $dataset, $node->uid, 'download'); + $file_size = tripal_format_bytes($history_content['file_size']); + $step_content['history_content_' . $history_content['id'] . '_' . $index]['download_link'] = [ + '#type' => 'item', + '#title' => t('Download File'), + '#markup' => l($history_content['name'], $proxy_url) . ' (' . $file_size . ')', + ]; } - switch ($history_content['extension']) { - case 'html': + // If this is an HTML file then add a view link. + if ($history_content['extension'] == 'html'){ + $dataset_id = $history_content['id']; + $dataset = tripal_galaxy_get_dataset($submission, $dataset_id); + $proxy_url = tripal_galaxy_get_proxy_url($submission, $dataset, $node->uid, 'viewer'); + $step_content['history_content_' . $history_content['id'] . '_' . $index]['html_view'] = [ + '#type' => 'item', + '#title' => t('View report'), + '#markup' => l($history_content['name'], $proxy_url), + '#description' => '' . t('Note: It may take a few moments for the results page to load.') . '', + ]; + } + // If this is not an HTML file then provide link to view the file + // unless it exceeds 1MB. If Galaxy provides a peek then show that. + else { + // Any files that are smaller than 1MB can be shown in a browser. + if ($history_content['file_size'] < pow(10, 6)) { // SPF: originally this was $history_content['dataset_id'] but for // some reason that value seems off for v17.09 as it does not // point to the correct dataset. Rather the 'id' does. However, @@ -1154,82 +1160,34 @@ function tripal_galaxy_workflow_report(int $sid) { // same. $dataset_id = $history_content['id']; $dataset = tripal_galaxy_get_dataset($submission, $dataset_id); - $proxy_url = tripal_galaxy_get_proxy_url($submission, $dataset, $node->uid, 'viewer'); + $proxy_url = tripal_galaxy_get_proxy_url($submission, $dataset, $node->uid, 'viewer-full'); $step_content['history_content_' . $history_content['id'] . '_' . $index]['html_view'] = [ '#type' => 'item', - '#title' => t('View Results'), - '#markup' => l($history_content['name'], $proxy_url), + '#title' => t('View File'), + '#markup' => l($history_content['name'], $proxy_url, ['attributes' => ['target' => '_blank']] ), '#description' => '' . t('Note: It may take a few moments for the results page to load.') . '', ]; - break; + } + else { + $step_content['history_content_' . $history_content['id'] . '_' . $index]['html_view'] = [ + '#type' => 'item', + '#title' => t('View File'), + '#markup' => 'Result file is too large to view. Please download.', + ]; + } - default: - // Any files that are smaller than 1MB can be shown in a browser. - if ($history_content['file_size'] < pow(10, 6)) { - // SPF: originally this was $history_content['dataset_id'] but for - // some reason that value seems off for v17.09 as it does not - // point to the correct dataset. Rather the 'id' does. However, - // in v18.01 it seems fixed and both 'id' and 'dataset_id' are the - // same. - $dataset_id = $history_content['id']; - $dataset = tripal_galaxy_get_dataset($submission, $dataset_id); - $proxy_url = tripal_galaxy_get_proxy_url($submission, $dataset, $node->uid, 'viewer'); - $step_content['history_content_' . $history_content['id'] . '_' . $index]['html_view'] = [ - '#type' => 'item', - '#title' => t('View Results'), - '#markup' => l($history_content['name'], $proxy_url), - '#description' => '' . t('Note: It may take a few moments for the results page to load.') . '', - ]; - } - else { - $step_content['history_content_' . $history_content['id'] . '_' . $index]['html_view'] = [ - '#type' => 'item', - '#title' => t('View Results'), - '#markup' => 'Result file is too large to view. Please download.', - ]; - } - $peek_title = 'Peek at the results'; - if ($history_content['peek'] == NULL and isset($history_info)) { - $peek_title = 'Error message'; - $history_content['peek'] = $history_content['misc_info']; - } + // Provide a peek if one is provided. + if ($history_content['peek'] != NULL) { $step_content['history_content_' . $history_content['id'] . '_' . $index]['peek'] = [ - '#type' => 'item', - '#title' => $peek_title, - '#description' => 'A view of the top of the output file.', - '#markup' => $history_content['peek'], + '#type' => 'item', + '#title' => 'Peek', + '#description' => 'A short view of the top of the output file.', + '#markup' => '
' . $history_content['peek'] . '
', ]; - break; + } } // End switch ($history_content['extension']) { ... // end foreach ($history_contents as $index => $history_content) { ... - if (!$has_step_results) { - $step_content['no_results'] = [ - '#type' => 'markup', - '#markup' => t('There are currently no results for this step. The current state of this task is: %status', [ - '%status' => json_decode($history_info['state_details']), - ]), - ]; - } - - $step_name = $history_content['hid'] . ': ' . $history_content['name'] . ' (' . $history_content['state'] . ')'; - $fieldset = [ - '#type' => 'fieldset', - '#title' => $step_name, - '#collapsed' => FALSE, - '#collapsible' => TRUE, - '#value' => render($step_content), - '#group' => 'result_tabs', - '#attributes' => [ - 'id' => 'tripal-galaxy-results-fieldset', - ], - '#attached' => [ - 'js' => [ - 'misc/collapse.js', - 'misc/form.js', - ], - ], - ]; - $content['result_tabs']['#children'] .= render($fieldset); + $content['history_content_' . $history_content['id'] . '_' . $index] = $step_content['history_content_' . $history_content['id'] . '_' . $index]; } } } @@ -1237,9 +1195,8 @@ function tripal_galaxy_workflow_report(int $sid) { if ($has_any_results) { $content['results'] = [ '#type' => 'item', - '#title' => t('Results'), - '#markup' => t('All files associated with the analysis, including input - files and all output files are listed below. If an error occurred during + '#title' => t('Result Files'), + '#markup' => t('Both the submitted files and result files are listed below. Click the filename to view or download results. If an error occurred during creation of any file it will be noted. Expand the field for the result below to view the status, peek or download result files.'), ]; @@ -1254,6 +1211,29 @@ function tripal_galaxy_workflow_report(int $sid) { ]; } + $rows[] = [ + [ + 'data' => 'Errors', + 'header' => TRUE, + ], + drupal_render($file_errors), + ]; + + $content['submission_details']['table'] = [ + '#type' => 'markup', + '#markup' => theme_table([ + 'header' => $headers, + 'rows' => $rows, + 'attributes' => [ + 'class' => 'tripal-galaxy-submission-table' + ], + 'sticky' => FALSE, + 'caption' => '', + 'colgroups' => [], + 'empty' => '', + ]), + ]; + return $content; } @@ -1765,9 +1745,6 @@ function tripal_galaxy_handle_uploaded_file($file, $type) { // Split the type into a node ID and form_key. list ($id, $form_key) = explode('-', $type); - - // Add another usage for this module. - file_usage_add($file, 'tripal_galaxy', $form_key, $id); } /** @@ -1869,6 +1846,7 @@ function tripal_galaxy_stream_link_proxy(string $proxy_id) { * A unique proxy ID that maps to a URL. */ function tripal_galaxy_results_viewer_full_page(string $proxy_id) { + dpm($_SESSION['tripal_galaxy_proxy_urls']); if (array_key_exists($proxy_id, $_SESSION['tripal_galaxy_proxy_urls'])) { $content = tripal_galaxy_stream_url_proxy($proxy_id);