forked from shibao/cannery
		
	rename ammo_type type to class
This commit is contained in:
		@@ -13,7 +13,7 @@ defmodule CanneryWeb.Components.AmmoTypeTableComponent do
 | 
			
		||||
          %{
 | 
			
		||||
            required(:id) => UUID.t(),
 | 
			
		||||
            required(:current_user) => User.t(),
 | 
			
		||||
            optional(:type) => AmmoType.type() | nil,
 | 
			
		||||
            optional(:class) => AmmoType.class() | nil,
 | 
			
		||||
            optional(:show_used) => boolean(),
 | 
			
		||||
            optional(:ammo_types) => [AmmoType.t()],
 | 
			
		||||
            optional(:actions) => Rendered.t(),
 | 
			
		||||
@@ -26,7 +26,7 @@ defmodule CanneryWeb.Components.AmmoTypeTableComponent do
 | 
			
		||||
      socket
 | 
			
		||||
      |> assign(assigns)
 | 
			
		||||
      |> assign_new(:show_used, fn -> false end)
 | 
			
		||||
      |> assign_new(:type, fn -> :all end)
 | 
			
		||||
      |> assign_new(:class, fn -> :all end)
 | 
			
		||||
      |> assign_new(:actions, fn -> [] end)
 | 
			
		||||
      |> display_ammo_types()
 | 
			
		||||
 | 
			
		||||
@@ -39,7 +39,7 @@ defmodule CanneryWeb.Components.AmmoTypeTableComponent do
 | 
			
		||||
             ammo_types: ammo_types,
 | 
			
		||||
             current_user: current_user,
 | 
			
		||||
             show_used: show_used,
 | 
			
		||||
             type: type,
 | 
			
		||||
             class: class,
 | 
			
		||||
             actions: actions
 | 
			
		||||
           }
 | 
			
		||||
         } = socket
 | 
			
		||||
@@ -48,7 +48,7 @@ defmodule CanneryWeb.Components.AmmoTypeTableComponent do
 | 
			
		||||
      [
 | 
			
		||||
        %{label: gettext("Cartridge"), key: :cartridge, type: :string},
 | 
			
		||||
        %{
 | 
			
		||||
          label: if(type == :shotgun, do: gettext("Gauge"), else: gettext("Caliber")),
 | 
			
		||||
          label: if(class == :shotgun, do: gettext("Gauge"), else: gettext("Caliber")),
 | 
			
		||||
          key: :caliber,
 | 
			
		||||
          type: :string
 | 
			
		||||
        },
 | 
			
		||||
@@ -59,7 +59,7 @@ defmodule CanneryWeb.Components.AmmoTypeTableComponent do
 | 
			
		||||
        %{label: gettext("Grains"), key: :grains, type: :string},
 | 
			
		||||
        %{label: gettext("Bullet type"), key: :bullet_type, type: :string},
 | 
			
		||||
        %{
 | 
			
		||||
          label: if(type == :shotgun, do: gettext("Slug core"), else: gettext("Bullet core")),
 | 
			
		||||
          label: if(class == :shotgun, do: gettext("Slug core"), else: gettext("Bullet core")),
 | 
			
		||||
          key: :bullet_core,
 | 
			
		||||
          type: :string
 | 
			
		||||
        },
 | 
			
		||||
@@ -147,8 +147,8 @@ defmodule CanneryWeb.Components.AmmoTypeTableComponent do
 | 
			
		||||
      })
 | 
			
		||||
      |> TableComponent.maybe_compose_columns(filtered_columns)
 | 
			
		||||
      |> TableComponent.maybe_compose_columns(
 | 
			
		||||
        %{label: gettext("Type"), key: :type, type: :atom},
 | 
			
		||||
        type in [:all, nil]
 | 
			
		||||
        %{label: gettext("Class"), key: :type, type: :atom},
 | 
			
		||||
        class in [:all, nil]
 | 
			
		||||
      )
 | 
			
		||||
      |> TableComponent.maybe_compose_columns(%{label: gettext("Name"), key: :name, type: :name})
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -8,11 +8,16 @@ defmodule CanneryWeb.AmmoGroupLive.Index do
 | 
			
		||||
 | 
			
		||||
  @impl true
 | 
			
		||||
  def mount(%{"search" => search}, _session, socket) do
 | 
			
		||||
    {:ok, socket |> assign(type: :all, show_used: false, search: search) |> display_ammo_groups()}
 | 
			
		||||
    socket =
 | 
			
		||||
      socket
 | 
			
		||||
      |> assign(class: :all, show_used: false, search: search)
 | 
			
		||||
      |> display_ammo_groups()
 | 
			
		||||
 | 
			
		||||
    {:ok, socket}
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def mount(_params, _session, socket) do
 | 
			
		||||
    {:ok, socket |> assign(type: :all, show_used: false, search: nil) |> display_ammo_groups()}
 | 
			
		||||
    {:ok, socket |> assign(class: :all, show_used: false, search: nil) |> display_ammo_groups()}
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  @impl true
 | 
			
		||||
@@ -119,26 +124,26 @@ defmodule CanneryWeb.AmmoGroupLive.Index do
 | 
			
		||||
    {:noreply, socket}
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def handle_event("change_type", %{"ammo_type" => %{"type" => "rifle"}}, socket) do
 | 
			
		||||
    {:noreply, socket |> assign(:type, :rifle) |> display_ammo_groups()}
 | 
			
		||||
  def handle_event("change_class", %{"ammo_type" => %{"class" => "rifle"}}, socket) do
 | 
			
		||||
    {:noreply, socket |> assign(:class, :rifle) |> display_ammo_groups()}
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def handle_event("change_type", %{"ammo_type" => %{"type" => "shotgun"}}, socket) do
 | 
			
		||||
    {:noreply, socket |> assign(:type, :shotgun) |> display_ammo_groups()}
 | 
			
		||||
  def handle_event("change_class", %{"ammo_type" => %{"class" => "shotgun"}}, socket) do
 | 
			
		||||
    {:noreply, socket |> assign(:class, :shotgun) |> display_ammo_groups()}
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def handle_event("change_type", %{"ammo_type" => %{"type" => "pistol"}}, socket) do
 | 
			
		||||
    {:noreply, socket |> assign(:type, :pistol) |> display_ammo_groups()}
 | 
			
		||||
  def handle_event("change_class", %{"ammo_type" => %{"class" => "pistol"}}, socket) do
 | 
			
		||||
    {:noreply, socket |> assign(:class, :pistol) |> display_ammo_groups()}
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def handle_event("change_type", %{"ammo_type" => %{"type" => _all}}, socket) do
 | 
			
		||||
    {:noreply, socket |> assign(:type, :all) |> display_ammo_groups()}
 | 
			
		||||
  def handle_event("change_class", %{"ammo_type" => %{"class" => _all}}, socket) do
 | 
			
		||||
    {:noreply, socket |> assign(:class, :all) |> display_ammo_groups()}
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  defp display_ammo_groups(
 | 
			
		||||
         %{
 | 
			
		||||
           assigns: %{
 | 
			
		||||
             type: type,
 | 
			
		||||
             class: class,
 | 
			
		||||
             search: search,
 | 
			
		||||
             current_user: current_user,
 | 
			
		||||
             show_used: show_used
 | 
			
		||||
@@ -148,7 +153,7 @@ defmodule CanneryWeb.AmmoGroupLive.Index do
 | 
			
		||||
    # get total number of ammo groups to determine whether to display onboarding
 | 
			
		||||
    # prompts
 | 
			
		||||
    ammo_groups_count = Ammo.get_ammo_groups_count!(current_user, true)
 | 
			
		||||
    ammo_groups = Ammo.list_ammo_groups(search, type, current_user, show_used)
 | 
			
		||||
    ammo_groups = Ammo.list_ammo_groups(search, class, current_user, show_used)
 | 
			
		||||
    ammo_types_count = Ammo.get_ammo_types_count!(current_user)
 | 
			
		||||
    containers_count = Containers.get_containers_count!(current_user)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -43,15 +43,17 @@
 | 
			
		||||
          :let={f}
 | 
			
		||||
          for={%{}}
 | 
			
		||||
          as={:ammo_type}
 | 
			
		||||
          phx-change="change_type"
 | 
			
		||||
          phx-submit="change_type"
 | 
			
		||||
          phx-change="change_class"
 | 
			
		||||
          phx-submit="change_class"
 | 
			
		||||
          class="flex items-center"
 | 
			
		||||
        >
 | 
			
		||||
          <%= label(f, :type, gettext("Type"), class: "title text-primary-600 text-lg text-center") %>
 | 
			
		||||
          <%= label(f, :class, gettext("Class"),
 | 
			
		||||
            class: "title text-primary-600 text-lg text-center"
 | 
			
		||||
          ) %>
 | 
			
		||||
 | 
			
		||||
          <%= select(
 | 
			
		||||
            f,
 | 
			
		||||
            :type,
 | 
			
		||||
            :class,
 | 
			
		||||
            [
 | 
			
		||||
              {gettext("All"), :all},
 | 
			
		||||
              {gettext("Rifle"), :rifle},
 | 
			
		||||
@@ -59,7 +61,7 @@
 | 
			
		||||
              {gettext("Pistol"), :pistol}
 | 
			
		||||
            ],
 | 
			
		||||
            class: "mx-2 my-1 min-w-md input input-primary",
 | 
			
		||||
            value: @type
 | 
			
		||||
            value: @class
 | 
			
		||||
          ) %>
 | 
			
		||||
        </.form>
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -18,15 +18,15 @@
 | 
			
		||||
      <%= dgettext("errors", "Oops, something went wrong! Please check the errors below.") %>
 | 
			
		||||
    </div>
 | 
			
		||||
 | 
			
		||||
    <%= label(f, :type, gettext("Type"), class: "title text-lg text-primary-600") %>
 | 
			
		||||
    <%= label(f, :class, gettext("Class"), class: "title text-lg text-primary-600") %>
 | 
			
		||||
    <%= select(
 | 
			
		||||
      f,
 | 
			
		||||
      :type,
 | 
			
		||||
      :class,
 | 
			
		||||
      [{gettext("Rifle"), :rifle}, {gettext("Shotgun"), :shotgun}, {gettext("Pistol"), :pistol}],
 | 
			
		||||
      class: "text-center col-span-2 input input-primary",
 | 
			
		||||
      maxlength: 255
 | 
			
		||||
    ) %>
 | 
			
		||||
    <%= error_tag(f, :type, "col-span-3 text-center") %>
 | 
			
		||||
    <%= error_tag(f, :class, "col-span-3 text-center") %>
 | 
			
		||||
 | 
			
		||||
    <%= label(f, :name, gettext("Name"), class: "title text-lg text-primary-600") %>
 | 
			
		||||
    <%= text_input(f, :name,
 | 
			
		||||
@@ -48,7 +48,7 @@
 | 
			
		||||
      <%= gettext("Dimensions") %>
 | 
			
		||||
    </h2>
 | 
			
		||||
 | 
			
		||||
    <%= if Changeset.get_field(@changeset, :type) in [:rifle, :pistol] do %>
 | 
			
		||||
    <%= if Changeset.get_field(@changeset, :class) in [:rifle, :pistol] do %>
 | 
			
		||||
      <%= label(f, :cartridge, gettext("Cartridge"), class: "title text-lg text-primary-600") %>
 | 
			
		||||
      <%= text_input(f, :cartridge,
 | 
			
		||||
        class: "text-center col-span-2 input input-primary",
 | 
			
		||||
@@ -63,7 +63,7 @@
 | 
			
		||||
    <%= label(
 | 
			
		||||
      f,
 | 
			
		||||
      :caliber,
 | 
			
		||||
      if(Changeset.get_field(@changeset, :type) == :shotgun,
 | 
			
		||||
      if(Changeset.get_field(@changeset, :class) == :shotgun,
 | 
			
		||||
        do: gettext("Gauge"),
 | 
			
		||||
        else: gettext("Caliber")
 | 
			
		||||
      ),
 | 
			
		||||
@@ -76,7 +76,7 @@
 | 
			
		||||
    ) %>
 | 
			
		||||
    <%= error_tag(f, :caliber, "col-span-3 text-center") %>
 | 
			
		||||
 | 
			
		||||
    <%= if Changeset.get_field(@changeset, :type) == :shotgun do %>
 | 
			
		||||
    <%= if Changeset.get_field(@changeset, :class) == :shotgun do %>
 | 
			
		||||
      <%= label(f, :unfired_length, gettext("Unfired shell length"),
 | 
			
		||||
        class: "title text-lg text-primary-600"
 | 
			
		||||
      ) %>
 | 
			
		||||
@@ -139,7 +139,7 @@
 | 
			
		||||
    <%= label(
 | 
			
		||||
      f,
 | 
			
		||||
      :bullet_core,
 | 
			
		||||
      if(Changeset.get_field(@changeset, :type) == :shotgun,
 | 
			
		||||
      if(Changeset.get_field(@changeset, :class) == :shotgun,
 | 
			
		||||
        do: gettext("Slug core"),
 | 
			
		||||
        else: gettext("Bullet core")
 | 
			
		||||
      ),
 | 
			
		||||
@@ -152,7 +152,7 @@
 | 
			
		||||
    ) %>
 | 
			
		||||
    <%= error_tag(f, :bullet_core, "col-span-3 text-center") %>
 | 
			
		||||
 | 
			
		||||
    <%= if Changeset.get_field(@changeset, :type) in [:rifle, :pistol] do %>
 | 
			
		||||
    <%= if Changeset.get_field(@changeset, :class) in [:rifle, :pistol] do %>
 | 
			
		||||
      <%= label(f, :jacket_type, gettext("Jacket type"), class: "title text-lg text-primary-600") %>
 | 
			
		||||
      <%= text_input(f, :jacket_type,
 | 
			
		||||
        class: "text-center col-span-2 input input-primary",
 | 
			
		||||
@@ -172,7 +172,7 @@
 | 
			
		||||
    ) %>
 | 
			
		||||
    <%= error_tag(f, :case_material, "col-span-3 text-center") %>
 | 
			
		||||
 | 
			
		||||
    <%= if Changeset.get_field(@changeset, :type) == :shotgun do %>
 | 
			
		||||
    <%= if Changeset.get_field(@changeset, :class) == :shotgun do %>
 | 
			
		||||
      <%= label(f, :wadding, gettext("Wadding"), class: "title text-lg text-primary-600") %>
 | 
			
		||||
      <%= text_input(f, :wadding,
 | 
			
		||||
        class: "text-center col-span-2 input input-primary",
 | 
			
		||||
@@ -240,7 +240,7 @@
 | 
			
		||||
    ) %>
 | 
			
		||||
    <%= error_tag(f, :powder_type, "col-span-3 text-center") %>
 | 
			
		||||
 | 
			
		||||
    <%= if Changeset.get_field(@changeset, :type) in [:rifle, :pistol] do %>
 | 
			
		||||
    <%= if Changeset.get_field(@changeset, :class) in [:rifle, :pistol] do %>
 | 
			
		||||
      <%= label(f, :powder_grains_per_charge, gettext("Powder grains per charge"),
 | 
			
		||||
        class: "title text-lg text-primary-600"
 | 
			
		||||
      ) %>
 | 
			
		||||
@@ -262,7 +262,7 @@
 | 
			
		||||
    ) %>
 | 
			
		||||
    <%= error_tag(f, :pressure, "col-span-3 text-center") %>
 | 
			
		||||
 | 
			
		||||
    <%= if Changeset.get_field(@changeset, :type) == :shotgun do %>
 | 
			
		||||
    <%= if Changeset.get_field(@changeset, :class) == :shotgun do %>
 | 
			
		||||
      <%= label(f, :dram_equivalent, gettext("Dram equivalent"),
 | 
			
		||||
        class: "title text-lg text-primary-600"
 | 
			
		||||
      ) %>
 | 
			
		||||
@@ -275,7 +275,7 @@
 | 
			
		||||
      <%= hidden_input(f, :dram_equivalent, value: nil) %>
 | 
			
		||||
    <% end %>
 | 
			
		||||
 | 
			
		||||
    <%= if Changeset.get_field(@changeset, :type) in [:rifle, :pistol] do %>
 | 
			
		||||
    <%= if Changeset.get_field(@changeset, :class) in [:rifle, :pistol] do %>
 | 
			
		||||
      <%= label(f, :muzzle_velocity, gettext("Muzzle velocity"),
 | 
			
		||||
        class: "title text-lg text-primary-600"
 | 
			
		||||
      ) %>
 | 
			
		||||
 
 | 
			
		||||
@@ -8,11 +8,11 @@ defmodule CanneryWeb.AmmoTypeLive.Index do
 | 
			
		||||
 | 
			
		||||
  @impl true
 | 
			
		||||
  def mount(%{"search" => search}, _session, socket) do
 | 
			
		||||
    {:ok, socket |> assign(type: :all, show_used: false, search: search) |> list_ammo_types()}
 | 
			
		||||
    {:ok, socket |> assign(class: :all, show_used: false, search: search) |> list_ammo_types()}
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def mount(_params, _session, socket) do
 | 
			
		||||
    {:ok, socket |> assign(type: :all, show_used: false, search: nil) |> list_ammo_types()}
 | 
			
		||||
    {:ok, socket |> assign(class: :all, show_used: false, search: nil) |> list_ammo_types()}
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  @impl true
 | 
			
		||||
@@ -86,28 +86,28 @@ defmodule CanneryWeb.AmmoTypeLive.Index do
 | 
			
		||||
    {:noreply, socket |> push_patch(to: search_path)}
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def handle_event("change_type", %{"ammo_type" => %{"type" => "rifle"}}, socket) do
 | 
			
		||||
    {:noreply, socket |> assign(:type, :rifle) |> list_ammo_types()}
 | 
			
		||||
  def handle_event("change_class", %{"ammo_type" => %{"class" => "rifle"}}, socket) do
 | 
			
		||||
    {:noreply, socket |> assign(:class, :rifle) |> list_ammo_types()}
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def handle_event("change_type", %{"ammo_type" => %{"type" => "shotgun"}}, socket) do
 | 
			
		||||
    {:noreply, socket |> assign(:type, :shotgun) |> list_ammo_types()}
 | 
			
		||||
  def handle_event("change_class", %{"ammo_type" => %{"class" => "shotgun"}}, socket) do
 | 
			
		||||
    {:noreply, socket |> assign(:class, :shotgun) |> list_ammo_types()}
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def handle_event("change_type", %{"ammo_type" => %{"type" => "pistol"}}, socket) do
 | 
			
		||||
    {:noreply, socket |> assign(:type, :pistol) |> list_ammo_types()}
 | 
			
		||||
  def handle_event("change_class", %{"ammo_type" => %{"class" => "pistol"}}, socket) do
 | 
			
		||||
    {:noreply, socket |> assign(:class, :pistol) |> list_ammo_types()}
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def handle_event("change_type", %{"ammo_type" => %{"type" => _all}}, socket) do
 | 
			
		||||
    {:noreply, socket |> assign(:type, :all) |> list_ammo_types()}
 | 
			
		||||
  def handle_event("change_class", %{"ammo_type" => %{"class" => _all}}, socket) do
 | 
			
		||||
    {:noreply, socket |> assign(:class, :all) |> list_ammo_types()}
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  defp list_ammo_types(
 | 
			
		||||
         %{assigns: %{type: type, search: search, current_user: current_user}} = socket
 | 
			
		||||
         %{assigns: %{class: class, search: search, current_user: current_user}} = socket
 | 
			
		||||
       ) do
 | 
			
		||||
    socket
 | 
			
		||||
    |> assign(
 | 
			
		||||
      ammo_types: Ammo.list_ammo_types(search, current_user, type),
 | 
			
		||||
      ammo_types: Ammo.list_ammo_types(search, current_user, class),
 | 
			
		||||
      ammo_types_count: Ammo.get_ammo_types_count!(current_user)
 | 
			
		||||
    )
 | 
			
		||||
  end
 | 
			
		||||
 
 | 
			
		||||
@@ -22,15 +22,15 @@
 | 
			
		||||
        :let={f}
 | 
			
		||||
        for={%{}}
 | 
			
		||||
        as={:ammo_type}
 | 
			
		||||
        phx-change="change_type"
 | 
			
		||||
        phx-submit="change_type"
 | 
			
		||||
        phx-change="change_class"
 | 
			
		||||
        phx-submit="change_class"
 | 
			
		||||
        class="flex items-center"
 | 
			
		||||
      >
 | 
			
		||||
        <%= label(f, :type, gettext("Type"), class: "title text-primary-600 text-lg text-center") %>
 | 
			
		||||
        <%= label(f, :class, gettext("Class"), class: "title text-primary-600 text-lg text-center") %>
 | 
			
		||||
 | 
			
		||||
        <%= select(
 | 
			
		||||
          f,
 | 
			
		||||
          :type,
 | 
			
		||||
          :class,
 | 
			
		||||
          [
 | 
			
		||||
            {gettext("All"), :all},
 | 
			
		||||
            {gettext("Rifle"), :rifle},
 | 
			
		||||
@@ -38,7 +38,7 @@
 | 
			
		||||
            {gettext("Pistol"), :pistol}
 | 
			
		||||
          ],
 | 
			
		||||
          class: "mx-2 my-1 min-w-md input input-primary",
 | 
			
		||||
          value: @type
 | 
			
		||||
          value: @class
 | 
			
		||||
        ) %>
 | 
			
		||||
      </.form>
 | 
			
		||||
 | 
			
		||||
@@ -79,7 +79,7 @@
 | 
			
		||||
        ammo_types={@ammo_types}
 | 
			
		||||
        current_user={@current_user}
 | 
			
		||||
        show_used={@show_used}
 | 
			
		||||
        type={@type}
 | 
			
		||||
        class={@class}
 | 
			
		||||
      >
 | 
			
		||||
        <:actions :let={ammo_type}>
 | 
			
		||||
          <div class="px-4 py-2 space-x-4 flex justify-center items-center">
 | 
			
		||||
 
 | 
			
		||||
@@ -116,11 +116,11 @@ defmodule CanneryWeb.AmmoTypeLive.Show do
 | 
			
		||||
    socket |> display_ammo_type(ammo_type)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  defp fields_to_display(%AmmoType{type: type}) do
 | 
			
		||||
  defp fields_to_display(%AmmoType{class: class}) do
 | 
			
		||||
    [
 | 
			
		||||
      %{label: gettext("Cartridge:"), key: :cartridge, type: :string},
 | 
			
		||||
      %{
 | 
			
		||||
        label: if(type == :shotgun, do: gettext("Gauge:"), else: gettext("Caliber:")),
 | 
			
		||||
        label: if(class == :shotgun, do: gettext("Gauge:"), else: gettext("Caliber:")),
 | 
			
		||||
        key: :caliber,
 | 
			
		||||
        type: :string
 | 
			
		||||
      },
 | 
			
		||||
 
 | 
			
		||||
@@ -42,14 +42,14 @@
 | 
			
		||||
 | 
			
		||||
  <hr class="hr" />
 | 
			
		||||
 | 
			
		||||
  <%= if @ammo_type.type || @custom_fields? do %>
 | 
			
		||||
  <%= if @ammo_type.class || @custom_fields? do %>
 | 
			
		||||
    <div class="grid sm:grid-cols-2 gap-4 text-center justify-center items-center">
 | 
			
		||||
      <h3 class="title text-lg">
 | 
			
		||||
        <%= gettext("Type") %>
 | 
			
		||||
        <%= gettext("Class") %>
 | 
			
		||||
      </h3>
 | 
			
		||||
 | 
			
		||||
      <span class="text-primary-600">
 | 
			
		||||
        <%= case @ammo_type.type do %>
 | 
			
		||||
        <%= case @ammo_type.class do %>
 | 
			
		||||
          <% :shotgun -> %>
 | 
			
		||||
            <%= gettext("Shotgun") %>
 | 
			
		||||
          <% :rifle -> %>
 | 
			
		||||
 
 | 
			
		||||
@@ -11,13 +11,13 @@ defmodule CanneryWeb.ContainerLive.Show do
 | 
			
		||||
 | 
			
		||||
  @impl true
 | 
			
		||||
  def mount(_params, _session, socket),
 | 
			
		||||
    do: {:ok, socket |> assign(type: :all, view_table: true)}
 | 
			
		||||
    do: {:ok, socket |> assign(class: :all, view_table: true)}
 | 
			
		||||
 | 
			
		||||
  @impl true
 | 
			
		||||
  def handle_params(%{"id" => id}, _session, %{assigns: %{current_user: current_user}} = socket) do
 | 
			
		||||
    socket =
 | 
			
		||||
      socket
 | 
			
		||||
      |> assign(view_table: true)
 | 
			
		||||
      |> assign(:view_table, true)
 | 
			
		||||
      |> render_container(id, current_user)
 | 
			
		||||
 | 
			
		||||
    {:noreply, socket}
 | 
			
		||||
@@ -86,30 +86,30 @@ defmodule CanneryWeb.ContainerLive.Show do
 | 
			
		||||
    {:noreply, socket |> assign(:view_table, !view_table) |> render_container()}
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def handle_event("change_type", %{"ammo_type" => %{"type" => "rifle"}}, socket) do
 | 
			
		||||
    {:noreply, socket |> assign(:type, :rifle) |> render_container()}
 | 
			
		||||
  def handle_event("change_class", %{"ammo_type" => %{"class" => "rifle"}}, socket) do
 | 
			
		||||
    {:noreply, socket |> assign(:class, :rifle) |> render_container()}
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def handle_event("change_type", %{"ammo_type" => %{"type" => "shotgun"}}, socket) do
 | 
			
		||||
    {:noreply, socket |> assign(:type, :shotgun) |> render_container()}
 | 
			
		||||
  def handle_event("change_class", %{"ammo_type" => %{"class" => "shotgun"}}, socket) do
 | 
			
		||||
    {:noreply, socket |> assign(:class, :shotgun) |> render_container()}
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def handle_event("change_type", %{"ammo_type" => %{"type" => "pistol"}}, socket) do
 | 
			
		||||
    {:noreply, socket |> assign(:type, :pistol) |> render_container()}
 | 
			
		||||
  def handle_event("change_class", %{"ammo_type" => %{"class" => "pistol"}}, socket) do
 | 
			
		||||
    {:noreply, socket |> assign(:class, :pistol) |> render_container()}
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def handle_event("change_type", %{"ammo_type" => %{"type" => _all}}, socket) do
 | 
			
		||||
    {:noreply, socket |> assign(:type, :all) |> render_container()}
 | 
			
		||||
  def handle_event("change_class", %{"ammo_type" => %{"class" => _all}}, socket) do
 | 
			
		||||
    {:noreply, socket |> assign(:class, :all) |> render_container()}
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  @spec render_container(Socket.t(), Container.id(), User.t()) :: Socket.t()
 | 
			
		||||
  defp render_container(
 | 
			
		||||
         %{assigns: %{type: type, live_action: live_action}} = socket,
 | 
			
		||||
         %{assigns: %{class: class, live_action: live_action}} = socket,
 | 
			
		||||
         id,
 | 
			
		||||
         current_user
 | 
			
		||||
       ) do
 | 
			
		||||
    %{name: container_name} = container = Containers.get_container!(id, current_user)
 | 
			
		||||
    ammo_groups = Ammo.list_ammo_groups_for_container(container, type, current_user)
 | 
			
		||||
    ammo_groups = Ammo.list_ammo_groups_for_container(container, class, current_user)
 | 
			
		||||
    original_counts = ammo_groups |> Ammo.get_original_counts(current_user)
 | 
			
		||||
    cprs = ammo_groups |> Ammo.get_cprs(current_user)
 | 
			
		||||
    last_used_dates = ammo_groups |> ActivityLog.get_last_used_dates(current_user)
 | 
			
		||||
 
 | 
			
		||||
@@ -90,15 +90,15 @@
 | 
			
		||||
      :let={f}
 | 
			
		||||
      for={%{}}
 | 
			
		||||
      as={:ammo_type}
 | 
			
		||||
      phx-change="change_type"
 | 
			
		||||
      phx-submit="change_type"
 | 
			
		||||
      phx-change="change_class"
 | 
			
		||||
      phx-submit="change_class"
 | 
			
		||||
      class="flex items-center"
 | 
			
		||||
    >
 | 
			
		||||
      <%= label(f, :type, gettext("Type"), class: "title text-primary-600 text-lg text-center") %>
 | 
			
		||||
      <%= label(f, :class, gettext("Class"), class: "title text-primary-600 text-lg text-center") %>
 | 
			
		||||
 | 
			
		||||
      <%= select(
 | 
			
		||||
        f,
 | 
			
		||||
        :type,
 | 
			
		||||
        :class,
 | 
			
		||||
        [
 | 
			
		||||
          {gettext("All"), :all},
 | 
			
		||||
          {gettext("Rifle"), :rifle},
 | 
			
		||||
@@ -106,7 +106,7 @@
 | 
			
		||||
          {gettext("Pistol"), :pistol}
 | 
			
		||||
        ],
 | 
			
		||||
        class: "mx-2 my-1 min-w-md input input-primary",
 | 
			
		||||
        value: @type
 | 
			
		||||
        value: @class
 | 
			
		||||
      ) %>
 | 
			
		||||
    </.form>
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -10,11 +10,11 @@ defmodule CanneryWeb.RangeLive.Index do
 | 
			
		||||
 | 
			
		||||
  @impl true
 | 
			
		||||
  def mount(%{"search" => search}, _session, socket) do
 | 
			
		||||
    {:ok, socket |> assign(type: :all, search: search) |> display_shot_groups()}
 | 
			
		||||
    {:ok, socket |> assign(class: :all, search: search) |> display_shot_groups()}
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def mount(_params, _session, socket) do
 | 
			
		||||
    {:ok, socket |> assign(type: :all, search: nil) |> display_shot_groups()}
 | 
			
		||||
    {:ok, socket |> assign(class: :all, search: nil) |> display_shot_groups()}
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  @impl true
 | 
			
		||||
@@ -102,27 +102,27 @@ defmodule CanneryWeb.RangeLive.Index do
 | 
			
		||||
    {:noreply, socket |> push_patch(to: Routes.range_index_path(Endpoint, :search, search_term))}
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def handle_event("change_type", %{"ammo_type" => %{"type" => "rifle"}}, socket) do
 | 
			
		||||
    {:noreply, socket |> assign(:type, :rifle) |> display_shot_groups()}
 | 
			
		||||
  def handle_event("change_class", %{"ammo_type" => %{"class" => "rifle"}}, socket) do
 | 
			
		||||
    {:noreply, socket |> assign(:class, :rifle) |> display_shot_groups()}
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def handle_event("change_type", %{"ammo_type" => %{"type" => "shotgun"}}, socket) do
 | 
			
		||||
    {:noreply, socket |> assign(:type, :shotgun) |> display_shot_groups()}
 | 
			
		||||
  def handle_event("change_class", %{"ammo_type" => %{"class" => "shotgun"}}, socket) do
 | 
			
		||||
    {:noreply, socket |> assign(:class, :shotgun) |> display_shot_groups()}
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def handle_event("change_type", %{"ammo_type" => %{"type" => "pistol"}}, socket) do
 | 
			
		||||
    {:noreply, socket |> assign(:type, :pistol) |> display_shot_groups()}
 | 
			
		||||
  def handle_event("change_class", %{"ammo_type" => %{"class" => "pistol"}}, socket) do
 | 
			
		||||
    {:noreply, socket |> assign(:class, :pistol) |> display_shot_groups()}
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def handle_event("change_type", %{"ammo_type" => %{"type" => _all}}, socket) do
 | 
			
		||||
    {:noreply, socket |> assign(:type, :all) |> display_shot_groups()}
 | 
			
		||||
  def handle_event("change_class", %{"ammo_type" => %{"class" => _all}}, socket) do
 | 
			
		||||
    {:noreply, socket |> assign(:class, :all) |> display_shot_groups()}
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  @spec display_shot_groups(Socket.t()) :: Socket.t()
 | 
			
		||||
  defp display_shot_groups(
 | 
			
		||||
         %{assigns: %{type: type, search: search, current_user: current_user}} = socket
 | 
			
		||||
         %{assigns: %{class: class, search: search, current_user: current_user}} = socket
 | 
			
		||||
       ) do
 | 
			
		||||
    shot_groups = ActivityLog.list_shot_groups(search, type, current_user)
 | 
			
		||||
    shot_groups = ActivityLog.list_shot_groups(search, class, current_user)
 | 
			
		||||
    ammo_groups = Ammo.list_staged_ammo_groups(current_user)
 | 
			
		||||
    chart_data = shot_groups |> get_chart_data_for_shot_group()
 | 
			
		||||
    original_counts = ammo_groups |> Ammo.get_original_counts(current_user)
 | 
			
		||||
 
 | 
			
		||||
@@ -79,15 +79,15 @@
 | 
			
		||||
        :let={f}
 | 
			
		||||
        for={%{}}
 | 
			
		||||
        as={:ammo_type}
 | 
			
		||||
        phx-change="change_type"
 | 
			
		||||
        phx-submit="change_type"
 | 
			
		||||
        phx-change="change_class"
 | 
			
		||||
        phx-submit="change_class"
 | 
			
		||||
        class="flex items-center"
 | 
			
		||||
      >
 | 
			
		||||
        <%= label(f, :type, gettext("Type"), class: "title text-primary-600 text-lg text-center") %>
 | 
			
		||||
        <%= label(f, :class, gettext("Class"), class: "title text-primary-600 text-lg text-center") %>
 | 
			
		||||
 | 
			
		||||
        <%= select(
 | 
			
		||||
          f,
 | 
			
		||||
          :type,
 | 
			
		||||
          :class,
 | 
			
		||||
          [
 | 
			
		||||
            {gettext("All"), :all},
 | 
			
		||||
            {gettext("Rifle"), :rifle},
 | 
			
		||||
@@ -95,7 +95,7 @@
 | 
			
		||||
            {gettext("Pistol"), :pistol}
 | 
			
		||||
          ],
 | 
			
		||||
          class: "mx-2 my-1 min-w-md input input-primary",
 | 
			
		||||
          value: @type
 | 
			
		||||
          value: @class
 | 
			
		||||
        ) %>
 | 
			
		||||
      </.form>
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user