/
stores.go
53 lines (45 loc) · 1.27 KB
/
stores.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package stores
import (
"strings"
"github.com/qor/application"
"github.com/dfang/qor-demo/models/stores"
"github.com/qor/admin"
"github.com/qor/qor"
"github.com/qor/qor/resource"
"github.com/qor/qor/utils"
"github.com/qor/validations"
)
// New new home app
func New(config *Config) *App {
return &App{Config: config}
}
func NewWithDefault() *App {
return &App{Config: &Config{}}
}
// App home app
type App struct {
Config *Config
}
// Config home config struct
type Config struct {
}
// ConfigureApplication configure application
func (app App) ConfigureApplication(application *application.Application) {
app.ConfigureAdmin(application.Admin)
}
// ConfigureAdmin configure admin interface
func (App) ConfigureAdmin(Admin *admin.Admin) {
// Add Store
store := Admin.AddResource(&stores.Store{}, &admin.Config{Menu: []string{"Store Management"}})
store.Meta(&admin.Meta{Name: "Owner", Type: "single_edit"})
store.AddValidator(&resource.Validator{
Handler: func(record interface{}, metaValues *resource.MetaValues, context *qor.Context) error {
if meta := metaValues.Get("Name"); meta != nil {
if name := utils.ToString(meta.Value); strings.TrimSpace(name) == "" {
return validations.NewError(record, "Name", "Name can't be blank")
}
}
return nil
},
})
}