plugins/caldav: introduce helper CalendarObject type
This commit is contained in:
parent
3d1f278fae
commit
ee5ce517d1
3 changed files with 21 additions and 5 deletions
|
@ -59,3 +59,19 @@ func getCalendar(u *url.URL, session *alps.Session) (*caldav.Client, *caldav.Cal
|
|||
}
|
||||
return c, &calendars[0], nil
|
||||
}
|
||||
|
||||
type CalendarObject struct {
|
||||
*caldav.CalendarObject
|
||||
}
|
||||
|
||||
func newCalendarObjectList(cos []caldav.CalendarObject) []CalendarObject {
|
||||
l := make([]CalendarObject, len(cos))
|
||||
for i := range cos {
|
||||
l[i] = CalendarObject{&cos[i]}
|
||||
}
|
||||
return l
|
||||
}
|
||||
|
||||
func (ao CalendarObject) URL() string {
|
||||
return "/calendar/" + url.PathEscape(ao.Path)
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
{{range .Events}}
|
||||
{{$event := index .Data.Events 0}}
|
||||
<li>
|
||||
<a href="/calendar/{{$event.Path | pathescape}}">{{$event.Props.Text "SUMMARY"}}</a>
|
||||
<a href="{{$event.URL}}">{{$event.Props.Text "SUMMARY"}}</a>
|
||||
({{$event.DateTimeStart nil | formatdate}} — {{$event.DateTimeEnd nil | formatdate}})
|
||||
</li>
|
||||
{{end}}
|
||||
|
|
|
@ -15,14 +15,14 @@ type CalendarRenderData struct {
|
|||
alps.BaseRenderData
|
||||
Time time.Time
|
||||
Calendar *caldav.Calendar
|
||||
Events []caldav.CalendarObject
|
||||
Events []CalendarObject
|
||||
PrevPage, NextPage string
|
||||
}
|
||||
|
||||
type EventRenderData struct {
|
||||
alps.BaseRenderData
|
||||
Calendar *caldav.Calendar
|
||||
Event *caldav.CalendarObject
|
||||
Event CalendarObject
|
||||
}
|
||||
|
||||
var monthPageLayout = "2006-01"
|
||||
|
@ -90,7 +90,7 @@ func registerRoutes(p *alps.GoPlugin, u *url.URL) {
|
|||
BaseRenderData: *alps.NewBaseRenderData(ctx),
|
||||
Time: start,
|
||||
Calendar: calendar,
|
||||
Events: events,
|
||||
Events: newCalendarObjectList(events),
|
||||
PrevPage: start.AddDate(0, -1, 0).Format(monthPageLayout),
|
||||
NextPage: start.AddDate(0, 1, 0).Format(monthPageLayout),
|
||||
})
|
||||
|
@ -142,7 +142,7 @@ func registerRoutes(p *alps.GoPlugin, u *url.URL) {
|
|||
return ctx.Render(http.StatusOK, "event.html", &EventRenderData{
|
||||
BaseRenderData: *alps.NewBaseRenderData(ctx),
|
||||
Calendar: calendar,
|
||||
Event: event,
|
||||
Event: CalendarObject{event},
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue