Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue when using editor.Tags and reference.SelectRepeater #59

Closed
nilslice opened this issue Feb 2, 2017 · 6 comments
Closed

Issue when using editor.Tags and reference.SelectRepeater #59

nilslice opened this issue Feb 2, 2017 · 6 comments
Assignees

Comments

@nilslice
Copy link
Contributor

nilslice commented Feb 2, 2017

values in fields for select repeaters and tags end up being merged/copied into one another in some scenarios

example where it can be reproduced:

package content

import (
	"fmt"

	"github.com/bosssauce/reference"

	"github.com/ponzu-cms/ponzu/management/editor"
	"github.com/ponzu-cms/ponzu/system/item"
)

type Channel struct {
	item.Item

	Title  string   `json:"title"`
	Videos []string `json:"videos"`
	Rating string   `json:"rating"`
	Tags   []string `json:"tags"`
}

// MarshalEditor writes a buffer of html to edit a Channel within the CMS
// and implements editor.Editable
func (c *Channel) MarshalEditor() ([]byte, error) {
	view, err := editor.Form(c,
		// Take note that the first argument to these Input-like functions
		// is the string version of each Channel field, and must follow
		// this pattern for auto-decoding and auto-encoding reasons:
		editor.Field{
			View: editor.Input("Title", c, map[string]string{
				"label":       "Title",
				"type":        "text",
				"placeholder": "Enter the Title here",
			}),
		},
		editor.Field{
			View: reference.SelectRepeater("Videos", c, map[string]string{
				"label": "Videos",
			}, "Video", `{{.title}} ({{.rating}})`),
		},
		editor.Field{
			View: editor.Select("Rating", c, map[string]string{
				"label": "Rating",
			}, map[string]string{
				"G":     "G",
				"PG":    "PG",
				"PG-13": "PG-13",
				"R":     "R",
			}),
		},
		editor.Field{
			View: editor.Tags("Tags", c, map[string]string{
				"label": "Tags",
			}),
		},
	)

	if err != nil {
		return nil, fmt.Errorf("Failed to render Channel editor view: %s", err.Error())
	}

	return view, nil
}

func init() {
	item.Types["Channel"] = func() interface{} { return new(Channel) }
}

func (c *Channel) String() string {
	return c.Title
}

func (c *Channel) Push() []string {
	return []string{
		"videos",
	}
}
@arjanvaneersel
Copy link

arjanvaneersel commented Feb 20, 2017

The issue I'm having with Ponzu in the other thread has to do with exactly the same code.I went back to the recording of the gopher academy training on Ponzu to do the exercise again to get the hang of Ponzu. However the updates to channel.go now result in a panic error as soon as I try to create a new channel via admin. Am i doing something wrong or is this connected to this bug?

package content

import ( 
"fmt"

"github.com/ponzu-cms/ponzu/management/editor" 
"github.com/ponzu-cms/ponzu/system/item" 
"github.com/arjanvaneersel/gotv/addons/github.com/bosssauce/reference" 
)

type Channel struct { 
item.Item

Title string `json:"title"` 
Videos []string `json:"videos"` 
Rating string `json:"rating"` 
Tags []string `json:"tags"` 
}

// MarshalEditor writes a buffer of html to edit a Channel within the CMS 
// and implements editor.Editable 
func (c *Channel) MarshalEditor() ([]byte, error) { 
view, err := editor.Form(c, 
// Take note that the first argument to these Input-like functions 
// is the string version of each Channel field, and must follow 
// this pattern for auto-decoding and auto-encoding reasons: 
editor.Field{ 
View: editor.Input("Title", c, map[string]string{ 
"label": "Title", 
"type": "text", 
"placeholder": "Enter the Title here", 
}), 
}, 
editor.Field{ 
View: reference.SelectRepeater("Videos", c, map[string]string{ 
"label": "Videos", 
}, "Video", `{{.title}} ({{.rating}})`), 
}, 
editor.Field{ 
View: editor.Select("Rating", c, map[string]string{ 
"label": "Rating", 
}, map[string]string{ 
"G": "G", 
"PG": "PG", 
"PG-13": "PG-13", 
"R": "R", 
}), 
}, 
editor.Field{ 
View: editor.Tags("Tags", c, map[string]string{ 
"label": "Tags", 
}), 
}, 
)

if err != nil { 
return nil, fmt.Errorf("Failed to render Channel editor view: %s", err.Error()) 
}

return view, nil 
}

func init() { 
item.Types["Channel"] = func() interface{} { return new(Channel) } 
}

The error I get:
2017/02/19 09:09:07 http: panic serving [::1]:39134: interface conversion: interface {} is nil, not string
goroutine 36 [running]:
net/http.(*conn).serve.func1(0xc4201583c0)
/usr/local/go/src/net/http/server.go:1721 +0xd0
panic(0x895a00, 0xc42013da40)
/usr/local/go/src/runtime/panic.go:489 +0x2cf
github.com/ponzu-cms/ponzu/system/addon.ContentAll(0x90f229, 0x5, 0xc420017650, 0x0, 0xc420017650)
/home/arjan/Development/Go/src/github.com/ponzu-cms/ponzu/system/addon/api.go:21 +0x3d2
github.com/arjanvaneersel/gotv/addons/github.com/bosssauce/reference.encodeDataToOptions(0x90f229, 0x5, 0x91bd00, 0x18, 0xc420104980, 0x1, 0x1)
/home/arjan/Development/Go/src/github.com/arjanvaneersel/gotv/addons/github.com/bosssauce/reference/reference.go:122 +0xac
github.com/arjanvaneersel/gotv/addons/github.com/bosssauce/reference.SelectRepeater(0x90fee4, 0x6, 0x8f7d40, 0xc420151050, 0xc4200175f0, 0x90f229, 0x5, 0x91bd00, 0x18, 0x7f2df8309440, ...)
/home/arjan/Development/Go/src/github.com/arjanvaneersel/gotv/addons/github.com/bosssauce/reference/reference.go:57 +0x384
github.com/arjanvaneersel/gotv/cmd/ponzu/vendor/github.com/ponzu-cms/ponzu/content.(*Channel).MarshalEditor(0xc420151050, 0xc420104940, 0xe200000000000000, 0x8, 0xe20fd6032780c56a, 0x0)
/home/arjan/Development/Go/src/github.com/arjanvaneersel/gotv/cmd/ponzu/vendor/github.com/ponzu-cms/ponzu/content/channel.go:37 +0x280
github.com/arjanvaneersel/gotv/cmd/ponzu/vendor/github.com/ponzu-cms/ponzu/management/manager.Manage(0xb38580, 0xc420151050, 0xc420117e75, 0x7, 0xc420151050, 0x1, 0x0, 0x0, 0x0)
/home/arjan/Development/Go/src/github.com/arjanvaneersel/gotv/cmd/ponzu/vendor/github.com/ponzu-cms/ponzu/management/manager/manager.go:122 +0x4c
github.com/arjanvaneersel/gotv/cmd/ponzu/vendor/github.com/ponzu-cms/ponzu/system/admin.editHandler(0xb3ea80, 0xc4219b4460, 0xc420188000)
/home/arjan/Development/Go/src/github.com/arjanvaneersel/gotv/cmd/ponzu/vendor/github.com/ponzu-cms/ponzu/system/admin/handlers.go:1490 +0x27f0
net/http.HandlerFunc.ServeHTTP(0x935828, 0xb3ea80, 0xc4219b4460, 0xc420188000)
/usr/local/go/src/net/http/server.go:1942 +0x44
github.com/arjanvaneersel/gotv/cmd/ponzu/vendor/github.com/ponzu-cms/ponzu/system/admin/user.Auth.func1(0xb3ea80, 0xc4219b4460, 0xc420188000)
/home/arjan/Development/Go/src/github.com/arjanvaneersel/gotv/cmd/ponzu/vendor/github.com/ponzu-cms/ponzu/system/admin/user/auth.go:55 +0xda
net/http.HandlerFunc.ServeHTTP(0xc4201040b0, 0xb3ea80, 0xc4219b4460, 0xc420188000)
/usr/local/go/src/net/http/server.go:1942 +0x44
net/http.(*ServeMux).ServeHTTP(0xb803a0, 0xb3ea80, 0xc4219b4460, 0xc420188000)
/usr/local/go/src/net/http/server.go:2238 +0x130
net/http.serverHandler.ServeHTTP(0xc420090b00, 0xb3ea80, 0xc4219b4460, 0xc420188000)
/usr/local/go/src/net/http/server.go:2568 +0x92
net/http.(*conn).serve(0xc4201583c0, 0xb3f380, 0xc420100480)
/usr/local/go/src/net/http/server.go:1825 +0x612
created by net/http.(*Server).Serve
/usr/local/go/src/net/http/server.go:2668 +0x2ce

@nilslice
Copy link
Contributor Author

Hi @arjanvaneersel -

However the updates to channel.go now result in a panic error as soon as I try to create a new channel via admin.

Which updates do you mean?

@arjanvaneersel
Copy link

I obviously haven't been clear. I'm doing the exercise as shown in the recording of the gopher academy training on Ponzu again. After the creation of alle the content types the go files are being changed in the training, so I follow along. The moment when I "update" the editor.Field for Videos, which was just a normal input type, to reference.SelectRepeater and build and run Ponzu again, then I get this error when going into Ponzu's editor for this content type.

@nilslice
Copy link
Contributor Author

nilslice commented Feb 21, 2017 via email

@arjanvaneersel
Copy link

That indeed did it. I relied on the auto import function of gogland and never even thought about something as simple as checking the import path... Thanks for your help.

@nilslice
Copy link
Contributor Author

Excellent! Glad it fixed the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants