2024-06-03 16:19:34 +07:00
|
|
|
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"
|
2024-06-04 21:08:36 +07:00
|
|
|
import "github.com/tigorlazuardi/redmage/models"
|
2024-06-03 16:19:34 +07:00
|
|
|
|
|
|
|
type Data struct {
|
2024-06-04 21:08:36 +07:00
|
|
|
ScheduleHistories api.ScheduleHistoryListResult
|
|
|
|
Params api.ScheduleHistoryListParams
|
|
|
|
FirstSchedule *models.ScheduleHistory
|
|
|
|
LastSchedule *models.ScheduleHistory
|
|
|
|
IsCurrent bool
|
2024-06-03 16:19:34 +07:00
|
|
|
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) {
|
|
|
|
<main class="prose min-w-full">
|
|
|
|
<h1>Schedule History ({ time.Local.String() })</h1>
|
|
|
|
<div class="divider my-0"></div>
|
2024-06-04 21:08:36 +07:00
|
|
|
@dateBar(data)
|
|
|
|
if len(data.ScheduleHistories.Schedules) == 0 {
|
2024-06-03 16:19:34 +07:00
|
|
|
<h2>There are no history schedules found for current date.</h2>
|
|
|
|
}
|
2024-06-04 21:08:36 +07:00
|
|
|
if len(data.ScheduleHistories.Schedules) > 0 {
|
|
|
|
for _, history := range data.ScheduleHistories.SplitByDay() {
|
2024-06-05 14:20:21 +07:00
|
|
|
<h1 class="mb-6 mt-8 max-xs:text-xl">{ history.Date.Format("Monday, 02 January 2006") }</h1>
|
2024-06-04 21:08:36 +07:00
|
|
|
<div class="divider my-2"></div>
|
|
|
|
<div class="grid sm:grid-cols-[1fr,9fr] gap-x-4 gap-y-2 sm:gap-y-4">
|
|
|
|
<span class="font-bold max-sm:hidden text-center">Time</span>
|
|
|
|
<span class="font-bold max-sm:hidden">Event</span>
|
|
|
|
for i, schedule := range history.Schedules {
|
|
|
|
if i > 0 {
|
|
|
|
<div class="divider sm:hidden"></div>
|
|
|
|
}
|
|
|
|
<div
|
|
|
|
x-data={ fmt.Sprintf(`{ time: %d, get tooltip() { return dayjs.unix(this.time).tz(dayjs.tz.guess()).format('ddd, D MMM YYYY HH:mm:ss Z') } }`, schedule.CreatedAt) }
|
|
|
|
:data-tip="tooltip"
|
|
|
|
class="tooltip"
|
|
|
|
>
|
|
|
|
<p class="font-bold max-sm:text-left my-0">
|
|
|
|
{ time.Unix(schedule.CreatedAt, 0).Format("15:04:05") }
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
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>
|
|
|
|
}
|
2024-06-03 16:19:34 +07:00
|
|
|
}
|
2024-06-04 21:08:36 +07:00
|
|
|
</div>
|
|
|
|
}
|
2024-06-03 16:19:34 +07:00
|
|
|
}
|
2024-06-04 21:08:36 +07:00
|
|
|
if len(data.ScheduleHistories.Schedules) > 20 {
|
|
|
|
@dateBar(data)
|
2024-06-03 16:42:40 +07:00
|
|
|
}
|
|
|
|
@actionButton(data)
|
2024-06-03 16:19:34 +07:00
|
|
|
</main>
|
|
|
|
}
|
|
|
|
|
2024-06-03 16:42:40 +07:00
|
|
|
templ actionButton(data Data) {
|
|
|
|
<div class="xs:hidden">
|
2024-06-04 21:08:36 +07:00
|
|
|
@components.ActionButton(actionButtonItems(data)...)
|
2024-06-03 16:42:40 +07:00
|
|
|
</div>
|
|
|
|
}
|
|
|
|
|
2024-06-04 21:08:36 +07:00
|
|
|
func actionButtonItems(data Data) []templ.Component {
|
|
|
|
out := make([]templ.Component, 0, 2)
|
2024-06-05 11:12:20 +07:00
|
|
|
if len(data.ScheduleHistories.Schedules) >= int(data.Params.Limit) || data.Params.Reversed {
|
2024-06-04 21:08:36 +07:00
|
|
|
out = append(out, actionButtonNext(data))
|
|
|
|
}
|
2024-06-05 14:20:21 +07:00
|
|
|
if !data.IsCurrent {
|
|
|
|
out = append(out, actionButtonPrev(data))
|
|
|
|
}
|
2024-06-04 21:08:36 +07:00
|
|
|
if data.IsCurrent {
|
|
|
|
out = append(out, actionButtonRefresh())
|
|
|
|
}
|
|
|
|
return out
|
|
|
|
}
|
|
|
|
|
|
|
|
templ dateBar(data Data) {
|
2024-06-03 16:42:40 +07:00
|
|
|
<div
|
|
|
|
class="flex flex-wrap justify-between my-4 items-center"
|
|
|
|
hx-boost="true"
|
|
|
|
hx-select="#root-content"
|
|
|
|
hx-swap="outerHTML"
|
|
|
|
hx-target="#root-content"
|
|
|
|
>
|
2024-06-04 21:08:36 +07:00
|
|
|
if data.IsCurrent {
|
|
|
|
<div class="tooltip" data-tip="Refresh">
|
|
|
|
<a
|
|
|
|
href="/history"
|
|
|
|
class="btn btn-primary btn-outline btn-square text-base-100"
|
|
|
|
>
|
|
|
|
@icons.Refresh("w-6 h-6")
|
|
|
|
</a>
|
|
|
|
</div>
|
2024-06-03 16:42:40 +07:00
|
|
|
} else {
|
2024-06-04 21:08:36 +07:00
|
|
|
<div class="tooltip" data-tip="Previous">
|
|
|
|
<a
|
|
|
|
href={ templ.SafeURL(fmt.Sprintf("/history?time=%d&direction=before", data.ScheduleHistories.GetFirstTime().Unix())) }
|
|
|
|
class="btn btn-primary btn-outline btn-square text-base-100"
|
|
|
|
>
|
|
|
|
@icons.ChevronBoldLeft("w-6 h-6")
|
|
|
|
</a>
|
|
|
|
</div>
|
2024-06-03 16:42:40 +07:00
|
|
|
}
|
2024-06-05 11:12:20 +07:00
|
|
|
if len(data.ScheduleHistories.Schedules) >= int(data.Params.Limit) || data.Params.Reversed {
|
2024-06-04 21:08:36 +07:00
|
|
|
<div class="tooltip" data-tip="Next">
|
|
|
|
<a
|
|
|
|
href={ templ.SafeURL(fmt.Sprintf("/history?time=%d", data.ScheduleHistories.GetLastTime().Unix())) }
|
|
|
|
class="btn btn-primary btn-outline btn-square text-base-100 no-underline"
|
|
|
|
>
|
|
|
|
@icons.ChevronBoldRight("w-6 h-6")
|
|
|
|
</a>
|
|
|
|
</div>
|
2024-06-03 16:42:40 +07:00
|
|
|
}
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
|
|
|
|
templ actionButtonNext(data Data) {
|
|
|
|
<a
|
2024-06-04 21:08:36 +07:00
|
|
|
href={ templ.SafeURL(fmt.Sprintf("/history?time=%d", data.ScheduleHistories.GetLastTime().Unix())) }
|
2024-06-03 16:42:40 +07:00
|
|
|
class="btn btn-ghost btn-sm no-underline m-0"
|
|
|
|
>Next</a>
|
|
|
|
}
|
|
|
|
|
|
|
|
templ actionButtonPrev(data Data) {
|
|
|
|
<a
|
2024-06-04 21:08:36 +07:00
|
|
|
href={ templ.SafeURL(fmt.Sprintf("/history?time=%d&direction=before", data.ScheduleHistories.GetFirstTime().Unix())) }
|
2024-06-03 16:42:40 +07:00
|
|
|
class="btn btn-ghost btn-sm no-underline m-0"
|
|
|
|
>Previous</a>
|
|
|
|
}
|
|
|
|
|
2024-06-04 21:08:36 +07:00
|
|
|
templ actionButtonRefresh() {
|
|
|
|
<a
|
|
|
|
href="/history"
|
|
|
|
class="btn btn-ghost btn-sm no-underline m-0"
|
|
|
|
>Refresh</a>
|
|
|
|
}
|
|
|
|
|
2024-06-03 16:19:34 +07:00
|
|
|
templ subredditLink(subreddit string) {
|
|
|
|
<a href={ templ.URL(fmt.Sprintf("/subreddits/details/%s", subreddit)) } class="text-primary">{ subreddit }</a>
|
|
|
|
}
|