Skip to content

Commit

Permalink
modify default table model configs
Browse files Browse the repository at this point in the history
  • Loading branch information
cg33 committed Sep 28, 2019
1 parent 00f7855 commit 99e9704
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
4 changes: 2 additions & 2 deletions examples/datamodel/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import (
func GetUserTable() (userTable table.Table) {

userTable = table.NewDefaultTable(table.Config{
Driver: "mysql",
Driver: db.DriverMysql,
CanAdd: true,
Editable: true,
Deletable: true,
Exportable: true,
Connection: "default",
Connection: table.DefaultConnectionName,
PrimaryKey: table.PrimaryKey{
Type: db.Int,
Name: table.DefaultPrimaryKeyName,
Expand Down
36 changes: 32 additions & 4 deletions plugins/admin/modules/table/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ type PrimaryKey struct {
Name string
}

const DefaultPrimaryKeyName = "id"
const (
DefaultPrimaryKeyName = "id"
DefaultConnectionName = "default"
)

type DefaultTable struct {
info *types.InfoPanel
Expand Down Expand Up @@ -107,12 +110,12 @@ type Config struct {
}

var DefaultConfig = Config{
Driver: "mysql",
Driver: db.DriverMysql,
CanAdd: true,
Editable: true,
Deletable: true,
Exportable: false,
Connection: "default",
Connection: DefaultConnectionName,
PrimaryKey: PrimaryKey{
Type: db.Int,
Name: DefaultPrimaryKeyName,
Expand All @@ -124,10 +127,35 @@ func (config Config) SetPrimaryKeyType(typ string) Config {
return config
}

func (config Config) SetCanAdd(canAdd bool) Config {
config.CanAdd = canAdd
return config
}

func (config Config) SetEditable(editable bool) Config {
config.Editable = editable
return config
}

func (config Config) SetDeletable(deletable bool) Config {
config.Deletable = deletable
return config
}

func (config Config) SetExportable(exportable bool) Config {
config.Exportable = exportable
return config
}

func (config Config) SetConnection(connection string) Config {
config.Connection = connection
return config
}

func DefaultConfigWithDriver(driver string) Config {
return Config{
Driver: driver,
Connection: "default",
Connection: DefaultConnectionName,
CanAdd: true,
Editable: true,
Deletable: true,
Expand Down

0 comments on commit 99e9704

Please sign in to comment.