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