Redmage/views/schedulehistoriesview/schedulesview.templ

110 lines
4.1 KiB
Plaintext
Raw Normal View History

package schedulehistoriesview
import "github.com/tigorlazuardi/redmage/views"
import "github.com/tigorlazuardi/redmage/views/components"
import "time"
import "github.com/tigorlazuardi/redmage/api"
import "fmt"
templ ScheduleHistoriesview(c *views.Context, data Data) {
@components.Doctype() {
@components.Head(c,
components.HeadTitle("Schedule History"),
)
@components.Body(c) {
@ScheduleHistoriesContent(c, data)
}
}
}
templ ScheduleHistoriesContent(c *views.Context, data Data) {
<main class="prose min-w-full">
@components.Container() {
if data.Error != "" {
@components.ErrorToast(data.Error)
} else {
<h1>Schedule History</h1>
<div class="divider"></div>
if data.Total < 1 {
<h2>There are no history schedules to be found. You can populate this page's history by manually trigger a <a href="/subreddits" class="text-primary">Subreddit</a> { "for" } downloading.</h2>
}
if data.Total > 0 {
<div class="grid">
for _, scheduleGroup := range data.splitByDays() {
<h2>{ scheduleGroup.Day.Format("Monday, _2 January 2006") }</h2>
<div class="divider"></div>
<div class="hidden sm:grid sm:grid-cols-[1fr,3fr]">
<span class="font-bold">Time</span>
<span class="font-bold">Event</span>
</div>
for _, schedule := range scheduleGroup.Schedules {
<div class="grid sm:grid-cols-[1fr,3fr] mb-4 sm:mb-2">
<span>
<div
data-name="schedule-tooltip"
class="tooltip"
data-tip={ time.Unix(schedule.CreatedAt, 10).In(time.Local).Format(time.RFC3339) }
>
<span class="font-bold">{ time.Unix(schedule.CreatedAt, 10).In(time.Local).Format("15:04:05") }</span>
</div>
</span>
if api.ScheduleStatus(schedule.Status) == api.ScheduleStatusDisabled {
<span>
Subreddit
@subredditLink(schedule.Subreddit)
scheduler has been set to { api.ScheduleStatusDisabled.String() } status.
</span>
} else if api.ScheduleStatus(schedule.Status) == api.ScheduleStatusEnabled {
<span>
Subreddit
@subredditLink(schedule.Subreddit)
{ " " }
has been <b>{ api.ScheduleStatusEnabled.String() }</b> { "for" } automatic scheduling.
</span>
} else if api.ScheduleStatus(schedule.Status) == api.ScheduleStatusStandby {
<span>
Subreddit
@subredditLink(schedule.Subreddit)
{ " " }
has finished
<b class="text-secondary">{ api.ScheduleStatusDownloading.String() }</b>
and turned to <b>{ api.ScheduleStatusStandby.String() }</b> status.
</span>
} else if api.ScheduleStatus(schedule.Status) == api.ScheduleStatusEnqueued {
<span>
Subreddit
@subredditLink(schedule.Subreddit)
{ " " }
is <b class="text-accent">{ api.ScheduleStatusEnqueued.String() } </b> { "for" } downloading.
</span>
} else if api.ScheduleStatus(schedule.Status) == api.ScheduleStatusDownloading {
<span>
Subreddit
@subredditLink(schedule.Subreddit)
{ " " }
has started <b class="text-secondary">{ api.ScheduleStatusDownloading.String() }</b>.
</span>
} else if api.ScheduleStatus(schedule.Status) == api.ScheduleStatusError {
<span>
Subreddit
@subredditLink(schedule.Subreddit)
{ " " }
finishes <b class="text-secondary">{ api.ScheduleStatusDownloading.String() }</b>
with <b class="text-error">{ api.ScheduleStatusError.String() }</b> of <span class="text-error">"{ schedule.ErrorMessage }"</span>.
</span>
}
</div>
}
}
</div>
<script> document.querySelectorAll(`[data-name="schedule-tooltip"]`).forEach((el) => el.dataset.tip = dayjs(el.dataset.tip).tz(dayjs.tz.guess()).format('ddd, D MMM YYYY HH:mm:ss Z') ) </script>
}
}
}
</main>
}
templ subredditLink(subreddit string) {
<a href={ templ.URL(fmt.Sprintf("/subreddits/details/%s", subreddit)) } class="text-primary">{ subreddit }</a>
}