forked from shibao/cannery
add more ammo type fields, filter index columns
This commit is contained in:
@ -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>
|
||||
|
@ -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..."),
|
||||
|
@ -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
|
||||
|
@ -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 %>
|
||||
<%= for {_label, field, type} <- @columns_to_display do %>
|
||||
<td class="p-2">
|
||||
<%= ammo_type |> Map.get(field) %>
|
||||
</td>
|
||||
<% end %>
|
||||
|
||||
<%= for field <- [
|
||||
:rimfire,
|
||||
:tracer,
|
||||
:incendiary,
|
||||
:blank,
|
||||
:corrosive
|
||||
] do %>
|
||||
<td class="p-2">
|
||||
<%= ammo_type |> Map.get(field) |> humanize() %>
|
||||
</td>
|
||||
<% end %>
|
||||
|
||||
<%= for field <- [:manufacturer, :sku] do %>
|
||||
<td class="p-2">
|
||||
<%= ammo_type |> Map.get(field) %>
|
||||
<%= case type do %>
|
||||
<% :boolean -> %>
|
||||
<%= ammo_type |> Map.get(field) |> humanize() %>
|
||||
<% _other -> %>
|
||||
<%= ammo_type |> Map.get(field) %>
|
||||
<% end %>
|
||||
</td>
|
||||
<% end %>
|
||||
|
||||
|
@ -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 %> :
|
||||
|
Reference in New Issue
Block a user