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

simply a bit algo

parent f389aaf0
No related branches found
No related tags found
2 merge requests!203Foldseek pages,!186Refactor facet autocomplete
Pipeline #120404 passed
This commit is part of merge request !186. Comments created here will be created in the context of that merge request.
...@@ -226,7 +226,7 @@ function isItemFilter(type: string | undefined) { ...@@ -226,7 +226,7 @@ function isItemFilter(type: string | undefined) {
</script> </script>
<template> <template>
<v-autocomplete :model-value="props.modelValue" class="mx-2" @click:clear="clearFilters" v-bind="autocompleteProps" <v-autocomplete :model-value="props.modelValue" @click:clear="clearFilters" v-bind="autocompleteProps"
@update:focused="updateAutocompleteFocused" @update:modelValue="emitUpdateModelValue" :loading="!hasFacetDistribution" :disabled="!hasFacetDistribution"> @update:focused="updateAutocompleteFocused" @update:modelValue="emitUpdateModelValue" :loading="!hasFacetDistribution" :disabled="!hasFacetDistribution">
<template #item="{ props, item }"> <template #item="{ props, item }">
<v-list-item v-if="isItemFilter(item?.raw?.type)" v-bind="{ ...props, active: false }" :title="item.title" <v-list-item v-if="isItemFilter(item?.raw?.type)" v-bind="{ ...props, active: false }" :title="item.title"
......
...@@ -310,49 +310,30 @@ function focusedOrBlur(isFocused: boolean) { ...@@ -310,49 +310,30 @@ function focusedOrBlur(isFocused: boolean) {
: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 #top> <template #top>
<template v-if="mobile"> <v-card variant="flat" color="transparent">
<v-toolbar> <v-badge :content="totalHits" color="primary" class="mx-2"> <v-card-title>
<v-btn prepend-icon="md:download" :loading="pendingDownloadData" variant="text" color="primary"
@click="downloadData()">{{
props.title }}
</v-btn>
</v-badge></v-toolbar>
<v-toolbar>
<v-text-field v-model="search" label="Search..." hide-details="auto"
prepend-inner-icon="mdi-magnify" single-line clearable :disabled="pendingDownloadData"
class="mx-2" @update:focused="focusedOrBlur"></v-text-field>
</v-toolbar>
<v-toolbar>
<AutocompleteMeiliFacets v-model:modelValue="msFilterCompo"
v-bind="props.autocompleteMeiliFacetsProps" :is-valid-filters="isValidFilters">
</AutocompleteMeiliFacets>
</v-toolbar>
</template>
<template v-else>
<v-toolbar>
<v-badge :content="totalHits" color="primary" class="mr-3"> <v-badge :content="totalHits" color="primary" class="mr-3">
<v-btn prepend-icon="md:download" :loading="pendingDownloadData" variant="text" color="primary" <v-btn prepend-icon="md:download" :loading="pendingDownloadData" variant="text" color="primary"
@click="downloadData()">{{ @click="downloadData()">{{
props.title }} props.title }}
</v-btn> </v-btn>
</v-badge> </v-badge>
<v-spacer></v-spacer> </v-card-title>
<v-col> <v-card-title>
<v-card variant="flat" color="transparent" :min-width="400" class="mx-2" :rounded="false"> <v-text-field v-model="search" label="Search..." hide-details="auto" :disabled="pendingDownloadData"
<v-text-field v-model="search" label="Search..." hide-details="auto" prepend-inner-icon="mdi-magnify" single-line clearable
:disabled="pendingDownloadData" prepend-inner-icon="mdi-magnify" single-line clearable @update:focused="focusedOrBlur"></v-text-field>
@update:focused="focusedOrBlur"></v-text-field> </v-card-title>
</v-card> <v-card-title>
</v-col><v-col> <AutocompleteMeiliFacets v-model="msFilterCompo" v-bind="props.autocompleteMeiliFacetsProps"
<v-card variant="flat" color="transparent" :min-width="600" class="mx-2" :rounded="false"> :is-valid-filters="isValidFilters">
<AutocompleteMeiliFacets v-model="msFilterCompo" v-bind="props.autocompleteMeiliFacetsProps" </AutocompleteMeiliFacets>
:is-valid-filters="isValidFilters">
</AutocompleteMeiliFacets>
</v-card> </v-card-title>
</v-col>
</v-toolbar>
</template>
</v-card>
</template> </template>
<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">
......
...@@ -20,63 +20,41 @@ export function useMeiliFilters(filters: MaybeRef<FilterItem[] | undefined>) { ...@@ -20,63 +20,41 @@ export function useMeiliFilters(filters: MaybeRef<FilterItem[] | undefined>) {
const position = index + 1 const position = index + 1
switch (position % 4) { switch (position % 4) {
case 0: case 0:
// if this is the first time pass by an outeroperator
if (previousOperator === undefined) { if (previousOperator === undefined) {
const newFilter = acc.splice(-3).join("") const newFilter = acc.splice(-3).join("")
if (sanitizedValue === 'AND') { if (sanitizedValue === 'OR') {
acc.push(newFilter) acc = [[newFilter]]
} }
else { else {
acc.push([newFilter]) acc.push(newFilter)
} }
} }
previousOperator = sanitizedValue previousOperator = sanitizedValue
break; break;
case 3: case 3:
// if last element
acc.push(`'${sanitizedValue}'`) acc.push(`'${sanitizedValue}'`)
const newFilter = acc.splice(-3).join("")
if (previousOperator === undefined) { if (previousOperator === 'AND') {
const newFilter = acc.splice(-3).join("")
acc.push(newFilter) acc.push(newFilter)
} }
else { else {
const newFilter = acc.splice(-3).join("") const previousElem = acc.slice(-1)[0]
console.log("new filter:", newFilter) if (Array.isArray(previousElem)) {
if (previousOperator === 'AND') { acc.slice(-1)[0].push(newFilter)
acc.push(newFilter)
} }
else { else {
console.log("previous operator is OR") const previousElem = acc.splice(-1)[0]
const previousElem = acc.slice(-1)[0] acc.push([previousElem, newFilter])
console.log(previousElem)
if (Array.isArray(previousElem)) {
acc.slice(-1)[0].push(newFilter)
}
else {
const previousElem = acc.splice(-1)[0]
console.log(previousElem)
console.log([...acc])
acc.push([previousElem, newFilter])
}
} }
} }
break break
default: default:
acc.push(sanitizedValue) acc.push(sanitizedValue)
break; break;
} }
console.log(position)
console.log([...acc])
return acc return acc
}, []) }, [])
console.log(arrayFilters)
return arrayFilters return arrayFilters
} else { } else {
......
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