Clean up.
This commit is contained in:
parent
60afbb18c0
commit
8c3f04e859
5 changed files with 26 additions and 27 deletions
|
|
@ -26,7 +26,7 @@ func (*Extension) Templates() []*gen.Template {
|
||||||
gen.NewTemplate("admin").
|
gen.NewTemplate("admin").
|
||||||
Funcs(template.FuncMap{
|
Funcs(template.FuncMap{
|
||||||
"fieldName": fieldName,
|
"fieldName": fieldName,
|
||||||
"fieldLabel": fieldLabel,
|
"fieldLabel": FieldLabel,
|
||||||
"fieldIsPointer": fieldIsPointer,
|
"fieldIsPointer": fieldIsPointer,
|
||||||
}).
|
}).
|
||||||
ParseFS(templateDir, "templates/*tmpl"),
|
ParseFS(templateDir, "templates/*tmpl"),
|
||||||
|
|
@ -51,13 +51,14 @@ func fieldName(name string) string {
|
||||||
return strings.Join(parts, "")
|
return strings.Join(parts, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func fieldLabel(name string) string {
|
func FieldLabel(name string) string {
|
||||||
if len(name) == 0 {
|
if len(name) == 0 {
|
||||||
return name
|
return name
|
||||||
}
|
}
|
||||||
|
|
||||||
out := strings.ReplaceAll(name, "_", " ")
|
name = strings.ReplaceAll(name, "_id", "_ID")
|
||||||
return upperFirst(out)
|
name = strings.ReplaceAll(name, "_", " ")
|
||||||
|
return upperFirst(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func fieldIsPointer(f *gen.Field) bool {
|
func fieldIsPointer(f *gen.Field) bool {
|
||||||
|
|
|
||||||
|
|
@ -138,7 +138,7 @@ func (h *Handler) PasswordTokenList(ctx echo.Context) (*EntityList, error) {
|
||||||
|
|
||||||
list := &EntityList{
|
list := &EntityList{
|
||||||
Columns: []string{
|
Columns: []string{
|
||||||
"User id",
|
"User ID",
|
||||||
"Created at",
|
"Created at",
|
||||||
},
|
},
|
||||||
Entities: make([]EntityValues, 0, len(res)),
|
Entities: make([]EntityValues, 0, len(res)),
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ type PasswordToken struct {
|
||||||
// Fields of the PasswordToken.
|
// Fields of the PasswordToken.
|
||||||
func (PasswordToken) Fields() []ent.Field {
|
func (PasswordToken) Fields() []ent.Field {
|
||||||
return []ent.Field{
|
return []ent.Field{
|
||||||
|
// TODO rename to Token
|
||||||
field.String("hash").
|
field.String("hash").
|
||||||
Sensitive().
|
Sensitive().
|
||||||
NotEmpty(),
|
NotEmpty(),
|
||||||
|
|
|
||||||
|
|
@ -129,6 +129,7 @@ func (h *Admin) EntityAddSubmit(n *gen.Type) echo.HandlerFunc {
|
||||||
return redirect.
|
return redirect.
|
||||||
New(ctx).
|
New(ctx).
|
||||||
Route(routenames.AdminEntityList(n.Name)).
|
Route(routenames.AdminEntityList(n.Name)).
|
||||||
|
StatusCode(http.StatusFound).
|
||||||
Go()
|
Go()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -154,6 +155,7 @@ func (h *Admin) EntityEditSubmit(n *gen.Type) echo.HandlerFunc {
|
||||||
return redirect.
|
return redirect.
|
||||||
New(ctx).
|
New(ctx).
|
||||||
Route(routenames.AdminEntityList(n.Name)).
|
Route(routenames.AdminEntityList(n.Name)).
|
||||||
|
StatusCode(http.StatusFound).
|
||||||
Go()
|
Go()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -177,6 +179,7 @@ func (h *Admin) EntityDeleteSubmit(n *gen.Type) echo.HandlerFunc {
|
||||||
return redirect.
|
return redirect.
|
||||||
New(ctx).
|
New(ctx).
|
||||||
Route(routenames.AdminEntityList(n.Name)).
|
Route(routenames.AdminEntityList(n.Name)).
|
||||||
|
StatusCode(http.StatusFound).
|
||||||
Go()
|
Go()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
"unicode"
|
|
||||||
|
|
||||||
"entgo.io/ent/entc/gen"
|
"entgo.io/ent/entc/gen"
|
||||||
"entgo.io/ent/entc/load"
|
"entgo.io/ent/entc/load"
|
||||||
|
|
@ -49,15 +47,6 @@ func AdminEntityForm(ctx echo.Context, isNew bool, schema *load.Schema, values u
|
||||||
|
|
||||||
nodes := make(Group, 0)
|
nodes := make(Group, 0)
|
||||||
|
|
||||||
label := func(name string) string {
|
|
||||||
if len(name) == 0 {
|
|
||||||
return name
|
|
||||||
}
|
|
||||||
text := []rune(strings.ReplaceAll(name, "_", " "))
|
|
||||||
text[0] = unicode.ToUpper(text[0])
|
|
||||||
return string(text)
|
|
||||||
}
|
|
||||||
|
|
||||||
getValue := func(name string) string {
|
getValue := func(name string) string {
|
||||||
if value := ctx.FormValue(name); value != "" {
|
if value := ctx.FormValue(name); value != "" {
|
||||||
return value
|
return value
|
||||||
|
|
@ -78,22 +67,27 @@ func AdminEntityForm(ctx echo.Context, isNew bool, schema *load.Schema, values u
|
||||||
// TODO sensitive edits
|
// TODO sensitive edits
|
||||||
switch f.Info.Type {
|
switch f.Info.Type {
|
||||||
case field.TypeString:
|
case field.TypeString:
|
||||||
inputType := "text"
|
p := InputFieldParams{
|
||||||
if f.Sensitive {
|
|
||||||
inputType = "password"
|
|
||||||
}
|
|
||||||
nodes = append(nodes, InputField(InputFieldParams{
|
|
||||||
Name: f.Name,
|
Name: f.Name,
|
||||||
InputType: inputType,
|
InputType: "text",
|
||||||
Label: label(f.Name),
|
Label: admin.FieldLabel(f.Name),
|
||||||
Value: getValue(f.Name),
|
Value: getValue(f.Name),
|
||||||
}))
|
}
|
||||||
|
|
||||||
|
if f.Sensitive {
|
||||||
|
p.InputType = "password"
|
||||||
|
if !isNew {
|
||||||
|
p.Placeholder = "*****"
|
||||||
|
p.Help = "SENSITIVE: This field will only be updated if a value is provided."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
nodes = append(nodes, InputField(p))
|
||||||
case field.TypeTime:
|
case field.TypeTime:
|
||||||
// todo make this easier
|
// todo make this easier
|
||||||
nodes = append(nodes, InputField(InputFieldParams{
|
nodes = append(nodes, InputField(InputFieldParams{
|
||||||
Name: f.Name,
|
Name: f.Name,
|
||||||
InputType: "text",
|
InputType: "text",
|
||||||
Label: label(f.Name),
|
Label: admin.FieldLabel(f.Name),
|
||||||
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),
|
||||||
}))
|
}))
|
||||||
|
|
@ -102,13 +96,13 @@ func AdminEntityForm(ctx echo.Context, isNew bool, schema *load.Schema, values u
|
||||||
nodes = append(nodes, InputField(InputFieldParams{
|
nodes = append(nodes, InputField(InputFieldParams{
|
||||||
Name: f.Name,
|
Name: f.Name,
|
||||||
InputType: "number",
|
InputType: "number",
|
||||||
Label: label(f.Name),
|
Label: admin.FieldLabel(f.Name),
|
||||||
Value: getValue(f.Name),
|
Value: getValue(f.Name),
|
||||||
}))
|
}))
|
||||||
case field.TypeBool:
|
case field.TypeBool:
|
||||||
nodes = append(nodes, Checkbox(CheckboxParams{
|
nodes = append(nodes, Checkbox(CheckboxParams{
|
||||||
Name: f.Name,
|
Name: f.Name,
|
||||||
Label: label(f.Name),
|
Label: admin.FieldLabel(f.Name),
|
||||||
Checked: getValue(f.Name) == "true",
|
Checked: getValue(f.Name) == "true",
|
||||||
}))
|
}))
|
||||||
case field.TypeEnum:
|
case field.TypeEnum:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue