plugins/caldav: add pagination to calendar view
This commit is contained in:
parent
a1b43cc5a8
commit
9fe20a604c
2 changed files with 28 additions and 6 deletions
|
@ -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"}}
|
||||
|
|
|
@ -12,8 +12,10 @@ import (
|
|||
|
||||
type CalendarRenderData struct {
|
||||
koushin.BaseRenderData
|
||||
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),
|
||||
})
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in a new issue