From d386653a641907f4b9d29ab30e5e156638414bce Mon Sep 17 00:00:00 2001
From: tom
Date: Fri, 2 May 2025 21:41:11 +0200
Subject: [PATCH] working on #6 and fixed #13
---
Backend/endpoints/team.go | 24 +++++-
Backend/static/css/styles.css | 15 ++++
Backend/static/script.js | 8 ++
Backend/templates/pages.templ | 37 ++++++---
Backend/templates/pages_templ.go | 127 +++++++++++++++++++++++++------
5 files changed, 171 insertions(+), 40 deletions(-)
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)
}
- ")
+ 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, "")
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
}