prevent errors in javascript generation

This commit is contained in:
Arnaud Delcasse 2025-10-09 12:22:55 +02:00
parent 3cc4d9452a
commit 2e5351847d
3 changed files with 58 additions and 42 deletions

View File

@ -4,22 +4,24 @@
{{if eq (len .ViewState.bookings_history) 0}} {{if eq (len .ViewState.bookings_history) 0}}
<div class="m-10 text-center text-gray-600">Aucun trajet dans le passé</div> <div class="m-10 text-center text-gray-600">Aucun trajet dans le passé</div>
{{else}} {{else}}
{{$inrange := false}}
<div x-data="{ <div x-data="{
bookings: [ bookings: [
{{range $index, $booking := .ViewState.bookings_history}}{{if $index}},{{end}}{ {{range .ViewState.bookings_history}}{{if $inrange}},{{end}}{{$inrange = true}}{{$driver := index $.ViewState.drivers_map .Driver.Id}}{{$passenger := index $.ViewState.passengers_map .Passenger.Id}}{
id: '{{$booking.Id}}', id: '{{.Id}}',
driverId: '{{$booking.Driver.Id}}', driverId: '{{if .Driver}}{{.Driver.Id}}{{end}}',
driverFirstName: '{{ (index $.ViewState.drivers_map $booking.Driver.Id).Data.first_name }}', driverFirstName: '{{if $driver.ID}}{{ jsEscape $driver.Data.first_name }}{{end}}',
driverLastName: '{{ (index $.ViewState.drivers_map $booking.Driver.Id).Data.last_name }}', driverLastName: '{{if $driver.ID}}{{ jsEscape $driver.Data.last_name }}{{end}}',
passengerId: '{{$booking.Passenger.Id}}', passengerId: '{{if .Passenger}}{{.Passenger.Id}}{{end}}',
passengerFirstName: '{{ (index $.ViewState.passengers_map $booking.Passenger.Id).Data.first_name }}', passengerFirstName: '{{if $passenger.Data}}{{ jsEscape $passenger.Data.first_name }}{{end}}',
passengerLastName: '{{ (index $.ViewState.passengers_map $booking.Passenger.Id).Data.last_name }}', passengerLastName: '{{if $passenger.Data}}{{ jsEscape $passenger.Data.last_name }}{{end}}',
pickupAddress: '{{$booking.PassengerPickupAddress}}', pickupAddress: '{{ jsEscape .PassengerPickupAddress }}',
dropAddress: '{{$booking.PassengerDropAddress}}', dropAddress: '{{ jsEscape .PassengerDropAddress }}',
pickupDate: '{{ timeFormat $booking.PassengerPickupDate.AsTime "02/01/2006 15:04" }}', pickupDate: '{{if .PassengerPickupDate}}{{ timeFormat .PassengerPickupDate.AsTime "02/01/2006 15:04" }}{{end}}',
status: '{{$booking.Status.String}}', status: '{{.Status.String}}',
price: '{{if $booking.Price}}{{ printf "%.2f" (round2 $booking.Price.Amount) }}{{else}}N/A{{end}}', price: '{{if .Price}}{{ printf "%.2f" (round2 .Price.Amount) }}{{else}}N/A{{end}}',
currency: '{{if $booking.Price}}{{$booking.Price.Currency}}{{end}}' currency: '{{if .Price}}{{.Price.Currency}}{{end}}'
}{{end}} }{{end}}
], ],
currentPage: 1, currentPage: 1,

View File

@ -4,22 +4,24 @@
{{if eq (len .ViewState.bookings) 0}} {{if eq (len .ViewState.bookings) 0}}
<div class="m-10 text-center text-gray-600">Aucun trajet déclaré</div> <div class="m-10 text-center text-gray-600">Aucun trajet déclaré</div>
{{else}} {{else}}
{{$inrange := false}}
<div x-data="{ <div x-data="{
bookings: [ bookings: [
{{range $index, $booking := .ViewState.bookings}}{{if $index}},{{end}}{ {{range .ViewState.bookings}}{{if $inrange}},{{end}}{{$inrange = true}}{{$driver := index $.ViewState.drivers_map .Driver.Id}}{{$passenger := index $.ViewState.passengers_map .Passenger.Id}}{
id: '{{$booking.Id}}', id: '{{.Id}}',
driverId: '{{$booking.Driver.Id}}', driverId: '{{if .Driver}}{{.Driver.Id}}{{end}}',
driverFirstName: '{{ jsEscape (index $.ViewState.drivers_map $booking.Driver.Id).Data.first_name }}', driverFirstName: '{{if $driver.ID}}{{ jsEscape $driver.Data.first_name }}{{end}}',
driverLastName: '{{ jsEscape (index $.ViewState.drivers_map $booking.Driver.Id).Data.last_name }}', driverLastName: '{{if $driver.ID}}{{ jsEscape $driver.Data.last_name }}{{end}}',
passengerId: '{{$booking.Passenger.Id}}', passengerId: '{{if .Passenger}}{{.Passenger.Id}}{{end}}',
passengerFirstName: '{{ jsEscape (index $.ViewState.passengers_map $booking.Passenger.Id).Data.first_name }}', passengerFirstName: '{{if $passenger.Data}}{{ jsEscape $passenger.Data.first_name }}{{end}}',
passengerLastName: '{{ jsEscape (index $.ViewState.passengers_map $booking.Passenger.Id).Data.last_name }}', passengerLastName: '{{if $passenger.Data}}{{ jsEscape $passenger.Data.last_name }}{{end}}',
pickupAddress: '{{ jsEscape $booking.PassengerPickupAddress }}', pickupAddress: '{{ jsEscape .PassengerPickupAddress }}',
dropAddress: '{{ jsEscape $booking.PassengerDropAddress }}', dropAddress: '{{ jsEscape .PassengerDropAddress }}',
pickupDate: '{{ timeFormat $booking.PassengerPickupDate.AsTime "02/01/2006 15:04" }}', pickupDate: '{{if .PassengerPickupDate}}{{ timeFormat .PassengerPickupDate.AsTime "02/01/2006 15:04" }}{{end}}',
status: '{{$booking.Status.String}}', status: '{{.Status.String}}',
price: '{{if $booking.Price}}{{ printf "%.2f" (round2 $booking.Price.Amount) }}{{else}}N/A{{end}}', price: '{{if .Price}}{{ printf "%.2f" (round2 .Price.Amount) }}{{else}}N/A{{end}}',
currency: '{{if $booking.Price}}{{$booking.Price.Currency}}{{end}}' currency: '{{if .Price}}{{.Price.Currency}}{{end}}'
}{{end}} }{{end}}
], ],
currentPage: 1, currentPage: 1,

View File

@ -4,22 +4,25 @@
{{if eq (len .ViewState.bookings_history) 0}} {{if eq (len .ViewState.bookings_history) 0}}
<div class="m-10 text-center text-gray-600">Aucun trajet dans le passé</div> <div class="m-10 text-center text-gray-600">Aucun trajet dans le passé</div>
{{else}} {{else}}
{{$inrange := false}}
<div x-data="{ <div x-data="{
bookings: [ bookings: [
{{range $index, $booking := .ViewState.bookings_history}}{{if $index}},{{end}}{ {{range .ViewState.bookings_history}}{{if $inrange}},{{end}}{{$inrange = true}}{{$driver := index $.ViewState.drivers_map .DriverId}}{{$passenger := index $.ViewState.passengers_map .PassengerId}}{
id: '{{$booking.Id}}', id: '{{.Id}}',
driverId: '{{$booking.DriverId}}', driverId: '{{.DriverId}}',
driverFirstName: '{{ (index $.ViewState.drivers_map $booking.DriverId).Data.first_name }}', driverFirstName: '{{if $driver.ID}}{{ jsEscape $driver.Data.first_name }}{{end}}',
driverLastName: '{{ (index $.ViewState.drivers_map $booking.DriverId).Data.last_name }}', driverLastName: '{{if $driver.ID}}{{ jsEscape $driver.Data.last_name }}{{end}}',
passengerId: '{{$booking.PassengerId}}', passengerId: '{{.PassengerId}}',
passengerFirstName: '{{ (index $.ViewState.passengers_map $booking.PassengerId).Data.first_name }}', passengerFirstName: '{{if $passenger.Data}}{{ jsEscape $passenger.Data.first_name }}{{end}}',
passengerLastName: '{{ (index $.ViewState.passengers_map $booking.PassengerId).Data.last_name }}', passengerLastName: '{{if $passenger.Data}}{{ jsEscape $passenger.Data.last_name }}{{end}}',
pickupLabel: '{{$booking.Journey.PassengerPickup.Properties.label}}', pickupLabel: '{{if .Journey}}{{ jsEscape .Journey.PassengerPickup.Properties.label }}{{end}}',
dropLabel: '{{$booking.Journey.PassengerDrop.Properties.label}}', dropLabel: '{{if .Journey}}{{ jsEscape .Journey.PassengerDrop.Properties.label }}{{end}}',
pickupDate: '{{ $booking.Journey.PassengerPickupDate.Format "02/01/2006 15:04" }}', pickupDate: '{{if .Journey}}{{ timeFormat .Journey.PassengerPickupDate "02/01/2006 15:04" }}{{end}}',
status: '{{$booking.Status}}', status: '{{.Status}}',
price: '{{ printf "%.2f" (round2 $booking.Journey.Price.Amount) }}', price: '{{if .Journey}}{{ printf "%.2f" (round2 .Journey.Price.Amount) }}{{end}}',
currency: '{{$booking.Journey.Price.Currency}}' currency: '{{if .Journey}}{{.Journey.Price.Currency}}{{end}}',
motivation: {{ if .Data.motivation }}'{{ jsEscape .Data.motivation }}'{{ else }}''{{ end }}
}{{end}} }{{end}}
], ],
currentPage: 1, currentPage: 1,
@ -46,6 +49,10 @@
if (status === 'VALIDATED') return { class: 'p-1 text-xs bg-co-green rounded-xl', text: 'Validé' }; if (status === 'VALIDATED') return { class: 'p-1 text-xs bg-co-green rounded-xl', text: 'Validé' };
if (status === 'CANCELLED') return { class: 'p-1 text-xs bg-co-red text-white rounded-xl', text: 'Annulé' }; if (status === 'CANCELLED') return { class: 'p-1 text-xs bg-co-red text-white rounded-xl', text: 'Annulé' };
return { class: '', text: '' }; return { class: '', text: '' };
},
guaranteedMotivations: {{ json .ViewState.guaranteed_trip_motivations }},
isGuaranteedTrip(motivation) {
return this.guaranteedMotivations.includes(motivation);
} }
}"> }">
@ -80,6 +87,11 @@
<td class="whitespace-nowrap py-4 pl-4 pr-3 text-sm sm:pl-6" x-text="booking.pickupDate"></td> <td class="whitespace-nowrap py-4 pl-4 pr-3 text-sm sm:pl-6" x-text="booking.pickupDate"></td>
<td class="whitespace-nowrap py-4 pl-4 pr-3 text-sm sm:pl-6"> <td class="whitespace-nowrap py-4 pl-4 pr-3 text-sm sm:pl-6">
<span :class="getStatusBadge(booking.status).class" x-text="getStatusBadge(booking.status).text"></span> <span :class="getStatusBadge(booking.status).class" x-text="getStatusBadge(booking.status).text"></span>
<template x-if="booking.motivation && isGuaranteedTrip(booking.motivation)">
<div class="mt-4">
<span class="text-xs p-2 bg-co-green text-white rounded-2xl" x-text="'Trajet garanti : ' + booking.motivation"></span>
</div>
</template>
</td> </td>
<td class="whitespace-nowrap py-4 pl-4 pr-3 text-sm sm:pl-6"> <td class="whitespace-nowrap py-4 pl-4 pr-3 text-sm sm:pl-6">
<span x-text="booking.price + ' ' + booking.currency"></span> <span x-text="booking.price + ' ' + booking.currency"></span>