diff --git a/lib/cannery/ammo/ammo_type.ex b/lib/cannery/ammo/ammo_type.ex index 4465cba..fcd4194 100644 --- a/lib/cannery/ammo/ammo_type.ex +++ b/lib/cannery/ammo/ammo_type.ex @@ -13,12 +13,25 @@ defmodule Cannery.Ammo.AmmoType do @primary_key {:id, :binary_id, autogenerate: true} @foreign_key_type :binary_id schema "ammo_types" do - field :bullet_type, :string - field :case_material, :string - field :desc, :string - field :manufacturer, :string field :name, :string - field :grain, :integer + field :desc, :string + + # https://en.wikipedia.org/wiki/Bullet#Abbreviations + field :bullet_type, :string + field :bullet_core, :string + field :cartridge, :string + field :caliber, :string + field :case_material, :string + field :grains, :integer + field :pressure, :string + field :rimfire, :boolean, null: false, default: false + field :tracer, :boolean, null: false, default: false + field :incendiary, :boolean, null: false, default: false + field :blank, :boolean, null: false, default: false + field :corrosive, :boolean, null: false, default: false + + field :manufacturer, :string + field :sku, :string has_many :ammo_groups, AmmoGroup @@ -27,12 +40,22 @@ defmodule Cannery.Ammo.AmmoType do @type t :: %AmmoType{ id: id(), - bullet_type: String.t(), - case_material: String.t(), - desc: String.t(), - manufacturer: String.t(), name: String.t(), - grain: integer(), + 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(), + rimfire: boolean(), + tracer: boolean(), + incendiary: boolean(), + blank: boolean(), + corrosive: boolean(), + manufacturer: String.t(), + sku: String.t(), ammo_groups: [AmmoGroup.t()] | nil, inserted_at: NaiveDateTime.t(), updated_at: NaiveDateTime.t() @@ -44,7 +67,24 @@ defmodule Cannery.Ammo.AmmoType do @spec changeset(t() | new_ammo_type(), attrs :: map()) :: Changeset.t(t() | new_ammo_type()) def changeset(ammo_type, attrs) do ammo_type - |> cast(attrs, [:name, :desc, :case_material, :bullet_type, :grain, :manufacturer]) + |> cast(attrs, [ + :name, + :desc, + :bullet_type, + :bullet_core, + :cartridge, + :caliber, + :case_material, + :grains, + :pressure, + :rimfire, + :tracer, + :incendiary, + :blank, + :corrosive, + :manufacturer, + :sku + ]) |> validate_required([:name]) 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 0bb038e..26a77b3 100644 --- a/lib/cannery_web/live/ammo_type_live/form_component.ex +++ b/lib/cannery_web/live/ammo_type_live/form_component.ex @@ -63,26 +63,104 @@ defmodule CanneryWeb.AmmoTypeLive.FormComponent do <%= error_tag(f, :desc) %> - <%= label(f, :case_material, class: "mr-4 title text-lg text-primary-500") %> - <%= text_input(f, :case_material, class: "text-center col-span-2 input input-primary") %> -
- <%= error_tag(f, :case_material) %> -
- + + Example bullet type abbreviations + <%= label(f, :bullet_type, class: "mr-4 title text-lg text-primary-500") %> - <%= text_input(f, :bullet_type, class: "text-center col-span-2 input input-primary") %> + <%= text_input(f, :bullet_type, + class: "text-center col-span-2 input input-primary", + placeholder: "FMJ" + ) %>
<%= error_tag(f, :bullet_type) %>
- <%= label(f, :grain, class: "mr-4 title text-lg text-primary-500") %> - <%= number_input(f, :grain, - step: "any", + <%= label(f, :bullet_core, class: "mr-4 title text-lg text-primary-500") %> + <%= text_input(f, :bullet_core, class: "text-center col-span-2 input input-primary", - min: 0 + placeholder: "Steel" ) %>
- <%= error_tag(f, :grain) %> + <%= error_tag(f, :bullet_core) %> +
+ + <%= label(f, :cartridge, class: "mr-4 title text-lg text-primary-500") %> + <%= text_input(f, :cartridge, + class: "text-center col-span-2 input input-primary", + placeholder: "5.56x46mm NATO" + ) %> +
+ <%= error_tag(f, :cartridge) %> +
+ + <%= label(f, :caliber, class: "mr-4 title text-lg text-primary-500") %> + <%= text_input(f, :caliber, + class: "text-center col-span-2 input input-primary", + placeholder: ".223" + ) %> +
+ <%= error_tag(f, :caliber) %> +
+ + <%= label(f, :case_material, class: "mr-4 title text-lg text-primary-500") %> + <%= text_input(f, :case_material, + class: "text-center col-span-2 input input-primary", + placeholder: "Brass" + ) %> +
+ <%= error_tag(f, :case_material) %> +
+ + <%= label(f, :grains, class: "mr-4 title text-lg text-primary-500") %> + <%= number_input(f, :grains, + step: "1", + class: "text-center col-span-2 input input-primary", + min: 1 + ) %> +
+ <%= error_tag(f, :grains) %> +
+ + <%= label(f, :pressure, class: "mr-4 title text-lg text-primary-500") %> + <%= text_input(f, :pressure, + class: "text-center col-span-2 input input-primary", + placeholder: "+P" + ) %> +
+ <%= error_tag(f, :pressure) %> +
+ + <%= 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) %> +
+ + <%= label(f, :tracer, class: "mr-4 title text-lg text-primary-500") %> + <%= checkbox(f, :tracer, class: "text-center col-span-2 checkbox") %> +
+ <%= error_tag(f, :tracer) %> +
+ + <%= label(f, :incendiary, class: "mr-4 title text-lg text-primary-500") %> + <%= checkbox(f, :incendiary, class: "text-center col-span-2 checkbox") %> +
+ <%= error_tag(f, :incendiary) %> +
+ + <%= label(f, :blank, class: "mr-4 title text-lg text-primary-500") %> + <%= checkbox(f, :blank, class: "text-center col-span-2 checkbox") %> +
+ <%= error_tag(f, :blank) %> +
+ + <%= label(f, :corrosive, class: "mr-4 title text-lg text-primary-500") %> + <%= checkbox(f, :corrosive, class: "text-center col-span-2 checkbox") %> +
+ <%= error_tag(f, :corrosive) %>
<%= label(f, :manufacturer, class: "mr-4 title text-lg text-primary-500") %> @@ -91,6 +169,12 @@ defmodule CanneryWeb.AmmoTypeLive.FormComponent do <%= error_tag(f, :manufacturer) %> + <%= label(f, :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) %> +
+ <%= submit("Save", phx_disable_with: "Saving...", class: "mx-auto col-span-3 btn btn-primary" 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 4b8ab08..00e72e2 100644 --- a/lib/cannery_web/live/ammo_type_live/index.html.heex +++ b/lib/cannery_web/live/ammo_type_live/index.html.heex @@ -22,21 +22,27 @@ - - - - - + <%= for field <- [ + :name, + :bullet_type, + :bullet_core, + :cartridge, + :caliber, + :case_material, + :grains, + :pressure, + :rimfire, + :tracer, + :incendiary, + :blank, + :corrosive, + :manufacturer, + :sku + ] do %> + + <% end %> @@ -44,37 +50,59 @@ <%= for ammo_type <- @ammo_types do %> - - - - - + <%= for field <- [ + :name, + :bullet_type, + :bullet_core, + :cartridge, + :caliber, + :case_material, + :grains, + :pressure + ] do %> + + <% end %> - + <% end %> - <%= live_patch to: Routes.ammo_type_index_path(@socket, :edit, ammo_type), - class: "text-primary-500 link" do %> - - <% end %> + <%= for field <- [:manufacturer, :sku] do %> + + <% end %> - <%= link to: "#", - class: "text-primary-500 link", - phx_click: "delete", - phx_value_id: ammo_type.id, - data: [confirm: "Are you sure you want to delete this ammo?"] do %> - - <% end %> + <% end %> 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 cbed458..eb39ca4 100644 --- a/lib/cannery_web/live/ammo_type_live/show.html.heex +++ b/lib/cannery_web/live/ammo_type_live/show.html.heex @@ -1,39 +1,16 @@ -
+

<%= @ammo_type.name %>

-
- <%= if @ammo_type.desc do %> - - Desc: <%= @ammo_type.desc %> - - <% end %> - - <%= if @ammo_type.case_material do %> - - Case material: <%= @ammo_type.case_material %> - - <% end %> - - <%= if @ammo_type.bullet_type do %> - - Bullet type: <%= @ammo_type.bullet_type %> - - <% end %> - - <%= if @ammo_type.grain do %> - - Grain: <%= @ammo_type.grain %> - - <% end %> - - <%= if @ammo_type.manufacturer do %> - - Manufacturer: <%= @ammo_type.manufacturer %> - - <% end %> -
+ <%= if @ammo_type.desc do %> + + <%= @ammo_type.desc %> + + <% end %>
<%= live_patch to: Routes.ammo_type_show_path(@socket, :edit, @ammo_type), @@ -49,9 +26,61 @@ <% end %>
-
+
-
+
+ <%= for field <- [ + :bullet_type, + :bullet_core, + :cartridge, + :caliber, + :case_material, + :grains, + :pressure + ] do %> + <%= if @ammo_type |> Map.get(field) do %> +

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

+ + + <%= @ammo_type |> Map.get(field) %> + + <% end %> + <% end %> + + <%= for field <- [ + :rimfire, + :tracer, + :incendiary, + :blank, + :corrosive + ] do %> +

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

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

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

+ + + <%= @ammo_type |> Map.get(field) %> + + <% end %> + <% end %> +
+ +
+ +
<%= if @ammo_type.ammo_groups |> Enum.empty?() do %> No ammo for this type <% else %> diff --git a/lib/cannery_web/live/modal_component.ex b/lib/cannery_web/live/modal_component.ex index 5a0be9b..b004bcc 100644 --- a/lib/cannery_web/live/modal_component.ex +++ b/lib/cannery_web/live/modal_component.ex @@ -20,15 +20,15 @@ defmodule CanneryWeb.ModalComponent do phx-target={"#{@id}"} phx-page-loading > -
<%= 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 %> -
+
<%= live_component(@component, @opts) %>
diff --git a/lib/cannery_web/templates/layout/live.html.heex b/lib/cannery_web/templates/layout/live.html.heex index 256f7f9..a88bba8 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 895d3c3..628e715 100644 --- a/priv/repo/migrations/20210903015537_create_ammo_types.exs +++ b/priv/repo/migrations/20210903015537_create_ammo_types.exs @@ -6,10 +6,23 @@ defmodule Cannery.Repo.Migrations.CreateAmmoTypes do add :id, :binary_id, primary_key: true add :name, :string add :desc, :text - add :case_material, :string + + # https://en.wikipedia.org/wiki/Bullet#Abbreviations add :bullet_type, :string - add :grain, :integer + add :bullet_core, :string + add :cartridge, :string + add :caliber, :string + add :case_material, :string + add :grains, :integer + add :pressure, :string + add :rimfire, :boolean, null: false, default: false + add :tracer, :boolean, null: false, default: false + add :incendiary, :boolean, null: false, default: false + add :blank, :boolean, null: false, default: false + add :corrosive, :boolean, null: false, default: false + add :manufacturer, :string + add :sku, :string timestamps() end
- Name - - Case material - - Bullet type - - Grain - - Manufacturer - + <%= field |> humanize() %> +
- <%= ammo_type.name %> - - <%= ammo_type.case_material %> - - <%= ammo_type.bullet_type %> - - <%= ammo_type.grain %> - - <%= ammo_type.manufacturer %> - + <%= ammo_type |> Map.get(field) %> + - <%= live_redirect("View", to: Routes.ammo_type_show_path(@socket, :show, ammo_type)) %> + <%= for field <- [ + :rimfire, + :tracer, + :incendiary, + :blank, + :corrosive + ] do %> + + <%= ammo_type |> Map.get(field) |> humanize() %> + + <%= ammo_type |> Map.get(field) %> + +
+ <%= live_redirect to: Routes.ammo_type_show_path(@socket, :show, ammo_type), + class: "text-primary-500 link" do %> + + <% end %> + + <%= live_patch to: Routes.ammo_type_index_path(@socket, :edit, ammo_type), + class: "text-primary-500 link" do %> + + <% end %> + + <%= link to: "#", + class: "text-primary-500 link", + phx_click: "delete", + phx_value_id: ammo_type.id, + data: [confirm: "Are you sure you want to delete this ammo?"] do %> + + <% end %> +