diff --git a/lib/music_library_web/controllers/stats_controller.ex b/lib/music_library_web/controllers/stats_controller.ex index 51fe8d25..82cf877a 100644 --- a/lib/music_library_web/controllers/stats_controller.ex +++ b/lib/music_library_web/controllers/stats_controller.ex @@ -4,7 +4,10 @@ defmodule MusicLibraryWeb.StatsController do alias MusicLibrary.Records def index(conn, _params) do - records_count_by_format = Records.count_records_by_format() + records_count_by_format = + Records.count_records_by_format() + |> Enum.sort_by(fn {_format, count} -> count end, :desc) + records_count = Enum.reduce(records_count_by_format, 0, fn {_, count}, acc -> acc + count end) latest_record = Records.get_latest_record!() diff --git a/lib/music_library_web/controllers/stats_html.ex b/lib/music_library_web/controllers/stats_html.ex index fd2d0f33..726d7d7f 100644 --- a/lib/music_library_web/controllers/stats_html.ex +++ b/lib/music_library_web/controllers/stats_html.ex @@ -6,13 +6,4 @@ defmodule MusicLibraryWeb.StatsHTML do alias MusicLibrary.Records.Record embed_templates "stats_html/*" - - defp format_records_count(records_count_by_format) do - records_count_by_format - |> Enum.sort_by(fn {_format, count} -> count end, :desc) - |> Enum.map(fn {format, count} -> - Integer.to_string(count) <> " " <> Record.format_long_label(format) - end) - |> Enum.join(", ") - end end diff --git a/lib/music_library_web/controllers/stats_html/index.html.heex b/lib/music_library_web/controllers/stats_html/index.html.heex index 383faee2..e3330341 100644 --- a/lib/music_library_web/controllers/stats_html/index.html.heex +++ b/lib/music_library_web/controllers/stats_html/index.html.heex @@ -1,59 +1,24 @@
-
-
-
-
- -
-

Total Records

-
-
-

<%= @records_count %>

-

- <%= format_records_count(@records_count_by_format) %> -

- -
-
-
+
+
{@latest_record.title} -

Latest record

+

+ Latest record +

- + <%= format_artist_names(@latest_record.artists) %> - <%= @latest_record.title %> + + <%= @latest_record.title %> +

@@ -67,6 +32,21 @@
+
+
+

Total Records

+
+
+

<%= @records_count %>

+ +
+
diff --git a/test/music_library_web/controllers/stats_controller_test.exs b/test/music_library_web/controllers/stats_controller_test.exs index 865490a6..7fadb55c 100644 --- a/test/music_library_web/controllers/stats_controller_test.exs +++ b/test/music_library_web/controllers/stats_controller_test.exs @@ -27,7 +27,9 @@ defmodule MusicLibraryWeb.StatsControllerTest do records |> Enum.frequencies_by(& &1.format) |> Enum.each(fn {format, count} -> - assert html_response(conn, 200) =~ "#{count} #{Record.format_long_label(format)}" + response = html_response(conn, 200) + assert response =~ "\n#{count}\n" + assert response =~ "\n#{Record.format_long_label(format)}\n" end) end