forked from shibao/cannery
		
	fix class filter helper functions
This commit is contained in:
		@@ -38,16 +38,16 @@ defmodule Cannery.Ammo do
 | 
				
			|||||||
      where: t.user_id == ^user_id,
 | 
					      where: t.user_id == ^user_id,
 | 
				
			||||||
      preload: ^@type_preloads
 | 
					      preload: ^@type_preloads
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    |> list_types_filter_class(Keyword.get(opts, :class, :all))
 | 
					    |> list_types_class(Keyword.get(opts, :class, :all))
 | 
				
			||||||
    |> list_types_filter_search(Keyword.get(opts, :search))
 | 
					    |> list_types_search(Keyword.get(opts, :search))
 | 
				
			||||||
    |> Repo.all()
 | 
					    |> Repo.all()
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @spec list_types_filter_search(Queryable.t(), search :: String.t() | nil) :: Queryable.t()
 | 
					  @spec list_types_search(Queryable.t(), search :: String.t() | nil) :: Queryable.t()
 | 
				
			||||||
  defp list_types_filter_search(query, search) when search in ["", nil],
 | 
					  defp list_types_search(query, search) when search in ["", nil],
 | 
				
			||||||
    do: query |> order_by([t: t], t.name)
 | 
					    do: query |> order_by([t: t], t.name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  defp list_types_filter_search(query, search) when search |> is_binary() do
 | 
					  defp list_types_search(query, search) when search |> is_binary() do
 | 
				
			||||||
    trimmed_search = String.trim(search)
 | 
					    trimmed_search = String.trim(search)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    query
 | 
					    query
 | 
				
			||||||
@@ -72,17 +72,11 @@ defmodule Cannery.Ammo do
 | 
				
			|||||||
    )
 | 
					    )
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @spec list_types_filter_class(Queryable.t(), Type.class() | :all) :: Queryable.t()
 | 
					  @spec list_types_class(Queryable.t(), Type.class() | :all) :: Queryable.t()
 | 
				
			||||||
  defp list_types_filter_class(query, :rifle),
 | 
					  defp list_types_class(query, class) when class in [:rifle, :pistol, :shotgun],
 | 
				
			||||||
    do: query |> where([t: t], t.class == :rifle)
 | 
					    do: query |> where([t: t], t.class == ^class)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  defp list_types_filter_class(query, :pistol),
 | 
					  defp list_types_class(query, _all), do: query
 | 
				
			||||||
    do: query |> where([t: t], t.class == :pistol)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  defp list_types_filter_class(query, :shotgun),
 | 
					 | 
				
			||||||
    do: query |> where([t: t], t.class == :shotgun)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  defp list_types_filter_class(query, _all), do: query
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @doc """
 | 
					  @doc """
 | 
				
			||||||
  Returns a count of types.
 | 
					  Returns a count of types.
 | 
				
			||||||
@@ -229,7 +223,9 @@ defmodule Cannery.Ammo do
 | 
				
			|||||||
  defp get_round_count_container_id(query, _nil), do: query
 | 
					  defp get_round_count_container_id(query, _nil), do: query
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @type get_grouped_round_count_option ::
 | 
					  @type get_grouped_round_count_option ::
 | 
				
			||||||
          {:types, [Type.t()] | nil} | {:containers, [Container.t()] | nil} | {:group_by, atom()}
 | 
					          {:types, [Type.t()] | nil}
 | 
				
			||||||
 | 
					          | {:containers, [Container.t()] | nil}
 | 
				
			||||||
 | 
					          | {:group_by, atom()}
 | 
				
			||||||
  @type get_grouped_round_count_options :: [get_grouped_round_count_option()]
 | 
					  @type get_grouped_round_count_options :: [get_grouped_round_count_option()]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @doc """
 | 
					  @doc """
 | 
				
			||||||
@@ -528,14 +524,8 @@ defmodule Cannery.Ammo do
 | 
				
			|||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @spec list_packs_class(Queryable.t(), Type.class() | :all) :: Queryable.t()
 | 
					  @spec list_packs_class(Queryable.t(), Type.class() | :all) :: Queryable.t()
 | 
				
			||||||
  defp list_packs_class(query, :rifle),
 | 
					  defp list_packs_class(query, class) when class in [:rifle, :pistol, :shotgun],
 | 
				
			||||||
    do: query |> where([t: t], t.class == :rifle)
 | 
					    do: query |> where([t: t], t.class == ^class)
 | 
				
			||||||
 | 
					 | 
				
			||||||
  defp list_packs_class(query, :pistol),
 | 
					 | 
				
			||||||
    do: query |> where([t: t], t.class == :pistol)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  defp list_packs_class(query, :shotgun),
 | 
					 | 
				
			||||||
    do: query |> where([t: t], t.class == :shotgun)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  defp list_packs_class(query, _all), do: query
 | 
					  defp list_packs_class(query, _all), do: query
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -170,7 +170,7 @@ msgstr ""
 | 
				
			|||||||
"Ungültige Nummer an Kopien. Muss zwischen 1 and %{max} liegen. War "
 | 
					"Ungültige Nummer an Kopien. Muss zwischen 1 and %{max} liegen. War "
 | 
				
			||||||
"%{multiplier}"
 | 
					"%{multiplier}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#: lib/cannery/ammo.ex:984
 | 
					#: lib/cannery/ammo.ex:974
 | 
				
			||||||
#, elixir-autogen, elixir-format
 | 
					#, elixir-autogen, elixir-format
 | 
				
			||||||
msgid "Invalid multiplier"
 | 
					msgid "Invalid multiplier"
 | 
				
			||||||
msgstr ""
 | 
					msgstr ""
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -153,7 +153,7 @@ msgstr ""
 | 
				
			|||||||
msgid "Invalid number of copies, must be between 1 and %{max}. Was %{multiplier}"
 | 
					msgid "Invalid number of copies, must be between 1 and %{max}. Was %{multiplier}"
 | 
				
			||||||
msgstr ""
 | 
					msgstr ""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#: lib/cannery/ammo.ex:984
 | 
					#: lib/cannery/ammo.ex:974
 | 
				
			||||||
#, elixir-autogen, elixir-format
 | 
					#, elixir-autogen, elixir-format
 | 
				
			||||||
msgid "Invalid multiplier"
 | 
					msgid "Invalid multiplier"
 | 
				
			||||||
msgstr ""
 | 
					msgstr ""
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -152,7 +152,7 @@ msgstr ""
 | 
				
			|||||||
msgid "Invalid number of copies, must be between 1 and %{max}. Was %{multiplier}"
 | 
					msgid "Invalid number of copies, must be between 1 and %{max}. Was %{multiplier}"
 | 
				
			||||||
msgstr ""
 | 
					msgstr ""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#: lib/cannery/ammo.ex:984
 | 
					#: lib/cannery/ammo.ex:974
 | 
				
			||||||
#, elixir-autogen, elixir-format
 | 
					#, elixir-autogen, elixir-format
 | 
				
			||||||
msgid "Invalid multiplier"
 | 
					msgid "Invalid multiplier"
 | 
				
			||||||
msgstr ""
 | 
					msgstr ""
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -168,7 +168,7 @@ msgstr "No se ha podido procesar el número de copias"
 | 
				
			|||||||
msgid "Invalid number of copies, must be between 1 and %{max}. Was %{multiplier}"
 | 
					msgid "Invalid number of copies, must be between 1 and %{max}. Was %{multiplier}"
 | 
				
			||||||
msgstr "Número inválido de copias, debe ser entre 1 y %{max}. Fue %{multiplier"
 | 
					msgstr "Número inválido de copias, debe ser entre 1 y %{max}. Fue %{multiplier"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#: lib/cannery/ammo.ex:984
 | 
					#: lib/cannery/ammo.ex:974
 | 
				
			||||||
#, elixir-autogen, elixir-format
 | 
					#, elixir-autogen, elixir-format
 | 
				
			||||||
msgid "Invalid multiplier"
 | 
					msgid "Invalid multiplier"
 | 
				
			||||||
msgstr "Multiplicador inválido"
 | 
					msgstr "Multiplicador inválido"
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -169,7 +169,7 @@ msgstr "Impossible d'analyser le nombre de copies"
 | 
				
			|||||||
msgid "Invalid number of copies, must be between 1 and %{max}. Was %{multiplier}"
 | 
					msgid "Invalid number of copies, must be between 1 and %{max}. Was %{multiplier}"
 | 
				
			||||||
msgstr "Nombre de copies invalide, doit être 1 et %{max}. Été %{multiplier}"
 | 
					msgstr "Nombre de copies invalide, doit être 1 et %{max}. Été %{multiplier}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#: lib/cannery/ammo.ex:984
 | 
					#: lib/cannery/ammo.ex:974
 | 
				
			||||||
#, elixir-autogen, elixir-format
 | 
					#, elixir-autogen, elixir-format
 | 
				
			||||||
msgid "Invalid multiplier"
 | 
					msgid "Invalid multiplier"
 | 
				
			||||||
msgstr "Multiplicateur invalide"
 | 
					msgstr "Multiplicateur invalide"
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -168,7 +168,7 @@ msgstr ""
 | 
				
			|||||||
msgid "Invalid number of copies, must be between 1 and %{max}. Was %{multiplier}"
 | 
					msgid "Invalid number of copies, must be between 1 and %{max}. Was %{multiplier}"
 | 
				
			||||||
msgstr ""
 | 
					msgstr ""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#: lib/cannery/ammo.ex:984
 | 
					#: lib/cannery/ammo.ex:974
 | 
				
			||||||
#, elixir-autogen, elixir-format
 | 
					#, elixir-autogen, elixir-format
 | 
				
			||||||
msgid "Invalid multiplier"
 | 
					msgid "Invalid multiplier"
 | 
				
			||||||
msgstr ""
 | 
					msgstr ""
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user