display used-up date on used-up ammo
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2022-11-07 01:36:28 -05:00
parent cc31958bbe
commit cfbec3189c
31 changed files with 230 additions and 141 deletions

View File

@ -4,7 +4,7 @@ defmodule CanneryWeb.Components.AmmoGroupCard do
"""
use CanneryWeb, :component
alias Cannery.Repo
alias Cannery.{Ammo, Repo}
alias CanneryWeb.Endpoint
def ammo_group_card(%{ammo_group: ammo_group} = assigns) do
@ -47,6 +47,13 @@ defmodule CanneryWeb.Components.AmmoGroupCard do
<%= @ammo_group.inserted_at |> display_datetime() %>
</span>
<%= if @ammo_group.count == 0 do %>
<span class="rounded-lg title text-lg">
<%= gettext("Used up on:") %>
<%= @ammo_group |> Ammo.get_last_used_shot_group() |> Map.get(:date) |> display_date() %>
</span>
<% end %>
<%= if @ammo_group.price_paid do %>
<span class="rounded-lg title text-lg">
<%= gettext("Price paid:") %>

View File

@ -6,7 +6,7 @@ defmodule CanneryWeb.Components.TableComponent do
- `:columns`: An array of maps containing the following keys
- `:label`: A gettext'd or otherwise user-facing string label for the
column. Can be nil
- `:key`: A string key used for sorting
- `:key`: An atom key used for sorting
- `:class`: Extra classes to be applied to the column element, if desired.
Optional
- `:sortable`: If false, will prevent the user from sorting with it.
@ -28,13 +28,13 @@ defmodule CanneryWeb.Components.TableComponent do
required(:columns) =>
list(%{
required(:label) => String.t() | nil,
required(:key) => String.t() | nil,
required(:key) => atom() | nil,
optional(:class) => String.t(),
optional(:sortable) => false
}),
required(:rows) =>
list(%{
(key :: String.t()) => any() | {custom_sort_value :: String.t(), value :: any()}
(key :: atom()) => any() | {custom_sort_value :: String.t(), value :: any()}
}),
optional(any()) => any()
},
@ -56,20 +56,19 @@ defmodule CanneryWeb.Components.TableComponent do
def handle_event(
"sort_by",
%{"sort-key" => key},
%{assigns: %{rows: rows, last_sort_key: key, sort_mode: sort_mode}} = socket
%{assigns: %{rows: rows, last_sort_key: last_sort_key, sort_mode: sort_mode}} = socket
) do
sort_mode = if sort_mode == :asc, do: :desc, else: :asc
rows = rows |> sort_by_custom_sort_value_or_value(key, sort_mode)
{:noreply, socket |> assign(sort_mode: sort_mode, rows: rows)}
end
key = key |> String.to_existing_atom()
def handle_event(
"sort_by",
%{"sort-key" => key},
%{assigns: %{rows: rows}} = socket
) do
rows = rows |> sort_by_custom_sort_value_or_value(key, :asc)
{:noreply, socket |> assign(last_sort_key: key, sort_mode: :asc, rows: rows)}
sort_mode =
case {key, sort_mode} do
{^last_sort_key, :asc} -> :desc
{^last_sort_key, :desc} -> :asc
{_new_sort_key, _last_sort_mode} -> :asc
end
rows = rows |> sort_by_custom_sort_value_or_value(key, sort_mode)
{:noreply, socket |> assign(last_sort_key: key, sort_mode: sort_mode, rows: rows)}
end
defp sort_by_custom_sort_value_or_value(rows, key, sort_mode) do

View File

@ -1,4 +1,4 @@
<div class="w-full overflow-x-auto border border-gray-600 rounded-lg shadow-lg bg-black">
<div id={@id} class="w-full overflow-x-auto border border-gray-600 rounded-lg shadow-lg bg-black">
<table class="min-w-full table-auto text-center bg-white">
<thead class="border-b border-primary-600">
<tr>