diff --git a/lib/cannery/accounts.ex b/lib/cannery/accounts.ex index 29bf497..d25d53f 100644 --- a/lib/cannery/accounts.ex +++ b/lib/cannery/accounts.ex @@ -74,7 +74,7 @@ defmodule Cannery.Accounts do """ @spec list_all_users_by_role(User.t()) :: %{String.t() => [User.t()]} def list_all_users_by_role(%User{role: :admin}) do - Repo.all(User) |> Enum.group_by(fn user -> user.role end) + Repo.all(from u in User, order_by: u.email) |> Enum.group_by(fn user -> user.role end) end @doc """ @@ -89,7 +89,7 @@ defmodule Cannery.Accounts do @spec list_users_by_role(:admin | :user) :: [User.t()] def list_users_by_role(role) do role = role |> to_string() - Repo.all(from u in User, where: u.role == ^role) + Repo.all(from u in User, where: u.role == ^role, order_by: u.email) end ## User registration diff --git a/lib/cannery/ammo.ex b/lib/cannery/ammo.ex index f64b76b..26b0350 100644 --- a/lib/cannery/ammo.ex +++ b/lib/cannery/ammo.ex @@ -19,7 +19,7 @@ defmodule Cannery.Ammo do """ @spec list_ammo_types(User.t()) :: [AmmoType.t()] def list_ammo_types(%User{id: user_id}), - do: Repo.all(from at in AmmoType, where: at.user_id == ^user_id) + do: Repo.all(from at in AmmoType, where: at.user_id == ^user_id, order_by: at.name) @doc """ Gets a single ammo_type. @@ -163,7 +163,8 @@ defmodule Cannery.Ammo do Repo.all( from am in AmmoGroup, where: am.ammo_type_id == ^ammo_type_id, - where: am.user_id == ^user_id + where: am.user_id == ^user_id, + order_by: am.id ) end @@ -180,9 +181,12 @@ defmodule Cannery.Ammo do @spec list_ammo_groups(User.t(), include_empty :: boolean()) :: [AmmoGroup.t()] def list_ammo_groups(%User{id: user_id}, include_empty \\ false) do if include_empty do - from am in AmmoGroup, where: am.user_id == ^user_id + from am in AmmoGroup, where: am.user_id == ^user_id, order_by: am.id else - from am in AmmoGroup, where: am.user_id == ^user_id, where: not (am.count == 0) + from am in AmmoGroup, + where: am.user_id == ^user_id, + where: not (am.count == 0), + order_by: am.id end |> Repo.all() end @@ -198,7 +202,12 @@ defmodule Cannery.Ammo do """ @spec list_staged_ammo_groups(User.t()) :: [AmmoGroup.t()] def list_staged_ammo_groups(%User{id: user_id}) do - Repo.all(from am in AmmoGroup, where: am.user_id == ^user_id, where: am.staged == true) + Repo.all( + from am in AmmoGroup, + where: am.user_id == ^user_id, + where: am.staged == true, + order_by: am.id + ) end @doc """ diff --git a/lib/cannery/containers.ex b/lib/cannery/containers.ex index 08827e3..2d2be35 100644 --- a/lib/cannery/containers.ex +++ b/lib/cannery/containers.ex @@ -20,7 +20,7 @@ defmodule Cannery.Containers do """ @spec list_containers(User.t()) :: [Container.t()] def list_containers(%User{id: user_id}), - do: Repo.all(from c in Container, where: c.user_id == ^user_id) + do: Repo.all(from c in Container, where: c.user_id == ^user_id, order_by: c.name) @doc """ Gets a single container. diff --git a/lib/cannery/invites.ex b/lib/cannery/invites.ex index e535c4d..f8788ad 100644 --- a/lib/cannery/invites.ex +++ b/lib/cannery/invites.ex @@ -20,7 +20,7 @@ defmodule Cannery.Invites do """ @spec list_invites(User.t()) :: [Invite.t()] def list_invites(%User{role: :admin}) do - Repo.all(Invite) + Repo.all(from i in Invite, order_by: i.name) end @doc """ diff --git a/lib/cannery/tags.ex b/lib/cannery/tags.ex index 4b6a9c0..8b3e960 100644 --- a/lib/cannery/tags.ex +++ b/lib/cannery/tags.ex @@ -18,7 +18,8 @@ defmodule Cannery.Tags do """ @spec list_tags(User.t()) :: [Tag.t()] - def list_tags(%{id: user_id}), do: Repo.all(from t in Tag, where: t.user_id == ^user_id) + def list_tags(%{id: user_id}), + do: Repo.all(from t in Tag, where: t.user_id == ^user_id, order_by: t.name) @doc """ Gets a single tag. diff --git a/lib/cannery_web/live/invite_live/index.ex b/lib/cannery_web/live/invite_live/index.ex index d48f7fb..3f4e0ad 100644 --- a/lib/cannery_web/live/invite_live/index.ex +++ b/lib/cannery_web/live/invite_live/index.ex @@ -138,16 +138,15 @@ defmodule CanneryWeb.InviteLive.Index do end defp display_invites(%{assigns: %{current_user: current_user}} = socket) do - invites = Invites.list_invites(current_user) |> Enum.sort_by(fn %{name: name} -> name end) + invites = Invites.list_invites(current_user) all_users = Accounts.list_all_users_by_role(current_user) admins = all_users |> Map.get(:admin, []) |> Enum.reject(fn %{id: user_id} -> user_id == current_user.id end) - |> Enum.sort_by(fn %{email: email} -> email end) - users = all_users |> Map.get(:user, []) |> Enum.sort_by(fn %{email: email} -> email end) + users = all_users |> Map.get(:user, []) socket |> assign(invites: invites, admins: admins, users: users) end end diff --git a/priv/gettext/errors.pot b/priv/gettext/errors.pot index 3697956..73a5229 100644 --- a/priv/gettext/errors.pot +++ b/priv/gettext/errors.pot @@ -132,7 +132,7 @@ msgid "must have the @ sign and no spaces" msgstr "" #, elixir-format, ex-autogen -#: lib/cannery/tags.ex:39 +#: lib/cannery/tags.ex:40 msgid "Tag not found" msgstr ""