From a1444b69dbb5e5188d83e8fd9a04cf285e374a2d Mon Sep 17 00:00:00 2001 From: Kieran Eglin Date: Fri, 5 Apr 2024 09:53:44 -0700 Subject: [PATCH] Added column and UI for apprise server --- lib/pinchflat/settings/setting.ex | 4 +++- lib/pinchflat_web/components/core_components.ex | 13 +++++++------ .../controllers/settings/setting_controller.ex | 2 +- .../controllers/settings/setting_html.ex | 7 +++++++ .../settings/setting_html/setting_form.html.heex | 12 ++++++++++-- ...240404221551_add_apprise_servers_to_settings.exs | 9 +++++++++ 6 files changed, 37 insertions(+), 10 deletions(-) create mode 100644 priv/repo/migrations/20240404221551_add_apprise_servers_to_settings.exs diff --git a/lib/pinchflat/settings/setting.ex b/lib/pinchflat/settings/setting.ex index 5fb7cf6..e7a89bb 100644 --- a/lib/pinchflat/settings/setting.ex +++ b/lib/pinchflat/settings/setting.ex @@ -9,7 +9,8 @@ defmodule Pinchflat.Settings.Setting do @allowed_fields [ :onboarding, :pro_enabled, - :yt_dlp_version + :yt_dlp_version, + :apprise_server ] @required_fields ~w( @@ -21,6 +22,7 @@ defmodule Pinchflat.Settings.Setting do field :onboarding, :boolean, default: true field :pro_enabled, :boolean, default: false field :yt_dlp_version, :string + field :apprise_server, :string end @doc false diff --git a/lib/pinchflat_web/components/core_components.ex b/lib/pinchflat_web/components/core_components.ex index f124b16..654b743 100644 --- a/lib/pinchflat_web/components/core_components.ex +++ b/lib/pinchflat_web/components/core_components.ex @@ -247,6 +247,7 @@ defmodule PinchflatWeb.CoreComponents do attr :label_suffix, :string, default: nil attr :value, :any attr :help, :string, default: nil + attr :html_help, :boolean, default: false attr :type, :string, default: "text", @@ -298,7 +299,7 @@ defmodule PinchflatWeb.CoreComponents do <%= @label %> <%= @label_suffix %> - <.help :if={@help}><%= @help %> + <.help :if={@help}><%= if @html_help, do: Phoenix.HTML.raw(@help), else: @help %> <.error :for={msg <- @errors}><%= msg %> """ @@ -325,7 +326,7 @@ defmodule PinchflatWeb.CoreComponents do - <.help :if={@help}><%= @help %> + <.help :if={@help}><%= if @html_help, do: Phoenix.HTML.raw(@help), else: @help %> <.error :for={msg <- @errors}><%= msg %> """ @@ -356,7 +357,7 @@ defmodule PinchflatWeb.CoreComponents do > - <.help :if={@help}><%= @help %> + <.help :if={@help}><%= if @html_help, do: Phoenix.HTML.raw(@help), else: @help %> <.error :for={msg <- @errors}><%= msg %> @@ -387,7 +388,7 @@ defmodule PinchflatWeb.CoreComponents do <%= render_slot(@inner_block) %> - <.help :if={@help}><%= @help %> + <.help :if={@help}><%= if @html_help, do: Phoenix.HTML.raw(@help), else: @help %> <.error :for={msg <- @errors}><%= msg %> """ @@ -411,7 +412,7 @@ defmodule PinchflatWeb.CoreComponents do ]} {@rest} ><%= Phoenix.HTML.Form.normalize_value("textarea", @value) %> - <.help :if={@help}><%= @help %> + <.help :if={@help}><%= if @html_help, do: Phoenix.HTML.raw(@help), else: @help %> <.error :for={msg <- @errors}><%= msg %> """ @@ -438,7 +439,7 @@ defmodule PinchflatWeb.CoreComponents do ]} {@rest} /> - <.help :if={@help}><%= @help %> + <.help :if={@help}><%= if @html_help, do: Phoenix.HTML.raw(@help), else: @help %> <.error :for={msg <- @errors}><%= msg %> """ diff --git a/lib/pinchflat_web/controllers/settings/setting_controller.ex b/lib/pinchflat_web/controllers/settings/setting_controller.ex index 7ed85ed..2ebd446 100644 --- a/lib/pinchflat_web/controllers/settings/setting_controller.ex +++ b/lib/pinchflat_web/controllers/settings/setting_controller.ex @@ -18,7 +18,7 @@ defmodule PinchflatWeb.Settings.SettingController do setting = Settings.record() case Settings.update_setting(setting, setting_params) do - {:ok, setting} -> + {:ok, _} -> conn |> put_flash(:info, "Settings updated successfully.") |> redirect(to: ~p"/settings") diff --git a/lib/pinchflat_web/controllers/settings/setting_html.ex b/lib/pinchflat_web/controllers/settings/setting_html.ex index 0bfc46e..47ad97c 100644 --- a/lib/pinchflat_web/controllers/settings/setting_html.ex +++ b/lib/pinchflat_web/controllers/settings/setting_html.ex @@ -10,4 +10,11 @@ defmodule PinchflatWeb.Settings.SettingHTML do attr :action, :string, required: true def setting_form(assigns) + + def apprise_server_help do + url = "https://github.com/caronc/apprise/wiki/URLBasics" + classes = "underline decoration-bodydark decoration-1 hover:decoration-white" + + ~s(Server endpoint for Apprise notifications when new media is found. See Apprise docs for more information) + end end diff --git a/lib/pinchflat_web/controllers/settings/setting_html/setting_form.html.heex b/lib/pinchflat_web/controllers/settings/setting_html/setting_form.html.heex index 0079180..f3ba48e 100644 --- a/lib/pinchflat_web/controllers/settings/setting_html/setting_form.html.heex +++ b/lib/pinchflat_web/controllers/settings/setting_html/setting_form.html.heex @@ -4,10 +4,18 @@

- TODO TEXT + Notification Settings

- <.input field={f[:pro_enabled]} type="toggle" label="Pro Enabled" help="Just for testing" /> + <.input + field={f[:apprise_server]} + type="text" + label="Apprise Server" + help={apprise_server_help()} + html_help={true} + inputclass="font-mono text-sm" + placeholder="https://discordapp.com/api/webhooks/{WebhookID}/{WebhookToken}" + /> <.button class="my-10 sm:mb-7.5 w-full sm:w-auto" rounding="rounded-lg">Save Settings diff --git a/priv/repo/migrations/20240404221551_add_apprise_servers_to_settings.exs b/priv/repo/migrations/20240404221551_add_apprise_servers_to_settings.exs new file mode 100644 index 0000000..bba04c6 --- /dev/null +++ b/priv/repo/migrations/20240404221551_add_apprise_servers_to_settings.exs @@ -0,0 +1,9 @@ +defmodule Pinchflat.Repo.Migrations.AddAppriseServersToSettings do + use Ecto.Migration + + def change do + alter table(:settings) do + add :apprise_server, :string + end + end +end