Skip to content

Commit

Permalink
fix(Tableau de bord): Pour l'année en cours, afficher la graphe appro…
Browse files Browse the repository at this point in the history
… des achats si l'outil suivi achats est utilisé (#4762)

Co-authored-by: Charline Laporte <charline.laporte@beta.gouv.fr>
Co-authored-by: Raphaël Odini <raphodn@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 17, 2024
1 parent e5eae34 commit f963e11
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions frontend/src/views/DashboardManager/EgalimProgression.vue
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ export default {
diagnosticYears: years,
allowedYears: years.map((year) => ({ text: year, value: year })),
showTeledeclarationPreview: false,
purchasesSummary: undefined,
}
},
computed: {
Expand All @@ -199,6 +200,9 @@ export default {
return null
},
approDiagnostic() {
if (this.isCurrentYear && this.purchasesSummary && this.purchasesSummary.valueTotalHt !== 0) {
return this.purchasesSummary
}
return this.centralDiagnostic || this.canteenDiagnostic
},
otherMeasuresDiagnostic() {
Expand Down Expand Up @@ -298,13 +302,31 @@ export default {
this.showTeledeclarationPreview = false
})
},
fetchPurchasesSummary() {
this.purchasesSummary = null
if (this.canteen?.id) {
return fetch(`/api/v1/canteenPurchasesSummary/${this.canteen.id}?year=${this.year}`)
.then((response) => (response.ok ? response.json() : {}))
.then((response) => (this.purchasesSummary = response))
.catch((e) => {
this.$store.dispatch("notifyServerError", e)
})
}
},
},
mounted() {
if (this.$route.query?.year && this.diagnosticYears.indexOf(+this.$route.query.year) > -1) {
this.year = +this.$route.query.year
this.$router.replace({ query: {} })
}
},
watch: {
year() {
if (this.isCurrentYear && !this.purchasesSummary) {
this.fetchPurchasesSummary()
}
},
},
}
</script>
Expand Down

0 comments on commit f963e11

Please sign in to comment.