added interface for workday and absence + multiday absences closes #38, #39

This commit is contained in:
2025-09-23 12:30:02 +02:00
parent 55b0332600
commit db6fc10c28
19 changed files with 1396 additions and 1034 deletions

View File

@@ -79,5 +79,5 @@ func showWeeks(w http.ResponseWriter, r *http.Request) {
workWeeks = append(workWeeks, weeks...)
}
// isRunningWeek := time.Since(lastSub) < 24*5*time.Hour //the last submission is this week and cannot be send yet
templates.TeamPage(workWeeks, userWeek).Render(r.Context(), w)
templates.TeamPage([]models.WorkWeek{userWeek, userWeek}, userWeek).Render(r.Context(), w)
}

View File

@@ -66,18 +66,18 @@ func getBookings(w http.ResponseWriter, r *http.Request) {
}
tsTo = tsTo.AddDate(0, 0, 1) // so that today is inside
workDays := models.GetWorkDays(user, tsFrom, tsTo)
sort.Slice(workDays, func(i, j int) bool {
return workDays[i].Day.After(workDays[j].Day)
days := models.GetDays(user, tsFrom, tsTo)
sort.Slice(days, func(i, j int) bool {
return days[i].Date().After(days[j].Date())
})
lastSub := user.GetLastWorkWeekSubmission()
var aggregatedOvertime time.Duration
for _, day := range workDays {
if day.Day.Before(lastSub) {
for _, day := range days {
if day.Date().Before(lastSub) {
continue
}
aggregatedOvertime += day.CalcOvertime(user)
aggregatedOvertime += day.TimeOvertimeReal(user)
}
if reportedOvertime, err := user.GetReportedOvertime(); err == nil {
user.Overtime = (reportedOvertime + aggregatedOvertime).Round(time.Minute)
@@ -88,12 +88,13 @@ func getBookings(w http.ResponseWriter, r *http.Request) {
if r.Header.Get("Accept") == "application/json" {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(workDays)
json.NewEncoder(w).Encode(days)
return
}
ctx := context.WithValue(r.Context(), "user", user)
templates.TimePage(workDays, lastSub).Render(ctx, w)
ctx = context.WithValue(ctx, "days", days)
templates.TimePage([]models.WorkDay{}, lastSub).Render(ctx, w)
}
func updateBooking(w http.ResponseWriter, r *http.Request) {