-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
1,433 additions
and
975 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
231 changes: 231 additions & 0 deletions
231
packages/frontend-usagers/src/components/demande-sejour/table.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
</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> |
Oops, something went wrong.