Skip to content
Snippets Groups Projects
Commit 1b3a95c6 authored by Remi  PLANEL's avatar Remi PLANEL
Browse files

WIP: download data

parent 55116884
No related branches found
No related tags found
1 merge request!167Download server data
Pipeline #118975 failed
...@@ -51,7 +51,7 @@ const msFilter: Ref<string | undefined> = ref(undefined) ...@@ -51,7 +51,7 @@ const msFilter: Ref<string | undefined> = ref(undefined)
const page = ref(1) const page = ref(1)
let loading = ref(false) let loading = ref(false)
const expanded = ref([]) const expanded = ref([])
const { height } = useDisplay(); const { height, mobile } = useDisplay();
const minTableHeight = ref(400) const minTableHeight = ref(400)
const computedTableHeight = computed(() => { const computedTableHeight = computed(() => {
const computedHeight = height.value - 350 const computedHeight = height.value - 350
...@@ -314,6 +314,7 @@ function clearSearch() { ...@@ -314,6 +314,7 @@ function clearSearch() {
search.value = "" search.value = ""
} }
const { pending: pendingDownloadData, downloadCsv } = useCsvDownload(props.db)
...@@ -331,11 +332,11 @@ function clearSearch() { ...@@ -331,11 +332,11 @@ function clearSearch() {
</v-card-text> </v-card-text>
<v-card-text> <v-card-text>
<v-row> <v-row>
<v-col cols="5"> <v-col :cols="mobile ? 12 : 5">
<v-text-field v-model="search" label="Search..." hide-details prepend-inner-icon="mdi-magnify" <v-text-field v-model="search" label="Search..." hide-details prepend-inner-icon="mdi-magnify"
single-line clearable></v-text-field> single-line clearable></v-text-field>
</v-col> </v-col>
<v-col> <v-col :cols="mobile ? 12 : 6">
<v-autocomplete ref="autocompleteInput" hide-details v-model:model-value="filterOrSearch" <v-autocomplete ref="autocompleteInput" hide-details v-model:model-value="filterOrSearch"
auto-select-first chips clearable label="Filter results..." :items="autocompleteItems" single-line auto-select-first chips clearable label="Filter results..." :items="autocompleteItems" single-line
item-value="value" item-title="title" multiple return-object prepend-inner-icon="md:search" item-value="value" item-title="title" multiple return-object prepend-inner-icon="md:search"
...@@ -353,9 +354,17 @@ function clearSearch() { ...@@ -353,9 +354,17 @@ function clearSearch() {
</template> </template>
</v-autocomplete> </v-autocomplete>
</v-col> </v-col>
<v-col :cols="mobile ? 'auto' : 1">
<v-badge :content="totalHits" color="primary">
<v-btn icon="md:download"
@click="downloadCsv(props.db, toValue(search), { ...notPaginatedParams.value, filter: toValue(computedFilter), sort: msSortBy.value })">
</v-btn>
</v-badge>
</v-col>
</v-row> </v-row>
<v-row v-if="props.db === 'structure'"> <v-row v-if="props.db === 'structure'">
<v-col> <v-col>
<v-range-slider v-model="plddtRange" density="compact" hide-details="auto" label="pLDDT" step="0.1" <v-range-slider v-model="plddtRange" density="compact" hide-details="auto" label="pLDDT" step="0.1"
@update:modelValue="throttleSearch()"> @update:modelValue="throttleSearch()">
<template v-slot:prepend> <template v-slot:prepend>
...@@ -371,11 +380,14 @@ function clearSearch() { ...@@ -371,11 +380,14 @@ function clearSearch() {
</v-col> </v-col>
</v-row> </v-row>
</v-card-text> </v-card-text>
<v-toolbar flat color="transparent"> </v-toolbar>
<v-data-table-server v-if="!msError" v-model:page="page" color="primary" v-bind="dataTableServerProps" <v-data-table-server v-if="!msError" v-model:page="page" color="primary" v-bind="dataTableServerProps"
v-model:items-per-page="hitsPerPage" v-model:sortBy="sortByRef" v-model:expanded="expanded" fixed-header v-model:items-per-page="hitsPerPage" v-model:sortBy="sortByRef" v-model:expanded="expanded" fixed-header
:loading="loading" :items="msResult?.hits ?? []" :items-length="totalHits" density="compact" :loading="loading" :items="msResult?.hits ?? []" :items-length="totalHits" density="compact"
:items-per-page-options="itemsPerPage" :height="computedTableHeight" class="elevation-1 mt-2"> :items-per-page-options="itemsPerPage" :height="computedTableHeight" class="elevation-1 mt-2">
<template v-for="(slot, index) of Object.keys(slots)" :key="index" v-slot:[slot]="data"> <template v-for="(slot, index) of Object.keys(slots)" :key="index" v-slot:[slot]="data">
<slot :name="slot" v-bind="data"></slot> <slot :name="slot" v-bind="data"></slot>
</template> </template>
......
...@@ -11,6 +11,8 @@ const itemValue = ref("id"); ...@@ -11,6 +11,8 @@ const itemValue = ref("id");
const { width } = useDisplay(); const { width } = useDisplay();
const scaleTransform: Ref<string[]> = ref([]) const scaleTransform: Ref<string[]> = ref([])
const facets = ref([ const facets = ref([
"replicon", "replicon",
"type", "type",
...@@ -80,10 +82,7 @@ onMounted(async () => { ...@@ -80,10 +82,7 @@ onMounted(async () => {
async function getAllHits(params) { async function getAllHits(params) {
if (params.index === 'refseq') { if (params.index === 'refseq') {
console.log(params.index)
const { data, error } = await useAsyncMeiliSearch(params) const { data, error } = await useAsyncMeiliSearch(params)
console.log(error.value)
console.log(data.value)
allHits.value = data.value allHits.value = data.value
} }
} }
...@@ -281,12 +280,11 @@ const scaleType = ref("linear") ...@@ -281,12 +280,11 @@ const scaleType = ref("linear")
</v-expansion-panels> </v-expansion-panels>
<ServerDbTable title="RefSeq" db="refseq" :sortBy="sortBy" :facets="facets" <ServerDbTable title="RefSeq" db="refseq" :sortBy="sortBy" :facets="facets"
:data-table-server-props="dataTableServerProps" @refresh:search="getAllHits"> :data-table-server-props="dataTableServerProps">
<template #top> <template #top>
<v-toolbar><v-toolbar-title class="text-capitalize"> <v-toolbar><v-toolbar-title class="text-capitalize">
RefSeq RefSeq
</v-toolbar-title><v-spacer></v-spacer> </v-toolbar-title><v-spacer></v-spacer>
</v-toolbar> </v-toolbar>
</template> </template>
<template #[`item.accession_in_sys`]="{ item }"> <template #[`item.accession_in_sys`]="{ item }">
......
...@@ -2,31 +2,29 @@ import { ref } from 'vue'; ...@@ -2,31 +2,29 @@ import { ref } from 'vue';
import Papa from 'papaparse'; import Papa from 'papaparse';
import { saveAs } from "file-saver"; import { saveAs } from "file-saver";
export function useCsvDownload(index: MaybeRef<string>, baseName: MaybeRef<string> = "df" export function useCsvDownload(baseName: MaybeRef<string> = "df"
) { ) {
const pending = ref(false) const pending = ref(false)
const { search: msSearch, result: msResult } = useMeiliSearch(toValue(index))
// const { search: msSearch, result: msResult } = useMeiliSearch(toValue(index))
const filename = ref(`${toValue(baseName)}-data.csv`) const filename = ref(`${toValue(baseName)}-data.csv`)
const downloadCsv = async ( const downloadCsv = async (
index: MaybeRef<string>,
query: MaybeRef<string>, query: MaybeRef<string>,
filter: MaybeRef<string>,
sortBy: MaybeRef<string[]>,
params: MaybeRef<Record<string, any>>, params: MaybeRef<Record<string, any>>,
) => { ) => {
filename.value = `${toValue(baseName)}-${toValue(filter)}.csv` filename.value = `${toValue(baseName)}-${toValue(params).filter}.csv`
pending.value = true pending.value = true
try { try {
await msSearch( const { data, error } = await useAsyncMeiliSearch({
toValue(query), index: toValue(index),
{ params: toValue(params),
...toValue(params), query: toValue(query)
filter: toValue(filter), })
sort: toValue(sortBy)
}) const csvContent = Papa.unparse(toValue(data).hits);
const csvContent = Papa.unparse(toValue(msResult).hits);
// console.log(csvContent) // console.log(csvContent)
const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' }); const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' });
saveAs(blob, `${toValue(filename)}`); saveAs(blob, `${toValue(filename)}`);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment