本文整理汇总了Golang中github.com/qor/qor/resource.Resourcer.EditAttrs方法的典型用法代码示例。如果您正苦于以下问题:Golang Resourcer.EditAttrs方法的具体用法?Golang Resourcer.EditAttrs怎么用?Golang Resourcer.EditAttrs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/qor/qor/resource.Resourcer
的用法示例。
在下文中一共展示了Resourcer.EditAttrs方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ConfigureQorResource
func (s Status) ConfigureQorResource(res resource.Resourcer) {
if res, ok := res.(*admin.Resource); ok {
if res.GetMeta("PublishStatus") == nil {
res.IndexAttrs(res.IndexAttrs(), "-PublishStatus")
res.NewAttrs(res.NewAttrs(), "-PublishStatus")
res.EditAttrs(res.EditAttrs(), "-PublishStatus")
res.ShowAttrs(res.ShowAttrs(), "-PublishStatus", false)
}
}
}
示例2: ConfigureQorResource
// ConfigureQorResource used to configure transition for qor admin
func (transition *Transition) ConfigureQorResource(res resource.Resourcer) {
if res, ok := res.(*admin.Resource); ok {
if res.GetMeta("State") == nil {
res.Meta(&admin.Meta{Name: "State", Permission: roles.Deny(roles.Update, roles.Anyone).Deny(roles.Create, roles.Anyone)})
}
res.IndexAttrs(res.IndexAttrs(), "-StateChangeLogs")
res.ShowAttrs(res.ShowAttrs(), "-StateChangeLogs", false)
res.NewAttrs(res.NewAttrs(), "-StateChangeLogs")
res.EditAttrs(res.EditAttrs(), "-StateChangeLogs")
}
}
示例3: 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)
}
}
示例4: ConfigureQorResourceBeforeInitialize
func (serialize *SerializableMeta) ConfigureQorResourceBeforeInitialize(res resource.Resourcer) {
if res, ok := res.(*admin.Resource); ok {
for _, gopath := range strings.Split(os.Getenv("GOPATH"), ":") {
admin.RegisterViewPath(path.Join(gopath, "src/github.com/qor/serializable_meta/views"))
}
if _, ok := res.Value.(SerializableMetaInterface); ok {
if res.GetMeta("Kind") == nil {
res.Meta(&admin.Meta{
Name: "Kind",
Type: "hidden",
Valuer: func(value interface{}, context *qor.Context) interface{} {
if context.GetDB().NewScope(value).PrimaryKeyZero() {
return nil
} else {
return value.(SerializableMetaInterface).GetSerializableArgumentKind()
}
},
})
}
if res.GetMeta("SerializableMeta") == nil {
res.Meta(&admin.Meta{
Name: "SerializableMeta",
Type: "serializable_meta",
Valuer: func(value interface{}, context *qor.Context) interface{} {
if serializeArgument, ok := value.(SerializableMetaInterface); ok {
return struct {
Value interface{}
Resource *admin.Resource
}{
Value: serializeArgument.GetSerializableArgument(serializeArgument),
Resource: serializeArgument.GetSerializableArgumentResource(),
}
}
return nil
},
Setter: func(result interface{}, metaValue *resource.MetaValue, context *qor.Context) {
if serializeArgument, ok := result.(SerializableMetaInterface); ok {
serializeArgumentResource := serializeArgument.GetSerializableArgumentResource()
value := serializeArgumentResource.NewStruct()
for _, meta := range serializeArgumentResource.GetMetas([]string{}) {
for _, metaValue := range metaValue.MetaValues.Values {
if meta.GetName() == metaValue.Name {
if setter := meta.GetSetter(); setter != nil {
setter(value, metaValue, context)
}
}
}
}
serializeArgument.SetSerializableArgumentValue(value)
}
},
})
}
res.NewAttrs("Kind", "SerializableMeta")
res.EditAttrs("ID", "Kind", "SerializableMeta")
}
}
}
示例5: ConfigureQorResourceBeforeInitialize
//.........这里部分代码省略.........
}
return nil
},
Setter: func(result interface{}, metaValue *resource.MetaValue, context *qor.Context) {
if serializeArgument, ok := result.(SerializableMetaInterface); ok {
if serializeArgumentResource := serializeArgument.GetSerializableArgumentResource(); serializeArgumentResource != nil {
var clearUpRecord, fillUpRecord func(record interface{}, metaors []resource.Metaor, metaValues []*resource.MetaValue)
// Keep original value, so if user don't have permission to update some fields, we won't lost the data
value := serializeArgument.GetSerializableArgument(serializeArgument)
for _, fc := range serializeArgumentResource.Validators {
context.AddError(fc(value, metaValue.MetaValues, context))
}
// Clear all nested slices if has related form data
clearUpRecord = func(record interface{}, metaors []resource.Metaor, metaValues []*resource.MetaValue) {
for _, meta := range metaors {
for _, metaValue := range metaValues {
if meta.GetName() == metaValue.Name {
if metaResource, ok := meta.GetResource().(*admin.Resource); ok && metaResource != nil && metaValue.MetaValues != nil {
nestedFieldValue := reflect.Indirect(reflect.ValueOf(record)).FieldByName(meta.GetFieldName())
if nestedFieldValue.Kind() == reflect.Struct {
clearUpRecord(nestedFieldValue.Addr().Interface(), metaResource.GetMetas([]string{}), metaValue.MetaValues.Values)
} else if nestedFieldValue.Kind() == reflect.Slice {
nestedFieldValue.Set(reflect.Zero(nestedFieldValue.Type()))
}
}
}
}
}
}
clearUpRecord(value, serializeArgumentResource.GetMetas([]string{}), metaValue.MetaValues.Values)
fillUpRecord = func(record interface{}, metaors []resource.Metaor, metaValues []*resource.MetaValue) {
for _, meta := range metaors {
for _, metaValue := range metaValues {
if meta.GetName() == metaValue.Name {
if metaResource, ok := meta.GetResource().(*admin.Resource); ok && metaResource != nil && metaValue.MetaValues != nil {
nestedFieldValue := reflect.Indirect(reflect.ValueOf(record)).FieldByName(meta.GetFieldName())
if nestedFieldValue.Kind() == reflect.Struct {
nestedValue := nestedFieldValue.Addr().Interface()
for _, fc := range metaResource.Validators {
context.AddError(fc(nestedValue, metaValue.MetaValues, context))
}
fillUpRecord(nestedValue, metaResource.GetMetas([]string{}), metaValue.MetaValues.Values)
for _, fc := range metaResource.Processors {
context.AddError(fc(nestedValue, metaValue.MetaValues, context))
}
}
if nestedFieldValue.Kind() == reflect.Slice {
nestedValue := reflect.New(nestedFieldValue.Type().Elem())
for _, fc := range metaResource.Validators {
context.AddError(fc(nestedValue, metaValue.MetaValues, context))
}
if destroy := metaValue.MetaValues.Get("_destroy"); destroy == nil || fmt.Sprint(destroy.Value) == "0" {
fillUpRecord(nestedValue.Interface(), metaResource.GetMetas([]string{}), metaValue.MetaValues.Values)
if !reflect.DeepEqual(reflect.Zero(nestedFieldValue.Type().Elem()).Interface(), nestedValue.Elem().Interface()) {
nestedFieldValue.Set(reflect.Append(nestedFieldValue, nestedValue.Elem()))
for _, fc := range metaResource.Processors {
context.AddError(fc(nestedValue, metaValue.MetaValues, context))
}
}
}
}
continue
}
if setter := meta.GetSetter(); setter != nil {
setter(record, metaValue, context)
continue
}
}
}
}
}
fillUpRecord(value, serializeArgumentResource.GetMetas([]string{}), metaValue.MetaValues.Values)
for _, fc := range serializeArgumentResource.Processors {
context.AddError(fc(value, metaValue.MetaValues, context))
}
serializeArgument.SetSerializableArgumentValue(value)
}
}
},
})
}
res.NewAttrs("Kind", "SerializableMeta")
res.EditAttrs("ID", "Kind", "SerializableMeta")
}
}
}