Fix enums in generated admin schema code.
This commit is contained in:
parent
3ffdea90c3
commit
be5c1f9197
5 changed files with 36 additions and 10 deletions
|
|
@ -199,6 +199,9 @@ func (h *Handler) UserCreate(ctx echo.Context) error {
|
|||
if payload.CreatedAt != nil {
|
||||
op.SetCreatedAt(*payload.CreatedAt)
|
||||
}
|
||||
if payload.Role != nil {
|
||||
op.SetRole(*payload.Role)
|
||||
}
|
||||
_, err := op.Save(ctx.Request().Context())
|
||||
return err
|
||||
}
|
||||
|
|
@ -222,6 +225,12 @@ func (h *Handler) UserUpdate(ctx echo.Context, id int) error {
|
|||
}
|
||||
op.SetVerified(payload.Verified)
|
||||
op.SetAdmin(payload.Admin)
|
||||
if payload.Role == nil {
|
||||
var empty user.Role
|
||||
op.SetRole(empty)
|
||||
} else {
|
||||
op.SetRole(*payload.Role)
|
||||
}
|
||||
_, err = op.Save(ctx.Request().Context())
|
||||
return err
|
||||
}
|
||||
|
|
@ -251,6 +260,7 @@ func (h *Handler) UserList(ctx echo.Context) (*EntityList, error) {
|
|||
"Verified",
|
||||
"Admin",
|
||||
"Created at",
|
||||
"Role",
|
||||
},
|
||||
Entities: make([]EntityValues, 0, len(res)),
|
||||
Page: page,
|
||||
|
|
@ -266,6 +276,7 @@ func (h *Handler) UserList(ctx echo.Context) (*EntityList, error) {
|
|||
fmt.Sprint(res[i].Verified),
|
||||
fmt.Sprint(res[i].Admin),
|
||||
res[i].CreatedAt.Format(h.Config.TimeFormat),
|
||||
fmt.Sprint(res[i].Role),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
@ -284,6 +295,7 @@ func (h *Handler) UserGet(ctx echo.Context, id int) (url.Values, error) {
|
|||
v.Set("email", entity.Email)
|
||||
v.Set("verified", fmt.Sprint(entity.Verified))
|
||||
v.Set("admin", fmt.Sprint(entity.Admin))
|
||||
v.Set("role", fmt.Sprint(entity.Role))
|
||||
return v, err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ type FieldSchema struct {
|
|||
Optional bool
|
||||
Immutable bool
|
||||
Sensitive bool
|
||||
Enums []Enum
|
||||
Enums []string
|
||||
}
|
||||
|
||||
const NamePasswordToken = "PasswordToken"
|
||||
|
|
@ -98,4 +98,16 @@ var fieldsUser = []*FieldSchema{
|
|||
Sensitive: false,
|
||||
Enums: nil,
|
||||
},
|
||||
{
|
||||
Name: "role",
|
||||
Type: field.TypeEnum,
|
||||
Optional: false,
|
||||
Immutable: false,
|
||||
Sensitive: false,
|
||||
Enums: []string{
|
||||
"read",
|
||||
"write",
|
||||
"admin",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
Optional bool
|
||||
Immutable bool
|
||||
Sensitive bool
|
||||
Enums []Enum
|
||||
Enums []string
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -35,12 +35,9 @@
|
|||
Immutable: {{ $f.Immutable }},
|
||||
Sensitive: {{ $f.Sensitive }},
|
||||
{{- if len $f.Enums }}
|
||||
Enums: []Enum{
|
||||
Enums: []string{
|
||||
{{- range $e := $f.Enums }}
|
||||
{
|
||||
Label: "{{ $e.Label }}",
|
||||
Value: "{{ $e.Value }}",
|
||||
},
|
||||
"{{ $e.Value }}",
|
||||
{{- end }}
|
||||
},
|
||||
{{- else }}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,11 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
package admin
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/mikestefanello/pagoda/ent/user"
|
||||
)
|
||||
|
||||
type PasswordToken struct {
|
||||
Token *string `form:"token"`
|
||||
|
|
@ -24,6 +28,7 @@ type User struct {
|
|||
Verified bool `form:"verified"`
|
||||
Admin bool `form:"admin"`
|
||||
CreatedAt *time.Time `form:"created_at"`
|
||||
Role *user.Role `form:"role"`
|
||||
}
|
||||
|
||||
func (e *User) GetName() string {
|
||||
|
|
|
|||
|
|
@ -92,8 +92,8 @@ func AdminEntity(r *ui.Request, entityType admin.EntityType, values url.Values)
|
|||
}
|
||||
for _, enum := range f.Enums {
|
||||
options = append(options, Choice{
|
||||
Label: enum.Label,
|
||||
Value: enum.Value,
|
||||
Label: enum,
|
||||
Value: enum,
|
||||
})
|
||||
}
|
||||
nodes = append(nodes, SelectList(OptionsParams{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue