From 81f0ec8830e21ecc9be4b625906f8ff4a4fe698e Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Fri, 4 Jul 2025 14:05:08 +0100 Subject: [PATCH] Render scrobble rules list with Fluxon table --- .../live/scrobble_rules_live/index.ex | 16 -- .../live/scrobble_rules_live/index.html.heex | 183 ++++++------------ priv/gettext/default.pot | 28 ++- priv/gettext/en/LC_MESSAGES/default.po | 28 ++- 4 files changed, 97 insertions(+), 158 deletions(-) diff --git a/lib/music_library_web/live/scrobble_rules_live/index.ex b/lib/music_library_web/live/scrobble_rules_live/index.ex index e33c8391..2777a517 100644 --- a/lib/music_library_web/live/scrobble_rules_live/index.ex +++ b/lib/music_library_web/live/scrobble_rules_live/index.ex @@ -118,20 +118,4 @@ defmodule MusicLibraryWeb.ScrobbleRulesLive.Index do "Disabled" end end - - defp enabled_badge_class(enabled) do - if enabled do - "text-green-800 bg-green-100 dark:bg-green-900 dark:text-green-300" - else - "text-red-800 bg-red-100 dark:bg-red-900 dark:text-red-300" - end - end - - defp type_badge_class(type) do - case type do - "album" -> "text-blue-800 bg-blue-100 dark:bg-blue-900 dark:text-blue-300" - "artist" -> "text-purple-800 bg-purple-100 dark:bg-purple-900 dark:text-purple-300" - _ -> "text-gray-800 bg-gray-100 dark:bg-gray-900 dark:text-gray-300" - end - end end diff --git a/lib/music_library_web/live/scrobble_rules_live/index.html.heex b/lib/music_library_web/live/scrobble_rules_live/index.html.heex index 77e1290a..d3ceafae 100644 --- a/lib/music_library_web/live/scrobble_rules_live/index.html.heex +++ b/lib/music_library_web/live/scrobble_rules_live/index.html.heex @@ -14,136 +14,75 @@ <.icon name="hero-plus" class="h-4 w-4 mr-2" /> {gettext("New Rule")} + <.button phx-click="apply_all_rules" class="!bg-green-600 hover:!bg-green-700"> + <.icon name="hero-play" class="h-4 w-4 mr-2" /> + {gettext("Apply All Rules")} +
-
-

- {gettext( - "Rules are applied automatically by the background worker, or you can apply them manually." - )} -

- <.button phx-click="apply_all_rules" class="!bg-green-600 hover:!bg-green-700"> - <.icon name="hero-play" class="h-4 w-4 mr-2" /> - {gettext("Apply All Rules")} - -
- -
-
- - - - - - - - - - - - - - - - - - - - - - - -
- {gettext("Type")} - - {gettext("Match Value")} - - {gettext("Target MusicBrainz ID")} - - {gettext("Status")} - - {gettext("Description")} - - {gettext("Created")} - - {gettext("Actions")} -
- - {rule_type_badge(scrobble_rule.type)} - - - {scrobble_rule.match_value} - - {scrobble_rule.target_musicbrainz_id} - - - {enabled_badge(scrobble_rule.enabled)} - - - {scrobble_rule.description} - - {Calendar.strftime(scrobble_rule.inserted_at, "%Y-%m-%d")} - - <.button - phx-click="apply_rule" - phx-value-id={scrobble_rule.id} - class="!bg-green-600 hover:!bg-green-700 !text-white !text-xs !px-2 !py-1" - > - <.icon name="hero-play" class="h-3 w-3" /> - - - <.button - phx-click="toggle_enabled" - phx-value-id={scrobble_rule.id} - class={[ - "!text-white !text-xs !px-2 !py-1", - if(scrobble_rule.enabled, - do: "!bg-yellow-600 hover:!bg-yellow-700", - else: "!bg-green-600 hover:!bg-green-700" - ) - ]} - > + <.table> + <.table_head> + <:col>{gettext("Type")} + <:col>{gettext("Match Value")} + <:col>{gettext("Target MusicBrainz ID")} + <:col>{gettext("Status")} + <:col>{gettext("Description")} + <:col>{gettext("Created")} + <:col> + + <.table_body> + <.table_row :for={{dom_id, scrobble_rule} <- @streams.scrobble_rules} id={dom_id}> + <:cell>{rule_type_badge(scrobble_rule.type)} + <:cell>{scrobble_rule.match_value} + <:cell class="whitespace-nowrap font-mono">{scrobble_rule.target_musicbrainz_id} + <:cell>{enabled_badge(scrobble_rule.enabled)} + <:cell>{scrobble_rule.description} + <:cell>{Calendar.strftime(scrobble_rule.inserted_at, "%Y-%m-%d")} + <:cell> + <.dropdown id={"actions-#{scrobble_rule.id}"} placement="bottom-end"> + <:toggle> +
+ {gettext("Actions")} <.icon - name={if scrobble_rule.enabled, do: "hero-pause", else: "hero-play"} - class="h-3 w-3" + name="hero-ellipsis-vertical" + class="-mt-1 h-5 w-5 text-zinc-500 dark:text-zinc-400 cursor-pointer" + aria-hidden="true" + data-slot="icon" /> - - - <.link patch={~p"/scrobble-rules/#{scrobble_rule}/edit"}> - <.button class="!bg-blue-600 hover:!bg-blue-700 !text-white !text-xs !px-2 !py-1"> - <.icon name="hero-pencil" class="h-3 w-3" /> - - - - <.button - phx-click="delete" - phx-value-id={scrobble_rule.id} - data-confirm={gettext("Are you sure you want to delete this rule?")} - class="!bg-red-600 hover:!bg-red-700 !text-white !text-xs !px-2 !py-1" - > - <.icon name="hero-trash" class="h-3 w-3" /> - -
-
-
+
+ + <.dropdown_button phx-click="apply_rule" phx-value-id={scrobble_rule.id}> + {gettext("Apply rule")} + + <.dropdown_button phx-click="toggle_enabled" phx-value-id={scrobble_rule.id}> + {if scrobble_rule.enabled, do: gettext("Disable rule"), else: gettext("Enable rule")} + + <.dropdown_link + id={"actions-#{scrobble_rule.id}-edit"} + patch={~p"/scrobble-rules/#{scrobble_rule}/edit"} + > + {gettext("Edit")} + + <.separator /> + <.dropdown_button + phx-click="delete" + phx-value-id={scrobble_rule.id} + data-confirm={gettext("Are you sure?")} + class={[ + "text-red-900! hover:bg-red-50! dark:text-red-500! dark:hover:bg-red-900/30! dark:hover:text-red-600!" + ]} + > + {gettext("Delete")} + + + + + + <.modal diff --git a/priv/gettext/default.pot b/priv/gettext/default.pot index 61b7fcac..c3c3caae 100644 --- a/priv/gettext/default.pot +++ b/priv/gettext/default.pot @@ -13,6 +13,7 @@ msgstr "" #: lib/music_library_web/components/record_components.ex #: lib/music_library_web/live/collection_live/show.html.heex +#: lib/music_library_web/live/scrobble_rules_live/index.html.heex #: lib/music_library_web/live/wishlist_live/show.html.heex #, elixir-autogen, elixir-format msgid "Are you sure?" @@ -33,6 +34,7 @@ msgstr "" #: lib/music_library_web/components/record_components.ex #: lib/music_library_web/live/collection_live/show.html.heex +#: lib/music_library_web/live/scrobble_rules_live/index.html.heex #: lib/music_library_web/live/wishlist_live/show.html.heex #, elixir-autogen, elixir-format msgid "Delete" @@ -41,6 +43,7 @@ msgstr "" #: lib/music_library_web/components/record_components.ex #: lib/music_library_web/live/collection_live/show.ex #: lib/music_library_web/live/collection_live/show.html.heex +#: lib/music_library_web/live/scrobble_rules_live/index.html.heex #: lib/music_library_web/live/wishlist_live/show.ex #: lib/music_library_web/live/wishlist_live/show.html.heex #, elixir-autogen, elixir-format @@ -974,11 +977,6 @@ msgstr "" msgid "Apply All Rules" msgstr "" -#: lib/music_library_web/live/scrobble_rules_live/index.html.heex -#, elixir-autogen, elixir-format -msgid "Are you sure you want to delete this rule?" -msgstr "" - #: lib/music_library_web/live/scrobble_rules_live/form_component.ex #, elixir-autogen, elixir-format msgid "Artist" @@ -1055,11 +1053,6 @@ msgstr "" msgid "Rule applied successfully. Updated %{count} tracks." msgstr "" -#: lib/music_library_web/live/scrobble_rules_live/index.html.heex -#, elixir-autogen, elixir-format -msgid "Rules are applied automatically by the background worker, or you can apply them manually." -msgstr "" - #: lib/music_library_web/live/scrobble_rules_live/form_component.ex #, elixir-autogen, elixir-format msgid "Save Rule" @@ -1107,3 +1100,18 @@ msgstr "" #, elixir-autogen, elixir-format msgid "e.g. The Dark Side of the Moon" msgstr "" + +#: lib/music_library_web/live/scrobble_rules_live/index.html.heex +#, elixir-autogen, elixir-format +msgid "Apply rule" +msgstr "" + +#: lib/music_library_web/live/scrobble_rules_live/index.html.heex +#, elixir-autogen, elixir-format +msgid "Disable rule" +msgstr "" + +#: lib/music_library_web/live/scrobble_rules_live/index.html.heex +#, elixir-autogen, elixir-format +msgid "Enable rule" +msgstr "" diff --git a/priv/gettext/en/LC_MESSAGES/default.po b/priv/gettext/en/LC_MESSAGES/default.po index 143112f2..c88f02ba 100644 --- a/priv/gettext/en/LC_MESSAGES/default.po +++ b/priv/gettext/en/LC_MESSAGES/default.po @@ -13,6 +13,7 @@ msgstr "" #: lib/music_library_web/components/record_components.ex #: lib/music_library_web/live/collection_live/show.html.heex +#: lib/music_library_web/live/scrobble_rules_live/index.html.heex #: lib/music_library_web/live/wishlist_live/show.html.heex #, elixir-autogen, elixir-format msgid "Are you sure?" @@ -33,6 +34,7 @@ msgstr "" #: lib/music_library_web/components/record_components.ex #: lib/music_library_web/live/collection_live/show.html.heex +#: lib/music_library_web/live/scrobble_rules_live/index.html.heex #: lib/music_library_web/live/wishlist_live/show.html.heex #, elixir-autogen, elixir-format msgid "Delete" @@ -41,6 +43,7 @@ msgstr "" #: lib/music_library_web/components/record_components.ex #: lib/music_library_web/live/collection_live/show.ex #: lib/music_library_web/live/collection_live/show.html.heex +#: lib/music_library_web/live/scrobble_rules_live/index.html.heex #: lib/music_library_web/live/wishlist_live/show.ex #: lib/music_library_web/live/wishlist_live/show.html.heex #, elixir-autogen, elixir-format @@ -974,11 +977,6 @@ msgstr "" msgid "Apply All Rules" msgstr "" -#: lib/music_library_web/live/scrobble_rules_live/index.html.heex -#, elixir-autogen, elixir-format -msgid "Are you sure you want to delete this rule?" -msgstr "" - #: lib/music_library_web/live/scrobble_rules_live/form_component.ex #, elixir-autogen, elixir-format, fuzzy msgid "Artist" @@ -1055,11 +1053,6 @@ msgstr "" msgid "Rule applied successfully. Updated %{count} tracks." msgstr "" -#: lib/music_library_web/live/scrobble_rules_live/index.html.heex -#, elixir-autogen, elixir-format -msgid "Rules are applied automatically by the background worker, or you can apply them manually." -msgstr "" - #: lib/music_library_web/live/scrobble_rules_live/form_component.ex #, elixir-autogen, elixir-format, fuzzy msgid "Save Rule" @@ -1107,3 +1100,18 @@ msgstr "" #, elixir-autogen, elixir-format msgid "e.g. The Dark Side of the Moon" msgstr "" + +#: lib/music_library_web/live/scrobble_rules_live/index.html.heex +#, elixir-autogen, elixir-format +msgid "Apply rule" +msgstr "" + +#: lib/music_library_web/live/scrobble_rules_live/index.html.heex +#, elixir-autogen, elixir-format +msgid "Disable rule" +msgstr "" + +#: lib/music_library_web/live/scrobble_rules_live/index.html.heex +#, elixir-autogen, elixir-format, fuzzy +msgid "Enable rule" +msgstr ""