From 8e62b3191504cd1b726b743b14be4fcdd23b07bd Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Mon, 27 Nov 2017 17:31:02 +0100 Subject: [PATCH] Improved company editform --- pages/company/company.pixy | 7 ++++++- utils/editform/editform.go | 15 +++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/pages/company/company.pixy b/pages/company/company.pixy index 302e3d27..19457548 100644 --- a/pages/company/company.pixy +++ b/pages/company/company.pixy @@ -3,7 +3,12 @@ component CompanyPage(company *arn.Company, user *arn.User) h1= company.Name.English - .company-description!= markdown.Render(company.Description) + .company-description + div!= markdown.Render(company.Description) + ul + each link in company.Links + li + a(href=link.URL, target="_blank", rel="noopener")= link.Title component CompanyTabs(company *arn.Company, user *arn.User) .tabs diff --git a/utils/editform/editform.go b/utils/editform/editform.go index 3f482e06..a467ed25 100644 --- a/utils/editform/editform.go +++ b/utils/editform/editform.go @@ -12,7 +12,7 @@ import ( "github.com/animenotifier/notify.moe/utils" ) -// Render ... +// Render renders a generic editing UI for any kind of datatype that has an ID. func Render(obj interface{}, title string, user *arn.User) string { t := reflect.TypeOf(obj).Elem() v := reflect.ValueOf(obj).Elem() @@ -25,12 +25,15 @@ func Render(obj interface{}, title string, user *arn.User) string { b.WriteString(`
`) b.WriteString(`
`) + // Title b.WriteString(`

`) b.WriteString(title) b.WriteString(`

`) + // Render the object with its fields RenderObject(&b, obj, "") + // Additional buttons when logged in if user != nil { b.WriteString(`
`) @@ -94,7 +97,7 @@ func RenderField(b *bytes.Buffer, v *reflect.Value, field reflect.StructField, i if field.Name == "IsDraft" { return } - case "[]*arn.ExternalMedia": + case "[]*arn.ExternalMedia", "[]*arn.Link": for sliceIndex := 0; sliceIndex < fieldValue.Len(); sliceIndex++ { b.WriteString(`
`) b.WriteString(`
` + strconv.Itoa(sliceIndex+1) + ". " + field.Name + `
`) @@ -104,7 +107,11 @@ func RenderField(b *bytes.Buffer, v *reflect.Value, field reflect.StructField, i RenderObject(b, arrayObj, arrayIDPrefix) // Preview - b.WriteString(components.ExternalMedia(fieldValue.Index(sliceIndex).Interface().(*arn.ExternalMedia))) + // elementValue := fieldValue.Index(sliceIndex) + // RenderArrayElement(b, &elementValue) + if field.Type.String() == "[]*arn.ExternalMedia" { + b.WriteString(components.ExternalMedia(fieldValue.Index(sliceIndex).Interface().(*arn.ExternalMedia))) + } // Remove button b.WriteString(`