From 44bdf6a7087e2048ec483dfb26d24ee16733dcd5 Mon Sep 17 00:00:00 2001 From: Kieran Eglin Date: Tue, 6 Feb 2024 12:10:43 -0800 Subject: [PATCH] Added new media_profile options to creation form; made show helper for rendering database items --- .../components/core_components.ex | 24 +++++++++++++++++++ .../media_profiles/media_profile_html.ex | 8 +++++++ .../media_profile_form.html.heex | 21 ++++++++++++++++ .../media_profile_html/show.html.heex | 11 +-------- 4 files changed, 54 insertions(+), 10 deletions(-) diff --git a/lib/pinchflat_web/components/core_components.ex b/lib/pinchflat_web/components/core_components.ex index e715b97..a2e9189 100644 --- a/lib/pinchflat_web/components/core_components.ex +++ b/lib/pinchflat_web/components/core_components.ex @@ -546,6 +546,30 @@ defmodule PinchflatWeb.CoreComponents do """ end + @doc """ + Renders a data list from a given map. Used in development to + quickly show the attributes of a database record. + """ + attr :map, :map, required: true + + def list_items_from_map(assigns) do + attrs = + Enum.filter(assigns.map, fn + {_, %{__struct__: _}} -> false + _ -> true + end) + + assigns = assign(assigns, iterable_attributes: attrs) + + ~H""" + <.list> + <:item :for={{k, v} <- @iterable_attributes} title={k}> + <%= v %> + + + """ + end + @doc """ Renders a back navigation link. diff --git a/lib/pinchflat_web/controllers/media_profiles/media_profile_html.ex b/lib/pinchflat_web/controllers/media_profiles/media_profile_html.ex index edb33ee..564a4cc 100644 --- a/lib/pinchflat_web/controllers/media_profiles/media_profile_html.ex +++ b/lib/pinchflat_web/controllers/media_profiles/media_profile_html.ex @@ -10,4 +10,12 @@ defmodule PinchflatWeb.MediaProfiles.MediaProfileHTML do attr :action, :string, required: true def media_profile_form(assigns) + + def friendly_format_type_options do + [ + {"Include (default)", :include}, + {"Exclude", :exclude}, + {"Only", :only} + ] + end end diff --git a/lib/pinchflat_web/controllers/media_profiles/media_profile_html/media_profile_form.html.heex b/lib/pinchflat_web/controllers/media_profiles/media_profile_html/media_profile_form.html.heex index ec7b13a..b0e79ab 100644 --- a/lib/pinchflat_web/controllers/media_profiles/media_profile_html/media_profile_form.html.heex +++ b/lib/pinchflat_web/controllers/media_profiles/media_profile_html/media_profile_form.html.heex @@ -4,10 +4,31 @@ <.input field={f[:name]} type="text" label="Name" /> <.input field={f[:output_path_template]} type="text" label="Output path template" /> + +

Subtitle Options

<.input field={f[:download_subs]} type="checkbox" label="Download Subs" /> <.input field={f[:download_auto_subs]} type="checkbox" label="Download Autogenerated Subs" /> <.input field={f[:embed_subs]} type="checkbox" label="Embed Subs" /> <.input field={f[:sub_langs]} type="text" label="Sub Langs" /> + +

Thumbnail Options

+ <.input field={f[:download_thumbnail]} type="checkbox" label="Download Thumbnail" /> + <.input field={f[:embed_thumbnail]} type="checkbox" label="Embed Thumbnail" /> + +

Release Format Options

+ <.input + field={f[:shorts_behaviour]} + options={friendly_format_type_options()} + type="select" + label="Include Shorts?" + /> + <.input + field={f[:livestream_behaviour]} + options={friendly_format_type_options()} + type="select" + label="Include Livestreams?" + /> + <:actions> <.button>Save Media profile diff --git a/lib/pinchflat_web/controllers/media_profiles/media_profile_html/show.html.heex b/lib/pinchflat_web/controllers/media_profiles/media_profile_html/show.html.heex index 1f23a8c..965f7e8 100644 --- a/lib/pinchflat_web/controllers/media_profiles/media_profile_html/show.html.heex +++ b/lib/pinchflat_web/controllers/media_profiles/media_profile_html/show.html.heex @@ -8,15 +8,6 @@ -<.list> - <:item - :for={ - attr <- ~w(name output_path_template download_subs download_auto_subs embed_subs sub_langs)a - } - title={attr} - > - <%= Map.get(@media_profile, attr) %> - - +<.list_items_from_map map={Map.from_struct(@media_profile)} /> <.back navigate={~p"/media_profiles"}>Back to media_profiles