From 8baf2f378a02c45535cba722ecc0073b0022034f Mon Sep 17 00:00:00 2001 From: tom Date: Thu, 20 Feb 2025 01:56:21 +0100 Subject: [PATCH] CHANGE: finalized user auth + added booking edit view --- Backend/endpoints/time.go | 51 +- Backend/endpoints/user.go | 4 +- Backend/models/booking.go | 28 +- Backend/models/user.go | 21 +- Backend/models/workDay.go | 33 +- Backend/static/css/styles.css | 178 ++++ Backend/static/script.js | 12 + Backend/templates/base.templ | 1 + Backend/templates/base_templ.go | 2 +- Backend/templates/base_templ.txt | 2 +- Backend/templates/overview_templ.txt | 33 - .../{overview.templ => timeComponents.templ} | 100 +-- ...rview_templ.go => timeComponents_templ.go} | 847 ++++++++---------- Backend/templates/timeComponents_templ.txt | 32 + Backend/templates/timeDashboard.templ | 14 + Backend/templates/timeDashboard_templ.go | 64 ++ Backend/templates/timeDashboard_templ.txt | 2 + 17 files changed, 852 insertions(+), 572 deletions(-) create mode 100644 Backend/static/script.js delete mode 100644 Backend/templates/overview_templ.txt rename Backend/templates/{overview.templ => timeComponents.templ} (65%) rename Backend/templates/{overview_templ.go => timeComponents_templ.go} (63%) create mode 100644 Backend/templates/timeComponents_templ.txt create mode 100644 Backend/templates/timeDashboard.templ create mode 100644 Backend/templates/timeDashboard_templ.go create mode 100644 Backend/templates/timeDashboard_templ.txt diff --git a/Backend/endpoints/time.go b/Backend/endpoints/time.go index 803dc92..a108b1b 100644 --- a/Backend/endpoints/time.go +++ b/Backend/endpoints/time.go @@ -4,6 +4,7 @@ import ( "arbeitszeitmessung/helper" "arbeitszeitmessung/models" "arbeitszeitmessung/templates" + "context" "encoding/json" "log" "net/http" @@ -42,15 +43,21 @@ func parseTimestamp(r *http.Request , get_key string, fallback string) (time.Tim // Returns bookings from DB with similar card uid -> checks for card uid in http query params func getBookings(w http.ResponseWriter, r *http.Request) { - card_uid := r.URL.Query().Get("card_uid") - if card_uid == "" && Session.Exists(r.Context(), "card_uid"){ - card_uid = Session.GetString(r.Context(), "user") - } - if card_uid == "" { - http.Error(w, "Missing card_uid query parameter", http.StatusBadRequest) + // if(!Session.Exists(r.Context(), "user")){ + // log.Println("No user in session storage!") + // http.Error(w, "Not logged in!", http.StatusForbidden) + // return + // } + + // user, err := (*models.User).GetByPersonalNummer(nil, Session.GetInt(r.Context(), "user")) + user, err := (*models.User).GetByPersonalNummer(nil, 123) + if(err != nil){ + log.Println("No user found with the given personal number!") + http.Error(w, "No user found", http.StatusNotFound) return } + tsFrom, err := parseTimestamp(r, "time_from", "2000-01-01") if(err != nil ){ log.Println("Error parsing 'from' time", err) @@ -65,19 +72,45 @@ func getBookings(w http.ResponseWriter, r *http.Request) { } tsTo = tsTo.AddDate(0,0,1) // so that today is inside - bookings, err := (*models.Booking).GetBookingsGrouped(nil, card_uid, tsFrom, tsTo) + bookings, err := (*models.Booking).GetBookingsGrouped(nil, user.CardUID, tsFrom, tsTo) if err != nil { log.Println("Error getting bookings: ", err) http.Error(w, "Internal Server Error", http.StatusInternalServerError) return } - templates.OverviewPage(bookings).Render(r.Context(), w) + ctx := context.WithValue(r.Context(), "user", user) + templates.TimeDashboard(bookings).Render(ctx, w) // w.Header().Set("Content-Type", "application/json") // json.NewEncoder(w).Encode(bookings) } +func updateBooking(w http.ResponseWriter, r *http.Request){ + r.ParseForm() + for index, possibleBooking := range r.PostForm{ + if(index[:7] == "booking"){ + booking_id, err := strconv.Atoi(index[8:]) + if(err != nil){ + log.Println("Error parsing bookingId", err) + continue + } + booking, err := (*models.Booking).GetBookingById(nil, booking_id) + if(err != nil){ + log.Println("Error getting booking!", err) + continue + } + parsedTime, err := time.Parse("15:04", possibleBooking[0]) + if(err != nil){ + log.Println("Error parsing time!", err) + continue + } + booking.UpdateTime(parsedTime) + } + } + getBookings(w, r) +} + // Updates a booking form the given json body -func updateBooking(w http.ResponseWriter, r *http.Request) { +func updateBookingAPI(w http.ResponseWriter, r *http.Request) { _booking_id := r.URL.Query().Get("counter_id") if _booking_id == "" { http.Error(w, "Missing bookingID query parameter", http.StatusBadRequest) diff --git a/Backend/endpoints/user.go b/Backend/endpoints/user.go index 585d3a6..9e98a31 100644 --- a/Backend/endpoints/user.go +++ b/Backend/endpoints/user.go @@ -45,7 +45,7 @@ func loginUser(w http.ResponseWriter, r *http.Request){ log.Println("No card_uid provided!") http.Error(w, "No card_uid provided", http.StatusBadRequest) } - user, err := (*models.User).GetById(nil, card_uid) + user, err := (*models.User).GetByCardUID(nil, card_uid) if(err != nil){ log.Println("No user found under this card_uid!") http.Error(w, "No user found!", http.StatusNotFound) @@ -54,7 +54,7 @@ func loginUser(w http.ResponseWriter, r *http.Request){ password := r.FormValue("password") if(user.Login(password)){ log.Printf("New succesfull user login from %s %s!\n", user.Vorname, user.Name) - Session.Put(r.Context(), "user", user.CardUID) + Session.Put(r.Context(), "user", user.PersonalNummer) http.Redirect(w, r, "/time", http.StatusSeeOther) //with this browser always uses GET } diff --git a/Backend/models/booking.go b/Backend/models/booking.go index 5a83347..4574e16 100644 --- a/Backend/models/booking.go +++ b/Backend/models/booking.go @@ -132,6 +132,9 @@ func (b *Booking) GetBookingsGrouped(card_uid string, tsFrom time.Time, tsTo tim var result []WorkDay for key, bookings := range grouped { day, _ := time.Parse("2006-01-02", key) + sort.Slice(bookings, func(i, j int) bool { + return bookings[i].Timestamp.Before(bookings[j].Timestamp) + }) result = append(result, WorkDay{Day: day, Bookings: bookings}) } @@ -157,11 +160,11 @@ func (b Booking) Save() { func (b *Booking) GetBookingType() string { switch b.CheckInOut{ - case (1): + case 1,3: //manuelle Änderung return "kommen" - case (2): + case 2, 4: //manuelle Änderung return "gehen" - case(255): + case 255: return "abgemeldet" default: return "Buchungs Typ unbekannt" @@ -203,3 +206,22 @@ func checkLastBooking(b Booking) bool { } return true } + +func (b *Booking) UpdateTime(newTime time.Time){ + hour, minute, _ := newTime.Clock() + if(hour == b.Timestamp.Local().Hour() && minute == b.Timestamp.Local().Minute()){ + return + } + // TODO: add check for time overlap + + var newBooking Booking + newBooking.Timestamp = time.Date(b.Timestamp.Year(), b.Timestamp.Month(), b.Timestamp.Day(), hour, minute, 0, 0, time.Local).UTC() + if(b.CheckInOut < 3){ + newBooking.CheckInOut = b.CheckInOut + 2 + } + if(b.CheckInOut == 255){ + newBooking.CheckInOut = 4 + } + b.Update(newBooking) + b.Save() +} diff --git a/Backend/models/user.go b/Backend/models/user.go index 3846524..e2823e8 100644 --- a/Backend/models/user.go +++ b/Backend/models/user.go @@ -10,6 +10,7 @@ type User struct { Name string `json:"name"` Vorname string `json:"vorname"` HauptbeschaeftigungsOrt int8 `json:"hauptbeschaeftigungsort"` + PersonalNummer int `json:"personal_nummer"` } func (u *User) GetAll() ([]User, error) { @@ -66,13 +67,27 @@ func (u *User) Logout() error { return nil } -func (u *User) GetById(card_uid string) (User, error) { +func (u *User) GetByCardUID(card_uid string) (User, error) { var user User - qStr, err := DB.Prepare((`SELECT card_uid, vorname, nachname, hauptbeschaeftigung_ort FROM personal_daten WHERE card_uid = $1;`)) + qStr, err := DB.Prepare((`SELECT personal_nummer, card_uid, vorname, nachname, hauptbeschaeftigung_ort FROM personal_daten WHERE card_uid = $1;`)) if err != nil { return user, err } - err = qStr.QueryRow(card_uid).Scan(&user.CardUID, &user.Vorname, &user.Name, &user.HauptbeschaeftigungsOrt) + err = qStr.QueryRow(card_uid).Scan(&user.PersonalNummer, &user.CardUID, &user.Vorname, &user.Name, &user.HauptbeschaeftigungsOrt) + if err != nil{ + return user, err + } + return user, nil +} + +func (u *User) GetByPersonalNummer (personalNummer int) (User, error) { + var user User + + qStr, err := DB.Prepare((`SELECT personal_nummer, card_uid, vorname, nachname, hauptbeschaeftigung_ort FROM personal_daten WHERE personal_nummer = $1;`)) + if err != nil { + return user, err + } + err = qStr.QueryRow(personalNummer).Scan(&user.PersonalNummer, &user.CardUID, &user.Vorname, &user.Name, &user.HauptbeschaeftigungsOrt) if err != nil{ return user, err } diff --git a/Backend/models/workDay.go b/Backend/models/workDay.go index da0a42e..86d3eb6 100644 --- a/Backend/models/workDay.go +++ b/Backend/models/workDay.go @@ -1,31 +1,34 @@ package models -import "time" +import ( + "time" +) type WorkDay struct { Day time.Time - workTime time.Duration Bookings []Booking + workTime time.Duration } +// Gets the duration someone worked that day func (d WorkDay) GetWorkTime() time.Duration{ - if(d.workTime > 0) { - return d.workTime + d.workTime = 0 + for i := 0; i < len(d.Bookings) - (1 + len(d.Bookings)%2); i += 2{ + start := d.Bookings[i].Timestamp + end := d.Bookings[i+1].Timestamp + d.workTime += end.Sub(start) } - var lastCame Booking - for _, booking := range d.Bookings{ - if(booking.CheckInOut == 1){//kommen - lastCame = booking - }else{ - d.workTime = d.workTime + booking.Timestamp.Sub(lastCame.Timestamp) - } - } - if(time.Since(d.Day) < 24 * time.Hour && len(d.Bookings) % 2 == 1){ - d.workTime += time.Since(lastCame.Timestamp) + + // checks if booking is today and has no gehen yet, so the time since last kommen booking is added to workTime + if(d.Day.Equal(time.Now().Truncate(24 * time.Hour)) && len(d.Bookings) % 2 == 1){ + d.workTime += time.Since(d.Bookings[len(d.Bookings)-1].Timestamp) } return d.workTime } +// Converts duration to string and replaces 0s with in +// +// -> output xhxmin func (d WorkDay) GetWorkTimeString() string { str := d.GetWorkTime().Abs().Round(time.Minute).String() str = str[:len(str)-2] + "in" @@ -35,10 +38,12 @@ func (d WorkDay) GetWorkTimeString() string { return "" } +// returns bool wheter the workday was ended with an automatic logout func (d WorkDay) RequiresAction() bool { return d.Bookings[len(d.Bookings)-1].CheckInOut == 255 } +// returns a integer percentage of how much day has been worked of func (d WorkDay) GetWorkDayProgress() uint8 { defaultWorkTime, _ := time.ParseDuration("7h42m") progress := (d.GetWorkTime().Seconds()/defaultWorkTime.Seconds())*100 diff --git a/Backend/static/css/styles.css b/Backend/static/css/styles.css index 1a07df8..04deaa6 100644 --- a/Backend/static/css/styles.css +++ b/Backend/static/css/styles.css @@ -541,6 +541,12 @@ } } @layer utilities { + .collapse { + visibility: collapse; + } + .relative { + position: relative; + } .static { position: static; } @@ -550,12 +556,30 @@ .col-span-3 { grid-column: span 3 / span 3; } + .col-span-5 { + grid-column: span 5 / span 5; + } + .col-span-full { + grid-column: 1 / -1; + } + .row-span-3 { + grid-row: span 3 / span 3; + } + .row-span-full { + grid-row: 1 / -1; + } .-my-1 { margin-block: calc(var(--spacing) * -1); } + .my-2 { + margin-block: calc(var(--spacing) * 2); + } .mt-1 { margin-top: calc(var(--spacing) * 1); } + .block { + display: block; + } .flex { display: flex; } @@ -565,6 +589,18 @@ .hidden { display: none; } + .inline { + display: inline; + } + .inline-flex { + display: inline-flex; + } + .list-item { + display: list-item; + } + .table { + display: table; + } .size-2 { width: calc(var(--spacing) * 2); height: calc(var(--spacing) * 2); @@ -591,18 +627,36 @@ .w-full { width: 100%; } + .max-w-\[70\%\] { + max-width: 70%; + } .flex-grow { flex-grow: 1; } .grow-1 { flex-grow: 1; } + .border-collapse { + border-collapse: collapse; + } + .transform { + transform: var(--tw-rotate-x) var(--tw-rotate-y) var(--tw-rotate-z) var(--tw-skew-x) var(--tw-skew-y); + } .cursor-pointer { cursor: pointer; } + .resize { + resize: both; + } + .grid-cols-4 { + grid-template-columns: repeat(4, minmax(0, 1fr)); + } .grid-cols-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); } + .grid-cols-subgrid { + grid-template-columns: subgrid; + } .flex-col { flex-direction: column; } @@ -641,6 +695,11 @@ border-bottom-width: calc(1px * calc(1 - var(--tw-divide-y-reverse))); } } + .divide-neutral-300 { + :where(& > :not(:last-child)) { + border-color: var(--color-neutral-300); + } + } .divide-neutral-400 { :where(& > :not(:last-child)) { border-color: var(--color-neutral-400); @@ -727,6 +786,9 @@ .text-accent { color: var(--color-accent); } + .text-black { + color: var(--color-black); + } .text-neutral-500 { color: var(--color-neutral-500); } @@ -742,9 +804,20 @@ .uppercase { text-transform: uppercase; } + .underline { + text-decoration-line: underline; + } + .outline { + outline-style: var(--tw-outline-style); + outline-width: 1px; + } .filter { filter: var(--tw-blur,) var(--tw-brightness,) var(--tw-contrast,) var(--tw-grayscale,) var(--tw-hue-rotate,) var(--tw-invert,) var(--tw-saturate,) var(--tw-sepia,) var(--tw-drop-shadow,); } + .backdrop-filter { + -webkit-backdrop-filter: var(--tw-backdrop-blur,) var(--tw-backdrop-brightness,) var(--tw-backdrop-contrast,) var(--tw-backdrop-grayscale,) var(--tw-backdrop-hue-rotate,) var(--tw-backdrop-invert,) var(--tw-backdrop-opacity,) var(--tw-backdrop-saturate,) var(--tw-backdrop-sepia,); + backdrop-filter: var(--tw-backdrop-blur,) var(--tw-backdrop-brightness,) var(--tw-backdrop-contrast,) var(--tw-backdrop-grayscale,) var(--tw-backdrop-hue-rotate,) var(--tw-backdrop-invert,) var(--tw-backdrop-opacity,) var(--tw-backdrop-saturate,) var(--tw-backdrop-sepia,); + } .transition { transition-property: color, background-color, border-color, outline-color, text-decoration-color, fill, stroke, --tw-gradient-from, --tw-gradient-via, --tw-gradient-to, opacity, box-shadow, transform, translate, scale, rotate, filter, -webkit-backdrop-filter, backdrop-filter; transition-timing-function: var(--tw-ease, var(--default-transition-timing-function)); @@ -759,6 +832,31 @@ --tw-duration: 300ms; transition-duration: 300ms; } + .group-\[\.edit\]\:block { + &:is(:where(.group):is(.edit) *) { + display: block; + } + } + .group-\[\.edit\]\:hidden { + &:is(:where(.group):is(.edit) *) { + display: none; + } + } + .group-\[\.edit\]\:inline { + &:is(:where(.group):is(.edit) *) { + display: inline; + } + } + .peer-\[\.edit\]\:block { + &:is(:where(.peer):is(.edit) ~ *) { + display: block; + } + } + .peer-\[\.edit\]\:hidden { + &:is(:where(.peer):is(.edit) ~ *) { + display: none; + } + } .placeholder\:text-neutral-400 { &::placeholder { color: var(--color-neutral-400); @@ -851,6 +949,20 @@ padding-inline: calc(var(--spacing) * 4); } } + .group-\[\.edit\]\:md\:block { + &:is(:where(.group):is(.edit) *) { + @media (width >= 48rem) { + display: block; + } + } + } + .md\:group-\[\.edit\]\:block { + @media (width >= 48rem) { + &:is(:where(.group):is(.edit) *) { + display: block; + } + } + } .print\:hidden { @media print { display: none; @@ -883,6 +995,31 @@ animation-timing-function: cubic-bezier(0, 0, 0.2, 1); } } +@property --tw-rotate-x { + syntax: "*"; + inherits: false; + initial-value: rotateX(0); +} +@property --tw-rotate-y { + syntax: "*"; + inherits: false; + initial-value: rotateY(0); +} +@property --tw-rotate-z { + syntax: "*"; + inherits: false; + initial-value: rotateZ(0); +} +@property --tw-skew-x { + syntax: "*"; + inherits: false; + initial-value: skewX(0); +} +@property --tw-skew-y { + syntax: "*"; + inherits: false; + initial-value: skewY(0); +} @property --tw-divide-x-reverse { syntax: "*"; inherits: false; @@ -902,6 +1039,11 @@ syntax: "*"; inherits: false; } +@property --tw-outline-style { + syntax: "*"; + inherits: false; + initial-value: solid; +} @property --tw-blur { syntax: "*"; inherits: false; @@ -938,6 +1080,42 @@ syntax: "*"; inherits: false; } +@property --tw-backdrop-blur { + syntax: "*"; + inherits: false; +} +@property --tw-backdrop-brightness { + syntax: "*"; + inherits: false; +} +@property --tw-backdrop-contrast { + syntax: "*"; + inherits: false; +} +@property --tw-backdrop-grayscale { + syntax: "*"; + inherits: false; +} +@property --tw-backdrop-hue-rotate { + syntax: "*"; + inherits: false; +} +@property --tw-backdrop-invert { + syntax: "*"; + inherits: false; +} +@property --tw-backdrop-opacity { + syntax: "*"; + inherits: false; +} +@property --tw-backdrop-saturate { + syntax: "*"; + inherits: false; +} +@property --tw-backdrop-sepia { + syntax: "*"; + inherits: false; +} @property --tw-duration { syntax: "*"; inherits: false; diff --git a/Backend/static/script.js b/Backend/static/script.js new file mode 100644 index 0000000..405464f --- /dev/null +++ b/Backend/static/script.js @@ -0,0 +1,12 @@ +function editDay(element, event, formId) { + var form = element + .closest(".grid-cols-subgrid") + .querySelector(".time-component > form"); + form.classList.toggle("edit"); + element.classList.toggle("edit"); + if (element.classList.contains("edit")) { + event.preventDefault(); + } else { + form.submit(); + } +} diff --git a/Backend/templates/base.templ b/Backend/templates/base.templ index 868fddd..aee9b30 100644 --- a/Backend/templates/base.templ +++ b/Backend/templates/base.templ @@ -6,5 +6,6 @@ templ Style(){ Arbeitszeit + } diff --git a/Backend/templates/base_templ.go b/Backend/templates/base_templ.go index c2b07f3..ecd5e79 100644 --- a/Backend/templates/base_templ.go +++ b/Backend/templates/base_templ.go @@ -29,7 +29,7 @@ func Style() templ.Component { templ_7745c5c3_Var1 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "Arbeitszeit") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "Arbeitszeit") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/Backend/templates/base_templ.txt b/Backend/templates/base_templ.txt index f6ec6b3..2692720 100644 --- a/Backend/templates/base_templ.txt +++ b/Backend/templates/base_templ.txt @@ -1 +1 @@ -Arbeitszeit \ No newline at end of file +Arbeitszeit \ No newline at end of file diff --git a/Backend/templates/overview_templ.txt b/Backend/templates/overview_templ.txt deleted file mode 100644 index b30e965..0000000 --- a/Backend/templates/overview_templ.txt +++ /dev/null @@ -1,33 +0,0 @@ -

Tom Tröger

Überstunden

4h 32min

-
-

- -

-
-
-

-: -

Arbeitszeit

-

Bitte anpassen

-

-

-
-
-
-
-
-
-
-
-
Fehler
Arbeitszeit unter regulär
Arbeitszeit vollständig
Überstunden
Keine Buchungen
-
-
\ No newline at end of file diff --git a/Backend/templates/overview.templ b/Backend/templates/timeComponents.templ similarity index 65% rename from Backend/templates/overview.templ rename to Backend/templates/timeComponents.templ index 456df40..d4b948b 100644 --- a/Backend/templates/overview.templ +++ b/Backend/templates/timeComponents.templ @@ -2,17 +2,19 @@ package templates import ( "arbeitszeitmessung/models" + "net/url" "time" "fmt" - "net/url" + "strconv" ) templ inputForm(){ {{ urlParams := ctx.Value("urlParams").(url.Values) + user := ctx.Value("user").(models.User) }}
-

Tom Tröger

+

{user.Vorname + " " + user.Name}

Überstunden

4h 32min

@@ -21,7 +23,7 @@ templ inputForm(){ @lineComponent()
- +
@@ -34,64 +36,42 @@ templ inputForm(){
} -templ bookingComponent(booking models.Booking) { -
-

{booking.Timestamp.Local().Format("15:04")} {booking.GetBookingType()}

-
-} - -templ lineComponent(){ -
- - - -
- - - -
-} - -templ dayComponent(workDay models.WorkDay, last bool){ - {{ last_border := "" - if(last) { - last_border = "border-b-0" - } - }} -
+templ dayComponent(workDay models.WorkDay){ +
+
@timeGaugeComponent(workDay.GetWorkDayProgress(), workDay.Day.Equal(time.Now().Truncate(24 * time.Hour)), workDay.RequiresAction())

{workDay.Day.Format("Mon")}: {workDay.Day.Format("02.01.2006")}

Arbeitszeit

if (workDay.RequiresAction()) {

Bitte anpassen

- }else{ -

{workDay.GetWorkTimeString()}

+ }else { +

{workDay.GetWorkTimeString()}

}
-
+
@lineComponent() -
+
for _, booking := range workDay.Bookings { @bookingComponent(booking) } -
+ +
+
+ @changeButtonComponent("time-" + workDay.Day.Format("2006-01-02"))
-
-
} -templ allBookings(bookings []models.WorkDay) { - for index, bookingGroup := range bookings { - @dayComponent(bookingGroup, index == len(bookings) -1) - } +templ changeButtonComponent(id string){ + } templ timeGaugeComponent(progress uint8, today bool, warning bool){ @@ -125,6 +105,27 @@ templ timeGaugeComponent(progress uint8, today bool, warning bool){ } } +templ lineComponent(){ +
+ + + +
+ + + +
+} + +templ bookingComponent(booking models.Booking) { +
+

+ {booking.Timestamp.Local().Format("15:04")} + + {booking.GetBookingType()}

+
+} + templ LegendComponent(){
Fehler
@@ -134,14 +135,3 @@ templ LegendComponent(){
Keine Buchungen
} - -templ OverviewPage(bookings []models.WorkDay){ - @Style() -
- @inputForm() - @allBookings(bookings) -
- @LegendComponent() - - -} diff --git a/Backend/templates/overview_templ.go b/Backend/templates/timeComponents_templ.go similarity index 63% rename from Backend/templates/overview_templ.go rename to Backend/templates/timeComponents_templ.go index 1ffed69..014b0c1 100644 --- a/Backend/templates/overview_templ.go +++ b/Backend/templates/timeComponents_templ.go @@ -12,6 +12,7 @@ import ( "arbeitszeitmessung/models" "fmt" "net/url" + "strconv" "time" ) @@ -38,7 +39,21 @@ func inputForm() templ.Component { ctx = templ.ClearChildren(ctx) urlParams := ctx.Value("urlParams").(url.Values) - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "

Tom Tröger

Überstunden

4h 32min

") + user := ctx.Value("user").(models.User) + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var2 string + templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(user.Vorname + " " + user.Name) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/timeComponents.templ`, Line: 17, Col: 64} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "

Überstunden

4h 32min

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -46,33 +61,342 @@ func inputForm() templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "\" name=\"time_from\" class=\"w-full bg-neutral-100 placeholder:text-neutral-400 text-neutral-700 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\" placeholder=\"Zeitraum von...\">
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) +} + +func dayComponent(workDay models.WorkDay) templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var5 := templ.GetChildren(ctx) + if templ_7745c5c3_Var5 == nil { + templ_7745c5c3_Var5 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = timeGaugeComponent(workDay.GetWorkDayProgress(), workDay.Day.Equal(time.Now().Truncate(24*time.Hour)), workDay.RequiresAction()).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var6 string + templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(workDay.Day.Format("Mon")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/timeComponents.templ`, Line: 44, Col: 77} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, ": ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var7 string + templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(workDay.Day.Format("02.01.2006")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/timeComponents.templ`, Line: 44, Col: 120} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "

Arbeitszeit

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if workDay.RequiresAction() { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, "

Bitte anpassen

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } else { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var8 string + templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(workDay.GetWorkTimeString()) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/timeComponents.templ`, Line: 49, Col: 56} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = lineComponent().Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + for _, booking := range workDay.Bookings { + templ_7745c5c3_Err = bookingComponent(booking).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = changeButtonComponent("time-"+workDay.Day.Format("2006-01-02")).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) +} + +func changeButtonComponent(id string) templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var10 := templ.GetChildren(ctx) + if templ_7745c5c3_Var10 == nil { + templ_7745c5c3_Var10 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Err = templ.RenderScriptItems(ctx, templ_7745c5c3_Buffer, templ.JSFuncCall("editDay", templ.JSExpression("this"), templ.JSExpression("event"), id)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) +} + +func timeGaugeComponent(progress uint8, today bool, warning bool) templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var12 := templ.GetChildren(ctx) + if templ_7745c5c3_Var12 == nil { + templ_7745c5c3_Var12 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + + 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 { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var13 = []any{"flex w-full items-center justify-center overflow-hidden rounded-full", bgColor} + templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var13...) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } else { + var templ_7745c5c3_Var16 = []any{"w-2 h-full bg-accent rounded-md", bgColor} + templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var16...) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 24, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + return nil + }) +} + +func lineComponent() templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var18 := templ.GetChildren(ctx) + if templ_7745c5c3_Var18 == nil { + templ_7745c5c3_Var18 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 26, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -81,278 +405,6 @@ func inputForm() templ.Component { } func bookingComponent(booking models.Booking) templ.Component { - return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { - templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context - if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { - return templ_7745c5c3_CtxErr - } - templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) - if !templ_7745c5c3_IsBuffer { - defer func() { - templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) - if templ_7745c5c3_Err == nil { - templ_7745c5c3_Err = templ_7745c5c3_BufErr - } - }() - } - ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Var4 := templ.GetChildren(ctx) - if templ_7745c5c3_Var4 == nil { - templ_7745c5c3_Var4 = templ.NopComponent - } - ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "

") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var5 string - templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(booking.Timestamp.Local().Format("15:04")) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/overview.templ`, Line: 39, Col: 47} - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5)) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, " ") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var6 string - templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(booking.GetBookingType()) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/overview.templ`, Line: 39, Col: 105} - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6)) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "

") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - return nil - }) -} - -func lineComponent() templ.Component { - return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { - templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context - if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { - return templ_7745c5c3_CtxErr - } - templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) - if !templ_7745c5c3_IsBuffer { - defer func() { - templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) - if templ_7745c5c3_Err == nil { - templ_7745c5c3_Err = templ_7745c5c3_BufErr - } - }() - } - ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Var7 := templ.GetChildren(ctx) - if templ_7745c5c3_Var7 == nil { - templ_7745c5c3_Var7 = templ.NopComponent - } - ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, "
") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - return nil - }) -} - -func dayComponent(workDay models.WorkDay, last bool) templ.Component { - return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { - templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context - if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { - return templ_7745c5c3_CtxErr - } - templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) - if !templ_7745c5c3_IsBuffer { - defer func() { - templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) - if templ_7745c5c3_Err == nil { - templ_7745c5c3_Err = templ_7745c5c3_BufErr - } - }() - } - ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Var8 := templ.GetChildren(ctx) - if templ_7745c5c3_Var8 == nil { - templ_7745c5c3_Var8 = templ.NopComponent - } - ctx = templ.ClearChildren(ctx) - last_border := "" - if last { - last_border = "border-b-0" - } - var templ_7745c5c3_Var9 = []any{"p-2 col-span-2 md:col-span-1 flex flex-row gap-2", last_border} - templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var9...) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "
") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = timeGaugeComponent(workDay.GetWorkDayProgress(), workDay.Day.Equal(time.Now().Truncate(24*time.Hour)), workDay.RequiresAction()).Render(ctx, templ_7745c5c3_Buffer) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, "

") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var11 string - templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(workDay.Day.Format("Mon")) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/overview.templ`, Line: 64, Col: 77} - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11)) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, ": ") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var12 string - templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(workDay.Day.Format("02.01.2006")) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/overview.templ`, Line: 64, Col: 120} - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12)) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, "

Arbeitszeit

") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - if workDay.RequiresAction() { - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "

Bitte anpassen

") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - } else { - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, "

") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var13 string - templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(workDay.GetWorkTimeString()) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/overview.templ`, Line: 69, Col: 55} - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13)) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "

") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, "
") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var14 = []any{"flex flex-row col-span-3 md:col-span-3 gap-2 w-full p-2", last_border} - templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var14...) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, "
") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = lineComponent().Render(ctx, templ_7745c5c3_Buffer) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, "
") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - for _, booking := range workDay.Bookings { - templ_7745c5c3_Err = bookingComponent(booking).Render(ctx, templ_7745c5c3_Buffer) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, "
") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var16 = []any{"border-r-0 p-2", last_border} - templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var16...) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 22, "
") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - return nil - }) -} - -func allBookings(bookings []models.WorkDay) templ.Component { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { @@ -373,119 +425,61 @@ func allBookings(bookings []models.WorkDay) templ.Component { templ_7745c5c3_Var19 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - for index, bookingGroup := range bookings { - templ_7745c5c3_Err = dayComponent(bookingGroup, index == len(bookings)-1).Render(ctx, templ_7745c5c3_Buffer) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 27, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err } - return nil - }) -} - -func timeGaugeComponent(progress uint8, today bool, warning bool) templ.Component { - return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { - templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context - if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { - return templ_7745c5c3_CtxErr + var templ_7745c5c3_Var20 string + templ_7745c5c3_Var20, templ_7745c5c3_Err = templ.JoinStringErrs(booking.Timestamp.Local().Format("15:04")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/timeComponents.templ`, Line: 123, Col: 103} } - templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) - if !templ_7745c5c3_IsBuffer { - defer func() { - templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) - if templ_7745c5c3_Err == nil { - templ_7745c5c3_Err = templ_7745c5c3_BufErr - } - }() + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var20)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err } - ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Var20 := templ.GetChildren(ctx) - if templ_7745c5c3_Var20 == nil { - templ_7745c5c3_Var20 = templ.NopComponent + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 28, " 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 + var templ_7745c5c3_Var21 string + templ_7745c5c3_Var21, templ_7745c5c3_Err = templ.JoinStringErrs("booking_" + strconv.Itoa(booking.CounterId)) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/timeComponents.templ`, Line: 124, Col: 59} } - if today { - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 25, "

") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var21 = []any{"flex w-full items-center justify-center overflow-hidden rounded-full", bgColor} - templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var21...) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 26, "
") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - } else { - var templ_7745c5c3_Var24 = []any{"w-2 h-full bg-accent rounded-md", bgColor} - templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var24...) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 29, "
") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var21)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 29, "\" 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=\"") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var22 string + templ_7745c5c3_Var22, templ_7745c5c3_Err = templ.JoinStringErrs(booking.Timestamp.Local().Format("15:04")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/timeComponents.templ`, Line: 124, Col: 342} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var22)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 30, "\"> ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var23 string + templ_7745c5c3_Var23, templ_7745c5c3_Err = templ.JoinStringErrs(booking.GetBookingType()) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/timeComponents.templ`, Line: 125, Col: 27} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var23)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 31, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err } return nil }) @@ -507,61 +501,12 @@ func LegendComponent() templ.Component { }() } ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Var26 := templ.GetChildren(ctx) - if templ_7745c5c3_Var26 == nil { - templ_7745c5c3_Var26 = templ.NopComponent + templ_7745c5c3_Var24 := templ.GetChildren(ctx) + if templ_7745c5c3_Var24 == nil { + templ_7745c5c3_Var24 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 31, "
Fehler
Arbeitszeit unter regulär
Arbeitszeit vollständig
Überstunden
Keine Buchungen
") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - return nil - }) -} - -func OverviewPage(bookings []models.WorkDay) templ.Component { - return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { - templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context - if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { - return templ_7745c5c3_CtxErr - } - templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) - if !templ_7745c5c3_IsBuffer { - defer func() { - templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) - if templ_7745c5c3_Err == nil { - templ_7745c5c3_Err = templ_7745c5c3_BufErr - } - }() - } - ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Var27 := templ.GetChildren(ctx) - if templ_7745c5c3_Var27 == nil { - templ_7745c5c3_Var27 = templ.NopComponent - } - ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Err = Style().Render(ctx, templ_7745c5c3_Buffer) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 32, "
") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = inputForm().Render(ctx, templ_7745c5c3_Buffer) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = allBookings(bookings).Render(ctx, templ_7745c5c3_Buffer) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 33, "
") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = LegendComponent().Render(ctx, templ_7745c5c3_Buffer) + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 32, "
Fehler
Arbeitszeit unter regulär
Arbeitszeit vollständig
Überstunden
Keine Buchungen
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/Backend/templates/timeComponents_templ.txt b/Backend/templates/timeComponents_templ.txt new file mode 100644 index 0000000..38e36a8 --- /dev/null +++ b/Backend/templates/timeComponents_templ.txt @@ -0,0 +1,32 @@ +

+

Überstunden

4h 32min

+
+
+

+: +

Arbeitszeit

+

Bitte anpassen

+

+

+
+
+
+
+ +
+
+
+
+

+ +

+
Fehler
Arbeitszeit unter regulär
Arbeitszeit vollständig
Überstunden
Keine Buchungen
\ No newline at end of file diff --git a/Backend/templates/timeDashboard.templ b/Backend/templates/timeDashboard.templ new file mode 100644 index 0000000..d33fb64 --- /dev/null +++ b/Backend/templates/timeDashboard.templ @@ -0,0 +1,14 @@ +package templates + +import "arbeitszeitmessung/models" + +templ TimeDashboard(workDays []models.WorkDay){ + @Style() +
+ @inputForm() + for _, bookingGroup := range workDays { + @dayComponent(bookingGroup) + } +
+ @LegendComponent() +} diff --git a/Backend/templates/timeDashboard_templ.go b/Backend/templates/timeDashboard_templ.go new file mode 100644 index 0000000..0aeed82 --- /dev/null +++ b/Backend/templates/timeDashboard_templ.go @@ -0,0 +1,64 @@ +// Code generated by templ - DO NOT EDIT. + +// templ: version: v0.3.833 +package templates + +//lint:file-ignore SA4006 This context is only used if a nested component is present. + +import "github.com/a-h/templ" +import templruntime "github.com/a-h/templ/runtime" + +import "arbeitszeitmessung/models" + +func TimeDashboard(workDays []models.WorkDay) templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var1 := templ.GetChildren(ctx) + if templ_7745c5c3_Var1 == nil { + templ_7745c5c3_Var1 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Err = Style().Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = inputForm().Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + for _, bookingGroup := range workDays { + templ_7745c5c3_Err = dayComponent(bookingGroup).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = LegendComponent().Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) +} + +var _ = templruntime.GeneratedTemplate diff --git a/Backend/templates/timeDashboard_templ.txt b/Backend/templates/timeDashboard_templ.txt new file mode 100644 index 0000000..5ed2565 --- /dev/null +++ b/Backend/templates/timeDashboard_templ.txt @@ -0,0 +1,2 @@ +
+
\ No newline at end of file