add more ammo type fields, filter index columns

This commit is contained in:
shibao 2022-02-15 22:33:36 -05:00
parent f30acd7fe2
commit 2ac379adaf
11 changed files with 192 additions and 108 deletions

View File

@ -23,6 +23,10 @@ defmodule Cannery.Ammo.AmmoType do
field :cartridge, :string
field :caliber, :string
field :case_material, :string
field :jacket_type, :string
field :muzzle_velocity, :integer
field :powder_type, :string
field :powder_grains_per_charge, :integer
field :grains, :integer
field :pressure, :string
field :primer_type, :string
@ -33,7 +37,7 @@ defmodule Cannery.Ammo.AmmoType do
field :corrosive, :boolean, null: false, default: false
field :manufacturer, :string
field :sku, :string
field :upc, :string
belongs_to :user, User
@ -51,6 +55,10 @@ defmodule Cannery.Ammo.AmmoType do
cartridge: String.t() | nil,
caliber: String.t() | nil,
case_material: String.t() | nil,
jacket_type: String.t() | nil,
muzzle_velocity: integer() | nil,
powder_type: String.t() | nil,
powder_grains_per_charge: integer() | nil,
grains: integer() | nil,
pressure: String.t() | nil,
primer_type: String.t() | nil,
@ -60,7 +68,7 @@ defmodule Cannery.Ammo.AmmoType do
blank: boolean(),
corrosive: boolean(),
manufacturer: String.t() | nil,
sku: String.t() | nil,
upc: String.t() | nil,
user_id: User.id(),
user: User.t() | nil,
ammo_groups: [AmmoGroup.t()] | nil,
@ -80,6 +88,10 @@ defmodule Cannery.Ammo.AmmoType do
:cartridge,
:caliber,
:case_material,
:jacket_type,
:muzzle_velocity,
:powder_type,
:powder_grains_per_charge,
:grains,
:pressure,
:primer_type,
@ -89,7 +101,7 @@ defmodule Cannery.Ammo.AmmoType do
:blank,
:corrosive,
:manufacturer,
:sku
:upc
]
@doc false

View File

@ -38,7 +38,8 @@ defmodule CanneryWeb.Components.AmmoGroupCard do
<%= if @ammo_group.price_paid do %>
<span class="rounded-lg title text-lg">
<%= gettext("Price paid:") %> <%= gettext("$%{amount}", amount: @ammo_group.price_paid |> :erlang.float_to_binary(decimals: 2)) %>
<%= gettext("Price paid:") %>
<%= gettext("$%{amount}", amount: @ammo_group.price_paid |> :erlang.float_to_binary(decimals: 2)) %>
</span>
<% end %>
</div>

View File

@ -18,7 +18,8 @@
<%= if @ammo_group.price_paid do %>
<span class="rounded-lg title text-lg">
<%= gettext("Price paid:") %> <%= gettext("$%{amount}", amount: @ammo_group.price_paid |> :erlang.float_to_binary(decimals: 2)) %>
<%= gettext("Price paid:") %>
<%= gettext("$%{amount}", amount: @ammo_group.price_paid |> :erlang.float_to_binary(decimals: 2)) %>
</span>
<% end %>
</div>

View File

@ -69,6 +69,40 @@
) %>
<%= error_tag(f, :case_material, "col-span-3 text-center") %>
<%= label(f, :jacket_type, gettext("Jacket type"), class: "mr-4 title text-lg text-primary-500") %>
<%= text_input(f, :jacket_type,
class: "text-center col-span-2 input input-primary",
placeholder: gettext("Bimetal")
) %>
<%= error_tag(f, :case_material, "col-span-3 text-center") %>
<%= label(f, :muzzle_velocity, gettext("Muzzle velocity"),
class: "mr-4 title text-lg text-primary-500"
) %>
<%= number_input(f, :muzzle_velocity,
step: "1",
class: "text-center col-span-2 input input-primary",
min: 1
) %>
<%= error_tag(f, :muzzle_velocity, "col-span-3 text-center") %>
<%= label(f, :powder_type, gettext("Powder type"), class: "mr-4 title text-lg text-primary-500") %>
<%= text_input(f, :powder_type,
class: "text-center col-span-2 input input-primary",
placeholder: gettext("Brass")
) %>
<%= error_tag(f, :powder_type, "col-span-3 text-center") %>
<%= label(f, :powder_grains_per_charge, gettext("Powder grains per charge"),
class: "mr-4 title text-lg text-primary-500"
) %>
<%= number_input(f, :powder_grains_per_charge,
step: "1",
class: "text-center col-span-2 input input-primary",
min: 1
) %>
<%= error_tag(f, :powder_grains_per_charge, "col-span-3 text-center") %>
<%= label(f, :grains, gettext("Grains"), class: "mr-4 title text-lg text-primary-500") %>
<%= number_input(f, :grains,
step: "1",
@ -115,9 +149,9 @@
<%= text_input(f, :manufacturer, class: "text-center col-span-2 input input-primary") %>
<%= error_tag(f, :manufacturer, "col-span-3 text-center") %>
<%= label(f, :sku, gettext("SKU"), class: "mr-4 title text-lg text-primary-500") %>
<%= text_input(f, :sku, class: "text-center col-span-2 input input-primary") %>
<%= error_tag(f, :sku, "col-span-3 text-center") %>
<%= label(f, :upc, gettext("UPC"), class: "mr-4 title text-lg text-primary-500") %>
<%= text_input(f, :upc, class: "text-center col-span-2 input input-primary") %>
<%= error_tag(f, :upc, "col-span-3 text-center") %>
<%= submit(dgettext("actions", "Save"),
phx_disable_with: dgettext("prompts", "Saving..."),

View File

@ -44,6 +44,36 @@ defmodule CanneryWeb.AmmoTypeLive.Index do
end
defp list_ammo_types(%{assigns: %{current_user: current_user}} = socket) do
socket |> assign(:ammo_types, Ammo.list_ammo_types(current_user))
ammo_types = Ammo.list_ammo_types(current_user)
columns_to_display =
[
{gettext("Name"), :name, :string},
{gettext("Bullet type"), :bullet_type, :string},
{gettext("Bullet core"), :bullet_core, :string},
{gettext("Cartridge"), :cartridge, :string},
{gettext("Caliber"), :caliber, :string},
{gettext("Case material"), :case_material, :string},
{gettext("Jacket type"), :jacket_type, :string},
{gettext("Muzzle velocity"), :muzzle_velocity, :string},
{gettext("Powder type"), :powder_type, :string},
{gettext("Powder grains per charge"), :powder_grains_per_charge, :string},
{gettext("Grains"), :grains, :string},
{gettext("Pressure"), :pressure, :string},
{gettext("Primer type"), :primer_type, :string},
{gettext("Rimfire"), :rimfire, :boolean},
{gettext("Tracer"), :tracer, :boolean},
{gettext("Incendiary"), :incendiary, :boolean},
{gettext("Blank"), :blank, :boolean},
{gettext("Corrosive"), :corrosive, :boolean},
{gettext("Manufacturer"), :manufacturer, :string},
{gettext("UPC"), :upc, :string}
]
# filter columns to only used ones
|> Enum.filter(fn {_label, field, _type} ->
ammo_types |> Enum.any?(fn ammo_type -> not (ammo_type |> Map.get(field) |> is_nil()) end)
end)
socket |> assign(ammo_types: ammo_types, columns_to_display: columns_to_display)
end
end

View File

@ -22,24 +22,7 @@
<table class="min-w-full table-auto text-center bg-white">
<thead class="border-b border-primary-600">
<tr>
<%= for field_name <- [
gettext("Name"),
gettext("Bullet type"),
gettext("Bullet core"),
gettext("Cartridge"),
gettext("Caliber"),
gettext("Case material"),
gettext("Grains"),
gettext("Pressure"),
gettext("Primer type"),
gettext("Rimfire"),
gettext("Tracer"),
gettext("Incendiary"),
gettext("Blank"),
gettext("Corrosive"),
gettext("Manufacturer"),
gettext("Sku")
] do %>
<%= for {field_name, _field, _type} <- @columns_to_display do %>
<th class="p-2">
<%= field_name %>
</th>
@ -51,37 +34,14 @@
<tbody>
<%= for ammo_type <- @ammo_types do %>
<tr id={"ammo_type-#{ammo_type.id}"}>
<%= for field <- [
:name,
:bullet_type,
:bullet_core,
:cartridge,
:caliber,
:case_material,
:grains,
:pressure,
:primer_type
] do %>
<td class="p-2">
<%= ammo_type |> Map.get(field) %>
</td>
<% end %>
<%= for field <- [
:rimfire,
:tracer,
:incendiary,
:blank,
:corrosive
] do %>
<%= for {_label, field, type} <- @columns_to_display do %>
<td class="p-2">
<%= case type do %>
<% :boolean -> %>
<%= ammo_type |> Map.get(field) |> humanize() %>
</td>
<% end %>
<%= for field <- [:manufacturer, :sku] do %>
<td class="p-2">
<% _other -> %>
<%= ammo_type |> Map.get(field) %>
<% end %>
</td>
<% end %>

View File

@ -38,6 +38,10 @@
{gettext("Cartridge"), :cartridge},
{gettext("Caliber"), :caliber},
{gettext("Case material"), :case_material},
{gettext("Jacket type"), :jacket_type},
{gettext("Muzzle velocity"), :muzzle_velocity},
{gettext("Powder type"), :powder_type},
{gettext("Powder grains per charge"), :powder_grains_per_charge},
{gettext("Grains"), :grains},
{gettext("Pressure"), :pressure},
{gettext("Primer type"), :primer_type}
@ -69,7 +73,7 @@
</span>
<% end %>
<%= for {field_name, field} <- [{"Manufacturer", :manufacturer}, {"Sku", :sku}] do %>
<%= for {field_name, field} <- [{"Manufacturer", :manufacturer}, {"UPC", :upc}] do %>
<%= if @ammo_type |> Map.get(field) do %>
<h3 class="mb-2 sm:mr-4 title text-lg">
<%= field_name %> :

View File

@ -126,7 +126,7 @@ msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/components/add_shot_group_component.html.heex:42
#: lib/cannery_web/live/ammo_group_live/form_component.html.heex:54
#: lib/cannery_web/live/ammo_type_live/form_component.html.heex:122
#: lib/cannery_web/live/ammo_type_live/form_component.html.heex:156
#: lib/cannery_web/live/container_live/form_component.html.heex:50
#: lib/cannery_web/live/invite_live/form_component.html.heex:28
#: lib/cannery_web/live/range_live/form_component.html.heex:40
@ -165,7 +165,7 @@ msgid "Record shots"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_group_live/show.html.heex:27
#: lib/cannery_web/live/ammo_group_live/show.html.heex:28
msgid "Ammo Details"
msgstr ""
@ -175,7 +175,7 @@ msgid "Add another container!"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_group_live/show.html.heex:48
#: lib/cannery_web/live/ammo_group_live/show.html.heex:49
msgid "Move to different container"
msgstr ""

View File

@ -44,7 +44,7 @@ msgid "Ammo type"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/show.html.heex:86
#: lib/cannery_web/live/ammo_type_live/show.html.heex:90
msgid "Average Price paid"
msgstr ""
@ -54,47 +54,48 @@ msgid "Background color"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/form_component.html.heex:106
#: lib/cannery_web/live/ammo_type_live/index.html.heex:38
#: lib/cannery_web/live/ammo_type_live/form_component.html.heex:140
#: lib/cannery_web/live/ammo_type_live/index.ex:67
msgid "Blank"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/form_component.html.heex:68
#: lib/cannery_web/live/ammo_type_live/form_component.html.heex:92
msgid "Brass"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/form_component.html.heex:44
#: lib/cannery_web/live/ammo_type_live/index.html.heex:28
#: lib/cannery_web/live/ammo_type_live/index.ex:53
#: lib/cannery_web/live/ammo_type_live/show.html.heex:37
msgid "Bullet core"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/form_component.html.heex:37
#: lib/cannery_web/live/ammo_type_live/index.html.heex:27
#: lib/cannery_web/live/ammo_type_live/index.ex:52
#: lib/cannery_web/live/ammo_type_live/show.html.heex:36
msgid "Bullet type"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/form_component.html.heex:58
#: lib/cannery_web/live/ammo_type_live/index.html.heex:30
#: lib/cannery_web/live/ammo_type_live/index.ex:55
#: lib/cannery_web/live/ammo_type_live/show.html.heex:39
msgid "Caliber"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/form_component.html.heex:51
#: lib/cannery_web/live/ammo_type_live/index.html.heex:29
#: lib/cannery_web/live/ammo_type_live/index.ex:54
#: lib/cannery_web/live/ammo_type_live/show.html.heex:38
msgid "Cartridge"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/form_component.html.heex:65
#: lib/cannery_web/live/ammo_type_live/index.html.heex:31
#: lib/cannery_web/live/ammo_type_live/index.ex:56
#: lib/cannery_web/live/ammo_type_live/show.html.heex:40
msgid "Case material"
msgstr ""
@ -113,8 +114,8 @@ msgid "Containers"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/form_component.html.heex:110
#: lib/cannery_web/live/ammo_type_live/index.html.heex:39
#: lib/cannery_web/live/ammo_type_live/form_component.html.heex:144
#: lib/cannery_web/live/ammo_type_live/index.ex:68
msgid "Corrosive"
msgstr ""
@ -196,15 +197,15 @@ msgid "FMJ"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/form_component.html.heex:72
#: lib/cannery_web/live/ammo_type_live/index.html.heex:32
#: lib/cannery_web/live/ammo_type_live/show.html.heex:41
#: lib/cannery_web/live/ammo_type_live/form_component.html.heex:106
#: lib/cannery_web/live/ammo_type_live/index.ex:61
#: lib/cannery_web/live/ammo_type_live/show.html.heex:45
msgid "Grains"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/form_component.html.heex:102
#: lib/cannery_web/live/ammo_type_live/index.html.heex:37
#: lib/cannery_web/live/ammo_type_live/form_component.html.heex:136
#: lib/cannery_web/live/ammo_type_live/index.ex:66
msgid "Incendiary"
msgstr ""
@ -277,8 +278,8 @@ msgid "Manage"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/form_component.html.heex:114
#: lib/cannery_web/live/ammo_type_live/index.html.heex:40
#: lib/cannery_web/live/ammo_type_live/form_component.html.heex:148
#: lib/cannery_web/live/ammo_type_live/index.ex:69
msgid "Manufacturer"
msgstr ""
@ -294,7 +295,7 @@ msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/form_component.html.heex:20
#: lib/cannery_web/live/ammo_type_live/index.html.heex:26
#: lib/cannery_web/live/ammo_type_live/index.ex:51
#: lib/cannery_web/live/container_live/form_component.html.heex:20
#: lib/cannery_web/live/invite_live/form_component.html.heex:20
#: lib/cannery_web/live/tag_live/form_component.ex:50
@ -332,7 +333,7 @@ msgid "No Ammo Types"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/show.html.heex:99
#: lib/cannery_web/live/ammo_type_live/show.html.heex:103
msgid "No ammo for this type"
msgstr ""
@ -377,9 +378,9 @@ msgid "On the bookshelf"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/form_component.html.heex:80
#: lib/cannery_web/live/ammo_type_live/index.html.heex:33
#: lib/cannery_web/live/ammo_type_live/show.html.heex:42
#: lib/cannery_web/live/ammo_type_live/form_component.html.heex:114
#: lib/cannery_web/live/ammo_type_live/index.ex:62
#: lib/cannery_web/live/ammo_type_live/show.html.heex:46
msgid "Pressure"
msgstr ""
@ -396,9 +397,9 @@ msgid "Price paid:"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/form_component.html.heex:87
#: lib/cannery_web/live/ammo_type_live/index.html.heex:34
#: lib/cannery_web/live/ammo_type_live/show.html.heex:43
#: lib/cannery_web/live/ammo_type_live/form_component.html.heex:121
#: lib/cannery_web/live/ammo_type_live/index.ex:63
#: lib/cannery_web/live/ammo_type_live/show.html.heex:47
msgid "Primer type"
msgstr ""
@ -408,16 +409,11 @@ msgid "Public Signups"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/form_component.html.heex:94
#: lib/cannery_web/live/ammo_type_live/index.html.heex:35
#: lib/cannery_web/live/ammo_type_live/form_component.html.heex:128
#: lib/cannery_web/live/ammo_type_live/index.ex:64
msgid "Rimfire"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/form_component.html.heex:118
msgid "SKU"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/home_live.ex:63
msgid "Secure:"
@ -458,18 +454,13 @@ msgstr ""
msgid "Simple:"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/index.html.heex:41
msgid "Sku"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/form_component.html.heex:47
msgid "Steel"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_group_live/show.html.heex:59
#: lib/cannery_web/live/ammo_group_live/show.html.heex:60
msgid "Stored in"
msgstr ""
@ -496,13 +487,13 @@ msgid "The self-hosted firearm tracker website"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_group_live/show.html.heex:64
#: lib/cannery_web/live/ammo_group_live/show.html.heex:65
msgid "This ammo group is not in a container"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/form_component.html.heex:98
#: lib/cannery_web/live/ammo_type_live/index.html.heex:36
#: lib/cannery_web/live/ammo_type_live/form_component.html.heex:132
#: lib/cannery_web/live/ammo_type_live/index.ex:65
msgid "Tracer"
msgstr ""
@ -580,14 +571,14 @@ msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_group_live/index.html.heex:78
#: lib/cannery_web/live/ammo_group_live/show.html.heex:45
#: lib/cannery_web/live/ammo_group_live/show.html.heex:46
#: lib/cannery_web/live/range_live/index.html.heex:30
msgid "Stage for range"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_group_live/index.html.heex:78
#: lib/cannery_web/live/ammo_group_live/show.html.heex:45
#: lib/cannery_web/live/ammo_group_live/show.html.heex:46
#: lib/cannery_web/live/range_live/index.html.heex:30
msgid "Unstage from range"
msgstr ""
@ -674,3 +665,50 @@ msgstr ""
#: lib/cannery_web/live/range_live/index.html.heex:49
msgid "Shot log"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/components/ammo_group_card.ex:42
#: lib/cannery_web/live/ammo_group_live/index.html.heex:63
#: lib/cannery_web/live/ammo_group_live/show.html.heex:22
#: lib/cannery_web/live/ammo_type_live/show.html.heex:94
msgid "$%{amount}"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/form_component.html.heex:75
msgid "Bimetal"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/form_component.html.heex:72
#: lib/cannery_web/live/ammo_type_live/index.ex:57
#: lib/cannery_web/live/ammo_type_live/show.html.heex:41
msgid "Jacket type"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/form_component.html.heex:79
#: lib/cannery_web/live/ammo_type_live/index.ex:58
#: lib/cannery_web/live/ammo_type_live/show.html.heex:42
msgid "Muzzle velocity"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/form_component.html.heex:96
#: lib/cannery_web/live/ammo_type_live/index.ex:60
#: lib/cannery_web/live/ammo_type_live/show.html.heex:44
msgid "Powder grains per charge"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/form_component.html.heex:89
#: lib/cannery_web/live/ammo_type_live/index.ex:59
#: lib/cannery_web/live/ammo_type_live/show.html.heex:43
msgid "Powder type"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/form_component.html.heex:152
#: lib/cannery_web/live/ammo_type_live/index.ex:70
msgid "UPC"
msgstr ""

View File

@ -98,8 +98,8 @@ msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_group_live/index.html.heex:107
#: lib/cannery_web/live/ammo_group_live/show.html.heex:40
#: lib/cannery_web/live/ammo_type_live/index.html.heex:104
#: lib/cannery_web/live/ammo_group_live/show.html.heex:41
#: lib/cannery_web/live/ammo_type_live/index.html.heex:64
msgid "Are you sure you want to delete this ammo?"
msgstr ""
@ -161,7 +161,7 @@ msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/components/add_shot_group_component.html.heex:44
#: lib/cannery_web/live/ammo_group_live/form_component.html.heex:55
#: lib/cannery_web/live/ammo_type_live/form_component.html.heex:123
#: lib/cannery_web/live/ammo_type_live/form_component.html.heex:157
#: lib/cannery_web/live/container_live/form_component.html.heex:52
#: lib/cannery_web/live/invite_live/form_component.html.heex:30
#: lib/cannery_web/live/range_live/form_component.html.heex:42

View File

@ -13,6 +13,10 @@ defmodule Cannery.Repo.Migrations.CreateAmmoTypes do
add :cartridge, :string
add :caliber, :string
add :case_material, :string
add :jacket_type, :string
add :muzzle_velocity, :integer
add :powder_type, :string
add :powder_grains_per_charge, :integer
add :grains, :integer
add :pressure, :string
add :primer_type, :string
@ -23,7 +27,7 @@ defmodule Cannery.Repo.Migrations.CreateAmmoTypes do
add :corrosive, :boolean, null: false, default: false
add :manufacturer, :string
add :sku, :string
add :upc, :string
add :user_id, references(:users, on_delete: :delete_all, type: :binary_id)