diff --git a/Backend/models/booking.go b/Backend/models/booking.go index cddaf2b..192fd34 100644 --- a/Backend/models/booking.go +++ b/Backend/models/booking.go @@ -135,7 +135,9 @@ func (b *Booking) GetBookingsGrouped(card_uid string, tsFrom time.Time, tsTo tim sort.Slice(bookings, func(i, j int) bool { return bookings[i].Timestamp.Before(bookings[j].Timestamp) }) - result = append(result, WorkDay{Day: day, Bookings: bookings}) + workDay := WorkDay{Day: day, Bookings: bookings} + workDay.GetWorkTime() + result = append(result, workDay) } sort.Slice(result, func(i, j int) bool { diff --git a/Backend/models/workDay.go b/Backend/models/workDay.go index a867566..5a8f534 100644 --- a/Backend/models/workDay.go +++ b/Backend/models/workDay.go @@ -9,10 +9,11 @@ type WorkDay struct { Day time.Time Bookings []Booking workTime time.Duration + pauseTime time.Duration } // Gets the duration someone worked that day -func (d WorkDay) GetWorkTime() time.Duration{ +func (d *WorkDay) GetWorkTime() time.Duration{ var workTime, pauseTime time.Duration var lastBooking Booking for _, booking := range d.Bookings{ @@ -41,37 +42,41 @@ func (d WorkDay) GetWorkTime() time.Duration{ pauseTime += diff } } + d.workTime = workTime + d.pauseTime = pauseTime return workTime } func formatDuration(d time.Duration) string{ hours := int(d.Hours()) minutes := int(d.Minutes()) % 60 - if d.Hours() > 0 { - return fmt.Sprintf("%dh %dmin", hours, minutes) - } + switch{ + case hours > 0: + return fmt.Sprintf("%dh %dmin", hours, minutes) + case minutes >0: return fmt.Sprintf("%dmin", minutes) + default: + return "" + } } // Converts duration to string and replaces 0s with in // // -> output xhxmin -func (d WorkDay) GetWorkTimeString() string { - str := formatDuration(d.GetWorkTime().Abs().Round(time.Minute)) - if(len(str) > 2){ - return str - } - return "" +func (d *WorkDay) GetWorkTimeString() (string, string) { + workString := formatDuration(d.workTime) + pauseString := formatDuration(d.pauseTime) + return workString, pauseString } // returns bool wheter the workday was ended with an automatic logout -func (d WorkDay) RequiresAction() bool { +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 +func (d *WorkDay) GetWorkDayProgress(user User) uint8 { + defaultWorkTime := time.Duration(user.Arbeitszeit * float32(time.Hour)) + progress := (d.workTime.Seconds()/defaultWorkTime.Seconds())*100 return uint8(progress) } diff --git a/Backend/static/css/styles.css b/Backend/static/css/styles.css index 6b73928..50586e6 100644 --- a/Backend/static/css/styles.css +++ b/Backend/static/css/styles.css @@ -642,6 +642,9 @@ .resize { resize: both; } + .grid-cols-2 { + grid-template-columns: repeat(2, minmax(0, 1fr)); + } .grid-cols-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); } @@ -654,6 +657,9 @@ .flex-row { flex-direction: row; } + .content-end { + align-content: flex-end; + } .items-center { align-items: center; } @@ -691,6 +697,12 @@ border-color: var(--color-neutral-400); } } + .self-end { + align-self: flex-end; + } + .justify-self-end { + justify-self: flex-end; + } .overflow-hidden { overflow: hidden; } @@ -777,6 +789,9 @@ .text-neutral-500 { color: var(--color-neutral-500); } + .text-neutral-600 { + color: var(--color-neutral-600); + } .text-neutral-700 { color: var(--color-neutral-700); } @@ -898,6 +913,11 @@ opacity: 50%; } } + .max-md\:grid { + @media (width < 48rem) { + display: grid; + } + } .md\:col-span-1 { @media (width >= 48rem) { grid-column: span 1 / span 1; @@ -918,11 +938,21 @@ display: block; } } + .md\:grid { + @media (width >= 48rem) { + display: grid; + } + } .md\:hidden { @media (width >= 48rem) { display: none; } } + .md\:inline { + @media (width >= 48rem) { + display: inline; + } + } .md\:grid-cols-5 { @media (width >= 48rem) { grid-template-columns: repeat(5, minmax(0, 1fr)); diff --git a/Backend/templates/timeComponents.templ b/Backend/templates/timeComponents.templ index f4334d4..aefe297 100644 --- a/Backend/templates/timeComponents.templ +++ b/Backend/templates/timeComponents.templ @@ -13,11 +13,13 @@ templ inputForm(){ urlParams := ctx.Value("urlParams").(url.Values) user := ctx.Value("user").(models.User) }} -
{user.Vorname + " " + user.Name}
+Überstunden
4h 32min
+{workDay.Day.Format("Mon")}: {workDay.Day.Format("02.01.2006")}
-Arbeitszeit
+{workDay.Day.Format("02.01.2006")}
+Arbeitszeit:
if (workDay.RequiresAction()) {Bitte anpassen
}else { -{workDay.GetWorkTimeString()}
+{work}
} +{pause}
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -53,7 +53,7 @@ func inputForm() templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "
Überstunden
4h 32min
Senden
Senden
")
+ 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: 46, Col: 77}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/timeComponents.templ`, Line: 48, Col: 94}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
if templ_7745c5c3_Err != nil {
@@ -144,13 +146,13 @@ func dayComponent(workDay models.WorkDay) templ.Component {
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: 46, Col: 120}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/timeComponents.templ`, Line: 48, Col: 137}
}
_, 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 Arbeitszeit:
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var9 string + templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(pause) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/timeComponents.templ`, Line: 55, Col: 38} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "
Ändern
Submit
Ändern
Submit
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -283,9 +298,9 @@ func timeGaugeComponent(progress uint8, today bool, warning bool) templ.Componen }() } ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Var12 := templ.GetChildren(ctx) - if templ_7745c5c3_Var12 == nil { - templ_7745c5c3_Var12 = templ.NopComponent + templ_7745c5c3_Var13 := templ.GetChildren(ctx) + if templ_7745c5c3_Var13 == nil { + templ_7745c5c3_Var13 = templ.NopComponent } ctx = templ.ClearChildren(ctx) @@ -294,10 +309,10 @@ func timeGaugeComponent(progress uint8, today bool, warning bool) templ.Componen case (warning): bgColor = "bg-red-600" break - case (progress > 0 && progress < 80): + case (progress > 0 && progress < 90): bgColor = "bg-orange-500" break - case (80 < progress && progress <= 110): + case (90 <= progress && progress <= 110): bgColor = "bg-accent" break case (progress > 110): @@ -308,65 +323,65 @@ func timeGaugeComponent(progress uint8, today bool, warning bool) templ.Componen break } if today { - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, "") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var20 string - templ_7745c5c3_Var20, templ_7745c5c3_Err = templ.JoinStringErrs(booking.Timestamp.Format("15:04")) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/timeComponents.templ`, Line: 125, Col: 95} - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var20)) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 28, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } var templ_7745c5c3_Var21 string - templ_7745c5c3_Var21, templ_7745c5c3_Err = templ.JoinStringErrs("booking_" + strconv.Itoa(booking.CounterId)) + templ_7745c5c3_Var21, templ_7745c5c3_Err = templ.JoinStringErrs(booking.Timestamp.Format("15:04")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/timeComponents.templ`, Line: 126, Col: 59} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/timeComponents.templ`, Line: 128, Col: 95} } _, 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, "\" type=\"time\" value=\"") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 29, " ") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 30, "\" type=\"time\" value=\"") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } var templ_7745c5c3_Var23 string - templ_7745c5c3_Var23, templ_7745c5c3_Err = templ.JoinStringErrs(booking.GetBookingType()) + templ_7745c5c3_Var23, templ_7745c5c3_Err = templ.JoinStringErrs(booking.Timestamp.Format("15:04")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/timeComponents.templ`, Line: 127, Col: 27} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/timeComponents.templ`, Line: 129, Col: 113} } _, 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, "