Display count of child release groups
This commit is contained in:
@@ -18,6 +18,7 @@ defmodule MusicLibrary.Records do
|
||||
:release,
|
||||
:genres,
|
||||
:musicbrainz_id,
|
||||
:musicbrainz_data,
|
||||
:cover_hash
|
||||
]
|
||||
end
|
||||
|
||||
@@ -15,7 +15,7 @@ defmodule MusicLibrary.Records.Record do
|
||||
field :cover_data, :binary
|
||||
field :cover_hash, :string
|
||||
field :musicbrainz_id, Ecto.UUID
|
||||
field :musicbrainz_data, :map
|
||||
field :musicbrainz_data, :map, default: %{}
|
||||
field :genres, {:array, :string}
|
||||
field :release, :string
|
||||
field :purchased_at, :utc_datetime
|
||||
@@ -53,6 +53,26 @@ defmodule MusicLibrary.Records.Record do
|
||||
|> unique_constraint(:musicbrainz_id, name: "records_musicbrainz_id_format_index")
|
||||
end
|
||||
|
||||
def child_release_groups(record) do
|
||||
record.musicbrainz_data
|
||||
|> Map.get("relations", [])
|
||||
|> Enum.filter(fn relation ->
|
||||
relation["target-type"] == "release_group" and
|
||||
relation["type"] == "included in" and
|
||||
relation["direction"] == "backward"
|
||||
end)
|
||||
end
|
||||
|
||||
def child_release_groups_count(record) do
|
||||
record.musicbrainz_data
|
||||
|> Map.get("relations", [])
|
||||
|> Enum.count(fn relation ->
|
||||
relation["target-type"] == "release_group" and
|
||||
relation["type"] == "included in" and
|
||||
relation["direction"] == "backward"
|
||||
end)
|
||||
end
|
||||
|
||||
@doc false
|
||||
def artist_changeset(artist, attrs) do
|
||||
artist
|
||||
|
||||
@@ -65,6 +65,12 @@
|
||||
· <%= Records.Record.format_long_label(record.format) %> · <%= Records.Record.type_long_label(
|
||||
record.type
|
||||
) %>
|
||||
<span :if={Records.Record.child_release_groups_count(record) > 0}>
|
||||
·
|
||||
<span class="inline-flex items-center rounded-md bg-gray-50 px-2 py-1 text-xs font-medium text-gray-600 ring-1 ring-inset ring-gray-500/10">
|
||||
<%= Records.Record.child_release_groups_count(record) %>
|
||||
</span>
|
||||
</span>
|
||||
</span>
|
||||
</p>
|
||||
</div>
|
||||
@@ -75,6 +81,12 @@
|
||||
<%= Records.Record.format_long_label(record.format) %> · <%= Records.Record.type_long_label(
|
||||
record.type
|
||||
) %>
|
||||
<span :if={Records.Record.child_release_groups_count(record) > 0}>
|
||||
·
|
||||
<span class="inline-flex items-center rounded-md bg-gray-50 px-2 py-1 text-xs font-medium text-gray-600 ring-1 ring-inset ring-gray-500/10">
|
||||
<%= Records.Record.child_release_groups_count(record) %>
|
||||
</span>
|
||||
</span>
|
||||
</p>
|
||||
</div>
|
||||
<div class="relative flex-none">
|
||||
|
||||
@@ -26,11 +26,13 @@ defmodule MusicLibraryWeb.RecordLive.Show do
|
||||
|
||||
@impl true
|
||||
def handle_params(%{"id" => id}, _, socket) do
|
||||
record = Records.get_record!(id)
|
||||
|
||||
{:noreply,
|
||||
socket
|
||||
|> assign(:nav_section, :records)
|
||||
|> assign(:page_title, page_title(socket.assigns.live_action))
|
||||
|> assign(:record, Records.get_record!(id))}
|
||||
|> assign(:record, record)}
|
||||
end
|
||||
|
||||
@impl true
|
||||
|
||||
@@ -16,7 +16,7 @@ msgstr ""
|
||||
msgid "Actions"
|
||||
msgstr ""
|
||||
|
||||
#: lib/music_library_web/live/record_live/index.html.heex:153
|
||||
#: lib/music_library_web/live/record_live/index.html.heex:165
|
||||
#: lib/music_library_web/live/record_live/show.html.heex:9
|
||||
#: lib/music_library_web/live/wishlist_live/index.html.heex:163
|
||||
#: lib/music_library_web/live/wishlist_live/show.html.heex:9
|
||||
@@ -61,7 +61,7 @@ msgstr ""
|
||||
msgid "Cover art"
|
||||
msgstr ""
|
||||
|
||||
#: lib/music_library_web/live/record_live/index.html.heex:155
|
||||
#: lib/music_library_web/live/record_live/index.html.heex:167
|
||||
#: lib/music_library_web/live/record_live/show.html.heex:12
|
||||
#: lib/music_library_web/live/wishlist_live/index.html.heex:165
|
||||
#: lib/music_library_web/live/wishlist_live/show.html.heex:12
|
||||
@@ -70,8 +70,8 @@ msgid "Delete"
|
||||
msgstr ""
|
||||
|
||||
#: lib/music_library_web/live/record_live/index.ex:55
|
||||
#: lib/music_library_web/live/record_live/index.html.heex:144
|
||||
#: lib/music_library_web/live/record_live/show.ex:50
|
||||
#: lib/music_library_web/live/record_live/index.html.heex:156
|
||||
#: lib/music_library_web/live/record_live/show.ex:52
|
||||
#: 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.html.heex:144
|
||||
@@ -176,7 +176,7 @@ msgstr ""
|
||||
msgid "No results"
|
||||
msgstr ""
|
||||
|
||||
#: lib/music_library_web/live/record_live/index.html.heex:89
|
||||
#: lib/music_library_web/live/record_live/index.html.heex:101
|
||||
#: lib/music_library_web/live/stats_live/index.html.heex:145
|
||||
#: lib/music_library_web/live/wishlist_live/index.html.heex:89
|
||||
#, elixir-autogen, elixir-format
|
||||
@@ -253,8 +253,8 @@ msgstr ""
|
||||
msgid "Search for records"
|
||||
msgstr ""
|
||||
|
||||
#: lib/music_library_web/live/record_live/index.html.heex:124
|
||||
#: lib/music_library_web/live/record_live/show.ex:49
|
||||
#: lib/music_library_web/live/record_live/index.html.heex:136
|
||||
#: lib/music_library_web/live/record_live/show.ex:51
|
||||
#: lib/music_library_web/live/wishlist_live/index.html.heex:124
|
||||
#: lib/music_library_web/live/wishlist_live/show.ex:49
|
||||
#, elixir-autogen, elixir-format
|
||||
@@ -317,7 +317,7 @@ msgstr ""
|
||||
msgid "Updated at"
|
||||
msgstr ""
|
||||
|
||||
#: lib/music_library_web/live/record_live/index.html.heex:134
|
||||
#: lib/music_library_web/live/record_live/index.html.heex:146
|
||||
#: lib/music_library_web/live/wishlist_live/index.html.heex:134
|
||||
#, elixir-autogen, elixir-format
|
||||
msgid "View on MusicBrainz"
|
||||
|
||||
Reference in New Issue
Block a user