Expanded entity form support.
This commit is contained in:
parent
8c4e99fbd0
commit
eaa37a0745
2 changed files with 50 additions and 28 deletions
|
|
@ -41,6 +41,14 @@ type (
|
||||||
Value string
|
Value string
|
||||||
Help string
|
Help string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CheckboxParams struct {
|
||||||
|
Form form.Form
|
||||||
|
FormField string
|
||||||
|
Name string
|
||||||
|
Label string
|
||||||
|
Checked bool
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func ControlGroup(controls ...Node) Node {
|
func ControlGroup(controls ...Node) Node {
|
||||||
|
|
@ -106,6 +114,26 @@ func Radios(el RadiosParams) Node {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Checkbox(el CheckboxParams) Node {
|
||||||
|
return Div(
|
||||||
|
Class("field"),
|
||||||
|
Div(
|
||||||
|
Class("control"),
|
||||||
|
Label(
|
||||||
|
Class("checkbox"),
|
||||||
|
Input(
|
||||||
|
Type("checkbox"),
|
||||||
|
Name(el.Name),
|
||||||
|
If(el.Checked, Checked()),
|
||||||
|
Value("true"),
|
||||||
|
),
|
||||||
|
Text(" "+el.Label),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
formFieldErrors(el.Form, el.FormField),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
func InputField(el InputFieldParams) Node {
|
func InputField(el InputFieldParams) Node {
|
||||||
return Div(
|
return Div(
|
||||||
Class("field"),
|
Class("field"),
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,8 @@ import (
|
||||||
|
|
||||||
func AdminEntityDelete(ctx echo.Context, entityTypeName string) error {
|
func AdminEntityDelete(ctx echo.Context, entityTypeName string) error {
|
||||||
r := ui.NewRequest(ctx)
|
r := ui.NewRequest(ctx)
|
||||||
|
r.Title = fmt.Sprintf("Delete %s", entityTypeName)
|
||||||
|
|
||||||
form := Form(
|
form := Form(
|
||||||
Method(http.MethodPost),
|
Method(http.MethodPost),
|
||||||
H2(Textf("Are you sure you want to delete this %s?", entityTypeName)),
|
H2(Textf("Are you sure you want to delete this %s?", entityTypeName)),
|
||||||
|
|
@ -39,7 +41,7 @@ func AdminEntityDelete(ctx echo.Context, entityTypeName string) error {
|
||||||
|
|
||||||
func AdminEntityForm(ctx echo.Context, schema *load.Schema, values url.Values) error {
|
func AdminEntityForm(ctx echo.Context, schema *load.Schema, values url.Values) error {
|
||||||
r := ui.NewRequest(ctx)
|
r := ui.NewRequest(ctx)
|
||||||
r.Title = fmt.Sprintf("Add %s", schema.Name) // TODO
|
r.Title = fmt.Sprintf("Add %s", schema.Name)
|
||||||
nodes := make(Group, 0)
|
nodes := make(Group, 0)
|
||||||
|
|
||||||
label := func(name string) string {
|
label := func(name string) string {
|
||||||
|
|
@ -83,7 +85,8 @@ func AdminEntityForm(ctx echo.Context, schema *load.Schema, values url.Values) e
|
||||||
Help: fmt.Sprintf("Use the following format: %s", time.Now().Format(time.RFC3339)),
|
Help: fmt.Sprintf("Use the following format: %s", time.Now().Format(time.RFC3339)),
|
||||||
Value: getValue(f.Name),
|
Value: getValue(f.Name),
|
||||||
}))
|
}))
|
||||||
case field.TypeInt:
|
case field.TypeInt, field.TypeInt8, field.TypeInt16, field.TypeInt32,
|
||||||
|
field.TypeInt64, field.TypeFloat32, field.TypeFloat64:
|
||||||
nodes = append(nodes, InputField(InputFieldParams{
|
nodes = append(nodes, InputField(InputFieldParams{
|
||||||
Name: f.Name,
|
Name: f.Name,
|
||||||
InputType: "number",
|
InputType: "number",
|
||||||
|
|
@ -91,29 +94,18 @@ func AdminEntityForm(ctx echo.Context, schema *load.Schema, values url.Values) e
|
||||||
Value: getValue(f.Name),
|
Value: getValue(f.Name),
|
||||||
}))
|
}))
|
||||||
case field.TypeBool:
|
case field.TypeBool:
|
||||||
// TODO
|
nodes = append(nodes, Checkbox(CheckboxParams{
|
||||||
nodes = append(nodes, P(Textf("%s not supported", f.Name)))
|
Name: f.Name,
|
||||||
|
Label: label(f.Name),
|
||||||
|
}))
|
||||||
case field.TypeEnum:
|
case field.TypeEnum:
|
||||||
// TODO
|
// TODO
|
||||||
nodes = append(nodes, P(Textf("%s not supported", f.Name)))
|
nodes = append(nodes, P(Textf("%s not supported", f.Name)))
|
||||||
// case numeric TODO
|
|
||||||
default:
|
default:
|
||||||
nodes = append(nodes, P(Textf("%s not supported", f.Name)))
|
nodes = append(nodes, P(Textf("%s not supported", f.Name)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//for _, e := range schema.Edges {
|
|
||||||
// if e.Inverse {
|
|
||||||
// continue
|
|
||||||
// }
|
|
||||||
// nodes = append(nodes, InputField(InputFieldParams{
|
|
||||||
// Name: e.Name,
|
|
||||||
// InputType: "number",
|
|
||||||
// Label: label(e.Name),
|
|
||||||
// Value: getValue(e.Name), // TODO load does not load this
|
|
||||||
// }))
|
|
||||||
//}
|
|
||||||
|
|
||||||
nodes = append(nodes, ControlGroup(
|
nodes = append(nodes, ControlGroup(
|
||||||
FormButton("is-primary", "Submit"),
|
FormButton("is-primary", "Submit"),
|
||||||
ButtonLink(r.Path(routenames.AdminEntityList(schema.Name)), "is-secondary", "Cancel"),
|
ButtonLink(r.Path(routenames.AdminEntityList(schema.Name)), "is-secondary", "Cancel"),
|
||||||
|
|
@ -131,11 +123,6 @@ type AdminEntityListParams struct {
|
||||||
Pager pager.Pager
|
Pager pager.Pager
|
||||||
}
|
}
|
||||||
|
|
||||||
type AdminEntityListRow struct {
|
|
||||||
ID int
|
|
||||||
Columns []string
|
|
||||||
}
|
|
||||||
|
|
||||||
func AdminEntityList(ctx echo.Context, params AdminEntityListParams) error {
|
func AdminEntityList(ctx echo.Context, params AdminEntityListParams) error {
|
||||||
r := ui.NewRequest(ctx)
|
r := ui.NewRequest(ctx)
|
||||||
r.Title = params.EntityType.Name
|
r.Title = params.EntityType.Name
|
||||||
|
|
@ -183,11 +170,18 @@ func AdminEntityList(ctx echo.Context, params AdminEntityListParams) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO pager
|
// TODO pager
|
||||||
return r.Render(layouts.Admin, Table(
|
return r.Render(layouts.Admin, Group{
|
||||||
|
ButtonLink(
|
||||||
|
r.Path(routenames.AdminEntityAdd(params.EntityType.Name)),
|
||||||
|
"is-link",
|
||||||
|
fmt.Sprintf("Add %s", params.EntityType.Name),
|
||||||
|
),
|
||||||
|
Table(
|
||||||
Class("table"),
|
Class("table"),
|
||||||
THead(
|
THead(
|
||||||
Tr(genHeader()),
|
Tr(genHeader()),
|
||||||
),
|
),
|
||||||
TBody(genRows()),
|
TBody(genRows()),
|
||||||
))
|
),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue