Files
arbeitszeitmessung/Backend/templates/timeComponents.templ

140 lines
7.0 KiB
Plaintext

package templates
import (
"arbeitszeitmessung/models"
"net/url"
"time"
"fmt"
"strconv"
)
templ inputForm(){
{{
urlParams := ctx.Value("urlParams").(url.Values)
user := ctx.Value("user").(models.User)
}}
<div class="col-span-full grid grid-cols-subgrid divide-x-1 divide-neutral-400">
<div class="bg-neutral-300 p-2 col-span-2 md:col-span-1">
<p class="font-bold uppercase">{user.Vorname + " " + user.Name}</p>
<p class="text-sm">Überstunden</p>
<p class="text-accent">4h 32min</p>
</div>
<form id="timeRangeForm" method="GET" class="bg-neutral-300 flex flex-row col-span-3 md:col-span-3 p-2 gap-2 ">
// <input type="hidden" value={urlParams.Get("card_uid")} name="card_uid" class="">
@lineComponent()
<div class="flex flex-col gap-2 justify-between grow-1">
<input type="date" value={urlParams.Get("time_from")} name="time_from" class="w-full bg-neutral-100 placeholder:text-neutral-400 text-neutral-700 text-sm border border-neutral-0 rounded-md px-3 py-2 transition duration-300 ease focus:outline-none focus:border-neutral-400 hover:border-neutral-300" placeholder="Zeitraum von...">
<input type="date" value={urlParams.Get("time_to")} name="time_to" class="w-full bg-neutral-100 placeholder:text-neutral-400 text-neutral-700 text-sm border border-neutral-0 rounded-md px-3 py-2 transition duration-300 ease focus:outline-none focus:border-neutral-400 hover:border-neutral-300" placeholder="Zeitraum bis...">
</div>
</form>
<div class="bg-neutral-300 border-r-0 p-2">
<button type="submit" form="timeRangeForm" class="bg-neutral-100 cursor-pointer rounded-md text-neutral-800 p-2 md:px-4 border text-center text-sm hover:text-white transition-colors border-neutral-900 focus:bg-neutral-700 active:bg-neutral-700 hover:bg-neutral-700 disabled:pointer-events-none disabled:opacity-50">
<p class="hidden md:block" >Senden</p>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="w-4 h-4 md:hidden">
<path d="m11.645 20.91-.007-.003-.022-.012a15.247 15.247 0 0 1-.383-.218 25.18 25.18 0 0 1-4.244-3.17C4.688 15.36 2.25 12.174 2.25 8.25 2.25 5.322 4.714 3 7.688 3A5.5 5.5 0 0 1 12 5.052 5.5 5.5 0 0 1 16.313 3c2.973 0 5.437 2.322 5.437 5.25 0 3.925-2.438 7.111-4.739 9.256a25.175 25.175 0 0 1-4.244 3.17 15.247 15.247 0 0 1-.383.219l-.022.012-.007.004-.003.001a.752.752 0 0 1-.704 0l-.003-.001Z" />
</svg>
</button>
</div>
</div>
}
templ dayComponent(workDay models.WorkDay){
<div class="col-span-full grid grid-cols-subgrid divide-x-1 divide-neutral-400 hover:bg-neutral-200 transition-colors">
<div class="p-2 col-span-2 md:col-span-1 flex flex-row gap-2">
@timeGaugeComponent(workDay.GetWorkDayProgress(), workDay.Day.Equal(time.Now().Truncate(24 * time.Hour)), workDay.RequiresAction())
<div>
<p class="" ><span class="font-bold uppercase" >{workDay.Day.Format("Mon")}:</span> {workDay.Day.Format("02.01.2006")}</p>
<p class=" text-sm mt-1">Arbeitszeit</p>
if (workDay.RequiresAction()) {
<p class="text-red-600">Bitte anpassen</p>
}else {
<p class=" text-accent">{workDay.GetWorkTimeString()}</p>
}
</div>
</div>
<div class="time-component flex flex-row col-span-3 md:col-span-3 gap-2 w-full p-2">
@lineComponent()
<form id={"time-" + workDay.Day.Format("2006-01-02")} class="flex flex-col gap-2 justify-between group w-full" method="post">
for _, booking := range workDay.Bookings {
@bookingComponent(booking)
}
</form>
</div>
<div class="p-2">
@changeButtonComponent("time-" + workDay.Day.Format("2006-01-02"))
</div>
</div>
}
templ changeButtonComponent(id string){
<button type="button" class="cursor-pointer rounded-md text-neutral-800 p-2 md:px-4 border text-center text-sm hover:text-white transition-colors border-neutral-900 hover:bg-neutral-700 disabled:pointer-events-none disabled:opacity-50 group" type="button" onclick={templ.JSFuncCall("editDay", templ.JSExpression("this"), templ.JSExpression("event"), id)}>
<p class="hidden md:block group-[.edit]:hidden">Ändern</p>
<p class="hidden group-[.edit]:md:block">Submit</p>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="w-4 h-4 md:hidden">
<path d="m11.645 20.91-.007-.003-.022-.012a15.247 15.247 0 0 1-.383-.218 25.18 25.18 0 0 1-4.244-3.17C4.688 15.36 2.25 12.174 2.25 8.25 2.25 5.322 4.714 3 7.688 3A5.5 5.5 0 0 1 12 5.052 5.5 5.5 0 0 1 16.313 3c2.973 0 5.437 2.322 5.437 5.25 0 3.925-2.438 7.111-4.739 9.256a25.175 25.175 0 0 1-4.244 3.17 15.247 15.247 0 0 1-.383.219l-.022.012-.007.004-.003.001a.752.752 0 0 1-.704 0l-.003-.001Z" />
</svg>
</button>
}
templ timeGaugeComponent(progress uint8, today bool, warning bool){
{{
var bgColor string
switch {
case (warning):
bgColor = "bg-red-600"
break
case (progress > 0 && progress < 80):
bgColor = "bg-orange-500"
break
case (80 < progress && progress <=110):
bgColor = "bg-accent"
break
case(progress > 110):
bgColor = "bg-purple-600"
break
default:
bgColor = "bg-neutral-400"
break
}
}}
if today {
<div class="flex-start flex w-2 h-full overflow-hidden rounded-full bg-neutral-300 print:hidden">
<div class={"flex w-full items-center justify-center overflow-hidden rounded-full", bgColor} style={fmt.Sprintf("height: %d%%", int(progress))}></div>
</div>
}else {
<div class={"w-2 h-full bg-accent rounded-md", bgColor} ></div>
}
}
templ lineComponent(){
<div class="flex flex-col w-2 py-2 items-center text-accent print:hidden" >
<svg class="size-2" viewBox="0 0 24 24" fill="currentColor">
<polygon points="12,2 22,12 12,22 2,12" />
</svg>
<div class="w-[2px] bg-accent flex-grow -my-1"></div>
<svg class="size-2" viewBox="0 0 24 24" fill="currentColor">
<polygon points="12,2 22,12 12,22 2,12" />
</svg>
</div>
}
templ bookingComponent(booking models.Booking) {
<div>
<p class="text-neutral-500">
<span class="text-neutral-700 group-[.edit]:hidden inline">{booking.Timestamp.Format("15:04")}</span>
<input name={"booking_" + strconv.Itoa(booking.CounterId)} class="text-neutral-700 group-[.edit]:inline hidden bg-neutral-100 text-sm border border-neutral-200 rounded-md px-3 py-2 transition duration-300 ease focus:outline-none focus:border-neutral-400 hover:border-neutral-300" type="time" value={booking.Timestamp.Local().Format("15:04")} />
{booking.GetBookingType()}</p>
</div>
}
templ LegendComponent(){
<div class="flex flex-row gap-4 md:mx-[10%] print:hidden">
<div class="flex flex-row items-center gap-2"><div class="rounded-full size-4 bg-red-600"></div><span>Fehler</span></div>
<div class="flex flex-row items-center gap-2"><div class="rounded-full size-4 bg-orange-500"></div><span>Arbeitszeit unter regulär</span></div>
<div class="flex flex-row items-center gap-2"><div class="rounded-full size-4 bg-accent"></div><span>Arbeitszeit vollständig</span></div>
<div class="flex flex-row items-center gap-2"><div class="rounded-full size-4 bg-purple-600"></div><span>Überstunden</span></div>
<div class="flex flex-row items-center gap-2"><div class="rounded-full size-4 bg-neutral-400"></div><span>Keine Buchungen</span></div>
</div>
}