Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The 1370 front bug rebond sur les mots cl s partir d une page de personne #247

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions components/common/Keywords.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<div role="list" aria-labelledby="mots-cles-libres" class="chip-lines v-chip-group" :class="isRtl ? 'rtl-text' : ''">
<template v-for="keyWord in freeKeywords" :key="keyWord.keyword + forceRenderKey" :title="keyWord.keyword">
<nuxt-link role="listitem"
:to="{ name: 'resultats', query: { q: keyWord.query ? keyWord.query : keyWord.keyword, domaine: 'theses' } }">
:to="{ name: 'resultats', query: { q: keyWord.query ? createKeywordQuery(keyWord.query) : createKeywordQuery(keyWord.keyword), domaine: 'theses', avancee: 'true' } }">
<v-chip label class="free-chip chips" tabindex="-1">
<span class="key-word-label">{{ keyWord.keyword }}</span>
</v-chip>
Expand All @@ -60,7 +60,7 @@
<div role="list" aria-labelledby="keywords-title" v-if="mixedKeywords.length > 0" class="chip-lines v-chip-group" :class="isRtl ? 'rtl-text' : ''">
<template v-for="keyWord in mixedKeywords" :key="keyWord.keyword + forceRenderKey" :title="keyWord.keyword">
<nuxt-link role="listitem"
:to="{ name: 'resultats', query: { q: keyWord.query ? keyWord.query : keyWord.keyword, domaine: 'theses' } }">
:to="{ name: 'resultats', query: { q: keyWord.query ? keyWord.query : keyWord.keyword, domaine: 'theses', avancee: 'true' } }">
<v-chip label class="chips" :class="keyWord.type === 'sujetsRameau' ? 'rameau-chip' : 'free-chip'"
tabindex="-1">
<span class="key-word-label">{{ keyWord.keyword }}</span>
Expand Down Expand Up @@ -201,6 +201,9 @@ function showAllKeywords() {
focusLastKeyword();
}

function createKeywordQuery(keyword) {
return "(sujetsLibelle:(" + keyword + ") OU sujetsRameauLibelle:(" + keyword + "))";
}

function focusLastKeyword() {
var chipGroup = document.querySelector('.v-chip-group');
Expand Down
13 changes: 12 additions & 1 deletion components/common/results/ResultComponents.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@

<script setup>
import { useDisplay } from "vuetify";
import { onMounted, ref, watch } from "vue";
import { onMounted, onBeforeUnmount, ref, watch } from "vue";

const currentRoute = useRoute();
const router = useRouter();
const { mobile } = useDisplay();
import { replaceAndEscape } from "../services/Common";
const { setShowingNumber, getFacetsRequest } = useStrategyAPI();
Expand Down Expand Up @@ -100,6 +101,8 @@ const props = defineProps({
}
});

const scrollPosition = ref(0);

/**
* Début gestionnaire clic
*/
Expand All @@ -115,10 +118,17 @@ const handleClick = (event) => {

onMounted(() => {
document.addEventListener("click", handleClick);

// Gestion du rachargement de page au clic sur le bouton charger plus de resultats
router.afterEach(() => {
window.scrollTo(0, scrollPosition.value);
})
});

onBeforeUnmount(() => {
document.removeEventListener("click", handleClick);

router.afterEach(() => {});
});

/**
Expand Down Expand Up @@ -155,6 +165,7 @@ function updateShowingNumber(newValue) {
}

function addTenResultsToList() {
scrollPosition.value = window.scrollY;
currentShowingNumber.value += 10;
setShowingNumber(currentShowingNumber.value);
}
Expand Down
54 changes: 26 additions & 28 deletions components/common/results/ResultPagination.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,38 +55,32 @@ const props = defineProps({
}
});

const currentPageNumber = ref();
const currentShowingNumber = ref();

onMounted(() => {
currentPageNumber.value = props.currentPageNumber;
currentShowingNumber.value = props.currentShowingNumber;
});
const currentPageNumber = ref(props.currentPageNumber);
const currentShowingNumber = ref(props.currentShowingNumber);

const nbPages = computed(() => {
if (currentShowingNumber.value && props.nbResults) return Math.ceil(props.nbResults / currentShowingNumber.value);
else return 0;
if (currentShowingNumber.value && props.nbResults) {
return Math.ceil(props.nbResults / currentShowingNumber.value);
} else {
return 0;
}
});


const { xlAndUp } = useDisplay();

const totalVisible = computed(() => {
if (nbPages.value > 10000)
if (xlAndUp.value) return 5;
else return 2;
else if (nbPages.value > 100)
if (xlAndUp.value) return 8;
else return 2;
else
if (xlAndUp.value) return "10";
else return 2;
})
if (nbPages.value > 10000) {
return xlAndUp.value ? 5 : 2;
} else if (nbPages.value > 100) {
return xlAndUp.value ? 8 : 2;
} else {
return xlAndUp.value ? "10" : 2;
}
});

/**
* Fonctions
*/

function bottomScrollsToTop() {
if (props.type === "bottom") scrollToTop();
}
Expand All @@ -101,14 +95,14 @@ function updatePageNumberFromSortingSelect(pageNumber) {
* Watchers
*/
watch(currentPageNumber, (newCurrentPageNumber, previousCurrentPageNumber) => {
if (typeof previousCurrentPageNumber !== "undefined") {
if (newCurrentPageNumber !== previousCurrentPageNumber) {
setPageNumber(newCurrentPageNumber);
emit("updatePage", newCurrentPageNumber);
}
});

watch(currentShowingNumber, (newShowingNumber, previousShowingNumber) => {
if (typeof previousShowingNumber !== 'undefined') {
if (newShowingNumber !== previousShowingNumber) {
setShowingNumber(newShowingNumber);
setPageNumber(1);
emit("updateShowingNumber", newShowingNumber);
Expand All @@ -117,14 +111,18 @@ watch(currentShowingNumber, (newShowingNumber, previousShowingNumber) => {
});

/**
* Watcher des autres barres de pagination
* Watcher pour props (éviter les updates récursifs)
*/
watch(() => props.currentPageNumber, () => {
currentPageNumber.value = props.currentPageNumber;
watch(() => props.currentPageNumber, (newVal) => {
if (newVal !== currentPageNumber.value) {
currentPageNumber.value = newVal;
}
});

watch(() => props.currentShowingNumber, () => {
currentShowingNumber.value = props.currentShowingNumber;
watch(() => props.currentShowingNumber, (newVal) => {
if (newVal !== currentShowingNumber.value) {
currentShowingNumber.value = newVal;
}
});
</script>

Expand Down
2 changes: 1 addition & 1 deletion components/personnes/PersonneView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ function conversionMotClesFormatTheses(motsCles) {
{
keyword: elem,
type: "sujet",
query: "sujetsLibelle:\"" + elem + "\" OU sujetsRameauLibelle:\"" + elem + "\""
query: "(sujetsLibelle:(" + elem + ") OU sujetsRameauLibelle:(" + elem + "))"
}))
}
return { mapSujets: keyword };
Expand Down
54 changes: 41 additions & 13 deletions composables/useStrategyAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const checkedFilters = ref([]);
const currentWorkingFacetName = ref("");
const labelMap = ref(new Map());
const facetsArray = ref([]);
const isAdvanced = ref();
let updateTimeout = null;

export default function() {
// import fonctions
Expand Down Expand Up @@ -43,22 +45,37 @@ export default function() {
*/
function setPageNumber(value) {
currentPageNumber.value = parseInt(value);
updateURL();
updateURLDebounced();
}

function setShowingNumber(value) {
currentShowingNumber.value = parseInt(value);
updateURL();
updateURLDebounced();
}

function setSorting(value) {
currentSorting.value = value;
updateURL();
updateURLDebounced();
}

function setDomaine(newDomain) {
domaine.value = newDomain;
updateURL();
updateURLDebounced();
}

/**
* Permet de limiter le nombre d'appels à la méthode updateURL()
*/
function updateURLDebounced() {
// Annule le précédent timeout si un appel est déjà en attente
if (updateTimeout) {
clearTimeout(updateTimeout);
}

// Planifie un nouvel appel après un délai court
updateTimeout = setTimeout(() => {
updateURL();
}, 300);
}

function getCurrentSorting() {
Expand All @@ -79,7 +96,7 @@ export default function() {

return new Promise((resolve) => {
currentFacets.value = parseFacetsValuesArray(objectsArray);
updateURL();
updateURLDebounced();
checkedFilters.value = objectsArray;
resolve();
});
Expand Down Expand Up @@ -112,14 +129,28 @@ export default function() {
const startingParameterDomaine = getURLParameter("domaine");
const startingParameterPage = mobile.value ? 1 : parseInt(getURLParameter("page"));
const startingParameterShowingNumber = mobile.value ? 10 : parseInt(getURLParameter("nb"));
const startingParameterAdvanced = getURLParameter("avancee");

// Comparer les paramètres actuels avec ceux existants
if (
currentSorting.value === startingParameterTri &&
currentFacets.value === startingParameterFiltres &&
query.value === startingParameterQ &&
domaine.value === startingParameterDomaine &&
currentPageNumber.value === startingParameterPage &&
currentShowingNumber.value === startingParameterShowingNumber &&
isAdvanced.value === startingParameterAdvanced
) {
resolve(); // Ne pas mettre à jour si les paramètres sont les mêmes
}

currentSorting.value = startingParameterTri ? startingParameterTri : "pertinence";
currentFacets.value = startingParameterFiltres ? startingParameterFiltres : "";
query.value = (startingParameterQ && typeof startingParameterQ !== "undefined") ? startingParameterQ : "*";
domaine.value = startingParameterDomaine ? startingParameterDomaine : "theses";
currentPageNumber.value = startingParameterPage ? startingParameterPage : 1;
currentShowingNumber.value = startingParameterShowingNumber ? startingParameterShowingNumber : 10;

isAdvanced.value = startingParameterAdvanced ? startingParameterAdvanced : false;

resolve();
});
Expand All @@ -145,18 +176,15 @@ export default function() {
if (currentShowingNumber.value) params["nb"] = currentShowingNumber.value;
if (currentSorting.value) params["tri"] = currentSorting.value;
if (domaine.value) params["domaine"] = domaine.value;

const isAdvanced = useState("isAdvanced");
if(isAdvanced.value) {
params["avancee"] = "true";
}
if (isAdvanced.value) params["avancee"] = isAdvanced.value;

return params;
}

function updateURL() {
if (router.currentRoute._value.name === "resultats") {
const routerParams = setParameters();

router.replace({
name: "resultats",
query: routerParams
Expand Down Expand Up @@ -198,9 +226,9 @@ export default function() {
* Routes
*/
function queryAPI() {
updateURL();
updateURLDebounced();

const isAdvanced = useState("isAdvanced");
// const isAdvanced = useState("isAdvanced");

query.value = (typeof query.value === "undefined") ? "*" : query.value;

Expand Down
Loading