Skip to content

Commit

Permalink
Implement Galaxy Markdown tag history_dataset_as_table.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmchilton committed Oct 17, 2023
1 parent 7c013cc commit 3bfacb7
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 0 deletions.
126 changes: 126 additions & 0 deletions client/src/components/Markdown/Elements/HistoryDatasetAsTable.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<script setup lang="ts">
import { computed } from "vue";
import { UrlDataProvider } from "@/components/providers/UrlDataProvider.js";
import LoadingSpan from "@/components/LoadingSpan.vue";
interface HistoryDatasetAsTableProps {
historyDatasetId: string;
compact: boolean;
showColumnHeaders: boolean;
title?: string;
footer?: string;
}
const props = withDefaults(defineProps<HistoryDatasetAsTableProps>(), {
compact: false,
showColumnHeaders: true,
title: null,
footer: null,
});
const itemUrl = computed(() => {
return `/api/datasets/${props.historyDatasetId}/get_content_as_text`;
});
const metaUrl = computed(() => {
return `/api/datasets/${props.historyDatasetId}`;
});
const expanded = false;
const contentClass = computed(() => {
if (expanded) {
return "embedded-dataset-expanded";
} else {
return "embedded-dataset";
}
});
function getFields(metaData: any) {
const fields = [];
const columnNames = metaData.metadata_column_names || [];
const columnCount = metaData.metadata_columns;
for (let i = 0; i < columnCount; i++) {
fields.push({
key: `${i}`,
label: columnNames[i] || i,
sortable: true,
});
}
return fields;
}
function getItems(textData: any, metaData: any) {
const tableData: object[] = [];
const delimiter: string = metaData.metadata_delimiter || "\t";
const comments: number = metaData.metadata_comment_lines || 0;
const lines = textData.split("\n");
lines.forEach((line: string, i: number) => {
if (i >= comments) {
const tabs = line.split(delimiter);
const rowData: string[] = [];
let hasData = false;
tabs.forEach((cellData: string, j: number) => {
const cellDataTrimmed = cellData.trim();
if (cellDataTrimmed) {
hasData = true;
}
rowData[j] = cellDataTrimmed;
});
if (hasData) {
tableData.push(rowData);
}
}
});
return tableData;
}
</script>

<template>
<b-card :no-body="props.compact">
<b-card-title v-if="title">
<b>{{ title }}</b>
</b-card-title>
<UrlDataProvider v-slot="{ result: itemContent, loading, error }" :url="itemUrl">
<LoadingSpan v-if="loading" message="Loading Dataset" />
<div v-else-if="error">{{ error }}</div>
<div v-else :class="contentClass">
<div v-if="itemContent.item_data">
<div>
<UrlDataProvider
v-slot="{ result: metaData, loading: metaLoading, error: metaError }"
:url="metaUrl">
<LoadingSpan v-if="metaLoading" message="Loading Metadata" />
<div v-else-if="metaError">{{ metaError }}</div>
<b-table
v-else
:thead-class="props.showColumnHeaders ? '' : 'd-none'"
striped
hover
:fields="getFields(metaData)"
:items="getItems(itemContent.item_data, metaData)" />
</UrlDataProvider>
</div>
</div>
<div v-else>No content found.</div>
<b-link v-if="itemContent.truncated" :href="itemContent.item_url"> Show More... </b-link>
</div>
</UrlDataProvider>
<b-card-footer v-if="footer">
{{ footer }}
</b-card-footer>
</b-card>
</template>

<style scoped>
.embedded-dataset {
max-height: 20rem;
overflow-y: auto;
}
.embedded-dataset-expanded {
max-height: 40rem;
overflow-y: auto;
}
</style>
19 changes: 19 additions & 0 deletions client/src/components/Markdown/MarkdownContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { computed, ref } from "vue";
import HistoryDatasetAsImage from "./Elements/HistoryDatasetAsImage.vue";
import HistoryDatasetAsTable from "./Elements/HistoryDatasetAsTable.vue";
import HistoryDatasetCollectionDisplay from "./Elements/HistoryDatasetCollection/CollectionDisplay.vue";
import HistoryDatasetDetails from "./Elements/HistoryDatasetDetails.vue";
import HistoryDatasetDisplay from "./Elements/HistoryDatasetDisplay.vue";
Expand Down Expand Up @@ -61,6 +62,17 @@ const props = defineProps({
const isCollapsible = computed(() => props.args.collapse !== undefined);
const isVisible = computed(() => !isCollapsible.value || toggle.value);
function argToBoolean(args, name, booleanDefault) {
const valueAsString = args[name];
if (valueAsString == "true") {
return true;
} else if (valueAsString == "false") {
return false;
} else {
return booleanDefault;
}
}
</script>

<template>
Expand All @@ -77,6 +89,13 @@ const isVisible = computed(() => !isCollapsible.value || toggle.value);
</div>
<HistoryLink v-else-if="name == 'history_link'" :args="args" :histories="histories" />
<HistoryDatasetAsImage v-else-if="name == 'history_dataset_as_image'" :args="args" />
<HistoryDatasetAsTable
v-else-if="name == 'history_dataset_as_table'"
:history-dataset-id="args.history_dataset_id"
:compact="argToBoolean(args, 'compact', false)"
:show-column-headers="argToBoolean(args, 'show_column_headers', true)"
:title="args.title"
:footer="args.footer" />
<HistoryDatasetLink v-else-if="name == 'history_dataset_link'" :args="args" />
<HistoryDatasetIndex v-else-if="name == 'history_dataset_index'" :args="args" />
<InvocationTime v-else-if="name == 'invocation_time'" :args="args" :invocations="invocations" />
Expand Down
10 changes: 10 additions & 0 deletions lib/galaxy/managers/markdown_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ class DynamicArguments:
"history_dataset_display": ["input", "output", "history_dataset_id"],
"history_dataset_embedded": ["input", "output", "history_dataset_id"],
"history_dataset_as_image": ["input", "output", "history_dataset_id", "path"],
"history_dataset_as_table": [
"input",
"output",
"history_dataset_id",
"path",
"title",
"footer",
"show_column_headers",
"compact",
],
"history_dataset_peek": ["input", "output", "history_dataset_id"],
"history_dataset_info": ["input", "output", "history_dataset_id"],
"history_dataset_link": ["input", "output", "history_dataset_id", "path", "label"],
Expand Down
19 changes: 19 additions & 0 deletions lib/galaxy/managers/markdown_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ def _remap(container, line):
_check_object(object_id, line)
hda = hda_manager.get_accessible(object_id, trans.user)
rval = self.handle_dataset_as_image(line, hda)
elif container == "history_dataset_as_table":
_check_object(object_id, line)
hda = hda_manager.get_accessible(object_id, trans.user)
rval = self.handle_dataset_as_table(line, hda)
elif container == "history_dataset_peek":
_check_object(object_id, line)
hda = hda_manager.get_accessible(object_id, trans.user)
Expand Down Expand Up @@ -218,6 +222,10 @@ def handle_dataset_display(self, line, hda):
def handle_dataset_as_image(self, line, hda):
pass

@abc.abstractmethod
def handle_dataset_as_table(self, line, hda):
pass

@abc.abstractmethod
def handle_dataset_peek(self, line, hda):
pass
Expand Down Expand Up @@ -334,6 +342,9 @@ def handle_history_link(self, line, history):
def handle_dataset_as_image(self, line, hda):
pass

def handle_dataset_as_table(self, line, hda):
pass

def handle_job_metrics(self, line, job):
pass

Expand Down Expand Up @@ -435,6 +446,14 @@ def handle_dataset_as_image(self, line, hda):
rval = (f"![{name}](data:image/png;base64,{base64_image_data})", True)
return rval

def handle_dataset_as_table(self, line, hda):
# TODO: this form of the rendering doesn't do anything special with advanced
# options yet but could easily be modified in the future. show_column_headers,
# compact, title, and footer should be handled in here to bring the PDF and the
# web rendering closer.
rval = self.handle_dataset_embedded(line, hda)
return rval

def handle_history_link(self, line, history):
if history:
content = literal_via_fence(history.name)
Expand Down

0 comments on commit 3bfacb7

Please sign in to comment.