Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
iNeoO committed Nov 14, 2024
1 parent ebedc96 commit b38598e
Show file tree
Hide file tree
Showing 8 changed files with 1,433 additions and 975 deletions.
689 changes: 536 additions & 153 deletions package-lock.json

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions packages/backend/src/controllers/demandeSejour/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ module.exports = async function get(req, res, next) {
const { id: userId } = decoded;
log.d("userId", { userId });

const titles = [
"idFonctionnelle",
"departementSuivi",
"libelle",
"periode",
"dateDebut",
"dateFin",
"editedAt",
"statut",
"periode",
];
const titles = {
dateDebut: "ds.date_debut",
dateFin: "ds.date_fin",
departementSuivi: "ds.departement_suivi",
editedAt: "ds.edited_at",
idFonctionnelle: "ds.id_fonctionnelle",
libelle: "ds.libelle",
periode: "ds.periode",
siret: "o.personne_morale->>'siret'",
statut: "ds.statut",
};

const paginationParams = sanityzePaginationParams(req.query, {
sortDirection: titles,
sortBy: titles,
});
const filterParams = sanityzeFiltersParams(req.query, titles);
try {
Expand Down
20 changes: 10 additions & 10 deletions packages/backend/src/helpers/queryParams.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ module.exports = {
}
const filters = Object.entries(filterParams)
.map(([key, value], index) => {
params.push(filterParams);
params.push(value);
if (Array.isArray(value)) {
return `${key} = ANY($${initialParams.length + index + 1})`;
}
return `${key} = $${initialParams.length + index + 1}`;
return `unaccent(${key}) ILIKE '%' || unaccent($${initialParams.length + index + 1}) || '%'`;
})
.join(" AND ");
return {
Expand All @@ -27,13 +27,11 @@ module.exports = {
limit = 10,
offset = 0,
sortBy = "",
sortDirection = "",
sortDirection = "ASC",
) => {
const validSort = sortBy ? `"${sortBy}"` : "";

const paginatedQuery = `
${query}
${validSort ? `ORDER BY ${validSort} ${sortDirection}` : ""}
${sortBy ? `ORDER BY ${sortBy} ${sortDirection}` : ""}
LIMIT $${params.length + 1}
OFFSET $${params.length + 2};
`;
Expand All @@ -50,9 +48,9 @@ module.exports = {
};
},
sanityzeFiltersParams: (queryParams, availableParams) =>
availableParams.reduce((acc, availableParam) => {
if (queryParams[availableParam]) {
acc[availableParam] = queryParams[availableParam];
Object.entries(availableParams).reduce((acc, [key, value]) => {
if (queryParams[key]) {
acc[value] = queryParams[key];
}
return acc;
}, {}),
Expand All @@ -70,7 +68,9 @@ module.exports = {
offset: isNaN(parseInt(offset, 10))
? (defaultParams?.offset ?? defaultOffset)
: parseInt(offset, 10),
sortBy: defaultParams?.sortBy?.includes(sortBy) ? sortBy : "",
sortBy: Object.prototype.hasOwnProperty.call(defaultParams.sortBy, sortBy)
? defaultParams.sortBy[sortBy]
: "",
sortDirection: defaultSortDirection.includes(sortDirection)
? sortDirection
: "",
Expand Down
8 changes: 5 additions & 3 deletions packages/backend/src/services/DemandeSejour.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-param-reassign */
const dayjs = require("dayjs");
const logger = require("../utils/logger");
const { applyPagination } = require("../helpers/queryParams");
const { applyFilters, applyPagination } = require("../helpers/queryParams");
const pool = require("../utils/pgpool").getPool();
const dsStatus = require("../helpers/ds-statuts");

Expand Down Expand Up @@ -901,11 +901,13 @@ module.exports.cancel = async (declarationId, userId) => {
module.exports.getNext = async (
organismesId,
{ sortBy, sortDirection, limit, offset },
filterParams,
) => {
const queryGet = query.getNext();
const filterQuery = applyFilters(queryGet, [organismesId], filterParams);
const paginatedQuery = applyPagination(
queryGet,
[organismesId],
filterQuery.query,
filterQuery.params,
limit,
offset,
sortBy,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<DsfrInputGroup
v-model="idFonctionnelleSync"
type="text"
name="libelle"
name="idFonmctionnelle"
label="Numéro de déclaration"
placeholder="Numéro de déclaration"
:label-visible="true"
Expand Down Expand Up @@ -88,22 +88,7 @@ const props = defineProps<{
status: string[];
}>();
const defaultStatus = [
demandesSejours.statuts.TRANSMISE,
demandesSejours.statuts.EN_COURS,
demandesSejours.statuts.A_MODIFIER,
demandesSejours.statuts.REFUSEE,
demandesSejours.statuts.ATTENTE_8_JOUR,
demandesSejours.statuts.TRANSMISE_8J,
demandesSejours.statuts.EN_COURS_8J,
demandesSejours.statuts.A_MODIFIER_8J,
demandesSejours.statuts.REFUSEE_8J,
demandesSejours.statuts.VALIDEE_8J,
demandesSejours.statuts.SEJOUR_EN_COURS,
demandesSejours.statuts.TERMINEE,
demandesSejours.statuts.ANNULEE,
demandesSejours.statuts.ABANDONNEE,
];
const defaultStatus = [...Object.values(demandesSejours.statuts)];
const emits = defineEmits<{
"update:idFonctionnelle": [string];
Expand Down
231 changes: 231 additions & 0 deletions packages/frontend-usagers/src/components/demande-sejour/table.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
<template>
<DemandeSejourTableFilters
v-model:id-fonctionnelle="idFonctionnelle"
v-model:libelle="libelle"
v-model:siret="siret"
v-model:status="status"
v-model:departement-suivi="departementSuivi"
v-model:saison="saison"
@filters-update="updateData"
/>
<DsfrDataTableV2Wrapper
v-model:limit="limit"
v-model:offset="offset"
v-model:sort="sort"
v-model:sort-direction="sortDirection"
:titles="titles"
:table-title="title"
:data="data"
:total="total"
row-id="declarationId"
is-bordered
is-sortable
@update-data="updateData"
>
<template #cell:dateDebut="{ row }">
{{ displayDate(row.dateDebut) }}
</template>
<template #cell:dateFin="{ row }">
{{ displayDate(row.dateDebut) }}
</template>
<template #cell-status="{ row }">
<div>
<!-- TODO -->
<DemandesSejourDemandeStatusBadge :statut="row.statut" />
</div>
</template>
<template #cell:custom-edit="{ row }">
<NuxtLink :to="`/demande-sejour/${row.declarationId}?defaultTabIndex=0`">
<DsfrButton
label="naviguer vers la demande séjour"
icon="ri:arrow-right-s-line"
icon-only
primary
size="small"
type="button"
/>
</NuxtLink>
</template>

Check warning on line 48 in packages/frontend-usagers/src/components/demande-sejour/table.vue

View workflow job for this annotation

GitHub Actions / lint-format-test

Insert `··`
</DsfrDataTableV2Wrapper>
</template>

<script setup>
import { NuxtLink } from "#build/components";
import dayjs from "dayjs";
const route = useRoute();
const demandeSejourStore = useDemandeSejourStore();
const departementStore = useDepartementStore();
const data = computed(() => demandeSejourStore.demandes);
const total = computed(() => demandeSejourStore.total);
const { query } = route;
const titles = [
{
key: "idFonctionnelle",
label: "Numéro de déclaration",
options: {
isSortable: true,
},
},
{
key: "departementSuivi",
label: "Département instructeur",
options: {
isSortable: true,
},
},
{
key: "siret",
label: "Établissement déclarant",
options: {
isSortable: true,
},
},
{
key: "libelle",
label: "Nom du séjour",
options: {
isSortable: true,
},
},
{
key: "periode",
label: "Saison",
options: {
isSortable: true,
},
},
{
key: "dateDebut",
label: "Date de début",
options: {
isSortable: true,
},
},
{
key: "dateDebut",
label: "Date de fin",
options: {
isSortable: true,
},
},
{
key: "statut",
label: "Statut",
options: {
isSortable: true,
},
},
{
key: "editedAt",
label: "Date de modification",
options: {
isSortable: true,
},
},
{
key: "custom-edit",
label: "Edit",
options: {
isFixedRight: true,
},
},
];
const sortableTitles = titles.flatMap((title) =>
title.options?.isSortable ? [title.key] : [],
);
const defaultStatus = [...Object.values(DeclarationSejour.statuts)];
const defaultDepartements = computed(() =>
departementStore.departements.map((d) => ({ label: d.text, value: d.value })),
);
const idFonctionnelle = ref(query.idFonctionnelle ?? "");
const libelle = ref(query.libelle ?? "");
const siret = ref(query.siret ?? "");
const departementSuivi = ref([]);
const status = ref(
query.statuts
? query.statuts
.split(",")
.filter((statut) => Object.values(defaultStatus).includes(statut))
: [],
);
const limit = ref(parseInt(query.limit, 10) || 10);
const offset = ref(parseInt(query.offset, 10) || 0);
const sort = ref(sortableTitles.includes(query.sort) ? query.sort : "");
const sortDirection = ref(
["", "asc", "desc"].includes(query.sortDirection) ? query.sortDirection : "",
);
const isValidParams = (params) =>
params !== null &&
params !== "" &&
(!Array.isArray(params) || params.length > 0);
const getSearchParams = () => ({
...(isValidParams(idFonctionnelle.value)
? { idFonctionnelle: idFonctionnelle.value }
: {}),
...(isValidParams(libelle.value) ? { libelle: libelle.value } : {}),
...(isValidParams(organisme.value) ? { organisme: organisme.value } : {}),
...(isValidParams(status.value) ? { statuts: status.value.join(",") } : {}),
});
let timeout = null;
const updateData = () => {
if (timeout) {
clearTimeout(timeout);
}
timeout = setTimeout(() => {
const query = {
limit: limit.value,
offset: offset.value,
...(isValidParams(sort.value) ? { sortBy: sort.value } : {}),
...(isValidParams(sortDirection.value)
? { sortDirection: sortDirection.value.toUpperCase() }
: {}),
search: getSearchParams(),
};
demandeSejourStore.fetchDemandes(query);
navigateTo({
query: {
limit: limit.value,
offset: offset.value,
...(isValidParams(sort.value) ? { sortBy: sort.value } : {}),
...(isValidParams(sortDirection.value)
? { sortDirection: sortDirection.value }
: {}),
...getSearchParams(),
},
});
}, 300);
};
onUnmounted(() => {
if (timeout) {
clearTimeout(timeout);
}
});
const displayDate = (date) => dayjs(date).format("DD/MM/YYYY");
const init = async () => {
await departementStore.fetch();
departementSuivi.value = query.departementSuivi
? query.departementSuivi
.split(",")
.filter((dep) => defaultDepartements.some((d) => d.value === dep))
: [];
updateData();
};
init();
</script>
Loading

0 comments on commit b38598e

Please sign in to comment.