fix ammo type displays
This commit is contained in:
		| @@ -61,7 +61,7 @@ defmodule CanneryWeb.AmmoTypeLive.Index do | ||||
|         {gettext("Grains"), :grains, :string}, | ||||
|         {gettext("Pressure"), :pressure, :string}, | ||||
|         {gettext("Primer type"), :primer_type, :string}, | ||||
|         {gettext("Rimfire"), :rimfire, :boolean}, | ||||
|         {gettext("Firing type"), :firing_type, :string}, | ||||
|         {gettext("Tracer"), :tracer, :boolean}, | ||||
|         {gettext("Incendiary"), :incendiary, :boolean}, | ||||
|         {gettext("Blank"), :blank, :boolean}, | ||||
| @@ -69,17 +69,12 @@ defmodule CanneryWeb.AmmoTypeLive.Index do | ||||
|         {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) | ||||
|       # if boolean, remove if all values are false | ||||
|       |> Enum.filter(fn {_label, field, type} -> | ||||
|         if type == :boolean do | ||||
|           ammo_types |> Enum.any?(fn ammo_type -> not (ammo_type |> Map.get(field) == false) end) | ||||
|         else | ||||
|           true | ||||
|         end | ||||
|         # remove columns if all values match defaults | ||||
|         default_value = if type == :boolean, do: false, else: nil | ||||
|  | ||||
|         ammo_types | ||||
|         |> Enum.any?(fn ammo_type -> not (ammo_type |> Map.get(field) == default_value) end) | ||||
|       end) | ||||
|  | ||||
|     socket |> assign(ammo_types: ammo_types, columns_to_display: columns_to_display) | ||||
|   | ||||
| @@ -35,70 +35,59 @@ | ||||
|  | ||||
|   <hr class="hr" /> | ||||
|  | ||||
|   <div class="grid sm:grid-cols-2 text-center justify-center items-center"> | ||||
|     <%= for {field_name, field} <- [ | ||||
|           {gettext("Bullet type"), :bullet_type}, | ||||
|           {gettext("Bullet core"), :bullet_core}, | ||||
|           {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} | ||||
|   <div class="grid sm:grid-cols-2 gap-4 text-center justify-center items-center"> | ||||
|     <%= for {field_name, field, type} <- [ | ||||
|           {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("Firing type"), :firing_type, :string}, | ||||
|           {gettext("Tracer"), :tracer, :boolean}, | ||||
|           {gettext("Incendiary"), :incendiary, :boolean}, | ||||
|           {gettext("Blank"), :blank, :boolean}, | ||||
|           {gettext("Corrosive"), :corrosive, :boolean}, | ||||
|           {gettext("Manufacturer"), :manufacturer, :string}, | ||||
|           {gettext("UPC"), :upc, :string} | ||||
|         ] do %> | ||||
|       <%= if @ammo_type |> Map.get(field) do %> | ||||
|         <h3 class="mb-2 sm:mr-4 title text-lg"> | ||||
|         <h3 class="title text-lg"> | ||||
|           <%= field_name %>: | ||||
|         </h3> | ||||
|  | ||||
|         <span class="mb-4 sm:mb-2 text-primary-600"> | ||||
|           <%= @ammo_type |> Map.get(field) %> | ||||
|         </span> | ||||
|       <% end %> | ||||
|     <% end %> | ||||
|  | ||||
|     <%= for {field_name, field} <- [ | ||||
|           {"Rimfire", :rimfire}, | ||||
|           {"Tracer", :tracer}, | ||||
|           {"Incendiary", :incendiary}, | ||||
|           {"Blank", :blank}, | ||||
|           {"Corrosive", :corrosive} | ||||
|         ] do %> | ||||
|       <h3 class="mb-2 sm:mr-4 title text-lg"> | ||||
|         <%= field_name %>: | ||||
|       </h3> | ||||
|  | ||||
|       <span class="mb-4 sm:mb-2 text-primary-600"> | ||||
|         <%= @ammo_type |> Map.get(field) |> humanize() %> | ||||
|       </span> | ||||
|     <% end %> | ||||
|  | ||||
|     <%= 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 %>: | ||||
|         </h3> | ||||
|  | ||||
|         <span class="mb-4 sm:mb-2 text-primary-600"> | ||||
|           <%= @ammo_type |> Map.get(field) %> | ||||
|         <span class="text-primary-600"> | ||||
|           <%= case type do %> | ||||
|             <% :boolean -> %> | ||||
|               <%= @ammo_type |> Map.get(field) |> humanize() %> | ||||
|             <% _ -> %> | ||||
|               <%= @ammo_type |> Map.get(field) %> | ||||
|           <% end %> | ||||
|         </span> | ||||
|       <% end %> | ||||
|     <% end %> | ||||
|  | ||||
|     <%= if @avg_cost_per_round do %> | ||||
|       <h3 class="mb-2 sm:mr-4 title text-lg"> | ||||
|       <h3 class="title text-lg"> | ||||
|         <%= gettext("Average Price paid") %>: | ||||
|       </h3> | ||||
|  | ||||
|       <span class="mb-4 sm:mb-2 text-primary-600"> | ||||
|       <span class="text-primary-600"> | ||||
|         <%= gettext("$%{amount}", | ||||
|           amount: @avg_cost_per_round |> :erlang.float_to_binary(decimals: 2) | ||||
|         ) %> | ||||
|       </span> | ||||
|     <% else %> | ||||
|       <h3 class="title text-lg col-span-2"> | ||||
|         <%= gettext("No cost information") %> | ||||
|         <%= display_emoji("😔") %> | ||||
|       </h3> | ||||
|     <% end %> | ||||
|   </div> | ||||
|  | ||||
| @@ -107,6 +96,7 @@ | ||||
|   <div> | ||||
|     <%= if @ammo_groups |> Enum.empty?() do %> | ||||
|       <%= gettext("No ammo for this type") %> | ||||
|       <%= display_emoji("😔") %> | ||||
|     <% else %> | ||||
|       <div class="flex flex-wrap justify-center items-center"> | ||||
|         <%= for ammo_group <- @ammo_groups do %> | ||||
|   | ||||
| @@ -20,8 +20,8 @@ | ||||
|                   container_name: @container.name | ||||
|                 ) | ||||
|             ] do %> | ||||
|           <%= tag.name %> | ||||
|           <i class="fa-fw fa-sm fas fa-trash"></i> | ||||
|         <%= tag.name %> | ||||
|         <i class="fa-fw fa-sm fas fa-trash"></i> | ||||
|       <% end %> | ||||
|     <% end %> | ||||
|  | ||||
| @@ -34,7 +34,7 @@ | ||||
|   </div> | ||||
|  | ||||
|   <%= unless tag_options(@tags, @container) |> Enum.empty?() do %> | ||||
|     <hr class="hr"> | ||||
|     <hr class="hr" /> | ||||
|  | ||||
|     <.form | ||||
|       let={f} | ||||
| @@ -44,7 +44,9 @@ | ||||
|       phx-target={@myself} | ||||
|       phx-submit="save" | ||||
|     > | ||||
|       <%= select(f, :tag_id, tag_options(@tags, @container), class: "text-center col-span-2 input input-primary") %> | ||||
|       <%= select(f, :tag_id, tag_options(@tags, @container), | ||||
|         class: "text-center col-span-2 input input-primary" | ||||
|       ) %> | ||||
|       <%= error_tag(f, :tag_id, "col-span-3 text-center") %> | ||||
|  | ||||
|       <%= submit(dgettext("actions", "Add"), | ||||
|   | ||||
| @@ -31,7 +31,6 @@ | ||||
|             <% end %> | ||||
|           </div> | ||||
|         </:tag_actions> | ||||
|  | ||||
|         <%= live_patch to: Routes.container_index_path(Endpoint, :edit, container), | ||||
|                    class: "text-primary-600 link", | ||||
|                    data: [qa: "edit-#{container.id}"] do %> | ||||
|   | ||||
| @@ -86,7 +86,8 @@ defmodule CanneryWeb.ContainerLive.Show do | ||||
|  | ||||
|   @spec render_container(Socket.t(), Container.id(), User.t()) :: Socket.t() | ||||
|   defp render_container(%{assigns: %{live_action: live_action}} = socket, id, current_user) do | ||||
|     %{name: container_name} = container = | ||||
|     %{name: container_name} = | ||||
|       container = | ||||
|       Containers.get_container!(id, current_user) | ||||
|       |> Repo.preload([:ammo_groups, :tags], force: true) | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user