97 lines
3.1 KiB
Plaintext
97 lines
3.1 KiB
Plaintext
package put
|
|
|
|
import "fmt"
|
|
import "strconv"
|
|
import "github.com/tigorlazuardi/redmage/views/utils"
|
|
|
|
type ScheduleInputData struct {
|
|
Value string
|
|
Error string
|
|
Valid string
|
|
Disabled bool
|
|
}
|
|
|
|
templ ScheduleInput(data ScheduleInputData) {
|
|
<div
|
|
id="schedule-input-group"
|
|
class="form-control w-full"
|
|
hx-get="/htmx/subreddits/validate/schedule"
|
|
hx-trigger="change"
|
|
hx-include="this"
|
|
hx-swap="outerHTML"
|
|
hx-target="this"
|
|
hx-select="#schedule-input-group"
|
|
>
|
|
<label for="schedule" class="label">
|
|
<span
|
|
class={ utils.CXX(
|
|
"label-text text-base", true,
|
|
"text-error", data.Error != "",
|
|
"text-success", data.Valid != "",
|
|
) }
|
|
>Schedule</span>
|
|
<div class="tooltip tooltip-left" data-tip="Whether to enable the scheduler or not">
|
|
<input type="checkbox" name="enable_schedule" value="1" class="toggle toggle-primary my-auto" checked?={ !data.Disabled }/>
|
|
</div>
|
|
</label>
|
|
<input
|
|
id="schedule"
|
|
name="schedule"
|
|
type="text"
|
|
placeholder="e.g. '@daily' or '0 0 * * MON'"
|
|
value={ data.Value }
|
|
class={ utils.CXX(
|
|
"input input-bordered", true,
|
|
"input-error text-error", data.Error != "" && !data.Disabled,
|
|
"input-success text-success", data.Valid != "" && !data.Disabled,
|
|
) }
|
|
x-data={ fmt.Sprintf(`{ init() { $el.setCustomValidity(%q) } }`, data.Error) }
|
|
list="cron-templates"
|
|
if data.Disabled {
|
|
disabled
|
|
} else {
|
|
required
|
|
}
|
|
/>
|
|
<div class="label">
|
|
<span
|
|
class={ utils.CXX(
|
|
"label-text min-h-[1rem]", true,
|
|
"text-error", data.Error != "" && !data.Disabled,
|
|
"text-success", data.Valid != "" && !data.Disabled,
|
|
) }
|
|
>
|
|
if data.Valid != "" {
|
|
{ data.Valid }
|
|
} else if data.Error != "" {
|
|
{ data.Error }. TIP: Try using the dropdown for examples and common expressions.
|
|
} else if !data.Disabled {
|
|
Uses cron syntax. Tip: Start by typing 'every' to get suggestions or search custom expressions via Google like 'cron every 6 hours'.
|
|
}
|
|
</span>
|
|
</div>
|
|
</div>
|
|
@scheduleDatalist()
|
|
}
|
|
|
|
templ scheduleDatalist() {
|
|
<datalist id="cron-templates">
|
|
<option value="@hourly">Every hour</option>
|
|
<option value="@daily">Every day at midnight</option>
|
|
<option value="@weekly">Every Sunday at midnight</option>
|
|
<option value="@monthly">Every start of month</option>
|
|
<option value="@yearly">Every start of year</option>
|
|
<option value="@annually">Every start of year</option>
|
|
<option value="0 0 * * MON">Every Monday at midnight</option>
|
|
<option value="0 0 * * TUE">Every Tuesday at midnight</option>
|
|
<option value="0 0 * * WED">Every Wednesday at midnight</option>
|
|
<option value="0 0 * * THU">Every Thursday at midnight</option>
|
|
<option value="0 0 * * FRI">Every Friday at midnight</option>
|
|
<option value="0 0 * * SAT">Every Saturday at midnight</option>
|
|
<option value="0 0 * * SUN">Every Sunday at midnight</option>
|
|
for i := 1; i < 24; i++ {
|
|
<option value={ fmt.Sprintf("0 %d * * *", i) }>Every day at { strconv.Itoa(i) } o'clock</option>
|
|
}
|
|
</datalist>
|
|
}
|