From 8d6bfaf035d6e4b900538a49f53eba387d3e2afc Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Sat, 28 Sep 2024 22:41:53 +0100 Subject: [PATCH] Put some stats on the home page --- .../controllers/stats_controller.ex | 10 ++++++++++ lib/music_library_web/controllers/stats_html.ex | 5 +++++ .../controllers/stats_html/index.html.heex | 13 +++++++++++++ lib/music_library_web/router.ex | 2 +- 4 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 lib/music_library_web/controllers/stats_controller.ex create mode 100644 lib/music_library_web/controllers/stats_html.ex create mode 100644 lib/music_library_web/controllers/stats_html/index.html.heex diff --git a/lib/music_library_web/controllers/stats_controller.ex b/lib/music_library_web/controllers/stats_controller.ex new file mode 100644 index 00000000..4e766cef --- /dev/null +++ b/lib/music_library_web/controllers/stats_controller.ex @@ -0,0 +1,10 @@ +defmodule MusicLibraryWeb.StatsController do + use MusicLibraryWeb, :controller + + alias MusicLibrary.Records + + def index(conn, _params) do + records_count = Records.count_records() + render(conn, :index, records_count: records_count) + end +end diff --git a/lib/music_library_web/controllers/stats_html.ex b/lib/music_library_web/controllers/stats_html.ex new file mode 100644 index 00000000..e7e4fe94 --- /dev/null +++ b/lib/music_library_web/controllers/stats_html.ex @@ -0,0 +1,5 @@ +defmodule MusicLibraryWeb.StatsHTML do + use MusicLibraryWeb, :html + + embed_templates "stats_html/*" +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 new file mode 100644 index 00000000..f8373a65 --- /dev/null +++ b/lib/music_library_web/controllers/stats_html/index.html.heex @@ -0,0 +1,13 @@ +
+

Music Library

+
+
+
Total Records
+
+
+ <%= @records_count %> +
+
+
+
+
diff --git a/lib/music_library_web/router.ex b/lib/music_library_web/router.ex index df87a45e..f78e41dc 100644 --- a/lib/music_library_web/router.ex +++ b/lib/music_library_web/router.ex @@ -19,8 +19,8 @@ defmodule MusicLibraryWeb.Router do get "/health", HealthController, :index get "/images/:record_id", ImageController, :show + get "/", StatsController, :index - live "/", RecordLive.Index, :index live "/records", RecordLive.Index, :index live "/records/import", RecordLive.Index, :import live "/records/:id/edit", RecordLive.Index, :edit