- add primer_type to ammo type

- fix ammo type typespec
- remove unused ammo type card
- mix format
This commit is contained in:
shibao 2022-02-07 23:38:03 -05:00
parent 94b88f9f9e
commit 22c148e93b
9 changed files with 35 additions and 65 deletions

View File

@ -24,6 +24,7 @@ defmodule Cannery.Ammo.AmmoType do
field :case_material, :string field :case_material, :string
field :grains, :integer field :grains, :integer
field :pressure, :string field :pressure, :string
field :primer_type, :string
field :rimfire, :boolean, null: false, default: false field :rimfire, :boolean, null: false, default: false
field :tracer, :boolean, null: false, default: false field :tracer, :boolean, null: false, default: false
field :incendiary, :boolean, null: false, default: false field :incendiary, :boolean, null: false, default: false
@ -41,21 +42,22 @@ defmodule Cannery.Ammo.AmmoType do
@type t :: %AmmoType{ @type t :: %AmmoType{
id: id(), id: id(),
name: String.t(), name: String.t(),
desc: String.t(), desc: String.t() | nil,
bullet_type: String.t(), bullet_type: String.t() | nil,
bullet_core: String.t(), bullet_core: String.t() | nil,
cartridge: String.t(), cartridge: String.t() | nil,
caliber: String.t(), caliber: String.t() | nil,
case_material: String.t(), case_material: String.t() | nil,
grains: integer(), grains: integer() | nil,
pressure: String.t(), pressure: String.t() | nil,
primer_type: String.t() | nil,
rimfire: boolean(), rimfire: boolean(),
tracer: boolean(), tracer: boolean(),
incendiary: boolean(), incendiary: boolean(),
blank: boolean(), blank: boolean(),
corrosive: boolean(), corrosive: boolean(),
manufacturer: String.t(), manufacturer: String.t() | nil,
sku: String.t(), sku: String.t() | nil,
ammo_groups: [AmmoGroup.t()] | nil, ammo_groups: [AmmoGroup.t()] | nil,
inserted_at: NaiveDateTime.t(), inserted_at: NaiveDateTime.t(),
updated_at: NaiveDateTime.t() updated_at: NaiveDateTime.t()
@ -77,6 +79,7 @@ defmodule Cannery.Ammo.AmmoType do
:case_material, :case_material,
:grains, :grains,
:pressure, :pressure,
:primer_type,
:rimfire, :rimfire,
:tracer, :tracer,
:incendiary, :incendiary,

View File

@ -43,7 +43,9 @@
</td> </td>
<td class="p-2"> <td class="p-2">
$ <%= ammo_group.price_paid |> :erlang.float_to_binary(decimals: 2) %> <%= if ammo_group.price_paid do %>
$ <%= ammo_group.price_paid |> :erlang.float_to_binary(decimals: 2) %>
<% end %>
</td> </td>
<td class="p-2"> <td class="p-2">

View File

@ -1,46 +0,0 @@
defmodule CanneryWeb.AmmoTypeLive.AmmoTypeCard do
@moduledoc """
Display card for an ammo type
"""
use CanneryWeb, :component
alias Cannery.Repo
alias CanneryWeb.Endpoint
def ammo_group_card(assigns) do
assigns = assigns |> assign(:ammo_group, assigns.ammo_group |> Repo.preload(:ammo_type))
~H"""
<div
id={"ammo_group-#{@ammo_group.id}"}
class="px-8 py-4 flex flex-col justify-center items-center
border border-gray-400 rounded-lg shadow-lg hover:shadow-md"
>
<%= live_redirect to: Routes.ammo_group_show_path(Endpoint, :show, @ammo_group),
class: "mb-2 link" do %>
<h1 class="title text-xl title-primary-500">
<%= @ammo_group.ammo_type.name %>
</h1>
<% end %>
<div class="flex flex-col justify-center items-center">
<span class="rounded-lg title text-lg">
Count: <%= @ammo_group.count %>
</span>
<%= if @ammo_group.notes do %>
<span class="rounded-lg title text-lg">
Notes: <%= @ammo_group.notes %>
</span>
<% end %>
<%= if @ammo_group.price_paid do %>
<span class="rounded-lg title text-lg">
Price paid: $ <%= @ammo_group.price_paid |> :erlang.float_to_binary(decimals: 2) %>
</span>
<% end %>
</div>
</div>
"""
end
end

View File

@ -117,6 +117,13 @@ defmodule CanneryWeb.AmmoTypeLive.FormComponent do
) %> ) %>
<%= error_tag(f, :pressure, "col-span-3 text-center") %> <%= error_tag(f, :pressure, "col-span-3 text-center") %>
<%= label(f, :primer_type, class: "mr-4 title text-lg text-primary-500") %>
<%= text_input(f, :primer_type,
class: "text-center col-span-2 input input-primary",
placeholder: "Boxer"
) %>
<%= error_tag(f, :primer_type, "col-span-3 text-center") %>
<%= label(f, :rimfire, class: "mr-4 title text-lg text-primary-500") %> <%= label(f, :rimfire, class: "mr-4 title text-lg text-primary-500") %>
<%= checkbox(f, :rimfire, class: "text-center col-span-2 checkbox") %> <%= checkbox(f, :rimfire, class: "text-center col-span-2 checkbox") %>
<%= error_tag(f, :rimfire, "col-span-3 text-center") %> <%= error_tag(f, :rimfire, "col-span-3 text-center") %>

View File

@ -31,6 +31,7 @@
:case_material, :case_material,
:grains, :grains,
:pressure, :pressure,
:primer_type,
:rimfire, :rimfire,
:tracer, :tracer,
:incendiary, :incendiary,
@ -58,7 +59,8 @@
:caliber, :caliber,
:case_material, :case_material,
:grains, :grains,
:pressure :pressure,
:primer_type
] do %> ] do %>
<td class="p-2"> <td class="p-2">
<%= ammo_type |> Map.get(field) %> <%= ammo_type |> Map.get(field) %>

View File

@ -36,11 +36,12 @@
:caliber, :caliber,
:case_material, :case_material,
:grains, :grains,
:pressure :pressure,
:primer_type
] do %> ] do %>
<%= if @ammo_type |> Map.get(field) do %> <%= if @ammo_type |> Map.get(field) do %>
<h3 class="mb-2 sm:mr-4 title text-lg"> <h3 class="mb-2 sm:mr-4 title text-lg">
<%= field |> humanize() %>: <%= field |> humanize() %> :
</h3> </h3>
<span class="mb-4 sm:mb-2 text-primary-600"> <span class="mb-4 sm:mb-2 text-primary-600">
@ -57,7 +58,7 @@
:corrosive :corrosive
] do %> ] do %>
<h3 class="mb-2 sm:mr-4 title text-lg"> <h3 class="mb-2 sm:mr-4 title text-lg">
<%= field |> humanize() %>: <%= field |> humanize() %> :
</h3> </h3>
<span class="mb-4 sm:mb-2 text-primary-600"> <span class="mb-4 sm:mb-2 text-primary-600">
@ -68,7 +69,7 @@
<%= for field <- [:manufacturer, :sku] do %> <%= for field <- [:manufacturer, :sku] do %>
<%= if @ammo_type |> Map.get(field) do %> <%= if @ammo_type |> Map.get(field) do %>
<h3 class="mb-2 sm:mr-4 title text-lg"> <h3 class="mb-2 sm:mr-4 title text-lg">
<%= field |> humanize() %>: <%= field |> humanize() %> :
</h3> </h3>
<span class="mb-4 sm:mb-2 text-primary-600"> <span class="mb-4 sm:mb-2 text-primary-600">

View File

@ -24,8 +24,8 @@ defmodule CanneryWeb.ModalComponent do
flex flex-col justify-start items-center flex flex-col justify-start items-center
bg-white border-2 rounded-lg"> bg-white border-2 rounded-lg">
<%= live_patch to: @return_to, <%= live_patch to: @return_to,
class: "absolute top-8 right-10 text-gray-500 hover:text-gray-800 class:
transition-all duration-500 ease-in-out" do %> "absolute top-8 right-10 text-gray-500 hover:text-gray-800 transition-all duration-500 ease-in-out" do %>
<i class="fa-fw fa-lg fas fa-times"></i> <i class="fa-fw fa-lg fas fa-times"></i>
<% end %> <% end %>
<div class="p-8 flex flex-col space-y-4 justify-start items-center"> <div class="p-8 flex flex-col space-y-4 justify-start items-center">

View File

@ -1,4 +1,4 @@
<main class="container min-w-full"> <main class="mb-8 container min-w-full">
<header> <header>
<CanneryWeb.Component.Topbar.topbar current_user={assigns[:current_user]}></CanneryWeb.Component.Topbar.topbar> <CanneryWeb.Component.Topbar.topbar current_user={assigns[:current_user]}></CanneryWeb.Component.Topbar.topbar>

View File

@ -15,6 +15,7 @@ defmodule Cannery.Repo.Migrations.CreateAmmoTypes do
add :case_material, :string add :case_material, :string
add :grains, :integer add :grains, :integer
add :pressure, :string add :pressure, :string
add :primer_type, :string
add :rimfire, :boolean, null: false, default: false add :rimfire, :boolean, null: false, default: false
add :tracer, :boolean, null: false, default: false add :tracer, :boolean, null: false, default: false
add :incendiary, :boolean, null: false, default: false add :incendiary, :boolean, null: false, default: false