|
@@ -58,9 +58,32 @@ func (collection *Collection) Configure(b *presets.Builder, db *gorm.DB) {
|
|
|
|
|
|
func EditSetterFunc(obj interface{}, field *presets.FieldContext, ctx *web.EventContext) (err error) {
|
|
|
var setting Setting
|
|
|
- for key := range ctx.R.Form {
|
|
|
- if strings.HasPrefix(key, fmt.Sprintf("%s.", field.Name)) {
|
|
|
- reflectutils.Set(&setting, strings.TrimPrefix(key, fmt.Sprintf("%s.", field.Name)), ctx.R.Form.Get(key))
|
|
|
+ var mediaBox = media_library.MediaBox{}
|
|
|
+ for fieldWithPrefix := range ctx.R.Form {
|
|
|
+ // make sure OpenGraphImageFromMediaLibrary.Description set after OpenGraphImageFromMediaLibrary.Values
|
|
|
+ if fieldWithPrefix == fmt.Sprintf("%s.%s", field.Name, "OpenGraphImageFromMediaLibrary.Values") {
|
|
|
+ err = mediaBox.Scan(ctx.R.FormValue(fieldWithPrefix))
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for fieldWithPrefix := range ctx.R.Form {
|
|
|
+ if strings.HasPrefix(fieldWithPrefix, fmt.Sprintf("%s.%s", field.Name, "OpenGraphImageFromMediaLibrary")) {
|
|
|
+ if fieldWithPrefix == fmt.Sprintf("%s.%s", field.Name, "OpenGraphImageFromMediaLibrary.Description") {
|
|
|
+ mediaBox.Description = ctx.R.Form.Get(fieldWithPrefix)
|
|
|
+ reflectutils.Set(&setting, "OpenGraphImageFromMediaLibrary", mediaBox)
|
|
|
+ }
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if fieldWithPrefix == fmt.Sprintf("%s.%s", field.Name, "OpenGraphMetadataString") {
|
|
|
+ metadata := GetOpenGraphMetadata(ctx.R.Form.Get(fieldWithPrefix))
|
|
|
+ reflectutils.Set(&setting, "OpenGraphMetadata", metadata)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if strings.HasPrefix(fieldWithPrefix, fmt.Sprintf("%s.", field.Name)) {
|
|
|
+ reflectutils.Set(&setting, strings.TrimPrefix(fieldWithPrefix, fmt.Sprintf("%s.", field.Name)), ctx.R.Form.Get(fieldWithPrefix))
|
|
|
}
|
|
|
}
|
|
|
return reflectutils.Set(obj, field.Name, setting)
|
|
@@ -93,6 +116,8 @@ func (collection *Collection) EditingComponentFunc(obj interface{}, field *prese
|
|
|
setting.Title = modelSetting.GetTitle()
|
|
|
setting.Description = modelSetting.GetDescription()
|
|
|
setting.Keywords = modelSetting.GetKeywords()
|
|
|
+ setting.OpenGraphTitle = modelSetting.GetOpenGraphTitle()
|
|
|
+ setting.OpenGraphDescription = modelSetting.GetOpenGraphDescription()
|
|
|
setting.OpenGraphURL = modelSetting.GetOpenGraphURL()
|
|
|
setting.OpenGraphType = modelSetting.GetOpenGraphType()
|
|
|
setting.OpenGraphImageURL = modelSetting.GetOpenGraphImageURL()
|
|
@@ -207,7 +232,6 @@ func (collection *Collection) pageFunc(ctx *web.EventContext) (_ web.PageRespons
|
|
|
)
|
|
|
seoComponents = append(seoComponents, comp)
|
|
|
}
|
|
|
-
|
|
|
return web.PageResponse{
|
|
|
PageTitle: msgr.PageTitle,
|
|
|
Body: h.If(editIsAllowed(ctx.R) == nil, VContainer(
|
|
@@ -238,7 +262,6 @@ func (collection *Collection) vseo(fieldPrefix string, seo *SEO, setting *Settin
|
|
|
msgr = i18n.MustGetModuleMessages(req, I18nSeoKey, Messages_en_US).(*Messages)
|
|
|
db = collection.getDBFromContext(req.Context())
|
|
|
)
|
|
|
-
|
|
|
if seo.name == collection.globalName {
|
|
|
seos = append(seos, seo)
|
|
|
} else {
|
|
@@ -284,9 +307,9 @@ func (collection *Collection) vseo(fieldPrefix string, seo *SEO, setting *Settin
|
|
|
),
|
|
|
VCard(
|
|
|
VCardText(
|
|
|
- VTextField().Counter(65).FieldName(fmt.Sprintf("%s.%s", fieldPrefix, "Title")).Label(msgr.Title).Value(setting.Title).Attr("@click", fmt.Sprintf("$refs.seo.tagInputsFocus($refs.%s)", fmt.Sprintf("%s_title", refPrefix))).Attr("ref", fmt.Sprintf("%s_title", refPrefix)),
|
|
|
- VTextField().Counter(150).FieldName(fmt.Sprintf("%s.%s", fieldPrefix, "Description")).Label(msgr.Description).Value(setting.Description).Attr("@click", fmt.Sprintf("$refs.seo.tagInputsFocus($refs.%s)", fmt.Sprintf("%s_description", refPrefix))).Attr("ref", fmt.Sprintf("%s_description", refPrefix)),
|
|
|
- VTextarea().Counter(255).Rows(2).AutoGrow(true).FieldName(fmt.Sprintf("%s.%s", fieldPrefix, "Keywords")).Label(msgr.Keywords).Value(setting.Keywords).Attr("@click", fmt.Sprintf("$refs.seo.tagInputsFocus($refs.%s)", fmt.Sprintf("%s_keywords", refPrefix))).Attr("ref", fmt.Sprintf("%s_keywords", refPrefix)),
|
|
|
+ VTextField().Counter(65).FieldName(fmt.Sprintf("%s.%s", fieldPrefix, "Title")).Label(msgr.Title).Value(setting.Title).Attr("@focus", fmt.Sprintf("$refs.seo.tagInputsFocus($refs.%s)", fmt.Sprintf("%s_title", refPrefix))).Attr("ref", fmt.Sprintf("%s_title", refPrefix)),
|
|
|
+ VTextField().Counter(150).FieldName(fmt.Sprintf("%s.%s", fieldPrefix, "Description")).Label(msgr.Description).Value(setting.Description).Attr("@focus", fmt.Sprintf("$refs.seo.tagInputsFocus($refs.%s)", fmt.Sprintf("%s_description", refPrefix))).Attr("ref", fmt.Sprintf("%s_description", refPrefix)),
|
|
|
+ VTextarea().Counter(255).Rows(2).AutoGrow(true).FieldName(fmt.Sprintf("%s.%s", fieldPrefix, "Keywords")).Label(msgr.Keywords).Value(setting.Keywords).Attr("@focus", fmt.Sprintf("$refs.seo.tagInputsFocus($refs.%s)", fmt.Sprintf("%s_keywords", refPrefix))).Attr("ref", fmt.Sprintf("%s_keywords", refPrefix)),
|
|
|
),
|
|
|
).Outlined(true).Flat(true),
|
|
|
|
|
@@ -294,11 +317,15 @@ func (collection *Collection) vseo(fieldPrefix string, seo *SEO, setting *Settin
|
|
|
VCard(
|
|
|
VCardText(
|
|
|
VRow(
|
|
|
- VCol(VTextField().FieldName(fmt.Sprintf("%s.%s", fieldPrefix, "OpenGraphURL")).Label(msgr.OpenGraphURL).Value(setting.OpenGraphURL)).Cols(6),
|
|
|
- VCol(VTextField().FieldName(fmt.Sprintf("%s.%s", fieldPrefix, "OpenGraphType")).Label(msgr.OpenGraphType).Value(setting.OpenGraphType)).Cols(6),
|
|
|
+ VCol(VTextField().FieldName(fmt.Sprintf("%s.%s", fieldPrefix, "OpenGraphTitle")).Label(msgr.OpenGraphTitle).Value(setting.OpenGraphTitle).Attr("@focus", fmt.Sprintf("$refs.seo.tagInputsFocus($refs.%s)", fmt.Sprintf("%s_og_title", refPrefix))).Attr("ref", fmt.Sprintf("%s_og_title", refPrefix))).Cols(6),
|
|
|
+ VCol(VTextField().FieldName(fmt.Sprintf("%s.%s", fieldPrefix, "OpenGraphDescription")).Label(msgr.OpenGraphDescription).Value(setting.OpenGraphDescription).Attr("@focus", fmt.Sprintf("$refs.seo.tagInputsFocus($refs.%s)", fmt.Sprintf("%s_og_description", refPrefix))).Attr("ref", fmt.Sprintf("%s_og_description", refPrefix))).Cols(6),
|
|
|
+ ),
|
|
|
+ VRow(
|
|
|
+ VCol(VTextField().FieldName(fmt.Sprintf("%s.%s", fieldPrefix, "OpenGraphURL")).Label(msgr.OpenGraphURL).Value(setting.OpenGraphURL).Attr("@focus", fmt.Sprintf("$refs.seo.tagInputsFocus($refs.%s)", fmt.Sprintf("%s_og_url", refPrefix))).Attr("ref", fmt.Sprintf("%s_og_url", refPrefix))).Cols(6),
|
|
|
+ VCol(VTextField().FieldName(fmt.Sprintf("%s.%s", fieldPrefix, "OpenGraphType")).Label(msgr.OpenGraphType).Value(setting.OpenGraphType).Attr("@focus", fmt.Sprintf("$refs.seo.tagInputsFocus($refs.%s)", fmt.Sprintf("%s_og_type", refPrefix))).Attr("ref", fmt.Sprintf("%s_og_type", refPrefix))).Cols(6),
|
|
|
),
|
|
|
VRow(
|
|
|
- VCol(VTextField().FieldName(fmt.Sprintf("%s.%s", fieldPrefix, "OpenGraphImageURL")).Label(msgr.OpenGraphImageURL).Value(setting.OpenGraphImageURL)).Cols(12),
|
|
|
+ VCol(VTextField().FieldName(fmt.Sprintf("%s.%s", fieldPrefix, "OpenGraphImageURL")).Label(msgr.OpenGraphImageURL).Value(setting.OpenGraphImageURL).Attr("@focus", fmt.Sprintf("$refs.seo.tagInputsFocus($refs.%s)", fmt.Sprintf("%s_og_imageurl", refPrefix))).Attr("ref", fmt.Sprintf("%s_og_imageurl", refPrefix))).Cols(12),
|
|
|
),
|
|
|
VRow(
|
|
|
VCol(views.QMediaBox(db).Label(msgr.OpenGraphImage).
|
|
@@ -321,6 +348,9 @@ func (collection *Collection) vseo(fieldPrefix string, seo *SEO, setting *Settin
|
|
|
},
|
|
|
},
|
|
|
})).Cols(12)),
|
|
|
+ VRow(
|
|
|
+ VCol(VTextarea().FieldName(fmt.Sprintf("%s.%s", fieldPrefix, "OpenGraphMetadataString")).Label(msgr.OpenGraphMetadata).Value(GetOpenGraphMetadataString(setting.OpenGraphMetadata)).Attr("@focus", fmt.Sprintf("$refs.seo.tagInputsFocus($refs.%s)", fmt.Sprintf("%s_og_metadata", refPrefix))).Attr("ref", fmt.Sprintf("%s_og_metadata", refPrefix))).Cols(12),
|
|
|
+ ),
|
|
|
),
|
|
|
).Outlined(true).Flat(true),
|
|
|
).Attr("ref", "seo")
|
|
@@ -348,24 +378,33 @@ func (collection *Collection) save(ctx *web.EventContext) (r web.EventResponse,
|
|
|
if !strings.HasPrefix(fieldWithPrefix, name) {
|
|
|
continue
|
|
|
}
|
|
|
-
|
|
|
field := strings.Replace(fieldWithPrefix, fmt.Sprintf("%s.", name), "", -1)
|
|
|
- if strings.HasPrefix(field, "OpenGraphImageFromMediaLibrary") {
|
|
|
- if field == "OpenGraphImageFromMediaLibrary.Values" {
|
|
|
- err = mediaBox.Scan(ctx.R.FormValue(fieldWithPrefix))
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
- settingVals["OpenGraphImageFromMediaLibrary"] = mediaBox
|
|
|
+ // make sure OpenGraphImageFromMediaLibrary.Description set after OpenGraphImageFromMediaLibrary.Values
|
|
|
+ if field == "OpenGraphImageFromMediaLibrary.Values" {
|
|
|
+ err = mediaBox.Scan(ctx.R.FormValue(fieldWithPrefix))
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
}
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ for fieldWithPrefix := range ctx.R.Form {
|
|
|
+ if !strings.HasPrefix(fieldWithPrefix, name) {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ field := strings.Replace(fieldWithPrefix, fmt.Sprintf("%s.", name), "", -1)
|
|
|
+ if strings.HasPrefix(field, "OpenGraphImageFromMediaLibrary") {
|
|
|
if field == "OpenGraphImageFromMediaLibrary.Description" {
|
|
|
mediaBox.Description = ctx.R.FormValue(fieldWithPrefix)
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
+ settingVals["OpenGraphImageFromMediaLibrary"] = mediaBox
|
|
|
}
|
|
|
- } else if strings.HasPrefix(field, "Variables") {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if strings.HasPrefix(field, "Variables") {
|
|
|
key := strings.Replace(field, "Variables.", "", -1)
|
|
|
variables[key] = ctx.R.FormValue(fieldWithPrefix)
|
|
|
} else {
|
|
@@ -374,6 +413,14 @@ func (collection *Collection) save(ctx *web.EventContext) (r web.EventResponse,
|
|
|
}
|
|
|
s := setting.GetSEOSetting()
|
|
|
for k, v := range settingVals {
|
|
|
+ if k == "OpenGraphMetadataString" {
|
|
|
+ metadata := GetOpenGraphMetadata(v.(string))
|
|
|
+ err = reflectutils.Set(&s, "OpenGraphMetadata", metadata)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ continue
|
|
|
+ }
|
|
|
err = reflectutils.Set(&s, k, v)
|
|
|
if err != nil {
|
|
|
return
|