本文整理匯總了Golang中github.com/qor/qor/resource.Resourcer.ConvertSectionToStrings方法的典型用法代碼示例。如果您正苦於以下問題:Golang Resourcer.ConvertSectionToStrings方法的具體用法?Golang Resourcer.ConvertSectionToStrings怎麽用?Golang Resourcer.ConvertSectionToStrings使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/qor/qor/resource.Resourcer
的用法示例。
在下文中一共展示了Resourcer.ConvertSectionToStrings方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ConfigureQorResource
// ConfigureQorResource configure sorting for qor admin
func (s *Sorting) ConfigureQorResource(res resource.Resourcer) {
if res, ok := res.(*admin.Resource); ok {
Admin := res.GetAdmin()
res.UseTheme("sorting")
if res.Config.Permission == nil {
res.Config.Permission = roles.NewPermission()
}
for _, gopath := range strings.Split(os.Getenv("GOPATH"), ":") {
admin.RegisterViewPath(path.Join(gopath, "src/github.com/qor/sorting/views"))
}
role := res.Config.Permission.Role
if _, ok := role.Get("sorting_mode"); !ok {
role.Register("sorting_mode", func(req *http.Request, currentUser interface{}) bool {
return req.URL.Query().Get("sorting") != ""
})
}
if res.GetMeta("Position") == nil {
res.Meta(&admin.Meta{
Name: "Position",
Valuer: func(value interface{}, ctx *qor.Context) interface{} {
db := ctx.GetDB()
var count int
var pos = value.(sortingInterface).GetPosition()
if _, ok := modelValue(value).(sortingDescInterface); ok {
if total, ok := db.Get("sorting_total_count"); ok {
count = total.(int)
} else {
var result = res.NewStruct()
db.New().Order("position DESC", true).First(result)
count = result.(sortingInterface).GetPosition()
db.InstantSet("sorting_total_count", count)
}
pos = count - pos + 1
}
primaryKey := ctx.GetDB().NewScope(value).PrimaryKeyValue()
url := path.Join(ctx.Request.URL.Path, fmt.Sprintf("%v", primaryKey), "sorting/update_position")
return template.HTML(fmt.Sprintf("<input type=\"number\" class=\"qor-sorting__position\" value=\"%v\" data-sorting-url=\"%v\" data-position=\"%v\">", pos, url, pos))
},
Permission: roles.Allow(roles.Read, "sorting_mode"),
})
}
attrs := res.ConvertSectionToStrings(res.IndexAttrs())
for _, attr := range attrs {
if attr != "Position" {
attrs = append(attrs, attr)
}
}
res.IndexAttrs(res.IndexAttrs(), "Position")
res.NewAttrs(res.NewAttrs(), "-Position")
res.EditAttrs(res.EditAttrs(), "-Position")
res.ShowAttrs(res.ShowAttrs(), "-Position", false)
router := Admin.GetRouter()
router.Post(fmt.Sprintf("/%v/%v/sorting/update_position", res.ToParam(), res.ParamIDName()), updatePosition)
}
}