auto month pre select

This commit is contained in:
Ruidy 2024-02-16 13:13:49 +01:00
parent 9bbd11588b
commit bd09500dfc
No known key found for this signature in database
GPG key ID: E00F51288CB857CC
3 changed files with 60 additions and 28 deletions

View file

@ -31,7 +31,7 @@ func handleReportsPage() echo.HandlerFunc {
if err != nil { if err != nil {
yearStr = time.Now().Format("2006") yearStr = time.Now().Format("2006")
} }
return renderTempl(c, http.StatusOK, views.Reports(constants.Months, yearStr)) return renderTempl(c, http.StatusOK, views.Reports(constants.Months, month, yearStr))
} }
} }

View file

@ -4,7 +4,7 @@ import (
"strconv" "strconv"
) )
templ Reports(months []string, year string) { templ Reports(months []string, m int, year string) {
@BaseLayout() { @BaseLayout() {
<hgroup> <hgroup>
<h1>Reports</h1> <h1>Reports</h1>
@ -30,8 +30,12 @@ templ Reports(months []string, year string) {
Month Month
<select name="month" id="month" autofocus> <select name="month" id="month" autofocus>
for i, month := range months { for i, month := range months {
if i+1 == m {
<option value={ strconv.Itoa(i + 1) } selected>{ month } </option>
} else {
<option value={ strconv.Itoa(i + 1) }>{ month } </option> <option value={ strconv.Itoa(i + 1) }>{ month } </option>
} }
}
</select> </select>
</label> </label>
<button> <button>

View file

@ -14,7 +14,7 @@ import (
"strconv" "strconv"
) )
func Reports(months []string, year string) templ.Component { func Reports(months []string, m int, year string) templ.Component {
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
if !templ_7745c5c3_IsBuffer { if !templ_7745c5c3_IsBuffer {
@ -46,6 +46,33 @@ func Reports(months []string, year string) templ.Component {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
for i, month := range months { for i, month := range months {
if i+1 == m {
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<option value=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(strconv.Itoa(i + 1)))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" selected>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var3 string
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(month)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/reports.templ`, Line: 33, Col: 61}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</option>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
} else {
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<option value=\"") _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<option value=\"")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
@ -58,12 +85,12 @@ func Reports(months []string, year string) templ.Component {
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
var templ_7745c5c3_Var3 string var templ_7745c5c3_Var4 string
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(month) templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(month)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/reports.templ`, Line: 32, Col: 51} return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/reports.templ`, Line: 35, Col: 52}
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3)) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@ -72,6 +99,7 @@ func Reports(months []string, year string) templ.Component {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
} }
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</select></label> <button>Submit</button></form><section id=\"report\"></section>") _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</select></label> <button>Submit</button></form><section id=\"report\"></section>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err