Can refresh musicbrainz_data for collection records
This commit is contained in:
@@ -135,6 +135,14 @@ defmodule MusicLibrary.Records do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def refresh_musicbrainz_data(record) do
|
||||||
|
with {:ok, data} <- musicbrainz().get_release_group(record.musicbrainz_id) do
|
||||||
|
record
|
||||||
|
|> Record.add_musicbrainz_data(data)
|
||||||
|
|> Repo.update()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
defp build_record_attrs(release_group, attrs) do
|
defp build_record_attrs(release_group, attrs) do
|
||||||
release_group
|
release_group
|
||||||
|> Record.attrs_from_release_group()
|
|> Record.attrs_from_release_group()
|
||||||
|
|||||||
@@ -43,6 +43,26 @@ defmodule MusicLibraryWeb.RecordLive.Show do
|
|||||||
{:noreply, push_navigate(socket, to: ~p"/records")}
|
{:noreply, push_navigate(socket, to: ~p"/records")}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def handle_event("refresh_musicbrainz_data", %{"id" => id}, socket) do
|
||||||
|
record = Records.get_record!(id)
|
||||||
|
|
||||||
|
case Records.refresh_musicbrainz_data(record) do
|
||||||
|
{:ok, updated_record} ->
|
||||||
|
{:noreply,
|
||||||
|
socket
|
||||||
|
|> put_flash(:info, gettext("MusicBrainz data refreshed successfully"))
|
||||||
|
|> assign(:record, updated_record)}
|
||||||
|
|
||||||
|
{:error, reason} ->
|
||||||
|
{:noreply,
|
||||||
|
socket
|
||||||
|
|> put_flash(
|
||||||
|
:error,
|
||||||
|
gettext("Error refreshing MusicBrainz data") <> "," <> inspect(reason)
|
||||||
|
)}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def handle_info({MusicLibraryWeb.RecordLive.FormComponent, {:saved, record}}, socket) do
|
def handle_info({MusicLibraryWeb.RecordLive.FormComponent, {:saved, record}}, socket) do
|
||||||
{:noreply, assign(socket, :record, record)}
|
{:noreply, assign(socket, :record, record)}
|
||||||
|
|||||||
@@ -4,6 +4,11 @@
|
|||||||
<%= gettext("Edit") %>
|
<%= gettext("Edit") %>
|
||||||
</.button>
|
</.button>
|
||||||
</.link>
|
</.link>
|
||||||
|
<.link phx-click={JS.push("refresh_musicbrainz_data", value: %{id: @record.id})}>
|
||||||
|
<.button>
|
||||||
|
<%= gettext("Refresh MB Data") %>
|
||||||
|
</.button>
|
||||||
|
</.link>
|
||||||
<.link
|
<.link
|
||||||
phx-click={JS.push("delete", value: %{id: @record.id})}
|
phx-click={JS.push("delete", value: %{id: @record.id})}
|
||||||
data-confirm={gettext("Are you sure?")}
|
data-confirm={gettext("Are you sure?")}
|
||||||
|
|||||||
+28
-13
@@ -17,7 +17,7 @@ msgid "Actions"
|
|||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: lib/music_library_web/live/record_live/index.html.heex:185
|
#: lib/music_library_web/live/record_live/index.html.heex:185
|
||||||
#: lib/music_library_web/live/record_live/show.html.heex:9
|
#: lib/music_library_web/live/record_live/show.html.heex:14
|
||||||
#: lib/music_library_web/live/wishlist_live/index.html.heex:195
|
#: lib/music_library_web/live/wishlist_live/index.html.heex:195
|
||||||
#: lib/music_library_web/live/wishlist_live/show.html.heex:9
|
#: lib/music_library_web/live/wishlist_live/show.html.heex:9
|
||||||
#, elixir-autogen, elixir-format
|
#, elixir-autogen, elixir-format
|
||||||
@@ -29,7 +29,7 @@ msgstr ""
|
|||||||
msgid "Attempting to reconnect"
|
msgid "Attempting to reconnect"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: lib/music_library_web/live/record_live/show.html.heex:127
|
#: lib/music_library_web/live/record_live/show.html.heex:132
|
||||||
#, elixir-autogen, elixir-format
|
#, elixir-autogen, elixir-format
|
||||||
msgid "Back to records"
|
msgid "Back to records"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
@@ -62,7 +62,7 @@ msgid "Cover art"
|
|||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: lib/music_library_web/live/record_live/index.html.heex:187
|
#: lib/music_library_web/live/record_live/index.html.heex:187
|
||||||
#: lib/music_library_web/live/record_live/show.html.heex:12
|
#: lib/music_library_web/live/record_live/show.html.heex:17
|
||||||
#: lib/music_library_web/live/wishlist_live/index.html.heex:197
|
#: lib/music_library_web/live/wishlist_live/index.html.heex:197
|
||||||
#: lib/music_library_web/live/wishlist_live/show.html.heex:12
|
#: lib/music_library_web/live/wishlist_live/show.html.heex:12
|
||||||
#, elixir-autogen, elixir-format
|
#, elixir-autogen, elixir-format
|
||||||
@@ -71,7 +71,7 @@ msgstr ""
|
|||||||
|
|
||||||
#: lib/music_library_web/live/record_live/index.ex:55
|
#: lib/music_library_web/live/record_live/index.ex:55
|
||||||
#: lib/music_library_web/live/record_live/index.html.heex:176
|
#: lib/music_library_web/live/record_live/index.html.heex:176
|
||||||
#: lib/music_library_web/live/record_live/show.ex:52
|
#: lib/music_library_web/live/record_live/show.ex:72
|
||||||
#: lib/music_library_web/live/record_live/show.html.heex:4
|
#: lib/music_library_web/live/record_live/show.html.heex:4
|
||||||
#: lib/music_library_web/live/wishlist_live/index.ex:55
|
#: lib/music_library_web/live/wishlist_live/index.ex:55
|
||||||
#: lib/music_library_web/live/wishlist_live/index.html.heex:176
|
#: lib/music_library_web/live/wishlist_live/index.html.heex:176
|
||||||
@@ -105,7 +105,7 @@ msgstr ""
|
|||||||
msgid "Formats"
|
msgid "Formats"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: lib/music_library_web/live/record_live/show.html.heex:49
|
#: lib/music_library_web/live/record_live/show.html.heex:54
|
||||||
#: lib/music_library_web/live/wishlist_live/show.html.heex:50
|
#: lib/music_library_web/live/wishlist_live/show.html.heex:50
|
||||||
#, elixir-autogen, elixir-format
|
#, elixir-autogen, elixir-format
|
||||||
msgid "Genres"
|
msgid "Genres"
|
||||||
@@ -128,7 +128,7 @@ msgstr ""
|
|||||||
msgid "Import from MusicBrainz"
|
msgid "Import from MusicBrainz"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: lib/music_library_web/live/record_live/show.html.heex:102
|
#: lib/music_library_web/live/record_live/show.html.heex:107
|
||||||
#: lib/music_library_web/live/wishlist_live/show.html.heex:95
|
#: lib/music_library_web/live/wishlist_live/show.html.heex:95
|
||||||
#, elixir-autogen, elixir-format
|
#, elixir-autogen, elixir-format
|
||||||
msgid "Inserted at"
|
msgid "Inserted at"
|
||||||
@@ -154,7 +154,7 @@ msgstr ""
|
|||||||
msgid "Logout"
|
msgid "Logout"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: lib/music_library_web/live/record_live/show.html.heex:57
|
#: lib/music_library_web/live/record_live/show.html.heex:62
|
||||||
#: lib/music_library_web/live/wishlist_live/show.html.heex:58
|
#: lib/music_library_web/live/wishlist_live/show.html.heex:58
|
||||||
#, elixir-autogen, elixir-format
|
#, elixir-autogen, elixir-format
|
||||||
msgid "MusicBrainz ID"
|
msgid "MusicBrainz ID"
|
||||||
@@ -204,7 +204,7 @@ msgstr ""
|
|||||||
msgid "Purchased at"
|
msgid "Purchased at"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: lib/music_library_web/live/record_live/show.html.heex:79
|
#: lib/music_library_web/live/record_live/show.html.heex:84
|
||||||
#, elixir-autogen, elixir-format
|
#, elixir-autogen, elixir-format
|
||||||
msgid "Purchased on"
|
msgid "Purchased on"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
@@ -254,7 +254,7 @@ msgid "Search for records"
|
|||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: lib/music_library_web/live/record_live/index.html.heex:156
|
#: lib/music_library_web/live/record_live/index.html.heex:156
|
||||||
#: lib/music_library_web/live/record_live/show.ex:51
|
#: lib/music_library_web/live/record_live/show.ex:71
|
||||||
#: lib/music_library_web/live/wishlist_live/index.html.heex:156
|
#: lib/music_library_web/live/wishlist_live/index.html.heex:156
|
||||||
#: lib/music_library_web/live/wishlist_live/show.ex:49
|
#: lib/music_library_web/live/wishlist_live/show.ex:49
|
||||||
#, elixir-autogen, elixir-format
|
#, elixir-autogen, elixir-format
|
||||||
@@ -311,7 +311,7 @@ msgstr ""
|
|||||||
msgid "Types"
|
msgid "Types"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: lib/music_library_web/live/record_live/show.html.heex:110
|
#: lib/music_library_web/live/record_live/show.html.heex:115
|
||||||
#: lib/music_library_web/live/wishlist_live/show.html.heex:103
|
#: lib/music_library_web/live/wishlist_live/show.html.heex:103
|
||||||
#, elixir-autogen, elixir-format
|
#, elixir-autogen, elixir-format
|
||||||
msgid "Updated at"
|
msgid "Updated at"
|
||||||
@@ -350,13 +350,13 @@ msgstr ""
|
|||||||
msgid "close"
|
msgid "close"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: lib/music_library_web/live/record_live/show.html.heex:67
|
#: lib/music_library_web/live/record_live/show.html.heex:72
|
||||||
#: lib/music_library_web/live/wishlist_live/show.html.heex:68
|
#: lib/music_library_web/live/wishlist_live/show.html.heex:68
|
||||||
#, elixir-autogen, elixir-format
|
#, elixir-autogen, elixir-format
|
||||||
msgid "Copy MusicBrainz ID to clipboard"
|
msgid "Copy MusicBrainz ID to clipboard"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: lib/music_library_web/live/record_live/show.html.heex:121
|
#: lib/music_library_web/live/record_live/show.html.heex:126
|
||||||
#: lib/music_library_web/live/wishlist_live/show.html.heex:114
|
#: lib/music_library_web/live/wishlist_live/show.html.heex:114
|
||||||
#, elixir-autogen, elixir-format
|
#, elixir-autogen, elixir-format
|
||||||
msgid "MusicBrainz data"
|
msgid "MusicBrainz data"
|
||||||
@@ -390,8 +390,23 @@ msgstr ""
|
|||||||
msgid "Number of included records"
|
msgid "Number of included records"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: lib/music_library_web/live/record_live/show.html.heex:90
|
#: lib/music_library_web/live/record_live/show.html.heex:95
|
||||||
#: lib/music_library_web/live/wishlist_live/show.html.heex:83
|
#: lib/music_library_web/live/wishlist_live/show.html.heex:83
|
||||||
#, elixir-autogen, elixir-format
|
#, elixir-autogen, elixir-format
|
||||||
msgid "Includes"
|
msgid "Includes"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#: lib/music_library_web/live/record_live/show.ex:61
|
||||||
|
#, elixir-autogen, elixir-format
|
||||||
|
msgid "Error refreshing MusicBrainz data"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: lib/music_library_web/live/record_live/show.ex:53
|
||||||
|
#, elixir-autogen, elixir-format
|
||||||
|
msgid "MusicBrainz data refreshed successfully"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: lib/music_library_web/live/record_live/show.html.heex:9
|
||||||
|
#, elixir-autogen, elixir-format
|
||||||
|
msgid "Refresh MB Data"
|
||||||
|
msgstr ""
|
||||||
|
|||||||
Reference in New Issue
Block a user