diff options
author | Simon Ser <contact@emersion.fr> | 2020-02-05 18:57:16 +0100 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2020-02-05 18:57:16 +0100 |
commit | 9fe20a604c3ccf3f5e6799ed82bbc1d30743fb32 (patch) | |
tree | 9f7220cfed3290674793c7237e0239d962eda32c /plugins | |
parent | a1b43cc5a81c51c35590ed2ea8f47171dc38669c (diff) | |
download | alps-9fe20a604c3ccf3f5e6799ed82bbc1d30743fb32.tar.gz alps-9fe20a604c3ccf3f5e6799ed82bbc1d30743fb32.zip |
plugins/caldav: add pagination to calendar view
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/caldav/public/calendar.html | 6 | ||||
-rw-r--r-- | plugins/caldav/routes.go | 28 |
2 files changed, 28 insertions, 6 deletions
diff --git a/plugins/caldav/public/calendar.html b/plugins/caldav/public/calendar.html index 6011f9e..1855f4f 100644 --- a/plugins/caldav/public/calendar.html +++ b/plugins/caldav/public/calendar.html @@ -7,6 +7,7 @@ </p> <h2>Calendar: {{.Calendar.Name}}</h2> +<h3>{{.Time.Format "January 2006"}}</h3> {{if .Events}} <ul> @@ -22,4 +23,9 @@ <p>No events.</p> {{end}} +<p> + <a href="/calendar?month={{.PrevPage}}">Previous</a> + ยท <a href="/calendar?month={{.NextPage}}">Next</a> +</p> + {{template "foot.html"}} diff --git a/plugins/caldav/routes.go b/plugins/caldav/routes.go index 7ff831d..51a9490 100644 --- a/plugins/caldav/routes.go +++ b/plugins/caldav/routes.go @@ -12,8 +12,10 @@ import ( type CalendarRenderData struct { koushin.BaseRenderData - Calendar *caldav.Calendar - Events []caldav.CalendarObject + Time time.Time + Calendar *caldav.Calendar + Events []caldav.CalendarObject + PrevPage, NextPage string } type EventRenderData struct { @@ -22,18 +24,29 @@ type EventRenderData struct { Event *caldav.CalendarObject } +var monthPageLayout = "2006-01" + func registerRoutes(p *koushin.GoPlugin, u *url.URL) { p.GET("/calendar", func(ctx *koushin.Context) error { + var start time.Time + if s := ctx.QueryParam("month"); s != "" { + var err error + start, err = time.Parse(monthPageLayout, s) + if err != nil { + return fmt.Errorf("failed to parse month: %v", err) + } + } else { + now := time.Now() + start = time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location()) + } + end := start.AddDate(0, 1, 0) + // TODO: multi-calendar support c, calendar, err := getCalendar(u, ctx.Session) if err != nil { return err } - now := time.Now() - start := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location()) - end := start.AddDate(0, 1, 0) - query := caldav.CalendarQuery{ CompRequest: caldav.CalendarCompRequest{ Name: "VCALENDAR", @@ -65,8 +78,11 @@ func registerRoutes(p *koushin.GoPlugin, u *url.URL) { return ctx.Render(http.StatusOK, "calendar.html", &CalendarRenderData{ BaseRenderData: *koushin.NewBaseRenderData(ctx), + Time: start, Calendar: calendar, Events: events, + PrevPage: start.AddDate(0, -1, 0).Format(monthPageLayout), + NextPage: start.AddDate(0, 1, 0).Format(monthPageLayout), }) }) |