diff --git a/Backend/endpoints/team.go b/Backend/endpoints/team.go index 843f899..c28cc72 100644 --- a/Backend/endpoints/team.go +++ b/Backend/endpoints/team.go @@ -79,15 +79,22 @@ func showWeeks(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, "/user/login", http.StatusSeeOther) return } + submissionDate := r.URL.Query().Get("submission_date") + lastSub := user.GetLastSubmission() + if submissionDate != "" { + submissionDate, err := time.Parse("2006-01-02", submissionDate) + if err == nil { + lastSub = getMonday(submissionDate) + } + } + userWeek := (*models.WorkWeek).GetWeek(nil, user, lastSub, true) + var workWeeks []models.WorkWeek teamMembers, err := user.GetTeamMembers() for _, member := range teamMembers { weeks := (*models.WorkWeek).GetSendWeeks(nil, member) workWeeks = append(workWeeks, weeks...) } - lastSub := user.GetLastSubmission() - log.Println(lastSub) - userWeek := (*models.WorkWeek).GetWeek(nil, user, lastSub, true) // 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) } @@ -115,3 +122,14 @@ func getWeeksTillNow(lastWeek time.Time) []time.Time { log.Println(weeks) return weeks } + +func getMonday(ts time.Time) time.Time { + if ts.Weekday() != time.Monday { + if ts.Weekday() == time.Sunday { + ts = ts.AddDate(0, 0, -6) + } else { + ts = ts.AddDate(0, 0, -int(ts.Weekday()-1)) + } + } + return ts +} diff --git a/Backend/static/css/styles.css b/Backend/static/css/styles.css index de29344..fda267f 100644 --- a/Backend/static/css/styles.css +++ b/Backend/static/css/styles.css @@ -550,6 +550,9 @@ .col-span-3 { grid-column: span 3 / span 3; } + .mx-auto { + margin-inline: auto; + } .-my-1 { margin-block: calc(var(--spacing) * -1); } @@ -591,6 +594,9 @@ .h-full { height: 100%; } + .w-1\/3 { + width: calc(1/3 * 100%); + } .w-2 { width: calc(var(--spacing) * 2); } @@ -633,6 +639,9 @@ .items-center { align-items: center; } + .justify-around { + justify-content: space-around; + } .justify-between { justify-content: space-between; } @@ -743,6 +752,9 @@ --tw-font-weight: var(--font-weight-bold); font-weight: var(--font-weight-bold); } + .whitespace-nowrap { + white-space: nowrap; + } .text-accent { color: var(--color-accent); } @@ -755,6 +767,9 @@ .text-neutral-800 { color: var(--color-neutral-800); } + .text-red-500 { + color: var(--color-red-500); + } .text-red-600 { color: var(--color-red-600); } diff --git a/Backend/static/script.js b/Backend/static/script.js index 7b8a3c6..5bc2abb 100644 --- a/Backend/static/script.js +++ b/Backend/static/script.js @@ -24,3 +24,11 @@ function editAbwesenheit(element, event) { newBookingComponent.style.display = "none"; } } + +function navigateWeek(element, event, direction) { + var dateInput = element.closest("form").querySelector("input[type=date]"); + var date = dateInput.valueAsDate; + date.setDate(date.getDate() + 7 * direction); + date.setHours(10); + dateInput.valueAsDate = date; +} diff --git a/Backend/templates/pages.templ b/Backend/templates/pages.templ index 6444e60..7f06164 100644 --- a/Backend/templates/pages.templ +++ b/Backend/templates/pages.templ @@ -94,19 +94,32 @@ templ TeamPage(weeks []models.WorkWeek, userWeek models.WorkWeek) { @weekDayComponent(userWeek.User, day) } -
-
-

Woche: { fmt.Sprintf("%02d-%d", kw, year) }

+
+ + + +

KW { fmt.Sprintf("%02d, %d", kw, year) }

+ + +

an Vorgesetzten senden

-
- - - - // if failed { - //

Fehlgeschlagen

- // } - - + + + + + if time.Since(userWeek.WeekStart) < 24*7*time.Hour { +

Die Woche kann erst am nächsten Montag abgesendet werden!

+ } + +
for _, week := range weeks { @employeComponent(week) diff --git a/Backend/templates/pages_templ.go b/Backend/templates/pages_templ.go index 06f3dcc..48c5395 100644 --- a/Backend/templates/pages_templ.go +++ b/Backend/templates/pages_templ.go @@ -254,46 +254,123 @@ func TeamPage(weeks []models.WorkWeek, userWeek models.WorkWeek) templ.Component return templ_7745c5c3_Err } } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "

Woche: ") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "

an Vorgesetzten senden

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var8 string - templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(strconv.Itoa(userWeek.User.PersonalNummer)) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/pages.templ`, Line: 94, Col: 87} - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8)) + templ_7745c5c3_Err = templ.RenderScriptItems(ctx, templ_7745c5c3_Buffer, templ.JSFuncCall("navigateWeek", templ.JSExpression("this"), templ.JSExpression("event"), "-1")) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "\">

KW ") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } var templ_7745c5c3_Var9 string - templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(userWeek.WeekStart.Format(time.DateOnly)) + templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%02d, %d", kw, year)) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/pages.templ`, Line: 109, Col: 85} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/pages.templ`, Line: 105, Col: 72} } _, 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, 17, "\">

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templ.RenderScriptItems(ctx, templ_7745c5c3_Buffer, templ.JSFuncCall("navigateWeek", templ.JSExpression("this"), templ.JSExpression("event"), "1")) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, "

an Vorgesetzten senden

Senden ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if time.Since(userWeek.WeekStart) < 24*7*time.Hour { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 27, "

Die Woche kann erst am nächsten Montag abgesendet werden!

") + 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 } @@ -303,7 +380,7 @@ func TeamPage(weeks []models.WorkWeek, userWeek models.WorkWeek) templ.Component return templ_7745c5c3_Err } } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, "") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 29, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -327,16 +404,16 @@ func NavPage() templ.Component { }() } ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Var10 := templ.GetChildren(ctx) - if templ_7745c5c3_Var10 == nil { - templ_7745c5c3_Var10 = templ.NopComponent + templ_7745c5c3_Var13 := templ.GetChildren(ctx) + if templ_7745c5c3_Var13 == nil { + templ_7745c5c3_Var13 = templ.NopComponent } ctx = templ.ClearChildren(ctx) templ_7745c5c3_Err = Base().Render(ctx, templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, "") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 30, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -360,9 +437,9 @@ func TeamPresencePage(teamPresence map[bool][]models.User) templ.Component { }() } ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Var11 := templ.GetChildren(ctx) - if templ_7745c5c3_Var11 == nil { - templ_7745c5c3_Var11 = templ.NopComponent + templ_7745c5c3_Var14 := templ.GetChildren(ctx) + if templ_7745c5c3_Var14 == nil { + templ_7745c5c3_Var14 = templ.NopComponent } ctx = templ.ClearChildren(ctx) templ_7745c5c3_Err = Base().Render(ctx, templ_7745c5c3_Buffer) @@ -373,7 +450,7 @@ func TeamPresencePage(teamPresence map[bool][]models.User) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, "

Anwesend

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 31, "

Anwesend

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -383,7 +460,7 @@ func TeamPresencePage(teamPresence map[bool][]models.User) templ.Component { return templ_7745c5c3_Err } } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, "

Nicht Anwesend

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 32, "

Nicht Anwesend

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -393,7 +470,7 @@ func TeamPresencePage(teamPresence map[bool][]models.User) templ.Component { return templ_7745c5c3_Err } } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 22, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 33, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err }