feat: initial commit

This commit is contained in:
2025-02-22 09:42:15 +01:00
parent ee4a65b345
commit e6e5c9b04d
43 changed files with 1191 additions and 247 deletions

View File

@ -42,18 +42,99 @@ templ FormTextarea(form *form.Form, id string, name string, label string) {
}
}
templ FormSelect(form *form.Form, id string, name string, label string, kvOptions ...string) {
type FormSelectOptions struct {
Options []formSelectOption
Attrs map[string]any
}
type FormSelectOptionFunc func(opts *FormSelectOptions)
func WithOptions(kvOptions ...string) FormSelectOptionFunc {
return func(opts *FormSelectOptions) {
opts.Options = keyValuesToOptions(kvOptions)
}
}
func WithAttrs(kvAttrs ...any) FormSelectOptionFunc {
return func(opts *FormSelectOptions) {
opts.Attrs = keyValuesToAttrs(kvAttrs)
}
}
func keyValuesToAttrs(kv []any) map[string]any {
if len(kv)%2 != 0 {
panic(errors.New("expected pair number of key/values"))
}
attrs := make(map[string]any, 0)
var key string
for idx := range kv {
if idx%2 == 0 {
key = kv[idx].(string)
continue
}
attrs[key] = kv[idx]
}
return attrs
}
type formSelectOption struct {
Value string
Label string
}
func keyValuesToOptions(kv []string) []formSelectOption {
if len(kv)%2 != 0 {
panic(errors.New("expected pair number of key/values"))
}
options := make([]formSelectOption, 0)
var key string
for idx := range kv {
if idx%2 == 0 {
key = kv[idx]
continue
}
options = append(options, formSelectOption{
Value: kv[idx],
Label: key,
})
}
return options
}
func newFormSelectOptions(funcs ...FormSelectOptionFunc) *FormSelectOptions {
opts := &FormSelectOptions{}
for _, fn := range funcs {
fn(opts)
}
return opts
}
templ FormSelect(form *form.Form, id string, name string, label string, funcs ...FormSelectOptionFunc) {
{{ opts := newFormSelectOptions(funcs...) }}
{{ field := form.Field(name) }}
if field != nil {
<div class="field">
<label class="label" for={ id }>{ label }</label>
<div class="control">
{{ err, hasErr := form.Error(name) }}
{{ value, hasValue := field.Get("value") }}
<div class="select is-fullwidth">
<select id={ id } name={ field.Name() } { field.Attrs()... }>
{{ options := keyValuesToOptions(kvOptions) }}
for _, o := range options {
<option value={ o.Value }>{ o.Label }</option>
<select id={ id } name={ field.Name() } { mergeAttrs(field.Attrs(), opts.Attrs)... }>
for _, o := range opts.Options {
<option
if hasValue && value == o.Value {
selected
}
value={ o.Value }
>{ o.Label }</option>
}
</select>
</div>
@ -65,30 +146,12 @@ templ FormSelect(form *form.Form, id string, name string, label string, kvOption
}
}
type SelectOption struct {
Value string
Label string
}
func keyValuesToOptions(kv []string) []SelectOption {
if len(kv)%2 != 0 {
panic(errors.New("expected pair number of key/values"))
}
options := make([]SelectOption, 0)
var key string
for idx := range kv {
if idx%2 == 0 {
key = kv[idx]
continue
func mergeAttrs(attrs ...map[string]any) map[string]any {
merged := make(form.Attrs)
for _, a := range attrs {
for k, v := range a {
merged[k] = v
}
options = append(options, SelectOption{
Value: kv[idx],
Label: key,
})
}
return options
return merged
}

View File

@ -327,7 +327,82 @@ func FormTextarea(form *form.Form, id string, name string, label string) templ.C
})
}
func FormSelect(form *form.Form, id string, name string, label string, kvOptions ...string) templ.Component {
type FormSelectOptions struct {
Options []formSelectOption
Attrs map[string]any
}
type FormSelectOptionFunc func(opts *FormSelectOptions)
func WithOptions(kvOptions ...string) FormSelectOptionFunc {
return func(opts *FormSelectOptions) {
opts.Options = keyValuesToOptions(kvOptions)
}
}
func WithAttrs(kvAttrs ...any) FormSelectOptionFunc {
return func(opts *FormSelectOptions) {
opts.Attrs = keyValuesToAttrs(kvAttrs)
}
}
func keyValuesToAttrs(kv []any) map[string]any {
if len(kv)%2 != 0 {
panic(errors.New("expected pair number of key/values"))
}
attrs := make(map[string]any, 0)
var key string
for idx := range kv {
if idx%2 == 0 {
key = kv[idx].(string)
continue
}
attrs[key] = kv[idx]
}
return attrs
}
type formSelectOption struct {
Value string
Label string
}
func keyValuesToOptions(kv []string) []formSelectOption {
if len(kv)%2 != 0 {
panic(errors.New("expected pair number of key/values"))
}
options := make([]formSelectOption, 0)
var key string
for idx := range kv {
if idx%2 == 0 {
key = kv[idx]
continue
}
options = append(options, formSelectOption{
Value: kv[idx],
Label: key,
})
}
return options
}
func newFormSelectOptions(funcs ...FormSelectOptionFunc) *FormSelectOptions {
opts := &FormSelectOptions{}
for _, fn := range funcs {
fn(opts)
}
return opts
}
func FormSelect(form *form.Form, id string, name string, label string, funcs ...FormSelectOptionFunc) templ.Component {
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
@ -348,6 +423,7 @@ func FormSelect(form *form.Form, id string, name string, label string, kvOptions
templ_7745c5c3_Var20 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
opts := newFormSelectOptions(funcs...)
field := form.Field(name)
if field != nil {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 26, "<div class=\"field\"><label class=\"label\" for=\"")
@ -357,7 +433,7 @@ func FormSelect(form *form.Form, id string, name string, label string, kvOptions
var templ_7745c5c3_Var21 string
templ_7745c5c3_Var21, templ_7745c5c3_Err = templ.JoinStringErrs(id)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/common/component/field.templ`, Line: 49, Col: 32}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/common/component/field.templ`, Line: 125, Col: 32}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var21))
if templ_7745c5c3_Err != nil {
@ -370,7 +446,7 @@ func FormSelect(form *form.Form, id string, name string, label string, kvOptions
var templ_7745c5c3_Var22 string
templ_7745c5c3_Var22, templ_7745c5c3_Err = templ.JoinStringErrs(label)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/common/component/field.templ`, Line: 49, Col: 42}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/common/component/field.templ`, Line: 125, Col: 42}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var22))
if templ_7745c5c3_Err != nil {
@ -381,6 +457,7 @@ func FormSelect(form *form.Form, id string, name string, label string, kvOptions
return templ_7745c5c3_Err
}
err, hasErr := form.Error(name)
value, hasValue := field.Get("value")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 29, "<div class=\"select is-fullwidth\"><select id=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
@ -388,7 +465,7 @@ func FormSelect(form *form.Form, id string, name string, label string, kvOptions
var templ_7745c5c3_Var23 string
templ_7745c5c3_Var23, templ_7745c5c3_Err = templ.JoinStringErrs(id)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/common/component/field.templ`, Line: 53, Col: 20}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/common/component/field.templ`, Line: 130, Col: 20}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var23))
if templ_7745c5c3_Err != nil {
@ -401,7 +478,7 @@ func FormSelect(form *form.Form, id string, name string, label string, kvOptions
var templ_7745c5c3_Var24 string
templ_7745c5c3_Var24, templ_7745c5c3_Err = templ.JoinStringErrs(field.Name())
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/common/component/field.templ`, Line: 53, Col: 42}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/common/component/field.templ`, Line: 130, Col: 42}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var24))
if templ_7745c5c3_Err != nil {
@ -411,7 +488,7 @@ func FormSelect(form *form.Form, id string, name string, label string, kvOptions
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templ.RenderAttributes(ctx, templ_7745c5c3_Buffer, field.Attrs())
templ_7745c5c3_Err = templ.RenderAttributes(ctx, templ_7745c5c3_Buffer, mergeAttrs(field.Attrs(), opts.Attrs))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@ -419,63 +496,72 @@ func FormSelect(form *form.Form, id string, name string, label string, kvOptions
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
options := keyValuesToOptions(kvOptions)
for _, o := range options {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 33, "<option value=\"")
for _, o := range opts.Options {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 33, "<option")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if hasValue && value == o.Value {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 34, " selected")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 35, " value=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var25 string
templ_7745c5c3_Var25, templ_7745c5c3_Err = templ.JoinStringErrs(o.Value)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/common/component/field.templ`, Line: 56, Col: 30}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/common/component/field.templ`, Line: 136, Col: 23}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var25))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 34, "\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 36, "\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var26 string
templ_7745c5c3_Var26, templ_7745c5c3_Err = templ.JoinStringErrs(o.Label)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/common/component/field.templ`, Line: 56, Col: 42}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/common/component/field.templ`, Line: 137, Col: 17}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var26))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 35, "</option>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 37, "</option>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 36, "</select></div>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 38, "</select></div>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if hasErr {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 37, "<p class=\"help is-danger\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 39, "<p class=\"help is-danger\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var27 string
templ_7745c5c3_Var27, templ_7745c5c3_Err = templ.JoinStringErrs(err.Message())
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/common/component/field.templ`, Line: 61, Col: 46}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/http/handler/webui/common/component/field.templ`, Line: 142, Col: 46}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var27))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 38, "</p>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 40, "</p>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 39, "</div></div>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 41, "</div></div>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@ -484,32 +570,14 @@ func FormSelect(form *form.Form, id string, name string, label string, kvOptions
})
}
type SelectOption struct {
Value string
Label string
}
func keyValuesToOptions(kv []string) []SelectOption {
if len(kv)%2 != 0 {
panic(errors.New("expected pair number of key/values"))
}
options := make([]SelectOption, 0)
var key string
for idx := range kv {
if idx%2 == 0 {
key = kv[idx]
continue
func mergeAttrs(attrs ...map[string]any) map[string]any {
merged := make(form.Attrs)
for _, a := range attrs {
for k, v := range a {
merged[k] = v
}
options = append(options, SelectOption{
Value: kv[idx],
Label: key,
})
}
return options
return merged
}
var _ = templruntime.GeneratedTemplate

View File

@ -10,9 +10,9 @@ type PageOptionFunc func(opts *PageOptions)
func WithTitle(title string) PageOptionFunc {
return func(opts *PageOptions) {
if title != "" {
opts.Title = title + " | Rkvst"
opts.Title = title + " | ClearCase"
} else {
opts.Title = "Rkvst"
opts.Title = "ClearCase"
}
}
}

View File

@ -18,9 +18,9 @@ type PageOptionFunc func(opts *PageOptions)
func WithTitle(title string) PageOptionFunc {
return func(opts *PageOptions) {
if title != "" {
opts.Title = title + " | Rkvst"
opts.Title = title + " | ClearCase"
} else {
opts.Title = "Rkvst"
opts.Title = "ClearCase"
}
}
}