package schedulehistories import "github.com/tigorlazuardi/redmage/views" import "github.com/tigorlazuardi/redmage/views/components" import "github.com/tigorlazuardi/redmage/api" import "fmt" import "time" import "github.com/tigorlazuardi/redmage/views/icons" import "github.com/tigorlazuardi/redmage/models" type Data struct { ScheduleHistories api.ScheduleHistoryListResult Params api.ScheduleHistoryListParams FirstSchedule *models.ScheduleHistory LastSchedule *models.ScheduleHistory IsCurrent bool Error string } templ View(c *views.Context, data Data) { @components.Doctype() { @components.Head(c, components.HeadTitle("Schedule History"), ) @components.Body(c) { @components.Container() { @Content(c, data) } @components.NotificationContainer() { if data.Error != "" { @components.ErrorNotication(data.Error) } } } } } templ Content(c *views.Context, data Data) {

Schedule History ({ time.Local.String() })

@dateBar(data) if len(data.ScheduleHistories.Schedules) == 0 {

There are no history schedules found for current date.

} if len(data.ScheduleHistories.Schedules) > 0 { for _, history := range data.ScheduleHistories.SplitByDay() {

{ history.Date.Format("Monday, 02 January 2006") }

Time Event for i, schedule := range history.Schedules { if i > 0 {
}

{ time.Unix(schedule.CreatedAt, 0).Format("15:04:05") }

if api.ScheduleStatus(schedule.Status) == api.ScheduleStatusDisabled { Subreddit @subredditLink(schedule.Subreddit) scheduler has been set to { api.ScheduleStatusDisabled.String() } status. } else if api.ScheduleStatus(schedule.Status) == api.ScheduleStatusEnabled { Subreddit @subredditLink(schedule.Subreddit) { " " } has been { api.ScheduleStatusEnabled.String() } { "for" } automatic scheduling. } else if api.ScheduleStatus(schedule.Status) == api.ScheduleStatusStandby { Subreddit @subredditLink(schedule.Subreddit) { " " } has finished { api.ScheduleStatusDownloading.String() } and turned to { api.ScheduleStatusStandby.String() } status. } else if api.ScheduleStatus(schedule.Status) == api.ScheduleStatusEnqueued { Subreddit @subredditLink(schedule.Subreddit) { " " } is { api.ScheduleStatusEnqueued.String() } { "for" } downloading. } else if api.ScheduleStatus(schedule.Status) == api.ScheduleStatusDownloading { Subreddit @subredditLink(schedule.Subreddit) { " " } has started { api.ScheduleStatusDownloading.String() }. } else if api.ScheduleStatus(schedule.Status) == api.ScheduleStatusError { Subreddit @subredditLink(schedule.Subreddit) { " " } finishes { api.ScheduleStatusDownloading.String() } with { api.ScheduleStatusError.String() } of "{ schedule.ErrorMessage }". } }
} } if len(data.ScheduleHistories.Schedules) > 20 { @dateBar(data) } @actionButton(data)
} templ actionButton(data Data) {
@components.ActionButton(actionButtonItems(data)...)
} func actionButtonItems(data Data) []templ.Component { out := make([]templ.Component, 0, 2) if !data.IsCurrent { out = append(out, actionButtonPrev(data)) } if len(data.ScheduleHistories.Schedules) >= int(data.Params.Limit) || data.Params.Reversed { out = append(out, actionButtonNext(data)) } if data.IsCurrent { out = append(out, actionButtonRefresh()) } return out } templ dateBar(data Data) {
if data.IsCurrent {
@icons.Refresh("w-6 h-6")
} else {
@icons.ChevronBoldLeft("w-6 h-6")
} if len(data.ScheduleHistories.Schedules) >= int(data.Params.Limit) || data.Params.Reversed {
@icons.ChevronBoldRight("w-6 h-6")
}
} templ actionButtonNext(data Data) { Next } templ actionButtonPrev(data Data) { Previous } templ actionButtonRefresh() { Refresh } templ subredditLink(subreddit string) { { subreddit } }