Skip to content

Commit

Permalink
Fixed: edit/detail url error
Browse files Browse the repository at this point in the history
  • Loading branch information
cg33 committed Jan 7, 2020
1 parent 2dbe65e commit 92bd010
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 21 deletions.
4 changes: 2 additions & 2 deletions plugins/admin/controller/detail.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

func ShowDetail(ctx *context.Context) {
prefix := ctx.Query("__prefix")
id := ctx.Query("id")
id := ctx.Query("__goadmin_detail_pk")
panel := table.Get(prefix)
user := auth.Auth(ctx)

Expand Down Expand Up @@ -55,7 +55,7 @@ func ShowDetail(ctx *context.Context) {

editUrl := modules.AorB(panel.GetEditable(), config.Url("/info/"+prefix+"/edit"+params.GetRouteParamStr()), "")
deleteUrl := modules.AorB(panel.GetDeletable(), config.Url("/delete/"+prefix), "")
infoUrl := config2.Get().Url("/info/" + prefix + params.GetRouteParamStrWithoutId())
infoUrl := config2.Get().Url("/info/" + prefix + params.GetRouteParamStr())

deleteJs := ""

Expand Down
8 changes: 4 additions & 4 deletions plugins/admin/modules/guard/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (e *ShowFormParam) GetUrl() string {
}

func (e *ShowFormParam) GetInfoUrl() string {
return config.Get().Url("/info/" + e.Prefix + e.Param.GetRouteParamStrWithoutId())
return config.Get().Url("/info/" + e.Prefix + e.Param.GetRouteParamStr())
}

func ShowForm(conn db.Connection) context.Handler {
Expand All @@ -45,7 +45,7 @@ func ShowForm(conn db.Connection) context.Handler {
return
}

id := ctx.Query(panel.GetPrimaryKey().Name)
id := ctx.Query("__goadmin_edit_pk")
if id == "" {
alert(ctx, panel, "wrong "+panel.GetPrimaryKey().Name, conn)
ctx.Abort()
Expand Down Expand Up @@ -116,7 +116,7 @@ func (e *EditFormParam) GetUrl() string {
}

func (e *EditFormParam) GetInfoUrl() string {
return config.Get().Url("/info/" + e.Prefix + e.Param.GetRouteParamStrWithoutId())
return config.Get().Url("/info/" + e.Prefix + e.Param.GetRouteParamStr())
}

func (e EditFormParam) getUrl(kind string) string {
Expand Down Expand Up @@ -159,7 +159,7 @@ func EditForm(srv service.List) context.Handler {
panel.GetPrimaryKey().Name, panel.GetInfo().GetSort())

if fromList {
previous = config.Get().Url("/info/" + prefix + param.GetRouteParamStrWithoutId())
previous = config.Get().Url("/info/" + prefix + param.GetRouteParamStr())
}

ctx.SetUserValue("edit_form_param", &EditFormParam{
Expand Down
6 changes: 3 additions & 3 deletions plugins/admin/modules/guard/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (e *ShowNewFormParam) GetUrl() string {
}

func (e *ShowNewFormParam) GetInfoUrl() string {
return config.Get().Url("/info/" + e.Prefix + e.Param.GetRouteParamStrWithoutId())
return config.Get().Url("/info/" + e.Prefix + e.Param.GetRouteParamStr())
}

func ShowNewForm(conn db.Connection) context.Handler {
Expand Down Expand Up @@ -104,7 +104,7 @@ func (e *NewFormParam) GetUrl() string {
}

func (e *NewFormParam) GetInfoUrl() string {
return config.Get().Url("/info/" + e.Prefix + e.Param.GetRouteParamStrWithoutId())
return config.Get().Url("/info/" + e.Prefix + e.Param.GetRouteParamStr())
}

func (e *NewFormParam) GetDetailUrl() string {
Expand Down Expand Up @@ -145,7 +145,7 @@ func NewForm(srv service.List) context.Handler {
param := parameter.GetParamFromUrl(previous, fromList, panel.GetInfo().DefaultPageSize, panel.GetPrimaryKey().Name, panel.GetInfo().GetSort())

if fromList {
previous = config.Get().Url("/info/" + prefix + param.GetRouteParamStrWithoutId())
previous = config.Get().Url("/info/" + prefix + param.GetRouteParamStr())
}

ctx.SetUserValue("new_form_param", &NewFormParam{
Expand Down
21 changes: 9 additions & 12 deletions plugins/admin/modules/parameter/parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"github.com/GoAdminGroup/go-admin/plugins/admin/modules"
"github.com/GoAdminGroup/go-admin/template/types"
"net/url"
"regexp"
"strconv"
"strings"
)
Expand All @@ -23,11 +22,11 @@ var keys = []string{"__page", "__pageSize", "__sort", "__columns", "__prefix", "
const operatorSuffix = "__operator__"

func GetParam(values url.Values, defaultPageSize int, primaryKey, defaultSort string) Parameters {
page := GetDefault(values, "__page", "1")
pageSize := GetDefault(values, "__pageSize", strconv.Itoa(defaultPageSize))
sortField := GetDefault(values, "__sort", primaryKey)
sortType := GetDefault(values, "__sort_type", defaultSort)
columns := GetDefault(values, "__columns", "")
page := getDefault(values, "__page", "1")
pageSize := getDefault(values, "__pageSize", strconv.Itoa(defaultPageSize))
sortField := getDefault(values, "__sort", primaryKey)
sortType := getDefault(values, "__sort_type", defaultSort)
columns := getDefault(values, "__columns", "")

fields := make(map[string]string)

Expand Down Expand Up @@ -124,10 +123,6 @@ func (param Parameters) GetRouteParamStr() string {
return "?__page=" + param.Page + param.GetFixedParamStr()
}

func (param Parameters) GetRouteParamStrWithoutId() string {
return regexp.MustCompile(`&id=[0-9]+`).ReplaceAllString(param.GetRouteParamStr(), "")
}

func (param Parameters) GetRouteParamStrWithoutPageSize() string {
return "?__page=" + param.Page + param.GetFixedParamStrWithoutPageSize()
}
Expand Down Expand Up @@ -158,7 +153,9 @@ func (param Parameters) GetFixedParamStrWithoutPageSize() string {
func (param Parameters) GetFixedParamStr() string {
str := "&"
for key, value := range param.Fields {
str += key + "=" + value + "&"
if key != "__goadmin_edit_pk" && key != "__goadmin_detail_pk" {
str += key + "=" + value + "&"
}
}
if len(param.Columns) > 0 {
return "&__columns=" + strings.Join(param.Columns, ",") + "&__pageSize=" + param.PageSize + "&__sort=" +
Expand All @@ -169,7 +166,7 @@ func (param Parameters) GetFixedParamStr() string {
}
}

func GetDefault(values url.Values, key, def string) string {
func getDefault(values url.Values, key, def string) string {
value := values.Get(key)
if value == "" {
return def
Expand Down

0 comments on commit 92bd010

Please sign in to comment.