Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] Add presets to cutoff date input #494

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions lib/pinchflat_web/controllers/sources/source_html.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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]}
Expand Down
Loading