- harden ammo context

- add user_id to ammo types
This commit is contained in:
shibao 2022-02-10 00:57:56 -05:00
parent 3b0850852e
commit e9ef44eb53
13 changed files with 325 additions and 242 deletions

View File

@ -13,12 +13,13 @@ defmodule Cannery.Ammo do
## Examples ## Examples
iex> list_ammo_types() iex> list_ammo_types(%User{id: 123})
[%AmmoType{}, ...] [%AmmoType{}, ...]
""" """
@spec list_ammo_types() :: [AmmoType.t()] @spec list_ammo_types(User.t()) :: [AmmoType.t()]
def list_ammo_types, do: Repo.all(AmmoType) def list_ammo_types(%User{id: user_id}),
do: Repo.all(from at in AmmoType, where: at.user_id == ^user_id)
@doc """ @doc """
Gets a single ammo_type. Gets a single ammo_type.
@ -27,15 +28,16 @@ defmodule Cannery.Ammo do
## Examples ## Examples
iex> get_ammo_type!(123) iex> get_ammo_type!(123, %User{id: 123})
%AmmoType{} %AmmoType{}
iex> get_ammo_type!(456) iex> get_ammo_type!(456, %User{id: 123})
** (Ecto.NoResultsError) ** (Ecto.NoResultsError)
""" """
@spec get_ammo_type!(AmmoType.id()) :: AmmoType.t() @spec get_ammo_type!(AmmoType.id(), User.t()) :: AmmoType.t()
def get_ammo_type!(id), do: Repo.get!(AmmoType, id) def get_ammo_type!(id, %User{id: user_id}),
do: Repo.one!(from at in AmmoType, where: at.id == ^id and at.user_id == ^user_id)
@doc """ @doc """
Gets the average cost of a single ammo type Gets the average cost of a single ammo type
@ -44,15 +46,18 @@ defmodule Cannery.Ammo do
## Examples ## Examples
iex> get_ammo_type!(123) iex> get_ammo_type!(123, %User{id: 123})
%AmmoType{} %AmmoType{}
iex> get_ammo_type!(456) iex> get_ammo_type!(456, %User{id: 123})
** (Ecto.NoResultsError) ** (Ecto.NoResultsError)
""" """
@spec get_average_cost_for_ammo_type!(AmmoType.t()) :: float() @spec get_average_cost_for_ammo_type!(AmmoType.t(), User.t()) :: float()
def get_average_cost_for_ammo_type!(%AmmoType{id: ammo_type_id}) do def get_average_cost_for_ammo_type!(
%AmmoType{id: ammo_type_id, user_id: user_id},
%User{id: user_id}
) do
Repo.one!( Repo.one!(
from ag in AmmoGroup, from ag in AmmoGroup,
where: ag.ammo_type_id == ^ammo_type_id, where: ag.ammo_type_id == ^ammo_type_id,
@ -66,62 +71,67 @@ defmodule Cannery.Ammo do
## Examples ## Examples
iex> create_ammo_type(%{field: value}) iex> create_ammo_type(%{field: value}, %User{id: 123})
{:ok, %AmmoType{}} {:ok, %AmmoType{}}
iex> create_ammo_type(%{field: bad_value}) iex> create_ammo_type(%{field: bad_value}, %User{id: 123})
{:error, %Changeset{}} {:error, %Changeset{}}
""" """
@spec create_ammo_type(attrs :: map()) :: @spec create_ammo_type(attrs :: map(), User.t()) ::
{:ok, AmmoType.t()} | {:error, Changeset.t(AmmoType.new_ammo_type())} {:ok, AmmoType.t()} | {:error, Changeset.t(AmmoType.new_ammo_type())}
def create_ammo_type(attrs \\ %{}), def create_ammo_type(attrs \\ %{}, %User{id: user_id}) do
do: %AmmoType{} |> AmmoType.changeset(attrs) |> Repo.insert() %AmmoType{}
|> AmmoType.create_changeset(attrs |> Map.put("user_id", user_id))
|> Repo.insert()
end
@doc """ @doc """
Updates a ammo_type. Updates a ammo_type.
## Examples ## Examples
iex> update_ammo_type(ammo_type, %{field: new_value}) iex> update_ammo_type(ammo_type, %{field: new_value}, %User{id: 123})
{:ok, %AmmoType{}} {:ok, %AmmoType{}}
iex> update_ammo_type(ammo_type, %{field: bad_value}) iex> update_ammo_type(ammo_type, %{field: bad_value}, %User{id: 123})
{:error, %Changeset{}} {:error, %Changeset{}}
""" """
@spec update_ammo_type(AmmoType.t(), attrs :: map()) :: @spec update_ammo_type(AmmoType.t(), attrs :: map(), User.t()) ::
{:ok, AmmoType.t()} | {:error, Changeset.t(AmmoType.t())} {:ok, AmmoType.t()} | {:error, Changeset.t(AmmoType.t())}
def update_ammo_type(%AmmoType{} = ammo_type, attrs), def update_ammo_type(%AmmoType{user_id: user_id} = ammo_type, attrs, %User{id: user_id}),
do: ammo_type |> AmmoType.changeset(attrs) |> Repo.update() do: ammo_type |> AmmoType.update_changeset(attrs) |> Repo.update()
@doc """ @doc """
Deletes a ammo_type. Deletes a ammo_type.
## Examples ## Examples
iex> delete_ammo_type(ammo_type) iex> delete_ammo_type(ammo_type, %User{id: 123})
{:ok, %AmmoType{}} {:ok, %AmmoType{}}
iex> delete_ammo_type(ammo_type) iex> delete_ammo_type(ammo_type, %User{id: 123})
{:error, %Changeset{}} {:error, %Changeset{}}
""" """
@spec delete_ammo_type(AmmoType.t()) :: @spec delete_ammo_type(AmmoType.t(), User.t()) ::
{:ok, AmmoType.t()} | {:error, Changeset.t(AmmoType.t())} {:ok, AmmoType.t()} | {:error, Changeset.t(AmmoType.t())}
def delete_ammo_type(%AmmoType{} = ammo_type), do: ammo_type |> Repo.delete() def delete_ammo_type(%AmmoType{user_id: user_id} = ammo_type, %User{id: user_id}),
do: ammo_type |> Repo.delete()
@doc """ @doc """
Deletes a ammo_type. Deletes a ammo_type.
## Examples ## Examples
iex> delete_ammo_type(ammo_type) iex> delete_ammo_type(ammo_type, %User{id: 123})
%AmmoType{} %AmmoType{}
""" """
@spec delete_ammo_type!(AmmoType.t()) :: AmmoType.t() @spec delete_ammo_type!(AmmoType.t(), User.t()) :: AmmoType.t()
def delete_ammo_type!(%AmmoType{} = ammo_type), do: ammo_type |> Repo.delete!() def delete_ammo_type!(%AmmoType{user_id: user_id} = ammo_type, %User{id: user_id}),
do: ammo_type |> Repo.delete!()
@doc """ @doc """
Returns an `%Changeset{}` for tracking ammo_type changes. Returns an `%Changeset{}` for tracking ammo_type changes.
@ -137,7 +147,7 @@ defmodule Cannery.Ammo do
@spec change_ammo_type(AmmoType.t() | AmmoType.new_ammo_type(), attrs :: map()) :: @spec change_ammo_type(AmmoType.t() | AmmoType.new_ammo_type(), attrs :: map()) ::
Changeset.t(AmmoType.t() | AmmoType.new_ammo_type()) Changeset.t(AmmoType.t() | AmmoType.new_ammo_type())
def change_ammo_type(%AmmoType{} = ammo_type, attrs \\ %{}), def change_ammo_type(%AmmoType{} = ammo_type, attrs \\ %{}),
do: AmmoType.changeset(ammo_type, attrs) do: AmmoType.update_changeset(ammo_type, attrs)
@doc """ @doc """
Returns the list of ammo_groups for a user and type. Returns the list of ammo_groups for a user and type.
@ -149,7 +159,7 @@ defmodule Cannery.Ammo do
""" """
@spec list_ammo_groups_for_type(AmmoType.t(), User.t()) :: [AmmoGroup.t()] @spec list_ammo_groups_for_type(AmmoType.t(), User.t()) :: [AmmoGroup.t()]
def list_ammo_groups_for_type(%AmmoType{id: ammo_type_id}, %User{id: user_id}) do def list_ammo_groups_for_type(%AmmoType{id: ammo_type_id, user_id: user_id}, %User{id: user_id}) do
Repo.all( Repo.all(
from am in AmmoGroup, from am in AmmoGroup,
where: am.ammo_type_id == ^ammo_type_id, where: am.ammo_type_id == ^ammo_type_id,
@ -178,77 +188,83 @@ defmodule Cannery.Ammo do
## Examples ## Examples
iex> get_ammo_group!(123) iex> get_ammo_group!(123, %User{id: 123})
%AmmoGroup{} %AmmoGroup{}
iex> get_ammo_group!(456) iex> get_ammo_group!(456, %User{id: 123})
** (Ecto.NoResultsError) ** (Ecto.NoResultsError)
""" """
@spec get_ammo_group!(AmmoGroup.id()) :: AmmoGroup.t() @spec get_ammo_group!(AmmoGroup.id(), User.t()) :: AmmoGroup.t()
def get_ammo_group!(id), do: Repo.get!(AmmoGroup, id) def get_ammo_group!(id, %User{id: user_id}),
do: Repo.one!(from am in AmmoGroup, where: am.id == ^id and am.user_id == ^user_id)
@doc """ @doc """
Creates a ammo_group. Creates a ammo_group.
## Examples ## Examples
iex> create_ammo_group(%{field: value}) iex> create_ammo_group(%{field: value}, %User{id: 123})
{:ok, %AmmoGroup{}} {:ok, %AmmoGroup{}}
iex> create_ammo_group(%{field: bad_value}) iex> create_ammo_group(%{field: bad_value}, %User{id: 123})
{:error, %Changeset{}} {:error, %Changeset{}}
""" """
@spec create_ammo_group(attrs :: map()) :: @spec create_ammo_group(attrs :: map(), User.t()) ::
{:ok, AmmoGroup.t()} | {:error, Changeset.t(AmmoGroup.new_ammo_group())} {:ok, AmmoGroup.t()} | {:error, Changeset.t(AmmoGroup.new_ammo_group())}
def create_ammo_group(attrs \\ %{}), def create_ammo_group(attrs \\ %{}, %User{id: user_id}) do
do: %AmmoGroup{} |> AmmoGroup.changeset(attrs) |> Repo.insert() %AmmoGroup{}
|> AmmoGroup.create_changeset(attrs |> Map.put("user_id", user_id))
|> Repo.insert()
end
@doc """ @doc """
Updates a ammo_group. Updates a ammo_group.
## Examples ## Examples
iex> update_ammo_group(ammo_group, %{field: new_value}) iex> update_ammo_group(ammo_group, %{field: new_value}, %User{id: 123})
{:ok, %AmmoGroup{}} {:ok, %AmmoGroup{}}
iex> update_ammo_group(ammo_group, %{field: bad_value}) iex> update_ammo_group(ammo_group, %{field: bad_value}, %User{id: 123})
{:error, %Changeset{}} {:error, %Changeset{}}
""" """
@spec update_ammo_group(AmmoGroup.t(), attrs :: map()) :: @spec update_ammo_group(AmmoGroup.t(), attrs :: map(), User.t()) ::
{:ok, AmmoGroup.t()} | {:error, Changeset.t(AmmoGroup.t())} {:ok, AmmoGroup.t()} | {:error, Changeset.t(AmmoGroup.t())}
def update_ammo_group(%AmmoGroup{} = ammo_group, attrs), def update_ammo_group(%AmmoGroup{user_id: user_id} = ammo_group, attrs, %User{id: user_id}),
do: ammo_group |> AmmoGroup.changeset(attrs) |> Repo.update() do: ammo_group |> AmmoGroup.update_changeset(attrs) |> Repo.update()
@doc """ @doc """
Deletes a ammo_group. Deletes a ammo_group.
## Examples ## Examples
iex> delete_ammo_group(ammo_group) iex> delete_ammo_group(ammo_group, %User{id: 123})
{:ok, %AmmoGroup{}} {:ok, %AmmoGroup{}}
iex> delete_ammo_group(ammo_group) iex> delete_ammo_group(ammo_group, %User{id: 123})
{:error, %Changeset{}} {:error, %Changeset{}}
""" """
@spec delete_ammo_group(AmmoGroup.t()) :: @spec delete_ammo_group(AmmoGroup.t(), User.t()) ::
{:ok, AmmoGroup.t()} | {:error, Changeset.t(AmmoGroup.t())} {:ok, AmmoGroup.t()} | {:error, Changeset.t(AmmoGroup.t())}
def delete_ammo_group(%AmmoGroup{} = ammo_group), do: ammo_group |> Repo.delete() def delete_ammo_group(%AmmoGroup{user_id: user_id} = ammo_group, %User{id: user_id}),
do: ammo_group |> Repo.delete()
@doc """ @doc """
Deletes a ammo_group. Deletes a ammo_group.
## Examples ## Examples
iex> delete_ammo_group!(ammo_group) iex> delete_ammo_group!(ammo_group, %User{id: 123})
%AmmoGroup{} %AmmoGroup{}
""" """
@spec delete_ammo_group!(AmmoGroup.t()) :: AmmoGroup.t() @spec delete_ammo_group!(AmmoGroup.t(), User.t()) :: AmmoGroup.t()
def delete_ammo_group!(%AmmoGroup{} = ammo_group), do: ammo_group |> Repo.delete!() def delete_ammo_group!(%AmmoGroup{user_id: user_id} = ammo_group, %User{id: user_id}),
do: ammo_group |> Repo.delete!()
@doc """ @doc """
Returns an `%Changeset{}` for tracking ammo_group changes. Returns an `%Changeset{}` for tracking ammo_group changes.
@ -262,5 +278,5 @@ defmodule Cannery.Ammo do
@spec change_ammo_group(AmmoGroup.t()) :: Changeset.t(AmmoGroup.t()) @spec change_ammo_group(AmmoGroup.t()) :: Changeset.t(AmmoGroup.t())
@spec change_ammo_group(AmmoGroup.t(), attrs :: map()) :: Changeset.t(AmmoGroup.t()) @spec change_ammo_group(AmmoGroup.t(), attrs :: map()) :: Changeset.t(AmmoGroup.t())
def change_ammo_group(%AmmoGroup{} = ammo_group, attrs \\ %{}), def change_ammo_group(%AmmoGroup{} = ammo_group, attrs \\ %{}),
do: AmmoGroup.changeset(ammo_group, attrs) do: AmmoGroup.update_changeset(ammo_group, attrs)
end end

View File

@ -44,10 +44,11 @@ defmodule Cannery.Ammo.AmmoGroup do
@type id :: UUID.t() @type id :: UUID.t()
@doc false @doc false
@spec changeset(t() | new_ammo_group(), attrs :: map()) :: Changeset.t(t() | new_ammo_group()) @spec create_changeset(t() | new_ammo_group(), attrs :: map()) ::
def changeset(ammo_group, attrs) do Changeset.t(t() | new_ammo_group())
def create_changeset(ammo_group, attrs) do
ammo_group ammo_group
|> cast(attrs, [:count, :price_paid, :notes, :tag_id, :ammo_type_id, :container_id, :user_id]) |> cast(attrs, [:count, :price_paid, :notes, :ammo_type_id, :container_id, :user_id])
|> validate_required([ |> validate_required([
:count, :count,
:ammo_type_id, :ammo_type_id,
@ -55,4 +56,17 @@ defmodule Cannery.Ammo.AmmoGroup do
:user_id :user_id
]) ])
end end
@doc false
@spec update_changeset(t() | new_ammo_group(), attrs :: map()) ::
Changeset.t(t() | new_ammo_group())
def update_changeset(ammo_group, attrs) do
ammo_group
|> cast(attrs, [:count, :price_paid, :notes, :ammo_type_id, :container_id, :user_id])
|> validate_required([
:count,
:ammo_type_id,
:container_id
])
end
end end

View File

@ -7,6 +7,7 @@ defmodule Cannery.Ammo.AmmoType do
use Ecto.Schema use Ecto.Schema
import Ecto.Changeset import Ecto.Changeset
alias Cannery.Accounts.User
alias Cannery.Ammo.{AmmoGroup, AmmoType} alias Cannery.Ammo.{AmmoGroup, AmmoType}
alias Ecto.{Changeset, UUID} alias Ecto.{Changeset, UUID}
@ -34,6 +35,8 @@ defmodule Cannery.Ammo.AmmoType do
field :manufacturer, :string field :manufacturer, :string
field :sku, :string field :sku, :string
belongs_to :user, User
has_many :ammo_groups, AmmoGroup has_many :ammo_groups, AmmoGroup
timestamps() timestamps()
@ -58,6 +61,8 @@ defmodule Cannery.Ammo.AmmoType do
corrosive: boolean(), corrosive: boolean(),
manufacturer: String.t() | nil, manufacturer: String.t() | nil,
sku: String.t() | nil, sku: String.t() | nil,
user_id: User.id(),
user: User.t() | nil,
ammo_groups: [AmmoGroup.t()] | nil, ammo_groups: [AmmoGroup.t()] | nil,
inserted_at: NaiveDateTime.t(), inserted_at: NaiveDateTime.t(),
updated_at: NaiveDateTime.t() updated_at: NaiveDateTime.t()
@ -65,11 +70,9 @@ defmodule Cannery.Ammo.AmmoType do
@type new_ammo_type :: %AmmoType{} @type new_ammo_type :: %AmmoType{}
@type id :: UUID.t() @type id :: UUID.t()
@doc false @spec changeset_fields() :: [atom()]
@spec changeset(t() | new_ammo_type(), attrs :: map()) :: Changeset.t(t() | new_ammo_type()) defp changeset_fields,
def changeset(ammo_type, attrs) do do: [
ammo_type
|> cast(attrs, [
:name, :name,
:desc, :desc,
:bullet_type, :bullet_type,
@ -87,7 +90,23 @@ defmodule Cannery.Ammo.AmmoType do
:corrosive, :corrosive,
:manufacturer, :manufacturer,
:sku :sku
]) ]
|> validate_required([:name])
@doc false
@spec create_changeset(t() | new_ammo_type(), attrs :: map()) ::
Changeset.t(t() | new_ammo_type())
def create_changeset(ammo_type, attrs) do
ammo_type
|> cast(attrs, [:user_id | changeset_fields()])
|> validate_required([:name, :user_id])
end
@doc false
@spec update_changeset(t() | new_ammo_type(), attrs :: map()) ::
Changeset.t(t() | new_ammo_type())
def update_changeset(ammo_type, attrs) do
ammo_type
|> cast(attrs, changeset_fields())
|> validate_required([:name, :user_id])
end end
end end

View File

@ -4,32 +4,38 @@ defmodule CanneryWeb.AmmoGroupLive.FormComponent do
""" """
use CanneryWeb, :live_component use CanneryWeb, :live_component
alias Cannery.{Ammo, Containers} alias Cannery.{Ammo, Containers}
alias Cannery.{Ammo.AmmoType, Containers.Container} alias Cannery.{Ammo.AmmoType, Containers.Container}
alias Ecto.Changeset alias Ecto.Changeset
@impl true @impl true
def update(%{ammo_group: ammo_group} = assigns, socket) do def update(%{ammo_group: _ammo_group} = assigns, socket) do
socket = socket |> assign(assigns) socket |> assign(assigns) |> update()
end
def update(%{assigns: %{ammo_group: ammo_group, current_user: current_user}} = socket) do
changeset = Ammo.change_ammo_group(ammo_group) changeset = Ammo.change_ammo_group(ammo_group)
containers = Containers.list_containers(socket.assigns.current_user) containers = Containers.list_containers(current_user)
ammo_types = Ammo.list_ammo_types() ammo_types = Ammo.list_ammo_types(current_user)
{:ok, socket |> assign(changeset: changeset, containers: containers, ammo_types: ammo_types)} {:ok, socket |> assign(changeset: changeset, containers: containers, ammo_types: ammo_types)}
end end
@impl true @impl true
def handle_event("validate", %{"ammo_group" => ammo_group_params}, socket) do def handle_event(
ammo_group_params = ammo_group_params |> Map.put("user_id", socket.assigns.current_user.id) "validate",
changeset = socket.assigns.ammo_group |> Ammo.change_ammo_group(ammo_group_params) %{"ammo_group" => ammo_group_params},
{:noreply, socket |> assign(:changeset, changeset)} %{assigns: %{ammo_group: ammo_group}} = socket
) do
socket = socket |> assign(:changeset, ammo_group |> Ammo.change_ammo_group(ammo_group_params))
{:noreply, socket}
end end
def handle_event("save", %{"ammo_group" => ammo_group_params}, socket) do def handle_event(
ammo_group_params = ammo_group_params |> Map.put("user_id", socket.assigns.current_user.id) "save",
save_ammo_group(socket, socket.assigns.action, ammo_group_params) %{"ammo_group" => ammo_group_params},
%{assigns: %{action: action}} = socket
) do
save_ammo_group(socket, action, ammo_group_params)
end end
@impl true @impl true
@ -99,41 +105,50 @@ defmodule CanneryWeb.AmmoGroupLive.FormComponent do
# HTML Helpers # HTML Helpers
@spec container_options([Container.t()]) :: [{String.t(), Container.id()}] @spec container_options([Container.t()]) :: [{String.t(), Container.id()}]
defp container_options(containers) do defp container_options(containers) do
containers |> Enum.map(fn container -> {container.name, container.id} end) containers |> Enum.map(fn %{id: id, name: name} -> {name, id} end)
end end
@spec ammo_type_options([AmmoType.t()]) :: [{String.t(), AmmoType.id()}] @spec ammo_type_options([AmmoType.t()]) :: [{String.t(), AmmoType.id()}]
defp ammo_type_options(ammo_types) do defp ammo_type_options(ammo_types) do
ammo_types |> Enum.map(fn ammo_type -> {ammo_type.name, ammo_type.id} end) ammo_types |> Enum.map(fn %{id: id, name: name} -> {name, id} end)
end end
# Save Helpers # Save Helpers
defp save_ammo_group(socket, :edit, ammo_group_params) do defp save_ammo_group(
socket.assigns.ammo_group %{assigns: %{ammo_group: ammo_group, current_user: current_user, return_to: return_to}} =
|> Ammo.update_ammo_group(ammo_group_params) socket,
|> case do :edit,
{:ok, _ammo_group} -> ammo_group_params
{:noreply, ) do
socket socket =
|> put_flash(:info, dgettext("prompts", "Ammo group updated successfully")) case Ammo.update_ammo_group(ammo_group, ammo_group_params, current_user) do
|> push_redirect(to: socket.assigns.return_to)} {:ok, _ammo_group} ->
prompt = dgettext("prompts", "Ammo group updated successfully")
socket |> put_flash(:info, prompt) |> push_redirect(to: return_to)
{:error, %Changeset{} = changeset} -> {:error, %Changeset{} = changeset} ->
{:noreply, socket |> assign(:changeset, changeset)} socket |> assign(:changeset, changeset)
end end
{:noreply, socket}
end end
defp save_ammo_group(socket, :new, ammo_group_params) do defp save_ammo_group(
case Ammo.create_ammo_group(ammo_group_params) do %{assigns: %{current_user: current_user, return_to: return_to}} = socket,
{:ok, _ammo_group} -> :new,
{:noreply, ammo_group_params
socket ) do
|> put_flash(:info, dgettext("prompts", "Ammo group created successfully")) socket =
|> push_redirect(to: socket.assigns.return_to)} case Ammo.create_ammo_group(ammo_group_params, current_user) do
{:ok, _ammo_group} ->
prompt = dgettext("prompts", "Ammo group created successfully")
socket |> put_flash(:info, prompt) |> push_redirect(to: return_to)
{:error, %Changeset{} = changeset} -> {:error, %Changeset{} = changeset} ->
{:noreply, socket |> assign(changeset: changeset)} socket |> assign(changeset: changeset)
end end
{:noreply, socket}
end end
end end

View File

@ -4,7 +4,6 @@ defmodule CanneryWeb.AmmoGroupLive.Index do
""" """
use CanneryWeb, :live_view use CanneryWeb, :live_view
alias Cannery.Ammo alias Cannery.Ammo
alias Cannery.Ammo.AmmoGroup alias Cannery.Ammo.AmmoGroup
@ -14,14 +13,14 @@ defmodule CanneryWeb.AmmoGroupLive.Index do
end end
@impl true @impl true
def handle_params(params, _url, socket) do def handle_params(params, _url, %{assigns: %{live_action: live_action}} = socket) do
{:noreply, apply_action(socket, socket.assigns.live_action, params)} {:noreply, apply_action(socket, live_action, params)}
end end
defp apply_action(socket, :edit, %{"id" => id}) do defp apply_action(%{assigns: %{current_user: current_user}} = socket, :edit, %{"id" => id}) do
socket socket
|> assign(:page_title, gettext("Edit Ammo group")) |> assign(:page_title, gettext("Edit Ammo group"))
|> assign(:ammo_group, Ammo.get_ammo_group!(id)) |> assign(:ammo_group, Ammo.get_ammo_group!(id, current_user))
end end
defp apply_action(socket, :new, _params) do defp apply_action(socket, :new, _params) do
@ -31,19 +30,19 @@ defmodule CanneryWeb.AmmoGroupLive.Index do
end end
defp apply_action(socket, :index, _params) do defp apply_action(socket, :index, _params) do
socket socket |> assign(:page_title, gettext("Listing Ammo groups")) |> assign(:ammo_group, nil)
|> assign(:page_title, gettext("Listing Ammo groups"))
|> assign(:ammo_group, nil)
end end
@impl true @impl true
def handle_event("delete", %{"id" => id}, socket) do def handle_event("delete", %{"id" => id}, %{assigns: %{current_user: current_user}} = socket) do
Ammo.get_ammo_group!(id) |> Ammo.delete_ammo_group!() Ammo.get_ammo_group!(id, current_user) |> Ammo.delete_ammo_group!(current_user)
{:noreply, socket |> display_ammo_groups()}
prompt = dgettext("prompts", "Ammo group deleted succesfully")
{:noreply, socket |> put_flash(:info, prompt) |> display_ammo_groups()}
end end
defp display_ammo_groups(%{assigns: %{current_user: current_user}} = socket) do defp display_ammo_groups(%{assigns: %{current_user: current_user}} = socket) do
ammo_groups = Ammo.list_ammo_groups(current_user) socket |> assign(:ammo_groups, Ammo.list_ammo_groups(current_user))
socket |> assign(:ammo_groups, ammo_groups)
end end
end end

View File

@ -9,27 +9,31 @@ defmodule CanneryWeb.AmmoGroupLive.Show do
@impl true @impl true
def mount(_params, session, socket) do def mount(_params, session, socket) do
socket = socket |> assign_defaults(session) {:ok, socket |> assign_defaults(session)}
{:ok, socket}
end end
@impl true @impl true
def handle_params(%{"id" => id}, _, socket) do def handle_params(
socket = %{"id" => id},
socket _,
|> assign( %{assigns: %{live_action: live_action, current_user: current_user}} = socket
page_title: page_title(socket.assigns.live_action), ) do
ammo_group: Ammo.get_ammo_group!(id) |> Repo.preload([:container, :ammo_type]) ammo_group = Ammo.get_ammo_group!(id, current_user) |> Repo.preload([:container, :ammo_type])
) {:noreply, socket |> assign(page_title: page_title(live_action), ammo_group: ammo_group)}
{:noreply, socket}
end end
@impl true @impl true
def handle_event("delete", _, socket) do def handle_event(
socket.assigns.ammo_group |> Ammo.delete_ammo_group!() "delete",
{:noreply, socket |> push_redirect(to: Routes.ammo_group_index_path(socket, :index))} _,
%{assigns: %{ammo_group: ammo_group, current_user: current_user}} = socket
) do
ammo_group |> Ammo.delete_ammo_group!(current_user)
prompt = dgettext("prompts", "Ammo group deleted succesfully")
redirect_to = Routes.ammo_group_index_path(socket, :index)
{:noreply, socket |> put_flash(:info, prompt) |> push_redirect(to: redirect_to)}
end end
defp page_title(:show), do: gettext("Show Ammo group") defp page_title(:show), do: gettext("Show Ammo group")

View File

@ -4,28 +4,29 @@ defmodule CanneryWeb.AmmoTypeLive.FormComponent do
""" """
use CanneryWeb, :live_component use CanneryWeb, :live_component
alias Cannery.Ammo alias Cannery.Ammo
alias Ecto.Changeset alias Ecto.Changeset
@impl true @impl true
def update(%{ammo_type: ammo_type} = assigns, socket) do def update(%{ammo_type: ammo_type} = assigns, socket) do
changeset = Ammo.change_ammo_type(ammo_type) {:ok, socket |> assign(assigns) |> assign(:changeset, Ammo.change_ammo_type(ammo_type))}
{:ok,
socket
|> assign(assigns)
|> assign(:changeset, changeset)}
end end
@impl true @impl true
def handle_event("validate", %{"ammo_type" => ammo_type_params}, socket) do def handle_event(
changeset = socket.assigns.ammo_type |> Ammo.change_ammo_type(ammo_type_params) "validate",
{:noreply, socket |> assign(:changeset, changeset)} %{"ammo_type" => ammo_type_params},
%{assigns: %{ammo_type: ammo_type}} = socket
) do
{:noreply, socket |> assign(:changeset, ammo_type |> Ammo.change_ammo_type(ammo_type_params))}
end end
def handle_event("save", %{"ammo_type" => ammo_type_params}, socket) do def handle_event(
save_ammo_type(socket, socket.assigns.action, ammo_type_params) "save",
%{"ammo_type" => ammo_type_params},
%{assigns: %{action: action}} = socket
) do
save_ammo_type(socket, action, ammo_type_params)
end end
@impl true @impl true
@ -161,29 +162,36 @@ defmodule CanneryWeb.AmmoTypeLive.FormComponent do
""" """
end end
defp save_ammo_type(socket, :edit, ammo_type_params) do defp save_ammo_type(
case Ammo.update_ammo_type(socket.assigns.ammo_type, ammo_type_params) do %{assigns: %{ammo_type: ammo_type, current_user: current_user, return_to: return_to}} =
{:ok, _ammo_type} -> socket,
{:noreply, :edit,
socket ammo_type_params
|> put_flash(:info, dgettext("prompts", "Ammo type updated successfully")) ) do
|> push_redirect(to: socket.assigns.return_to)} socket =
case Ammo.update_ammo_type(ammo_type, ammo_type_params, current_user) do
{:ok, %{name: ammo_type_name}} ->
prompt = dgettext("prompts", "%{name} updated successfully", name: ammo_type_name)
socket |> put_flash(:info, prompt) |> push_redirect(to: return_to)
{:error, %Changeset{} = changeset} -> {:error, %Changeset{} = changeset} ->
{:noreply, socket |> assign(:changeset, changeset)} socket |> assign(:changeset, changeset)
end end
{:noreply, socket}
end end
defp save_ammo_type(socket, :new, ammo_type_params) do defp save_ammo_type(%{assigns: %{return_to: return_to}} = socket, :new, ammo_type_params) do
case Ammo.create_ammo_type(ammo_type_params) do socket =
{:ok, _ammo_type} -> case Ammo.create_ammo_type(ammo_type_params) do
{:noreply, {:ok, %{name: ammo_type_name}} ->
socket prompt = dgettext("prompts", "%{name} created successfully", name: ammo_type_name)
|> put_flash(:info, dgettext("prompts", "Ammo type created successfully")) socket |> put_flash(:info, prompt) |> push_redirect(to: return_to)
|> push_redirect(to: socket.assigns.return_to)}
{:error, %Changeset{} = changeset} -> {:error, %Changeset{} = changeset} ->
{:noreply, socket |> assign(changeset: changeset)} socket |> assign(changeset: changeset)
end end
{:noreply, socket}
end end
end end

View File

@ -10,18 +10,18 @@ defmodule CanneryWeb.AmmoTypeLive.Index do
@impl true @impl true
def mount(_params, session, socket) do def mount(_params, session, socket) do
{:ok, socket |> assign_defaults(session) |> assign(:ammo_types, list_ammo_types())} {:ok, socket |> assign_defaults(session) |> list_ammo_types()}
end end
@impl true @impl true
def handle_params(params, _url, socket) do def handle_params(params, _url, %{assigns: %{live_action: live_action}} = socket) do
{:noreply, apply_action(socket, socket.assigns.live_action, params)} {:noreply, apply_action(socket, live_action, params)}
end end
defp apply_action(socket, :edit, %{"id" => id}) do defp apply_action(%{assigns: %{current_user: current_user}} = socket, :edit, %{"id" => id}) do
socket socket
|> assign(:page_title, gettext("Edit Ammo type")) |> assign(:page_title, gettext("Edit Ammo type"))
|> assign(:ammo_type, Ammo.get_ammo_type!(id)) |> assign(:ammo_type, Ammo.get_ammo_type!(id, current_user))
end end
defp apply_action(socket, :new, _params) do defp apply_action(socket, :new, _params) do
@ -31,20 +31,19 @@ defmodule CanneryWeb.AmmoTypeLive.Index do
end end
defp apply_action(socket, :index, _params) do defp apply_action(socket, :index, _params) do
socket socket |> assign(:page_title, gettext("Listing Ammo types")) |> assign(:ammo_type, nil)
|> assign(:page_title, gettext("Listing Ammo types"))
|> assign(:ammo_type, nil)
end end
@impl true @impl true
def handle_event("delete", %{"id" => id}, socket) do def handle_event("delete", %{"id" => id}, %{assigns: %{current_user: current_user}} = socket) do
ammo_type = Ammo.get_ammo_type!(id) %{name: name} = Ammo.get_ammo_type!(id, current_user) |> Ammo.delete_ammo_type!(current_user)
{:ok, _} = Ammo.delete_ammo_type(ammo_type)
{:noreply, socket |> assign(:ammo_types, list_ammo_types())} prompt = dgettext("prompts", "%{name} deleted succesfully", name: name)
{:noreply, socket |> put_flash(:info, prompt) |> list_ammo_types()}
end end
defp list_ammo_types do defp list_ammo_types(%{assigns: %{current_user: current_user}} = socket) do
Ammo.list_ammo_types() socket |> assign(:ammo_types, Ammo.list_ammo_types(current_user))
end end
end end

View File

@ -14,25 +14,32 @@ defmodule CanneryWeb.AmmoTypeLive.Show do
@impl true @impl true
def handle_params(%{"id" => id}, _, %{assigns: %{current_user: current_user}} = socket) do def handle_params(%{"id" => id}, _, %{assigns: %{current_user: current_user}} = socket) do
ammo_type = Ammo.get_ammo_type!(id) ammo_type = Ammo.get_ammo_type!(id, current_user)
ammo_groups = ammo_type |> Ammo.list_ammo_groups_for_type(current_user)
socket = socket =
socket socket
|> assign( |> assign(
page_title: page_title(socket.assigns.live_action), page_title: page_title(socket.assigns.live_action),
ammo_type: ammo_type, ammo_type: ammo_type,
ammo_groups: ammo_groups, ammo_groups: ammo_type |> Ammo.list_ammo_groups_for_type(current_user),
avg_cost_per_round: ammo_type |> Ammo.get_average_cost_for_ammo_type!() avg_cost_per_round: ammo_type |> Ammo.get_average_cost_for_ammo_type!(current_user)
) )
{:noreply, socket} {:noreply, socket}
end end
@impl true @impl true
def handle_event("delete", _, socket) do def handle_event(
socket.assigns.ammo_type |> Ammo.delete_ammo_type!() "delete",
{:noreply, socket |> push_redirect(to: Routes.ammo_type_index_path(socket, :index))} _,
%{assigns: %{ammo_type: ammo_type, current_user: current_user}} = socket
) do
%{name: ammo_type_name} = ammo_type |> Ammo.delete_ammo_type!(current_user)
prompt = dgettext("prompts", "%{name} deleted succesfully", name: ammo_type_name)
redirect_to = Routes.ammo_type_index_path(socket, :index)
{:noreply, socket |> put_flash(:info, prompt) |> push_redirect(to: redirect_to)}
end end
defp page_title(:show), do: gettext("Show Ammo type") defp page_title(:show), do: gettext("Show Ammo type")

View File

@ -76,7 +76,7 @@ msgid "Send instructions to reset password"
msgstr "" msgstr ""
#, elixir-format, ex-autogen #, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_group_live/index.ex:29 #: lib/cannery_web/live/ammo_group_live/index.ex:28
msgid "Add Ammo" msgid "Add Ammo"
msgstr "" msgstr ""
@ -91,11 +91,11 @@ msgid "New Ammo group"
msgstr "" msgstr ""
#, elixir-format, ex-autogen #, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_group_live/form_component.ex:90 #: lib/cannery_web/live/ammo_group_live/form_component.ex:96
#: lib/cannery_web/live/ammo_type_live/form_component.ex:155 #: lib/cannery_web/live/ammo_type_live/form_component.ex:156
#: lib/cannery_web/live/container_live/form_component.ex:79 #: lib/cannery_web/live/container_live/form_component.ex:79
#: lib/cannery_web/live/invite_live/form_component.ex:61 #: lib/cannery_web/live/invite_live/form_component.ex:61
#: lib/cannery_web/live/tag_live/form_component.ex:69 #: lib/cannery_web/live/tag_live/form_component.ex:62
msgid "Save" msgid "Save"
msgstr "" msgstr ""

View File

@ -111,7 +111,7 @@ msgid "Settings"
msgstr "" msgstr ""
#, elixir-format, ex-autogen #, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_group_live/form_component.ex:63 #: lib/cannery_web/live/ammo_group_live/form_component.ex:69
#: lib/cannery_web/live/ammo_group_live/index.html.heex:26 #: lib/cannery_web/live/ammo_group_live/index.html.heex:26
msgid "Count" msgid "Count"
msgstr "" msgstr ""
@ -123,8 +123,8 @@ msgid "Count:"
msgstr "" msgstr ""
#, elixir-format, ex-autogen #, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_group_live/index.ex:23 #: lib/cannery_web/live/ammo_group_live/index.ex:22
#: lib/cannery_web/live/ammo_group_live/show.ex:36 #: lib/cannery_web/live/ammo_group_live/show.ex:40
msgid "Edit Ammo group" msgid "Edit Ammo group"
msgstr "" msgstr ""
@ -134,7 +134,7 @@ msgid "Listing Ammo"
msgstr "" msgstr ""
#, elixir-format, ex-autogen #, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_group_live/index.ex:35 #: lib/cannery_web/live/ammo_group_live/index.ex:33
msgid "Listing Ammo groups" msgid "Listing Ammo groups"
msgstr "" msgstr ""
@ -144,7 +144,7 @@ msgid "No Ammo"
msgstr "" msgstr ""
#, elixir-format, ex-autogen #, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_group_live/form_component.ex:77 #: lib/cannery_web/live/ammo_group_live/form_component.ex:83
#: lib/cannery_web/live/ammo_group_live/index.html.heex:32 #: lib/cannery_web/live/ammo_group_live/index.html.heex:32
msgid "Notes" msgid "Notes"
msgstr "" msgstr ""
@ -156,7 +156,7 @@ msgid "Notes:"
msgstr "" msgstr ""
#, elixir-format, ex-autogen #, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_group_live/form_component.ex:70 #: lib/cannery_web/live/ammo_group_live/form_component.ex:76
#: lib/cannery_web/live/ammo_group_live/index.html.heex:29 #: lib/cannery_web/live/ammo_group_live/index.html.heex:29
msgid "Price paid" msgid "Price paid"
msgstr "" msgstr ""
@ -168,7 +168,7 @@ msgid "Price paid:"
msgstr "" msgstr ""
#, elixir-format, ex-autogen #, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_group_live/show.ex:35 #: lib/cannery_web/live/ammo_group_live/show.ex:39
msgid "Show Ammo group" msgid "Show Ammo group"
msgstr "" msgstr ""
@ -183,7 +183,7 @@ msgid "This ammo group is not in a container"
msgstr "" msgstr ""
#, elixir-format, ex-autogen #, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_group_live/form_component.ex:57 #: lib/cannery_web/live/ammo_group_live/form_component.ex:63
msgid "Ammo type" msgid "Ammo type"
msgstr "" msgstr ""
@ -193,93 +193,93 @@ msgid "Average Price paid"
msgstr "" msgstr ""
#, elixir-format, ex-autogen #, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/form_component.ex:139 #: lib/cannery_web/live/ammo_type_live/form_component.ex:140
#: lib/cannery_web/live/ammo_type_live/index.html.heex:38 #: lib/cannery_web/live/ammo_type_live/index.html.heex:38
msgid "Blank" msgid "Blank"
msgstr "" msgstr ""
#, elixir-format, ex-autogen #, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/form_component.ex:101 #: lib/cannery_web/live/ammo_type_live/form_component.ex:102
msgid "Brass" msgid "Brass"
msgstr "" msgstr ""
#, elixir-format, ex-autogen #, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/form_component.ex:77 #: lib/cannery_web/live/ammo_type_live/form_component.ex:78
#: lib/cannery_web/live/ammo_type_live/index.html.heex:28 #: lib/cannery_web/live/ammo_type_live/index.html.heex:28
#: lib/cannery_web/live/ammo_type_live/show.html.heex:37 #: lib/cannery_web/live/ammo_type_live/show.html.heex:37
msgid "Bullet core" msgid "Bullet core"
msgstr "" msgstr ""
#, elixir-format, ex-autogen #, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/form_component.ex:70 #: lib/cannery_web/live/ammo_type_live/form_component.ex:71
#: lib/cannery_web/live/ammo_type_live/index.html.heex:27 #: lib/cannery_web/live/ammo_type_live/index.html.heex:27
#: lib/cannery_web/live/ammo_type_live/show.html.heex:36 #: lib/cannery_web/live/ammo_type_live/show.html.heex:36
msgid "Bullet type" msgid "Bullet type"
msgstr "" msgstr ""
#, elixir-format, ex-autogen #, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/form_component.ex:91 #: lib/cannery_web/live/ammo_type_live/form_component.ex:92
#: lib/cannery_web/live/ammo_type_live/index.html.heex:30 #: lib/cannery_web/live/ammo_type_live/index.html.heex:30
#: lib/cannery_web/live/ammo_type_live/show.html.heex:39 #: lib/cannery_web/live/ammo_type_live/show.html.heex:39
msgid "Caliber" msgid "Caliber"
msgstr "" msgstr ""
#, elixir-format, ex-autogen #, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/form_component.ex:84 #: lib/cannery_web/live/ammo_type_live/form_component.ex:85
#: lib/cannery_web/live/ammo_type_live/index.html.heex:29 #: lib/cannery_web/live/ammo_type_live/index.html.heex:29
#: lib/cannery_web/live/ammo_type_live/show.html.heex:38 #: lib/cannery_web/live/ammo_type_live/show.html.heex:38
msgid "Cartridge" msgid "Cartridge"
msgstr "" msgstr ""
#, elixir-format, ex-autogen #, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/form_component.ex:98 #: lib/cannery_web/live/ammo_type_live/form_component.ex:99
#: lib/cannery_web/live/ammo_type_live/index.html.heex:31 #: lib/cannery_web/live/ammo_type_live/index.html.heex:31
#: lib/cannery_web/live/ammo_type_live/show.html.heex:40 #: lib/cannery_web/live/ammo_type_live/show.html.heex:40
msgid "Case material" msgid "Case material"
msgstr "" msgstr ""
#, elixir-format, ex-autogen #, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_group_live/form_component.ex:84 #: lib/cannery_web/live/ammo_group_live/form_component.ex:90
msgid "Container" msgid "Container"
msgstr "" msgstr ""
#, elixir-format, ex-autogen #, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/form_component.ex:143 #: lib/cannery_web/live/ammo_type_live/form_component.ex:144
#: lib/cannery_web/live/ammo_type_live/index.html.heex:39 #: lib/cannery_web/live/ammo_type_live/index.html.heex:39
msgid "Corrosive" msgid "Corrosive"
msgstr "" msgstr ""
#, elixir-format, ex-autogen #, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/form_component.ex:57 #: lib/cannery_web/live/ammo_type_live/form_component.ex:58
#: lib/cannery_web/live/container_live/form_component.ex:56 #: lib/cannery_web/live/container_live/form_component.ex:56
msgid "Description" msgid "Description"
msgstr "" msgstr ""
#, elixir-format, ex-autogen #, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/index.ex:23 #: lib/cannery_web/live/ammo_type_live/index.ex:23
#: lib/cannery_web/live/ammo_type_live/show.ex:39 #: lib/cannery_web/live/ammo_type_live/show.ex:46
msgid "Edit Ammo type" msgid "Edit Ammo type"
msgstr "" msgstr ""
#, elixir-format, ex-autogen #, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/form_component.ex:68 #: lib/cannery_web/live/ammo_type_live/form_component.ex:69
msgid "Example bullet type abbreviations" msgid "Example bullet type abbreviations"
msgstr "" msgstr ""
#, elixir-format, ex-autogen #, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/form_component.ex:73 #: lib/cannery_web/live/ammo_type_live/form_component.ex:74
msgid "FMJ" msgid "FMJ"
msgstr "" msgstr ""
#, elixir-format, ex-autogen #, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/form_component.ex:105 #: lib/cannery_web/live/ammo_type_live/form_component.ex:106
#: lib/cannery_web/live/ammo_type_live/index.html.heex:32 #: lib/cannery_web/live/ammo_type_live/index.html.heex:32
#: lib/cannery_web/live/ammo_type_live/show.html.heex:41 #: lib/cannery_web/live/ammo_type_live/show.html.heex:41
msgid "Grains" msgid "Grains"
msgstr "" msgstr ""
#, elixir-format, ex-autogen #, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/form_component.ex:135 #: lib/cannery_web/live/ammo_type_live/form_component.ex:136
#: lib/cannery_web/live/ammo_type_live/index.html.heex:37 #: lib/cannery_web/live/ammo_type_live/index.html.heex:37
msgid "Incendiary" msgid "Incendiary"
msgstr "" msgstr ""
@ -290,22 +290,22 @@ msgid "Listing Ammo Types"
msgstr "" msgstr ""
#, elixir-format, ex-autogen #, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/index.ex:35 #: lib/cannery_web/live/ammo_type_live/index.ex:34
msgid "Listing Ammo types" msgid "Listing Ammo types"
msgstr "" msgstr ""
#, elixir-format, ex-autogen #, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/form_component.ex:147 #: lib/cannery_web/live/ammo_type_live/form_component.ex:148
#: lib/cannery_web/live/ammo_type_live/index.html.heex:40 #: lib/cannery_web/live/ammo_type_live/index.html.heex:40
msgid "Manufacturer" msgid "Manufacturer"
msgstr "" msgstr ""
#, elixir-format, ex-autogen #, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/form_component.ex:53 #: lib/cannery_web/live/ammo_type_live/form_component.ex:54
#: lib/cannery_web/live/ammo_type_live/index.html.heex:26 #: lib/cannery_web/live/ammo_type_live/index.html.heex:26
#: lib/cannery_web/live/container_live/form_component.ex:49 #: lib/cannery_web/live/container_live/form_component.ex:49
#: lib/cannery_web/live/invite_live/form_component.ex:53 #: lib/cannery_web/live/invite_live/form_component.ex:53
#: lib/cannery_web/live/tag_live/form_component.ex:53 #: lib/cannery_web/live/tag_live/form_component.ex:46
msgid "Name" msgid "Name"
msgstr "" msgstr ""
@ -325,32 +325,32 @@ msgid "No ammo for this type"
msgstr "" msgstr ""
#, elixir-format, ex-autogen #, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/form_component.ex:113 #: lib/cannery_web/live/ammo_type_live/form_component.ex:114
#: lib/cannery_web/live/ammo_type_live/index.html.heex:33 #: lib/cannery_web/live/ammo_type_live/index.html.heex:33
#: lib/cannery_web/live/ammo_type_live/show.html.heex:42 #: lib/cannery_web/live/ammo_type_live/show.html.heex:42
msgid "Pressure" msgid "Pressure"
msgstr "" msgstr ""
#, elixir-format, ex-autogen #, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/form_component.ex:120 #: lib/cannery_web/live/ammo_type_live/form_component.ex:121
#: lib/cannery_web/live/ammo_type_live/index.html.heex:34 #: lib/cannery_web/live/ammo_type_live/index.html.heex:34
#: lib/cannery_web/live/ammo_type_live/show.html.heex:43 #: lib/cannery_web/live/ammo_type_live/show.html.heex:43
msgid "Primer type" msgid "Primer type"
msgstr "" msgstr ""
#, elixir-format, ex-autogen #, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/form_component.ex:127 #: lib/cannery_web/live/ammo_type_live/form_component.ex:128
#: lib/cannery_web/live/ammo_type_live/index.html.heex:35 #: lib/cannery_web/live/ammo_type_live/index.html.heex:35
msgid "Rimfire" msgid "Rimfire"
msgstr "" msgstr ""
#, elixir-format, ex-autogen #, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/form_component.ex:151 #: lib/cannery_web/live/ammo_type_live/form_component.ex:152
msgid "SKU" msgid "SKU"
msgstr "" msgstr ""
#, elixir-format, ex-autogen #, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/show.ex:38 #: lib/cannery_web/live/ammo_type_live/show.ex:45
msgid "Show Ammo type" msgid "Show Ammo type"
msgstr "" msgstr ""
@ -360,12 +360,12 @@ msgid "Sku"
msgstr "" msgstr ""
#, elixir-format, ex-autogen #, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/form_component.ex:80 #: lib/cannery_web/live/ammo_type_live/form_component.ex:81
msgid "Steel" msgid "Steel"
msgstr "" msgstr ""
#, elixir-format, ex-autogen #, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/form_component.ex:131 #: lib/cannery_web/live/ammo_type_live/form_component.ex:132
#: lib/cannery_web/live/ammo_type_live/index.html.heex:36 #: lib/cannery_web/live/ammo_type_live/index.html.heex:36
msgid "Tracer" msgid "Tracer"
msgstr "" msgstr ""
@ -451,7 +451,7 @@ msgid "Type:"
msgstr "" msgstr ""
#, elixir-format, ex-autogen #, elixir-format, ex-autogen
#: lib/cannery_web/live/tag_live/form_component.ex:57 #: lib/cannery_web/live/tag_live/form_component.ex:50
msgid "Background color" msgid "Background color"
msgstr "" msgstr ""
@ -487,7 +487,7 @@ msgid "Listing Invites"
msgstr "" msgstr ""
#, elixir-format, ex-autogen #, elixir-format, ex-autogen
#: lib/cannery_web/live/tag_live/index.ex:35 #: lib/cannery_web/live/tag_live/index.ex:34
#: lib/cannery_web/live/tag_live/index.html.heex:3 #: lib/cannery_web/live/tag_live/index.html.heex:3
msgid "Listing Tags" msgid "Listing Tags"
msgstr "" msgstr ""
@ -523,7 +523,7 @@ msgid "Tags can be added to your containers to help you organize"
msgstr "" msgstr ""
#, elixir-format, ex-autogen #, elixir-format, ex-autogen
#: lib/cannery_web/live/tag_live/form_component.ex:63 #: lib/cannery_web/live/tag_live/form_component.ex:56
msgid "Text color" msgid "Text color"
msgstr "" msgstr ""

View File

@ -77,12 +77,12 @@ msgid "Your account has been deleted"
msgstr "" msgstr ""
#, elixir-format, ex-autogen #, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_group_live/form_component.ex:132 #: lib/cannery_web/live/ammo_group_live/form_component.ex:145
msgid "Ammo group created successfully" msgid "Ammo group created successfully"
msgstr "" msgstr ""
#, elixir-format, ex-autogen #, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_group_live/form_component.ex:119 #: lib/cannery_web/live/ammo_group_live/form_component.ex:127
msgid "Ammo group updated successfully" msgid "Ammo group updated successfully"
msgstr "" msgstr ""
@ -94,24 +94,14 @@ msgid "Are you sure you want to delete this ammo?"
msgstr "" msgstr ""
#, elixir-format, ex-autogen #, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_group_live/form_component.ex:91 #: lib/cannery_web/live/ammo_group_live/form_component.ex:97
#: lib/cannery_web/live/ammo_type_live/form_component.ex:156 #: lib/cannery_web/live/ammo_type_live/form_component.ex:157
#: lib/cannery_web/live/container_live/form_component.ex:81 #: lib/cannery_web/live/container_live/form_component.ex:81
#: lib/cannery_web/live/invite_live/form_component.ex:63 #: lib/cannery_web/live/invite_live/form_component.ex:63
#: lib/cannery_web/live/tag_live/form_component.ex:71 #: lib/cannery_web/live/tag_live/form_component.ex:64
msgid "Saving..." msgid "Saving..."
msgstr "" msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/form_component.ex:182
msgid "Ammo type created successfully"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/form_component.ex:169
msgid "Ammo type updated successfully"
msgstr ""
#, elixir-format, ex-autogen #, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_type_live/show.html.heex:26 #: lib/cannery_web/live/ammo_type_live/show.html.heex:26
#: lib/cannery_web/live/container_live/index.html.heex:36 #: lib/cannery_web/live/container_live/index.html.heex:36
@ -152,16 +142,26 @@ msgid "Invite updated successfully"
msgstr "" msgstr ""
#, elixir-format, ex-autogen #, elixir-format, ex-autogen
#: lib/cannery_web/live/tag_live/form_component.ex:98 #: lib/cannery_web/live/ammo_type_live/form_component.ex:188
msgid "Tag created successfully" #: lib/cannery_web/live/tag_live/form_component.ex:97
msgid "%{name} created successfully"
msgstr "" msgstr ""
#, elixir-format, ex-autogen #, elixir-format, ex-autogen
#: lib/cannery_web/live/tag_live/index.ex:45 #: lib/cannery_web/live/ammo_type_live/index.ex:41
msgid "Tag deleted succesfully" #: lib/cannery_web/live/ammo_type_live/show.ex:39
#: lib/cannery_web/live/tag_live/index.ex:41
msgid "%{name} deleted succesfully"
msgstr "" msgstr ""
#, elixir-format, ex-autogen #, elixir-format, ex-autogen
#: lib/cannery_web/live/tag_live/form_component.ex:83 #: lib/cannery_web/live/ammo_type_live/form_component.ex:174
msgid "Tag updated successfully" #: lib/cannery_web/live/tag_live/form_component.ex:79
msgid "%{name} updated successfully"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/live/ammo_group_live/index.ex:40
#: lib/cannery_web/live/ammo_group_live/show.ex:33
msgid "Ammo group deleted succesfully"
msgstr "" msgstr ""

View File

@ -25,6 +25,8 @@ defmodule Cannery.Repo.Migrations.CreateAmmoTypes do
add :manufacturer, :string add :manufacturer, :string
add :sku, :string add :sku, :string
add :user_id, references(:users, on_delete: :delete_all, type: :binary_id)
timestamps() timestamps()
end end
end end