Added presets to cutoff date selector (#494)

This commit is contained in:
Kieran 2024-12-04 12:32:47 -08:00 committed by GitHub
parent 75fb1a6ab9
commit 0fb971dd0a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 46 additions and 10 deletions

View file

@ -27,6 +27,18 @@ defmodule PinchflatWeb.Sources.SourceHTML do
]
end
def cutoff_date_presets do
[
{"7 days", compute_date_offset(7)},
{"14 days", compute_date_offset(14)},
{"30 days", compute_date_offset(30)},
{"60 days", compute_date_offset(60)},
{"90 days", compute_date_offset(90)},
{"180 days", compute_date_offset(180)},
{"365 days", compute_date_offset(365)}
]
end
def rss_feed_url(conn, source) do
url(conn, ~p"/sources/#{source.uuid}/feed") <> ".xml"
end
@ -55,4 +67,13 @@ defmodule PinchflatWeb.Sources.SourceHTML do
Must end with .{{ ext }}. Same rules as Media Profile output path templates. #{help_button} to load your media profile's output template
"""
end
defp compute_date_offset(days) do
timezone = Application.get_env(:pinchflat, :timezone)
timezone
|> Timex.now()
|> Timex.shift(days: -days)
|> Timex.format!("{YYYY}-{0M}-{0D}")
end
end

View file

@ -111,16 +111,31 @@
/>
</section>
<.input
field={f[:download_cutoff_date]}
type="text"
label="Download Cutoff Date"
placeholder="YYYY-MM-DD"
maxlength="10"
pattern="((?:19|20)[0-9][0-9])-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])"
title="YYYY-MM-DD"
help="Only download media uploaded after this date. Leave blank to download all media. Must be in YYYY-MM-DD format. Old media may be deleted or downloaded if you change this date"
/>
<section x-data={"{ cutoffDate: '#{f[:download_cutoff_date].value}' }"}>
<.input
field={f[:download_cutoff_date]}
type="text"
label="Download Cutoff Date"
placeholder="YYYY-MM-DD"
maxlength="10"
pattern="((?:19|20)[0-9][0-9])-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])"
title="YYYY-MM-DD"
help="Only download media uploaded after this date. Leave blank to download all media. Must be in YYYY-MM-DD format. Old media may be deleted or downloaded if you change this date"
x-model="cutoffDate"
>
<:input_append>
<.input
prompt="Select preset"
name="download_cutoff_date_preset"
value=""
options={cutoff_date_presets()}
type="select"
inputclass="w-30 lg:w-60 ml-2 md:ml-4"
x-on:change={"cutoffDate = $event.target.value || '#{f[:download_cutoff_date].value}'"}
/>
</:input_append>
</.input>
</section>
<.input
field={f[:retention_period_days]}