Include wishlist count in stats page
This commit is contained in:
@@ -26,6 +26,14 @@ defmodule MusicLibrary.Wishlist do
|
||||
Repo.aggregate(search, :count)
|
||||
end
|
||||
|
||||
def count do
|
||||
q =
|
||||
from r in Record,
|
||||
where: is_nil(r.purchased_at)
|
||||
|
||||
Repo.aggregate(q, :count)
|
||||
end
|
||||
|
||||
defp build_search(query) do
|
||||
{:ok, parsed_query} = SearchParser.parse(query)
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
defmodule MusicLibraryWeb.StatsController do
|
||||
use MusicLibraryWeb, :controller
|
||||
|
||||
alias MusicLibrary.Records
|
||||
alias MusicLibrary.{Records, Wishlist}
|
||||
|
||||
def index(conn, _params) do
|
||||
collection_count_by_format =
|
||||
@@ -15,6 +15,8 @@ defmodule MusicLibraryWeb.StatsController do
|
||||
collection_count =
|
||||
Enum.reduce(collection_count_by_format, 0, fn {_, count}, acc -> acc + count end)
|
||||
|
||||
wishlist_count = Wishlist.count()
|
||||
|
||||
latest_record = Records.get_latest_record!()
|
||||
|
||||
conn
|
||||
@@ -23,6 +25,7 @@ defmodule MusicLibraryWeb.StatsController do
|
||||
collection_count_by_format: collection_count_by_format,
|
||||
collection_count_by_type: collection_count_by_type,
|
||||
collection_count: collection_count,
|
||||
wishlist_count: wishlist_count,
|
||||
latest_record: latest_record,
|
||||
nav_section: :stats
|
||||
)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<div>
|
||||
<dl class="mt-5 grid grid-cols-1 gap-5 sm:grid-cols-3">
|
||||
<dl class="mt-5 grid grid-cols-2 gap-5 sm:grid-cols-5">
|
||||
<div
|
||||
class="relative overflow-hidden rounded-lg bg-white px-4 pb-3 pt-5 shadow sm:px-6 sm:pt-6 sm:col-span-2 cursor-pointer"
|
||||
class="relative overflow-hidden rounded-lg bg-white px-4 pb-3 pt-5 shadow sm:px-6 sm:pt-6 col-span-2 sm:col-span-3 cursor-pointer"
|
||||
phx-click={JS.navigate(~p"/records/#{@latest_record}")}
|
||||
>
|
||||
<dt>
|
||||
@@ -41,6 +41,18 @@
|
||||
</a>
|
||||
</dd>
|
||||
</div>
|
||||
<div class="overflow-hidden rounded-lg bg-white px-4 pb-3 pt-5 shadow sm:px-6 sm:pt-6">
|
||||
<dt>
|
||||
<p class="truncate text-sm font-medium text-gray-500">
|
||||
<%= gettext("Total wishlist") %>
|
||||
</p>
|
||||
</dt>
|
||||
<dd class="flex items-baseline pb-6 sm:pb-7">
|
||||
<a href={~p"/wishlist"} class="text-2xl font-semibold text-gray-900 hover:text-gray-500">
|
||||
<%= @wishlist_count %>
|
||||
</a>
|
||||
</dd>
|
||||
</div>
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user