Skip to content

Commit

Permalink
Display cancellation reason + disable cancellation form if event not …
Browse files Browse the repository at this point in the history
…cancelled in Geotrek
  • Loading branch information
amandine-sahl committed Jun 30, 2023
1 parent 67c3a0d commit 05e9d0c
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 14 deletions.
13 changes: 13 additions & 0 deletions backend/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,19 @@ class GTEvents(db.Model):
published = db.Column(db.Boolean)
deleted = db.Column(db.Boolean)
cancelled = db.Column(db.Boolean)
cancellation_reason_id = db.Column(
db.Integer, db.ForeignKey("public.tourism_cancellationreason.id")
)
meeting_point = db.Column(db.Unicode)
start_time = db.Column(db.Time)

reservations = db.relationship(
"TReservations", lazy="joined", backref=db.backref("event", lazy="joined")
)
bilan = db.relationship("TAnimationsBilans", lazy="joined", uselist=False)
cancellation_reason = db.relationship(
"GTCancellationReason", lazy="select", uselist=False
)
info = db.relationship("TEventInfo", lazy="joined", uselist=False)
type = db.relationship("GTEventType", lazy="joined")

Expand Down Expand Up @@ -164,6 +170,13 @@ def is_reservation_possible_for(self, nb_people):
return False


class GTCancellationReason(db.Model):
__tablename__ = "tourism_cancellationreason"
__table_args__ = {"schema": "public"}
id = db.Column(db.Integer, primary_key=True)
label = db.Column(db.Unicode, nullable=False)


class GTEventType(db.Model):
__tablename__ = "tourism_touristiceventtype"
__table_args__ = {"schema": "public"}
Expand Down
8 changes: 8 additions & 0 deletions backend/core/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
TAnimationsBilans,
VExportBilan,
TEventInfo,
GTCancellationReason,
)


Expand Down Expand Up @@ -122,6 +123,12 @@ class Meta:
load_instance = True


class GTCancellationReasonSchema(SQLAlchemyAutoSchema):
class Meta:
model = GTCancellationReason
load_instance = True


class TAnimationsBilansSchema(SQLAlchemyAutoSchema):
class Meta:
model = TAnimationsBilans
Expand Down Expand Up @@ -158,6 +165,7 @@ class Meta:

type = fields.Nested(lambda: GTEventTypeSchema)
bilan = fields.Nested(lambda: TAnimationsBilansSchema)
cancellation_reason = fields.Nested(lambda: GTCancellationReasonSchema)
sum_participants = fields.Integer(dump_only=True)
sum_participants_liste_attente = fields.Integer(dump_only=True)
sum_participants_adultes = fields.Integer(dump_only=True)
Expand Down
6 changes: 3 additions & 3 deletions front-vite/src/components/EventCancelForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@
:disabled="Object.keys(errors).length > 0 || saving"
@click="onSubmit($event, values)"
>
<i class="pi pi-exclamation-triangle mr-2" />
<i class="pi pi-exclamation-triangle mr-2" />
<span v-if="annulation">
{{ saving ? 'Dé annulation en cours...' : 'Dé annuler l\'animation' }}
</span>
<span v-else>
{{ saving ? 'Annulation en cours...' : 'Annuler l\'animation' }}
</span>

</button>
<div v-if="error" class="text-red-500">
Une erreur est survenue :
Expand Down Expand Up @@ -72,7 +72,7 @@ const formSchema = yup.object().shape({
async function onSubmit (event: any, values: any) {
confirm.require({
target: event.target,
message: props.annulation
message: props.annulation
? 'Êtes vous sûr de vouloir dé-annuler cette animation ?'
: 'Êtes vous sûr de vouloir annuler cette animation ?',
icon: 'pi pi-exclamation-triangle',
Expand Down
29 changes: 18 additions & 11 deletions front-vite/src/views/EventListingView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
:attente-nb="data.sum_participants_liste_attente"
:display-text="false"
/>
{{ formatDateString(data.begin_date) || '?' }}
{{ formatDateString(data.begin_date) || '?' }}
<span v-if="data.end_date">
- {{ formatDateString(data.end_date) }}
</span>
Expand Down Expand Up @@ -208,6 +208,10 @@
<h2 class="text-red font-medium text-xl">Animation annulée</h2>
<div>
<strong> Raison: </strong>
<span>{{ selectedEvent.cancellation_reason?.label }}</span>
</div>
<div>
<strong> Commentaire: </strong>
<span>{{ selectedEvent.bilan?.raison_annulation }}</span>
</div>
</div>
Expand Down Expand Up @@ -358,7 +362,7 @@
:error="bilanError"
:original-data="selectedEvent.bilan"
:summary="selectedEventSummary"
@submit="onSaveBilan"
/>
Expand All @@ -374,15 +378,17 @@
<p-message severity="warn" :closable="false">
<div class="space-y-4 ml-4">
<p>L'annulation d'une animation doit d'abord être faite dans GeoTrek.</p>
<p>À partir de l'outil de réservation, l'annulation va déclencher l'envoi d'un mail à tous les inscrits
<p v-if="selectedEvent.cancelled == false">L'annulation d'une animation doit d'abord être faite dans GeoTrek.</p>

<p>Une fois l'animation annulée dans GeoTrek, le formulaire ci dessous va déclencher l'envoi d'un mail à tous les inscrits
pour leur préciser l'annulation de l'animation.</p>
</div>
</p-message>

{{ selectedEventCanceled }} , {{ selectedEventBilanCanceled }}
<event-cancel-form
v-if="selectedEvent.cancelled == true"
:raison-annulation="selectedEvent.bilan?.raison_annulation"
:annulation="selectedEventCanceled"
:annulation="selectedEventBilanCanceled"
:error="bilanError"
@submit="onSaveBilan"
/>
Expand All @@ -396,7 +402,7 @@
<div class="text-center">
<p class="mt-6 text-base leading-7 text-gray-600">Merci de sélectioner une animation dans la liste de gauche.</p>
</div>
</div>
</section>
</main>
Expand Down Expand Up @@ -491,6 +497,7 @@ const formOpened = ref(false)
const selectedEvent = ref<any>(null)
const selectedEventId = ref(parseInt(currentRoute.params.id as string))
const selectedEventCanceled = computed(() => selectedEvent.value?.cancelled === true)
const selectedEventBilanCanceled = computed(() => selectedEvent.value?.bilan?.annulation === true)
const selectedEventInfoRDV = ref<ResaEventInfo>({
info_rdv: ''
})
Expand Down Expand Up @@ -521,7 +528,7 @@ async function loadEvents () {
if (currentValue instanceof Date) {
params[key] = currentValue.toISOString()
}
}
}
})
try {
const data = await getEvents(params)
Expand All @@ -546,8 +553,8 @@ async function loadReservations (page: number = 0) {
resas.value = { results: [], total: 0 }
resas.value = await getReservations({
page: page + 1,
event_id: selectedEvent.value.id
})
event_id: selectedEvent.value.id
})
}
function onPageReservations($event: any) {
loadReservations($event.page)
Expand Down Expand Up @@ -712,7 +719,7 @@ onBeforeMount(async () => {
</script>

<style>
.p-tabview .p-tabview-panel,
.p-tabview .p-tabview-panel,
.p-tabview .p-tabview-panels{
margin: 0;
padding: 0;
Expand Down

0 comments on commit 05e9d0c

Please sign in to comment.