Example #1
0
File: seo.go Project: qor/seo
// ConfigureQorMetaBeforeInitialize configure SEO setting for qor admin
func (Setting) ConfigureQorMetaBeforeInitialize(meta resource.Metaor) {
	if meta, ok := meta.(*admin.Meta); ok {
		meta.Type = "seo"

		if meta.GetValuer() == nil {
			res := meta.GetBaseResource().(*admin.Resource)
			Admin := res.GetAdmin()

			tags := meta.FieldStruct.Struct.Tag.Get("seo")
			tagsArray := splitTags(tags)
			tagsArray = prependMainObjectTags(tagsArray, Admin.Config.DB.NewScope(res.Value).IndirectValue())

			meta.SetValuer(func(value interface{}, ctx *qor.Context) interface{} {
				settingField, _ := ctx.GetDB().NewScope(value).FieldByName(meta.FieldStruct.Struct.Name)
				setting := settingField.Field.Interface().(settingInterface).GetSetting()
				setting.Tags = tags
				setting.TagsArray = tagsArray
				return setting
			})
		}

		res := meta.GetBaseResource().(*admin.Resource)
		res.GetAdmin().RegisterViewPath("github.com/qor/seo/views")
		res.UseTheme("seo")
		registerFunctions(res)
	}
}
Example #2
0
// ConfigureQorMetaBeforeInitialize configure this field for Qor Admin
func (Base) ConfigureQorMetaBeforeInitialize(meta resource.Metaor) {
	if meta, ok := meta.(*admin.Meta); ok {
		meta.Type = "file"

		if meta.GetFormattedValuer() == nil {
			meta.SetFormattedValuer(func(value interface{}, context *qor.Context) interface{} {
				return utils.Stringify(meta.GetValuer()(value, context))
			})
		}
	}
}
Example #3
0
File: slug.go Project: qor/slug
// ConfigureQorMeta configure slug for qor admin
func (Slug) ConfigureQorMeta(meta resource.Metaor) {
	if meta, ok := meta.(*admin.Meta); ok {
		res := meta.GetBaseResource().(*admin.Resource)

		res.GetAdmin().RegisterViewPath("github.com/qor/slug/views")
		res.UseTheme("slug")

		name := strings.TrimSuffix(meta.Name, "WithSlug")
		if meta := res.GetMeta(name); meta != nil {
			meta.Type = "slug"
		} else {
			res.Meta(&admin.Meta{Name: name, Type: "slug"})
		}

		var fieldName = meta.Name
		res.AddValidator(func(record interface{}, metaValues *resource.MetaValues, context *qor.Context) error {
			if meta := metaValues.Get(fieldName); meta != nil {
				slug := utils.ToString(metaValues.Get(fieldName).Value)
				if slug == "" {
					return validations.NewError(record, fieldName, name+"'s slug can't be blank")
				} else if strings.Contains(slug, " ") {
					return validations.NewError(record, fieldName, name+"'s slug can't contains blank string")
				}
			} else {
				if field, ok := context.GetDB().NewScope(record).FieldByName(fieldName); ok && field.IsBlank {
					return validations.NewError(record, fieldName, name+"'s slug can't be blank")
				}
			}
			return nil
		})

		res.IndexAttrs(res.IndexAttrs(), "-"+fieldName)
		res.ShowAttrs(res.ShowAttrs(), "-"+fieldName, false)
		res.EditAttrs(res.EditAttrs(), "-"+fieldName)
		res.NewAttrs(res.NewAttrs(), "-"+fieldName)
	}
}
Example #4
0
func (Base) ConfigureQorMetaBeforeInitialize(meta resource.Metaor) {
	if meta, ok := meta.(*admin.Meta); ok {
		meta.Type = "file"

		if meta.GetFormattedValuer() == nil {
			meta.SetFormattedValuer(func(value interface{}, context *qor.Context) interface{} {
				return utils.Stringify(meta.GetValuer()(value, context))
			})
		}

		for _, gopath := range strings.Split(os.Getenv("GOPATH"), ":") {
			admin.RegisterViewPath(path.Join(gopath, "src/github.com/qor/media_library/views"))
		}
	}
}