Skip to content

Commit

Permalink
feat(admin): improve edit form
Browse files Browse the repository at this point in the history
  • Loading branch information
cg33 committed Aug 17, 2020
1 parent bbdeedc commit aec12a9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
4 changes: 4 additions & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ GO111MODULE=on go run main.go

<strong>[点击这里加微信群](http://quick.go-admin.cn/resource/wechat_qrcode.jpg)</strong>

<strong>注:在社区中如有问题提问,请务必清晰描述,包括但不限于问题详叙/问题代码/复现方法/已经尝试过的方法,时间生命可贵,请珍惜自己和别人的时间!</strong>

## 十分感谢

inspired by [laravel-admin](https://github.com/z-song/laravel-admin)
Expand All @@ -186,5 +188,7 @@ inspired by [laravel-admin](https://github.com/z-song/laravel-admin)
留下您的github/gitee用户名,我们将会展示在[捐赠名单](DONATION.md)中。

> 恰饭所需,作者精力时间有限,目前GoAdmin项目捐赠达666元,联系[作者](http://quick.go-admin.cn/resource/wechat_qrcode.jpg)可进vip用户群,vip群中您的问题将得到优先解答,同时也会根据您的需求进行分析和优先安排,vip群也会提供其他关于golang的福利。🙏
>
> 同时您也可以联系我,雇佣我的时间帮助您干活。
<img src="http://quick.go-admin.cn/official/assets/imgs/shoukuan.jpg" width="650" />
9 changes: 4 additions & 5 deletions plugins/admin/controller/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ func (h *Handler) showForm(ctx *context.Context, alert template2.HTML, prefix st
template.ExecuteOptions{Animation: alert == "" || ((len(animation) > 0) && animation[0])})

if isEdit {
showEditUrl := h.routePathWithPrefix("show_edit", prefix) + param.DeletePK().GetRouteParamStr()
ctx.AddHeader(constant.PjaxUrlHeader, showEditUrl)
ctx.AddHeader(constant.PjaxUrlHeader, h.routePathWithPrefix("show_edit", prefix)+
param.DeletePK().GetRouteParamStr())
}
return
}

infoUrl := h.routePathWithPrefix("info", prefix) + param.DeleteField(constant.EditPKKey,
parameter.PrimaryKey).GetRouteParamStr()
showEditUrl := h.routePathWithPrefix("show_edit", prefix) + param.DeletePK().GetRouteParamStr()
infoUrl := h.routePathWithPrefix("info", prefix) + param.DeleteField(constant.EditPKKey).GetRouteParamStr()
editUrl := h.routePathWithPrefix("edit", prefix)

referer := ctx.Referer()
Expand Down Expand Up @@ -133,7 +133,6 @@ func (h *Handler) showForm(ctx *context.Context, alert template2.HTML, prefix st
}, template.ExecuteOptions{Animation: alert == "" || ((len(animation) > 0) && animation[0]), NoCompress: f.NoCompress})

if isEdit {
showEditUrl := h.routePathWithPrefix("show_edit", prefix) + param.DeletePK().GetRouteParamStr()
ctx.AddHeader(constant.PjaxUrlHeader, showEditUrl)
}
}
Expand Down
24 changes: 22 additions & 2 deletions template/types/form.go
Original file line number Diff line number Diff line change
Expand Up @@ -1438,12 +1438,14 @@ func (f *FormPanel) GroupFieldWithValue(pk, id string, columns []string, res map
groupFormList = make([]FormFields, 0)
groupHeaders = make([]string, 0)
hasPK = false
existField = make([]string, 0)
)

if len(f.TabGroups) > 0 {
for index, group := range f.TabGroups {
list := make(FormFields, 0)
for _, fieldName := range group {
for index, fieldName := range group {
label := "_ga_group_" + strconv.Itoa(index)
field := f.FieldList.FindByFieldName(fieldName)
if field != nil && field.isNotBelongToATable() && !field.NotAllowEdit {
if !field.Hide {
Expand All @@ -1457,13 +1459,21 @@ func (f *FormPanel) GroupFieldWithValue(pk, id string, columns []string, res map
}
field.TableFields[z] = *(field.TableFields[z].UpdateValue(id, rowValue, res, sql()))
}
if utils.InArray(existField, field.Field) {
field.Field = field.Field + label
}
list = append(list, *field)
existField = append(existField, field.Field)
} else {
if field.Field == pk {
hasPK = true
}
rowValue := field.GetRawValue(columns, res[field.Field])
if utils.InArray(existField, field.Field) {
field.Field = field.Field + label
}
list = append(list, *(field.UpdateValue(id, rowValue, res, sql())))
existField = append(existField, field.Field)
}
}
}
Expand All @@ -1490,12 +1500,14 @@ func (f *FormPanel) GroupField(sql ...func() *db.SQL) ([]FormFields, []string) {
var (
groupFormList = make([]FormFields, 0)
groupHeaders = make([]string, 0)
existField = make([]string, 0)
)

for index, group := range f.TabGroups {
list := make(FormFields, 0)
for _, fieldName := range group {
for index, fieldName := range group {
field := f.FieldList.FindByFieldName(fieldName)
label := "_ga_group_" + strconv.Itoa(index)
if field != nil && field.isNotBelongToATable() && field.allowAdd() {
field.Editable = !field.DisplayButNotAdd
if !field.Hide {
Expand All @@ -1509,13 +1521,21 @@ func (f *FormPanel) GroupField(sql ...func() *db.SQL) ([]FormFields, []string) {
field.TableFields[z] = *(field.TableFields[z].UpdateDefaultValue(nil))
}
}
if utils.InArray(existField, field.Field) {
field.Field = field.Field + label
}
list = append(list, *field)
existField = append(existField, field.Field)
} else {
if utils.InArray(existField, field.Field) {
field.Field = field.Field + label
}
if len(sql) > 0 {
list = append(list, *(field.UpdateDefaultValue(sql[0]())))
} else {
list = append(list, *(field.UpdateDefaultValue(nil)))
}
existField = append(existField, field.Field)
}
}
}
Expand Down

0 comments on commit aec12a9

Please sign in to comment.