Make application work with empty database
This commit is contained in:
@@ -53,6 +53,17 @@ defmodule MusicLibrary.Collection do
|
|||||||
Repo.all(q)
|
Repo.all(q)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_latest_record do
|
||||||
|
q =
|
||||||
|
from r in Record,
|
||||||
|
where: not is_nil(r.purchased_at),
|
||||||
|
order_by: [{:desc, r.purchased_at}, order_alphabetically()],
|
||||||
|
limit: 1,
|
||||||
|
select: ^Records.essential_fields()
|
||||||
|
|
||||||
|
Repo.one(q)
|
||||||
|
end
|
||||||
|
|
||||||
def get_latest_record! do
|
def get_latest_record! do
|
||||||
q =
|
q =
|
||||||
from r in Record,
|
from r in Record,
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ defmodule MusicLibraryWeb.ChartComponents do
|
|||||||
attr :class, :string, default: ""
|
attr :class, :string, default: ""
|
||||||
attr :datum_click, :any, default: nil, doc: "the function for handling phx-click on each datum"
|
attr :datum_click, :any, default: nil, doc: "the function for handling phx-click on each datum"
|
||||||
|
|
||||||
def vertical_bar_chart(assigns) do
|
def vertical_bar_chart(assigns) when assigns.data != [] do
|
||||||
assigns =
|
assigns =
|
||||||
assigns
|
assigns
|
||||||
|> assign(:padding, 40)
|
|> assign(:padding, 40)
|
||||||
@@ -95,6 +95,14 @@ defmodule MusicLibraryWeb.ChartComponents do
|
|||||||
"""
|
"""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def vertical_bar_chart(assigns) do
|
||||||
|
~H"""
|
||||||
|
<div class={["w-full", @class]}>
|
||||||
|
{gettext("No data available")}
|
||||||
|
</div>
|
||||||
|
"""
|
||||||
|
end
|
||||||
|
|
||||||
defp max_value(data, value_fn) do
|
defp max_value(data, value_fn) do
|
||||||
max = Enum.max_by(data, value_fn)
|
max = Enum.max_by(data, value_fn)
|
||||||
value_fn.(max)
|
value_fn.(max)
|
||||||
|
|||||||
@@ -6,13 +6,14 @@ defmodule MusicLibraryWeb.StatsComponents do
|
|||||||
|
|
||||||
alias MusicLibrary.Records
|
alias MusicLibrary.Records
|
||||||
|
|
||||||
attr :record, Records.Record, required: true
|
attr :record, Records.Record, required: false
|
||||||
attr :title, :string, required: true
|
attr :title, :string, required: true
|
||||||
attr :class, :string
|
attr :class, :string
|
||||||
|
|
||||||
def album_preview(assigns) do
|
def album_preview(assigns) do
|
||||||
~H"""
|
~H"""
|
||||||
<div
|
<div
|
||||||
|
:if={@record}
|
||||||
class={[
|
class={[
|
||||||
"flex items-center rounded-md bg-white dark:bg-zinc-800 px-4 pb-5 pt-5 shadow-sm sm:px-6 sm:pt-6 cursor-pointer",
|
"flex items-center rounded-md bg-white dark:bg-zinc-800 px-4 pb-5 pt-5 shadow-sm sm:px-6 sm:pt-6 cursor-pointer",
|
||||||
@class
|
@class
|
||||||
@@ -44,6 +45,17 @@ defmodule MusicLibraryWeb.StatsComponents do
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div
|
||||||
|
:if={!@record}
|
||||||
|
class={[
|
||||||
|
"flex items-center rounded-md bg-white dark:bg-zinc-800 px-4 pb-5 pt-5 shadow-sm sm:px-6 sm:pt-6 cursor-pointer",
|
||||||
|
@class
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<p class="truncate text-xs sm:text-sm font-medium text-zinc-500 dark:text-zinc-400">
|
||||||
|
{gettext("No record found")}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
"""
|
"""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ defmodule MusicLibraryWeb.StatsLive.Index do
|
|||||||
|
|
||||||
def mount(_params, _session, socket) do
|
def mount(_params, _session, socket) do
|
||||||
current_date = DateTime.now!(socket.assigns.timezone) |> DateTime.to_date()
|
current_date = DateTime.now!(socket.assigns.timezone) |> DateTime.to_date()
|
||||||
latest_record = Collection.get_latest_record!()
|
latest_record = Collection.get_latest_record()
|
||||||
records_by_artists = Collection.count_records_by_artist(limit: 20)
|
records_by_artists = Collection.count_records_by_artist(limit: 20)
|
||||||
records_by_genre = Collection.count_records_by_genre(limit: 20)
|
records_by_genre = Collection.count_records_by_genre(limit: 20)
|
||||||
records_on_this_day = Collection.get_records_on_this_day(current_date)
|
records_on_this_day = Collection.get_records_on_this_day(current_date)
|
||||||
|
|||||||
@@ -1624,3 +1624,13 @@ msgstr ""
|
|||||||
#, elixir-autogen, elixir-format
|
#, elixir-autogen, elixir-format
|
||||||
msgid "Top %{n} Collection Genres"
|
msgid "Top %{n} Collection Genres"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#: lib/music_library_web/components/chart_components.ex
|
||||||
|
#, elixir-autogen, elixir-format
|
||||||
|
msgid "No data available"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: lib/music_library_web/components/stats_components.ex
|
||||||
|
#, elixir-autogen, elixir-format
|
||||||
|
msgid "No record found"
|
||||||
|
msgstr ""
|
||||||
|
|||||||
@@ -1624,3 +1624,13 @@ msgstr ""
|
|||||||
#, elixir-autogen, elixir-format, fuzzy
|
#, elixir-autogen, elixir-format, fuzzy
|
||||||
msgid "Top %{n} Collection Genres"
|
msgid "Top %{n} Collection Genres"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#: lib/music_library_web/components/chart_components.ex
|
||||||
|
#, elixir-autogen, elixir-format
|
||||||
|
msgid "No data available"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: lib/music_library_web/components/stats_components.ex
|
||||||
|
#, elixir-autogen, elixir-format
|
||||||
|
msgid "No record found"
|
||||||
|
msgstr ""
|
||||||
|
|||||||
Reference in New Issue
Block a user