refactor: mutualiser les templates booking-display en 3 partials partagés

This commit is contained in:
Arnaud Delcasse
2026-02-26 17:50:36 +01:00
parent 590bc4ff6a
commit 2f6a368523
6 changed files with 173 additions and 106 deletions

View File

@@ -0,0 +1,51 @@
{{define "booking_documents"}}
<div>
<p class="text-sm font-medium text-gray-500 my-4">Documents</p>
{{if eq (len .ViewState.documents) 0}}
<p class="p-12 text-gray-500 text-center text-md">Aucun document</p>
{{end}}
{{if gt (len .ViewState.documents) 0}}
<div class="-mx-4 mb-10 ring-1 ring-gray-300 sm:-mx-6 md:mx-0 md:rounded-lg">
<table class="min-w-full divide-y divide-gray-300 table-fixed">
<thead>
<tr>
<th scope="col" class="py-3.5 pl-4 pr-3 text-left text-sm font-semibold text-gray-900 sm:pl-6">Type</th>
<th scope="col" class="hidden px-3 py-3.5 text-left text-sm font-semibold text-gray-900 lg:table-cell">Nom du document</th>
<th scope="col" class="hidden px-3 py-3.5 text-left text-sm font-semibold text-gray-900 lg:table-cell">Ajout&eacute; le</th>
<th scope="col" class="relative py-3.5 pl-3 pr-4 sm:pr-6">
<span class="sr-only">Actions</span>
</th>
</tr>
</thead>
<tbody>
{{range .ViewState.documents}}
<tr>
<td class="relative py-4 pl-4 sm:pl-6 pr-3 text-sm">
<div class="font-medium text-gray-900">
<span class="bg-co-blue text-xs text-white rounded-xl p-1 mr-2">{{index $.ViewState.file_types_map .Metadata.Type}}</span>
</div>
</td>
<td class="px-3 py-3.5 text-sm text-gray-900 table-cell max-w-10 overflow-hidden">
<p class=" overflow-hidden">{{.Metadata.Name}}</p>
</td>
<td class="px-3 py-3.5 text-sm text-gray-500 lg:table-cell">{{.LastModified.Format "02/01/2006"}}</td>
<td class="relative py-3.5 pl-3 pr-4 sm:pr-6 text-right text-sm font-medium">
<a href="/app/vehicles/bookings/{{$.ViewState.booking.ID}}/documents/{{.FileName}}" target="_blank">
<button type="button" class="inline-flex items-center rounded-md border border-gray-300 bg-white px-3 py-2 text-sm font-medium leading-4 text-gray-700 shadow-sm hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-co-blue focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-30">Voir<span class="sr-only"> le document</span></button>
</a>
</td>
</tr>
{{end}}
<!-- More plans... -->
</tbody>
</table>
</div>
{{end}}
</div>
{{end}}

View File

@@ -0,0 +1,16 @@
{{define "booking_status_badge"}}
{{if eq .ViewState.status_management "manual"}}
{{$currentStatus := .ViewState.booking.ManualStatus}}
{{range .ViewState.status_options}}
{{if eq (index . "name") $currentStatus}}
{{if eq (index . "meta_status") "open"}}
<span class="ml-2 p-1 px-3 text-xs bg-co-blue text-white rounded-2xl align-middle">{{index . "label"}}</span>
{{else if eq (index . "meta_status") "active"}}
<span class="ml-2 p-1 px-3 text-xs bg-co-green text-white rounded-2xl align-middle">{{index . "label"}}</span>
{{else if eq (index . "meta_status") "closed"}}
<span class="ml-2 p-1 px-3 text-xs bg-co-red text-white rounded-2xl align-middle">{{index . "label"}}</span>
{{end}}
{{end}}
{{end}}
{{end}}
{{end}}

View File

@@ -0,0 +1,43 @@
{{define "booking_status_history"}}
{{if eq .ViewState.status_management "manual"}}
{{if .ViewState.booking.StatusHistory}}
<div class="py-4 sm:py-5">
<p class="text-sm font-medium text-gray-500 mb-4">Historique des statuts</p>
<div class="flow-root">
<ul role="list" class="-mb-8">
{{range .ViewState.booking.StatusHistory}}
<li>
<div class="relative pb-8">
<div class="relative flex space-x-3">
<div>
<span class="h-8 w-8 rounded-full bg-gray-200 flex items-center justify-center ring-8 ring-white">
<svg class="h-4 w-4 text-gray-500" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" d="M7.5 21L3 16.5m0 0L7.5 12M3 16.5h13.5m0-13.5L21 7.5m0 0L16.5 12M21 7.5H7.5" />
</svg>
</span>
</div>
<div class="flex min-w-0 flex-1 justify-between space-x-4 pt-1.5">
<div>
<p class="text-sm text-gray-500">
{{if .FromStatus}}{{$from := .FromStatus}}{{range $.ViewState.status_options}}{{if eq (index . "name") $from}}{{index . "label"}}{{end}}{{end}} &rarr; {{end}}{{$to := .ToStatus}}{{range $.ViewState.status_options}}{{if eq (index . "name") $to}}{{index . "label"}}{{end}}{{end}}
par <a href="/app/members/{{.UserID}}" class="font-medium text-co-blue hover:underline">{{.UserName}}</a>
({{.GroupName}})
</p>
{{if .Comment}}
<p class="mt-1 text-xs text-gray-400">{{.Comment}}</p>
{{end}}
</div>
<div class="whitespace-nowrap text-right text-sm text-gray-500">
{{.Date.Format "02/01/2006 15:04"}}
</div>
</div>
</div>
</div>
</li>
{{end}}
</ul>
</div>
</div>
{{end}}
{{end}}
{{end}}

View File

@@ -72,7 +72,10 @@
<div class="bg-white px-4 py-5 border-b border-gray-200 sm:px-6">
<div class="-ml-4 -mt-4 flex justify-between items-center flex-wrap sm:flex-nowrap">
<div class="ml-4 mt-4">
<h3 class="text-lg leading-6 font-medium text-gray-900">Réservation</h3>
<h3 class="text-lg leading-6 font-medium text-gray-900">
Réservation
{{template "booking_status_badge" .}}
</h3>
<p class="mt-1 text-sm text-gray-500">Informations utiles sur la réservation.</p>
</div>
<div class="ml-4 mt-4 flex-shrink-0">
@@ -101,9 +104,7 @@
<dt class="text-sm font-medium text-gray-500">Réservé par</dt>
<dd class="mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2">
{{if .ViewState.booking.Data.booked_by.user}}
<a href="/app/members/{{.ViewState.booking.Data.booked_by.user.id}}" class="flex inline">
<img class="h-5 w-5 rounded-co mr-1"
src="/app/members/{{.ViewState.booking.Data.booked_by.user.id}}/picture" alt="">
<a href="/app/members/{{.ViewState.booking.Data.booked_by.user.id}}" class="text-co-blue hover:underline">
{{.ViewState.booking.Data.booked_by.user.display_name}}
</a>
{{end}}
@@ -141,55 +142,8 @@
<dd class="mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2">{{(timeFrom .ViewState.booking.Enddate).Format
"02/01/2006 à 15:04"}}</dd>
</div>
<div>
<p class="text-sm font-medium text-gray-500 my-4">Documents</p>
{{if eq (len .ViewState.documents) 0}}
<p class="p-12 text-gray-500 text-center text-md">Aucun document</p>
{{end}}
{{if gt (len .ViewState.documents) 0}}
<div class="-mx-4 mb-10 ring-1 ring-gray-300 sm:-mx-6 md:mx-0 md:rounded-lg">
<table class="min-w-full divide-y divide-gray-300 table-fixed">
<thead>
<tr>
<th scope="col" class="py-3.5 pl-4 pr-3 text-left text-sm font-semibold text-gray-900 sm:pl-6">Type</th>
<th scope="col" class="hidden px-3 py-3.5 text-left text-sm font-semibold text-gray-900 lg:table-cell">Nom du document</th>
<th scope="col" class="hidden px-3 py-3.5 text-left text-sm font-semibold text-gray-900 lg:table-cell">Ajouté le</th>
<th scope="col" class="relative py-3.5 pl-3 pr-4 sm:pr-6">
<span class="sr-only">Actions</span>
</th>
</tr>
</thead>
<tbody>
{{range .ViewState.documents}}
<tr>
<td class="relative py-4 pl-4 sm:pl-6 pr-3 text-sm">
<div class="font-medium text-gray-900">
<span class="bg-co-blue text-xs text-white rounded-xl p-1 mr-2">{{index $.ViewState.file_types_map .Metadata.Type}}</span>
</div>
</td>
<td class="px-3 py-3.5 text-sm text-gray-900 table-cell max-w-10 overflow-hidden">
<p class=" overflow-hidden">{{.Metadata.Name}}</p>
</td>
<td class="px-3 py-3.5 text-sm text-gray-500 lg:table-cell">{{.LastModified.Format "02/01/2006"}}</td>
<td class="relative py-3.5 pl-3 pr-4 sm:pr-6 text-right text-sm font-medium">
<a href="/app/vehicles/bookings/{{$.ViewState.booking.ID}}/documents/{{.FileName}}" target="_blank">
<button type="button" class="inline-flex items-center rounded-md border border-gray-300 bg-white px-3 py-2 text-sm font-medium leading-4 text-gray-700 shadow-sm hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-co-blue focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-30">Voir<span class="sr-only"> le document</span></button>
</a>
</td>
</tr>
{{end}}
<!-- More plans... -->
</tbody>
</table>
</div>
{{end}}
</div>
{{template "booking_documents" .}}
{{template "booking_status_history" .}}
</dl>
</div>
</div>