Display count of child release groups

This commit is contained in:
Claudio Ortolina
2024-11-14 15:16:19 +00:00
parent cd106fe34f
commit dbdb698ef3
5 changed files with 45 additions and 10 deletions
+1
View File
@@ -18,6 +18,7 @@ defmodule MusicLibrary.Records do
:release,
:genres,
:musicbrainz_id,
:musicbrainz_data,
:cover_hash
]
end
+21 -1
View File
@@ -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