Switch to edge fields for passwordtoken.
This commit is contained in:
parent
acf8a830d7
commit
1b86097376
19 changed files with 217 additions and 109 deletions
|
|
@ -1,7 +1,6 @@
|
|||
package handlers
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
|
@ -76,9 +75,9 @@ func (h *Admin) middlewareEntityLoad(n *gen.Type) echo.MiddlewareFunc {
|
|||
switch {
|
||||
case err == nil:
|
||||
ctx.Set(entityIDContextKey, id)
|
||||
//ctx.Set(entityContextKey, entity) // TODO
|
||||
//ctx.Set(entityContextKey, entityValues)
|
||||
return next(ctx)
|
||||
case errors.Is(err, new(ent.NotFoundError)):
|
||||
case ent.IsNotFound(err):
|
||||
return echo.NewHTTPError(http.StatusNotFound, "entity not found")
|
||||
default:
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, err)
|
||||
|
|
@ -91,7 +90,7 @@ func (h *Admin) EntityList(n *gen.Type) echo.HandlerFunc {
|
|||
return func(ctx echo.Context) error {
|
||||
list, err := h.admin.List(ctx, n.Name)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, err)
|
||||
}
|
||||
|
||||
return pages.AdminEntityList(ctx, pages.AdminEntityListParams{
|
||||
|
|
@ -125,12 +124,13 @@ func (h *Admin) EntityAddSubmit(n *gen.Type) echo.HandlerFunc {
|
|||
}
|
||||
}
|
||||
|
||||
//
|
||||
//func (h *Admin) EntityEdit(p AdminEntityPlugin) echo.HandlerFunc {
|
||||
//func (h *Admin) EntityEdit(n *gen.Type) echo.HandlerFunc {
|
||||
// return func(ctx echo.Context) error {
|
||||
// return nil
|
||||
// v := ctx.Get(entityContextKey).(map[string][]string)
|
||||
// return pages.AdminEntityForm(ctx, h.getEntitySchema(n), v)
|
||||
// }
|
||||
//}
|
||||
|
||||
//
|
||||
//func (h *Admin) EntityEditSubmit(p AdminEntityPlugin) echo.HandlerFunc {
|
||||
// return func(ctx echo.Context) error {
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@ func AdminEntityForm(ctx echo.Context, schema *load.Schema, values url.Values) e
|
|||
|
||||
for _, f := range schema.Fields {
|
||||
// TODO cardinality?
|
||||
// TODO optional fields?
|
||||
switch f.Info.Type {
|
||||
case field.TypeString:
|
||||
nodes = append(nodes, InputField(InputFieldParams{
|
||||
|
|
@ -74,6 +75,7 @@ func AdminEntityForm(ctx echo.Context, schema *load.Schema, values url.Values) e
|
|||
Value: getValue(f.Name),
|
||||
}))
|
||||
case field.TypeTime:
|
||||
// todo make this easier
|
||||
nodes = append(nodes, InputField(InputFieldParams{
|
||||
Name: f.Name,
|
||||
InputType: "text",
|
||||
|
|
@ -81,6 +83,13 @@ 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)),
|
||||
Value: getValue(f.Name),
|
||||
}))
|
||||
case field.TypeInt:
|
||||
nodes = append(nodes, InputField(InputFieldParams{
|
||||
Name: f.Name,
|
||||
InputType: "number",
|
||||
Label: label(f.Name),
|
||||
Value: getValue(f.Name),
|
||||
}))
|
||||
case field.TypeBool:
|
||||
// TODO
|
||||
nodes = append(nodes, P(Textf("%s not supported", f.Name)))
|
||||
|
|
@ -93,17 +102,17 @@ func AdminEntityForm(ctx echo.Context, schema *load.Schema, values url.Values) e
|
|||
}
|
||||
}
|
||||
|
||||
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
|
||||
}))
|
||||
}
|
||||
//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(
|
||||
FormButton("is-primary", "Submit"),
|
||||
|
|
@ -148,8 +157,19 @@ func AdminEntityList(ctx echo.Context, params AdminEntityListParams) error {
|
|||
g = append(g, Td(Text(h)))
|
||||
}
|
||||
g = append(g,
|
||||
Td(ButtonLink(r.Path(routenames.AdminEntityEdit(params.EntityType.Name), row.ID), "is-link", "Edit")),
|
||||
Td(ButtonLink(r.Path(routenames.AdminEntityDelete(params.EntityType.Name), row.ID), "is-danger", "Delete")),
|
||||
Td(
|
||||
ButtonLink(
|
||||
r.Path(routenames.AdminEntityEdit(params.EntityType.Name), row.ID),
|
||||
"is-link",
|
||||
"Edit",
|
||||
),
|
||||
),
|
||||
Td(
|
||||
ButtonLink(r.Path(routenames.AdminEntityDelete(params.EntityType.Name), row.ID),
|
||||
"is-danger",
|
||||
"Delete",
|
||||
),
|
||||
),
|
||||
)
|
||||
return g
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue