diff options
Diffstat (limited to 'weed/admin/view/components/form_fields.templ')
| -rw-r--r-- | weed/admin/view/components/form_fields.templ | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/weed/admin/view/components/form_fields.templ b/weed/admin/view/components/form_fields.templ index 5ac5c9241..82d20d407 100644 --- a/weed/admin/view/components/form_fields.templ +++ b/weed/admin/view/components/form_fields.templ @@ -269,6 +269,55 @@ templ DurationInputField(data DurationInputFieldData) { } // Helper functions for duration conversion (used by DurationInputField) + +// Typed conversion functions for protobuf int32 (most common) - EXPORTED +func ConvertInt32SecondsToDisplayValue(seconds int32) float64 { + return convertIntSecondsToDisplayValue(int(seconds)) +} + +func GetInt32DisplayUnit(seconds int32) string { + return getIntDisplayUnit(int(seconds)) +} + +// Typed conversion functions for regular int +func convertIntSecondsToDisplayValue(seconds int) float64 { + if seconds == 0 { + return 0 + } + + // Check if it's evenly divisible by days + if seconds%(24*3600) == 0 { + return float64(seconds / (24 * 3600)) + } + + // Check if it's evenly divisible by hours + if seconds%3600 == 0 { + return float64(seconds / 3600) + } + + // Default to minutes + return float64(seconds / 60) +} + +func getIntDisplayUnit(seconds int) string { + if seconds == 0 { + return "minutes" + } + + // Check if it's evenly divisible by days + if seconds%(24*3600) == 0 { + return "days" + } + + // Check if it's evenly divisible by hours + if seconds%3600 == 0 { + return "hours" + } + + // Default to minutes + return "minutes" +} + func convertSecondsToUnit(seconds int) string { if seconds == 0 { return "minutes" @@ -303,4 +352,73 @@ func convertSecondsToValue(seconds int, unit string) float64 { default: return float64(seconds / 60) // Default to minutes } +} + +// IntervalFieldData represents interval input field data with separate value and unit +type IntervalFieldData struct { + FormFieldData + Seconds int // The interval value in seconds +} + +// IntervalField renders a Bootstrap interval input with number + unit dropdown (like task config) +templ IntervalField(data IntervalFieldData) { + <div class="mb-3"> + <label for={ data.Name } class="form-label"> + { data.Label } + if data.Required { + <span class="text-danger">*</span> + } + </label> + <div class="input-group"> + <input + type="number" + class="form-control" + id={ data.Name + "_value" } + name={ data.Name + "_value" } + value={ fmt.Sprintf("%.0f", convertSecondsToValue(data.Seconds, convertSecondsToUnit(data.Seconds))) } + step="1" + min="1" + if data.Required { + required + } + /> + <select + class="form-select" + id={ data.Name + "_unit" } + name={ data.Name + "_unit" } + style="max-width: 120px;" + if data.Required { + required + } + > + <option + value="minutes" + if convertSecondsToUnit(data.Seconds) == "minutes" { + selected + } + > + Minutes + </option> + <option + value="hours" + if convertSecondsToUnit(data.Seconds) == "hours" { + selected + } + > + Hours + </option> + <option + value="days" + if convertSecondsToUnit(data.Seconds) == "days" { + selected + } + > + Days + </option> + </select> + </div> + if data.Description != "" { + <div class="form-text text-muted">{ data.Description }</div> + } + </div> }
\ No newline at end of file |
