templates/calendar.go (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | package templates import ( "fmt" "time" g "go.alanpearce.eu/gomponents" c "go.alanpearce.eu/gomponents/components" . "go.alanpearce.eu/gomponents/html" "vimagination.zapto.org/ics" "go.alanpearce.eu/homestead/internal/calendar" ) func CalendarPage( site SiteSettings, page PageSettings, cal calendar.Calendar, ) g.Node { return Layout(site, page, Calendar(site, cal)) } func Calendar(site SiteSettings, cal calendar.Calendar) g.Node { past := true dates, err := cal.Availability(2) if err != nil { panic(err) } return Div(Class("calendar"), H2(g.Text("Calendar")), P(g.Text("Here you can roughly see when I'm busy in the next two weeks.")), P(Class("only-small-portrait"), g.Text("Rotate to see calendar view and previous days.")), Section(Class("calendar-grid"), g.Map(dates, func(date *calendar.CalendarDate) g.Node { if past && date.IsToday() { past = false } return Section(c.Classes{ "day": true, "past": past, "today": date.IsToday(), }, H3( Time( DateTime(date.Format(time.DateOnly)), g.Text(date.Format("Mon _2"))), ), g.Map(date.BusyPeriods, func(e *calendar.Busy) g.Node { return Div( c.Classes{ "event": true, "tentative": e.Type == ics.FreeBusyTypeBusyTentative, }, TitleAttr( fmt.Sprintf( "%sā%s", e.StartTime.Format(time.RFC1123), e.EndTime.Format(time.RFC1123), ), ), g.If(e.StartTime.Before(date.BeginningOfDay()), CTime(date.BeginningOfDay()), CTime(e.StartTime), ), g.Text("ā"), g.If(e.EndTime.After(date.EndOfDay()), CTime(date.EndOfDay()), CTime(e.EndTime), ), g.If(e.Type == ics.FreeBusyTypeBusyTentative, g.Text("?"), ), ) }), ) }), ), Footer( P(g.Textf("Timezone is %s", site.Timezone.String())), ), ) } func CTime(date calendar.Date) g.Node { return Time( DateTime(date.Format(time.RFC3339)), g.Text(date.Format("15:04")), ) } |