Skip to content

Commit c781a27

Browse files
author
stackdump
authored
Merge pull request #97 from allinbits/fix/event-render-noregistry
Fix/event render noregistry
2 parents 1f06463 + 9b498f0 commit c781a27

File tree

14 files changed

+142
-111
lines changed

14 files changed

+142
-111
lines changed

projects/gnoland/gno.land/p/eve000/event/component/calendar.gno

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package component
22

33
import (
44
"net/url"
5-
"strconv"
65
"strings"
76
"time"
87

@@ -61,7 +60,7 @@ func IcsCalendarFile(path string, a *Flyer) string {
6160
w("END:VEVENT\n")
6261

6362
for i, s := range a.Sessions {
64-
id := Pad3(strconv.Itoa(i))
63+
id := Pad3(i)
6564
if !include(id) {
6665
continue
6766
}
@@ -91,7 +90,7 @@ func IcsCalendarFile(path string, a *Flyer) string {
9190
default:
9291
w(f("# %s\n\n%s", a.Name, a.Description))
9392
for i, s := range a.Sessions {
94-
id := Pad3(strconv.Itoa(i))
93+
id := Pad3(i)
9594
if !include(id) {
9695
continue
9796
}

projects/gnoland/gno.land/p/eve000/event/component/component.gno

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,18 @@ func slugify(s string) string {
296296
return strings.Trim(re.ReplaceAllString(strings.ToLower(s), "-"), "-")
297297
}
298298

299-
func Pad3(s string) string {
299+
func Pad3(val interface{}) string {
300+
var s string
301+
switch v := val.(type) {
302+
case string:
303+
s = v
304+
case int:
305+
s = strconv.Itoa(v)
306+
case int64:
307+
s = strconv.FormatInt(v, 10)
308+
default:
309+
panic("Pad3: unsupported type")
310+
}
300311
for len(s) < 3 {
301312
s = "0" + s
302313
}

projects/gnoland/gno.land/p/eve000/event/component/flyer.gno

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func (a *Flyer) ToMarkdown(body ...Content) string {
110110
markdown += "## Locations\n\n" + locationsMarkdown
111111
}
112112
if _, ok := a.RenderOpts()["SvgFooter"]; ok {
113-
markdown += "[![Flyer SVG](" + a.ToSvgDataUrl() + ")](" + a.ToAnchor() + ")\n\n"
113+
markdown += "\n\n[![Flyer SVG](" + a.ToSvgDataUrl() + ")](" + a.ToAnchor() + ")\n\n"
114114
}
115115

116116
return markdown

projects/gnoland/gno.land/p/eve000/event/event.gno

Lines changed: 49 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@ import (
66
"time"
77

88
"gno.land/p/demo/avl"
9-
"gno.land/p/eve000/event/component"
9+
eve "gno.land/p/eve000/event/component"
1010
)
1111

12-
// FIXME either change interface or satisfy it
13-
//var _ Api = (*Event)(nil)
14-
1512
type Api interface {
1613
AddOrganizer(addr std.Address)
1714
AddProposer(addr, sender std.Address)
@@ -24,6 +21,8 @@ type Api interface {
2421
JoinAsAttendee()
2522
JoinWaitlist()
2623
ListRoles() []string
24+
// REVIEW: should setLive Event be part of the API? - we may not use due to versioning issues
25+
PublishEvent(evt *Event, opts map[string]interface{}) string
2726
RegisterEvent(evt *Event, opts map[string]interface{}) string
2827
RemoveOrganizer(addr std.Address)
2928
RemoveProposer(addr, sender std.Address)
@@ -53,13 +52,13 @@ type Storage struct {
5352
// the event object is protected for edits only by patching from specific 'sub-realms'
5453
type Event struct {
5554
Name string
56-
Location *component.Location
55+
Location *eve.Location
5756
StartDate time.Time
5857
EndDate time.Time
5958
Description string
60-
Sessions []*component.Session
61-
Status component.EventStatus
62-
AttendanceMode component.EventAttendanceMode
59+
Sessions []*eve.Session
60+
Status eve.EventStatus
61+
AttendanceMode eve.EventAttendanceMode
6362
Images []string
6463
renderOpts map[string]interface{}
6564
storage *Storage
@@ -69,7 +68,7 @@ func (evt *Event) SetEventName(name string) {
6968
evt.Name = name
7069
}
7170

72-
func (evt *Event) SetEventLocation(loc *component.Location) {
71+
func (evt *Event) SetEventLocation(loc *eve.Location) {
7372
evt.Location = loc
7473
}
7574

@@ -85,70 +84,69 @@ func (evt *Event) SetEventDescription(description string) {
8584
evt.Description = description
8685
}
8786

88-
func (evt *Event) SetSessions(sessions []*component.Session) {
87+
func (evt *Event) SetSessions(sessions []*eve.Session) {
8988
evt.Sessions = sessions
9089
}
9190

92-
func (evt *Event) AddSpeaker(s *component.Speaker) {
91+
func (evt *Event) AddSpeaker(s *eve.Speaker) {
9392
if evt.storage == nil {
9493
evt.storage = &Storage{}
9594
}
9695
if evt.storage.Speakers == nil {
9796
evt.storage.Speakers = &avl.Tree{}
9897
}
99-
id := component.Pad3(strconv.Itoa(evt.storage.Speakers.Size()))
100-
evt.storage.Speakers.Set(component.Pad3(id), s)
98+
id := eve.Pad3(evt.storage.Speakers.Size())
99+
evt.storage.Speakers.Set(eve.Pad3(id), s)
101100
}
102101

103-
func (evt *Event) AddLocation(loc *component.Location) {
102+
func (evt *Event) AddLocation(loc *eve.Location) {
104103
if evt.storage == nil {
105104
evt.storage = &Storage{}
106105
}
107106
if evt.storage.Locations == nil {
108107
evt.storage.Locations = &avl.Tree{}
109108
}
110-
id := component.Pad3(strconv.Itoa(evt.storage.Locations.Size()))
111-
evt.storage.Locations.Set(component.Pad3(id), loc)
109+
id := eve.Pad3(evt.storage.Locations.Size())
110+
evt.storage.Locations.Set(eve.Pad3(id), loc)
112111
}
113112

114-
func (evt *Event) AddSession(sess *component.Session) {
113+
func (evt *Event) AddSession(sess *eve.Session) {
115114
if evt.storage == nil {
116115
evt.storage = &Storage{}
117116
}
118117
if evt.storage.Sessions == nil {
119118
evt.storage.Sessions = &avl.Tree{}
120119
}
121-
// TODO: maybe Pad3 can accept interface so extras stringconv isn't needed here
122-
id := component.Pad3(strconv.Itoa(evt.storage.Sessions.Size()))
123-
evt.storage.Sessions.Set(component.Pad3(id), sess)
120+
id := eve.Pad3(strconv.Itoa(evt.storage.Sessions.Size()))
121+
evt.storage.Sessions.Set(eve.Pad3(id), sess)
124122
}
125123

126-
func (evt *Event) GetSpeaker(id string) *component.Speaker {
127-
s, ok := evt.storage.Speakers.Get(component.Pad3(id))
124+
func (evt *Event) GetSpeaker(id string) *eve.Speaker {
125+
s, ok := evt.storage.Speakers.Get(eve.Pad3(id))
128126
if !ok {
129127
panic("speaker not found: id=" + id)
130128
}
131-
return s.(*component.Speaker)
129+
return s.(*eve.Speaker)
132130
}
133131

134-
func (evt *Event) GetLocation(id string) *component.Location {
135-
l, ok := evt.storage.Locations.Get(component.Pad3(id))
132+
func (evt *Event) GetLocation(id string) *eve.Location {
133+
l, ok := evt.storage.Locations.Get(eve.Pad3(id))
136134
if !ok {
137135
panic("location not found: id=" + id)
138136
}
139-
return l.(*component.Location)
137+
return l.(*eve.Location)
140138
}
141139

142-
func (evt *Event) GetSession(id string) *component.Session {
143-
s, ok := evt.storage.Sessions.Get(component.Pad3(id))
140+
func (evt *Event) GetSession(id string) *eve.Session {
141+
s, ok := evt.storage.Sessions.Get(eve.Pad3(id))
144142
if !ok {
145143
panic("session not found: id=" + id)
146144
}
147-
return s.(*component.Session)
145+
return s.(*eve.Session)
148146
}
149147

150-
func (evt *Event) Flyer() *component.Flyer {
151-
flyer := &component.Flyer{
148+
func (evt *Event) Flyer() *eve.Flyer {
149+
flyer := &eve.Flyer{
152150
Name: evt.Name,
153151
Location: nil,
154152
StartDate: evt.StartDate,
@@ -163,7 +161,7 @@ func (evt *Event) Flyer() *component.Flyer {
163161
flyer.Location = &loc
164162
}
165163
if evt.Sessions != nil {
166-
flyer.Sessions = make([]*component.Session, len(evt.Sessions))
164+
flyer.Sessions = make([]*eve.Session, len(evt.Sessions))
167165
for i, s := range evt.Sessions {
168166
if s != nil {
169167
sessionCopy := *s
@@ -175,20 +173,36 @@ func (evt *Event) Flyer() *component.Flyer {
175173
return flyer
176174
}
177175

178-
// Event may not be a component (yet!) but it is where the render opts are stored.
179176
func (evt *Event) RenderOpts() map[string]interface{} {
180177
return evt.renderOpts
181178
}
182179

180+
func (evt *Event) initStorage() {
181+
for _, s := range evt.Sessions {
182+
evt.AddSession(s)
183+
evt.AddSpeaker(s.Speaker)
184+
evt.AddLocation(s.Location)
185+
}
186+
187+
}
188+
183189
func (evt *Event) SetRenderOpts(opts map[string]interface{}) {
184190
evt.renderOpts = opts
191+
if evt.storage == nil {
192+
evt.initStorage()
193+
}
194+
for _, s := range evt.Sessions {
195+
s.SetRenderOpts(opts)
196+
s.Speaker.SetRenderOpts(opts)
197+
s.Location.SetRenderOpts(opts)
198+
}
185199
}
186200

187201
func (evt *Event) ToAnchor() string {
188-
return component.StringToAnchor(evt.Name)
202+
return eve.StringToAnchor(evt.Name)
189203
}
190204

191205
// Render provides a syntactic sugar for rendering a Flyer using a template function.
192-
func (evt *Event) Render(path string, tpl func(path string, flyer *component.Flyer) string) string {
206+
func (evt *Event) Render(path string, tpl func(path string, flyer *eve.Flyer) string) string {
193207
return tpl(path, evt.Flyer())
194208
}

projects/gnoland/gno.land/p/eve000/event/registry.gno

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88

99
"gno.land/p/demo/avl"
1010
"gno.land/p/demo/ufmt"
11-
"gno.land/p/eve000/event/component"
11+
eve "gno.land/p/eve000/event/component"
1212
)
1313

1414
type Registry struct {
@@ -19,7 +19,7 @@ type Registry struct {
1919
patchRealm string // realm that is allowed to update the patch level, used for debugging and content management
2020
}
2121

22-
func (r *Registry) Render(path string, body ...component.Content) string {
22+
func (r *Registry) Render(path string, body ...eve.Content) string {
2323
fullURL := std.CurrentRealm().PkgPath() + path // REVIEW: is this really needed?
2424
u, err := url.Parse(fullURL)
2525
if err != nil {
@@ -32,14 +32,14 @@ func (r *Registry) Render(path string, body ...component.Content) string {
3232
}
3333
evt := r.GetEvent(event_id)
3434
switch {
35-
case component.HasQueryParam(q, "session"):
36-
return component.RenderComponent(path, evt.GetSession(q.Get("session")))
37-
case component.HasQueryParam(q, "location"):
38-
return component.RenderComponent(path, evt.GetLocation(q.Get("location")))
39-
case component.HasQueryParam(q, "speaker"):
40-
return component.RenderComponent(path, evt.GetSpeaker(q.Get("speaker")))
35+
case eve.HasQueryParam(q, "session"):
36+
return eve.RenderComponent(path, evt.GetSession(q.Get("session")))
37+
case eve.HasQueryParam(q, "location"):
38+
return eve.RenderComponent(path, evt.GetLocation(q.Get("location")))
39+
case eve.HasQueryParam(q, "speaker"):
40+
return eve.RenderComponent(path, evt.GetSpeaker(q.Get("speaker")))
4141
default:
42-
return component.RenderPage(path, evt.Flyer(), body...)
42+
return eve.RenderPage(path, evt.Flyer(), body...)
4343
}
4444
}
4545

@@ -67,7 +67,7 @@ func (r *Registry) SetPatchLevel(level int) {
6767
}
6868

6969
func (r *Registry) GetEvent(id string) *Event {
70-
e, ok := r.Events.Get(component.Pad3(id))
70+
e, ok := r.Events.Get(eve.Pad3(id))
7171
if !ok {
7272
panic("event not found" + id)
7373
}
@@ -88,17 +88,7 @@ func (r *Registry) RegisterEvent(e *Event, opts map[string]interface{}) string {
8888
}
8989
e.SetRenderOpts(opts)
9090

91-
// REVIEW: is there a better way to inject options?
92-
for _, s := range e.Sessions {
93-
s.SetRenderOpts(opts)
94-
e.AddSession(s)
95-
s.Speaker.SetRenderOpts(opts)
96-
e.AddSpeaker(s.Speaker) // REVIEW: why call addSpeaker if record was included as input?
97-
s.Location.SetRenderOpts(opts)
98-
e.AddLocation(s.Location)
99-
}
100-
101-
id := component.Pad3(strconv.Itoa(r.Events.Size())) // 001, 002, etc.
91+
id := eve.Pad3(r.Events.Size())
10292
r.Events.Set(id, e)
10393
return id
10494
}
Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
WIP
22
---
3+
High level TODOs for eve
4+
5+
- [ ] Focus on separation between Event -> Flyer objects for security and developer api
6+
- [ ] Refine ACL to make it more flexible between events
7+
- [ ] Test /events api with all registered events
8+
- [ ] Audit for security issues with event permissions re: realm-based perms
9+
- [ ] add rendering tests for each type of supported event config location/speaker/cancelled events
10+
11+
Consider a possible work-around for inability to share directly
12+
- we could integrate w/ google calendar - manually importing and ICS then sharing that link
13+
14+
BACKLOG
15+
-------
16+
317
- [ ] test ICS integration with gnocal server
418
- [ ] make sure HasRole and RenderCalendar are available at proper realms
519
- [ ] add URL pointers for aiblabs domain (for testing on aiblabs.com)
620
- [ ] fix event.ToJsonLD() to populate all fields states
7-
8-
BACKLOG
9-
-------
10-
1121
- [ ] update gnocal server to have a landing page in html, SVG + w/ jsonLD nested for structured data
1222
- [ ] fix/test the `/events` api
1323
- [ ] consider refactoring acl.gno for each event's specific needs
@@ -16,8 +26,4 @@ BACKLOG
1626
- [ ] test content blocks with callbacks
1727

1828
DONE
19-
-----
20-
- [x] fix http://127.0.0.1:8888/r/buidlthefuture000/events/onsite001?format=ics
21-
- [x] finish refactoring component.RenderPage - we now have registery.Render() involved calling component...
22-
- [x] add version number to bottom of /events page
23-
29+
-----

projects/gnoland/gno.land/r/buidlthefuture000/events/gnolandlaunch/app.gno

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"std"
55

66
"gno.land/p/eve000/event"
7-
"gno.land/p/eve000/event/component"
7+
eve "gno.land/p/eve000/event/component"
88
)
99

1010
type App struct{}
@@ -23,7 +23,7 @@ func (*App) Render(path string) (out string) {
2323
}
2424

2525
func (*App) RenderCalendar(path string) string {
26-
return app.LiveEvent().Render(path, component.IcsCalendarFile)
26+
return app.LiveEvent().Render(path, eve.IcsCalendarFile)
2727
}
2828

2929
func (*App) SetContent(key, markdown string) {
@@ -47,13 +47,17 @@ func (*App) LiveEvent() *event.Event {
4747
return registry.GetEvent(registry.LiveEventId)
4848
}
4949

50-
func (*App) RegisterEvent(evt *event.Event, opts map[string]interface{}) string {
51-
registry.SetRenderOpts(opts)
52-
id := registry.RegisterEvent(evt, opts)
50+
func (*App) PublishEvent(evt *event.Event, opts map[string]interface{}) string {
51+
id := app.RegisterEvent(evt, opts)
5352
registry.LiveEventId = id
5453
return id
5554
}
5655

56+
func (*App) RegisterEvent(evt *event.Event, opts map[string]interface{}) string {
57+
registry.SetRenderOpts(opts)
58+
return registry.RegisterEvent(evt, opts)
59+
}
60+
5761
func (*App) AdminSetRole(role string, addr std.Address) {
5862
acl.AdminSetRole(role, addr)
5963
}

0 commit comments

Comments
 (0)