From 22c148e93b72e75a15ec6fb4c11732adedf9be92 Mon Sep 17 00:00:00 2001 From: shibao Date: Mon, 7 Feb 2022 23:38:03 -0500 Subject: [PATCH] - add primer_type to ammo type - fix ammo type typespec - remove unused ammo type card - mix format --- lib/cannery/ammo/ammo_type.ex | 23 ++++++---- .../live/ammo_group_live/index.html.heex | 4 +- .../live/ammo_type_live/ammo_type_card.ex | 46 ------------------- .../live/ammo_type_live/form_component.ex | 7 +++ .../live/ammo_type_live/index.html.heex | 4 +- .../live/ammo_type_live/show.html.heex | 9 ++-- lib/cannery_web/live/modal_component.ex | 4 +- .../templates/layout/live.html.heex | 2 +- .../20210903015537_create_ammo_types.exs | 1 + 9 files changed, 35 insertions(+), 65 deletions(-) delete mode 100644 lib/cannery_web/live/ammo_type_live/ammo_type_card.ex diff --git a/lib/cannery/ammo/ammo_type.ex b/lib/cannery/ammo/ammo_type.ex index fcd4194c..dbad5d24 100644 --- a/lib/cannery/ammo/ammo_type.ex +++ b/lib/cannery/ammo/ammo_type.ex @@ -24,6 +24,7 @@ defmodule Cannery.Ammo.AmmoType do field :case_material, :string field :grains, :integer field :pressure, :string + field :primer_type, :string field :rimfire, :boolean, null: false, default: false field :tracer, :boolean, null: false, default: false field :incendiary, :boolean, null: false, default: false @@ -41,21 +42,22 @@ defmodule Cannery.Ammo.AmmoType do @type t :: %AmmoType{ id: id(), name: String.t(), - desc: String.t(), - bullet_type: String.t(), - bullet_core: String.t(), - cartridge: String.t(), - caliber: String.t(), - case_material: String.t(), - grains: integer(), - pressure: String.t(), + desc: String.t() | nil, + bullet_type: String.t() | nil, + bullet_core: String.t() | nil, + cartridge: String.t() | nil, + caliber: String.t() | nil, + case_material: String.t() | nil, + grains: integer() | nil, + pressure: String.t() | nil, + primer_type: String.t() | nil, rimfire: boolean(), tracer: boolean(), incendiary: boolean(), blank: boolean(), corrosive: boolean(), - manufacturer: String.t(), - sku: String.t(), + manufacturer: String.t() | nil, + sku: String.t() | nil, ammo_groups: [AmmoGroup.t()] | nil, inserted_at: NaiveDateTime.t(), updated_at: NaiveDateTime.t() @@ -77,6 +79,7 @@ defmodule Cannery.Ammo.AmmoType do :case_material, :grains, :pressure, + :primer_type, :rimfire, :tracer, :incendiary, diff --git a/lib/cannery_web/live/ammo_group_live/index.html.heex b/lib/cannery_web/live/ammo_group_live/index.html.heex index b32e68a4..61691138 100644 --- a/lib/cannery_web/live/ammo_group_live/index.html.heex +++ b/lib/cannery_web/live/ammo_group_live/index.html.heex @@ -43,7 +43,9 @@ - $ <%= 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 %> diff --git a/lib/cannery_web/live/ammo_type_live/ammo_type_card.ex b/lib/cannery_web/live/ammo_type_live/ammo_type_card.ex deleted file mode 100644 index a985d1ad..00000000 --- a/lib/cannery_web/live/ammo_type_live/ammo_type_card.ex +++ /dev/null @@ -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""" -
- <%= live_redirect to: Routes.ammo_group_show_path(Endpoint, :show, @ammo_group), - class: "mb-2 link" do %> -

- <%= @ammo_group.ammo_type.name %> -

- <% end %> - -
- - Count: <%= @ammo_group.count %> - - - <%= if @ammo_group.notes do %> - - Notes: <%= @ammo_group.notes %> - - <% end %> - - <%= if @ammo_group.price_paid do %> - - Price paid: $ <%= @ammo_group.price_paid |> :erlang.float_to_binary(decimals: 2) %> - - <% end %> -
-
- """ - end -end diff --git a/lib/cannery_web/live/ammo_type_live/form_component.ex b/lib/cannery_web/live/ammo_type_live/form_component.ex index 57aececa..45d72cc3 100644 --- a/lib/cannery_web/live/ammo_type_live/form_component.ex +++ b/lib/cannery_web/live/ammo_type_live/form_component.ex @@ -117,6 +117,13 @@ defmodule CanneryWeb.AmmoTypeLive.FormComponent do ) %> <%= 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") %> <%= checkbox(f, :rimfire, class: "text-center col-span-2 checkbox") %> <%= error_tag(f, :rimfire, "col-span-3 text-center") %> diff --git a/lib/cannery_web/live/ammo_type_live/index.html.heex b/lib/cannery_web/live/ammo_type_live/index.html.heex index 7641ac56..53feaf19 100644 --- a/lib/cannery_web/live/ammo_type_live/index.html.heex +++ b/lib/cannery_web/live/ammo_type_live/index.html.heex @@ -31,6 +31,7 @@ :case_material, :grains, :pressure, + :primer_type, :rimfire, :tracer, :incendiary, @@ -58,7 +59,8 @@ :caliber, :case_material, :grains, - :pressure + :pressure, + :primer_type ] do %> <%= ammo_type |> Map.get(field) %> diff --git a/lib/cannery_web/live/ammo_type_live/show.html.heex b/lib/cannery_web/live/ammo_type_live/show.html.heex index 353aa552..a62e26d8 100644 --- a/lib/cannery_web/live/ammo_type_live/show.html.heex +++ b/lib/cannery_web/live/ammo_type_live/show.html.heex @@ -36,11 +36,12 @@ :caliber, :case_material, :grains, - :pressure + :pressure, + :primer_type ] do %> <%= if @ammo_type |> Map.get(field) do %>

- <%= field |> humanize() %>: + <%= field |> humanize() %> :

@@ -57,7 +58,7 @@ :corrosive ] do %>

- <%= field |> humanize() %>: + <%= field |> humanize() %> :

@@ -68,7 +69,7 @@ <%= for field <- [:manufacturer, :sku] do %> <%= if @ammo_type |> Map.get(field) do %>

- <%= field |> humanize() %>: + <%= field |> humanize() %> :

diff --git a/lib/cannery_web/live/modal_component.ex b/lib/cannery_web/live/modal_component.ex index 640d96f2..0c70ae7a 100644 --- a/lib/cannery_web/live/modal_component.ex +++ b/lib/cannery_web/live/modal_component.ex @@ -24,8 +24,8 @@ defmodule CanneryWeb.ModalComponent do flex flex-col justify-start items-center bg-white border-2 rounded-lg"> <%= live_patch to: @return_to, - class: "absolute top-8 right-10 text-gray-500 hover:text-gray-800 - transition-all duration-500 ease-in-out" do %> + class: + "absolute top-8 right-10 text-gray-500 hover:text-gray-800 transition-all duration-500 ease-in-out" do %> <% end %>
diff --git a/lib/cannery_web/templates/layout/live.html.heex b/lib/cannery_web/templates/layout/live.html.heex index 93c044f2..56903887 100644 --- a/lib/cannery_web/templates/layout/live.html.heex +++ b/lib/cannery_web/templates/layout/live.html.heex @@ -1,4 +1,4 @@ -
+
diff --git a/priv/repo/migrations/20210903015537_create_ammo_types.exs b/priv/repo/migrations/20210903015537_create_ammo_types.exs index 628e7159..5f919c92 100644 --- a/priv/repo/migrations/20210903015537_create_ammo_types.exs +++ b/priv/repo/migrations/20210903015537_create_ammo_types.exs @@ -15,6 +15,7 @@ defmodule Cannery.Repo.Migrations.CreateAmmoTypes do add :case_material, :string add :grains, :integer add :pressure, :string + add :primer_type, :string add :rimfire, :boolean, null: false, default: false add :tracer, :boolean, null: false, default: false add :incendiary, :boolean, null: false, default: false