diff --git a/lib/pinchflat_web/controllers/sources/source_html.ex b/lib/pinchflat_web/controllers/sources/source_html.ex index b47e7f7..d9673eb 100644 --- a/lib/pinchflat_web/controllers/sources/source_html.ex +++ b/lib/pinchflat_web/controllers/sources/source_html.ex @@ -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 diff --git a/lib/pinchflat_web/controllers/sources/source_html/source_form.html.heex b/lib/pinchflat_web/controllers/sources/source_html/source_form.html.heex index 6dcead7..d4e41f2 100644 --- a/lib/pinchflat_web/controllers/sources/source_html/source_form.html.heex +++ b/lib/pinchflat_web/controllers/sources/source_html/source_form.html.heex @@ -111,16 +111,31 @@ /> - <.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" - /> +
+ <.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 field={f[:retention_period_days]}