diff --git a/CHANGELOG.md b/CHANGELOG.md index b58bb0db..0da01509 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # v0.8.0 -- Add search to catalog, ammo and container index -- Tweak urls for catalog, ammo and containers +- Add search to catalog, ammo, container and tag index +- Tweak urls for catalog, ammo, containers and tags # v0.7.2 - Code improvements diff --git a/lib/cannery/tags.ex b/lib/cannery/tags.ex index 6a00c4fa..8fcda101 100644 --- a/lib/cannery/tags.ex +++ b/lib/cannery/tags.ex @@ -15,11 +15,38 @@ defmodule Cannery.Tags do iex> list_tags(%User{id: 123}) [%Tag{}, ...] + iex> list_tags("cool", %User{id: 123}) + [%Tag{name: "my cool tag"}, ...] + """ @spec list_tags(User.t()) :: [Tag.t()] - def list_tags(%{id: user_id}), + @spec list_tags(search :: nil | String.t(), User.t()) :: [Tag.t()] + def list_tags(search \\ nil, user) + + def list_tags(search, %{id: user_id}) when search |> is_nil() or search == "", do: Repo.all(from t in Tag, where: t.user_id == ^user_id, order_by: t.name) + def list_tags(search, %{id: user_id}) when search |> is_binary() do + trimmed_search = String.trim(search) + + Repo.all( + from t in Tag, + where: t.user_id == ^user_id, + where: + fragment( + "search @@ websearch_to_tsquery('english', ?)", + ^trimmed_search + ), + order_by: { + :desc, + fragment( + "ts_rank_cd(search, websearch_to_tsquery('english', ?), 4)", + ^trimmed_search + ) + } + ) + end + @doc """ Gets a single tag. diff --git a/lib/cannery_web/live/tag_live/index.ex b/lib/cannery_web/live/tag_live/index.ex index 8159257a..f9f8674e 100644 --- a/lib/cannery_web/live/tag_live/index.ex +++ b/lib/cannery_web/live/tag_live/index.ex @@ -9,27 +9,53 @@ defmodule CanneryWeb.TagLive.Index do alias CanneryWeb.{Endpoint, ViewHelpers} @impl true - def mount(_params, _session, socket), do: {:ok, socket |> display_tags()} + def mount(%{"search" => search}, _session, socket) do + {:ok, socket |> assign(:search, search) |> display_tags()} + end + + def mount(_params, _session, socket) do + {:ok, socket |> assign(:search, nil) |> display_tags()} + end @impl true def handle_params(params, _url, %{assigns: %{live_action: live_action}} = socket) do - {:noreply, apply_action(socket, live_action, params) |> display_tags} + {:noreply, apply_action(socket, live_action, params)} end defp apply_action(%{assigns: %{current_user: current_user}} = socket, :edit, %{"id" => id}) do socket - |> assign(:page_title, gettext("Edit Tag")) - |> assign(:tag, Tags.get_tag!(id, current_user)) + |> assign( + page_title: gettext("Edit Tag"), + tag: Tags.get_tag!(id, current_user) + ) end defp apply_action(socket, :new, _params) do socket - |> assign(:page_title, gettext("New Tag")) - |> assign(:tag, %Tag{bg_color: ViewHelpers.random_color(), text_color: "#ffffff"}) + |> assign( + page_title: gettext("New Tag"), + tag: %Tag{bg_color: ViewHelpers.random_color(), text_color: "#ffffff"} + ) end defp apply_action(socket, :index, _params) do - socket |> assign(:page_title, gettext("Tags")) |> assign(:tag, nil) + socket + |> assign( + page_title: gettext("Tags"), + search: nil, + tag: nil + ) + |> display_tags() + end + + defp apply_action(socket, :search, %{"search" => search}) do + socket + |> assign( + page_title: gettext("Tags"), + search: search, + tag: nil + ) + |> display_tags() end @impl true @@ -39,7 +65,16 @@ defmodule CanneryWeb.TagLive.Index do {:noreply, socket |> put_flash(:info, prompt) |> display_tags()} end - defp display_tags(%{assigns: %{current_user: current_user}} = socket) do - socket |> assign(tags: Tags.list_tags(current_user)) + @impl true + def handle_event("search", %{"search" => %{"search_term" => ""}}, socket) do + {:noreply, socket |> push_patch(to: Routes.tag_index_path(Endpoint, :index))} + end + + def handle_event("search", %{"search" => %{"search_term" => search_term}}, socket) do + {:noreply, socket |> push_patch(to: Routes.tag_index_path(Endpoint, :search, search_term))} + end + + defp display_tags(%{assigns: %{search: search, current_user: current_user}} = socket) do + socket |> assign(tags: Tags.list_tags(search, current_user)) end end diff --git a/lib/cannery_web/live/tag_live/index.html.heex b/lib/cannery_web/live/tag_live/index.html.heex index 65e0cd88..a1203d23 100644 --- a/lib/cannery_web/live/tag_live/index.html.heex +++ b/lib/cannery_web/live/tag_live/index.html.heex @@ -5,7 +5,7 @@

<%= gettext("Tags can be added to your containers to help you organize") %>

- <%= if @tags |> Enum.empty?() do %> + <%= if @tags |> Enum.empty?() and @search |> is_nil() do %>

<%= gettext("No tags") %> <%= display_emoji("😔") %> @@ -19,7 +19,33 @@ <%= dgettext("actions", "New Tag") %> <% end %> + +
+ <.form + :let={f} + for={:search} + phx-change="search" + phx-submit="search" + class="grow self-stretch flex flex-col items-stretch" + data-qa="tag_search" + > + <%= text_input(f, :search_term, + class: "input input-primary", + value: @search, + phx_debounce: 300, + placeholder: gettext("Search tags") + ) %> + +
+
+ <%= if @tags |> Enum.empty?() do %> +

+ <%= gettext("No tags") %> + <%= display_emoji("😔") %> +

+ <% end %> + <%= for tag <- @tags do %> <.tag_card tag={tag}> <.link diff --git a/lib/cannery_web/router.ex b/lib/cannery_web/router.ex index c103c149..b78ae4d6 100644 --- a/lib/cannery_web/router.ex +++ b/lib/cannery_web/router.ex @@ -64,7 +64,8 @@ defmodule CanneryWeb.Router do live "/tags", TagLive.Index, :index live "/tags/new", TagLive.Index, :new - live "/tags/:id/edit", TagLive.Index, :edit + live "/tags/edit/:id", TagLive.Index, :edit + live "/tags/search/:search", TagLive.Index, :search live "/catalog", AmmoTypeLive.Index, :index live "/catalog/new", AmmoTypeLive.Index, :new diff --git a/priv/gettext/de/LC_MESSAGES/default.po b/priv/gettext/de/LC_MESSAGES/default.po index 9e00fa63..ca40aed4 100644 --- a/priv/gettext/de/LC_MESSAGES/default.po +++ b/priv/gettext/de/LC_MESSAGES/default.po @@ -162,7 +162,7 @@ msgstr "Einfache Anwendung:" msgid "Edit Invite" msgstr "Einladung bearbeiten" -#: lib/cannery_web/live/tag_live/index.ex:21 +#: lib/cannery_web/live/tag_live/index.ex:28 #, elixir-autogen, elixir-format msgid "Edit Tag" msgstr "Tag bearbeiten" @@ -277,7 +277,7 @@ msgstr "Neuer Behälter" msgid "New Invite" msgstr "Neue Einladung" -#: lib/cannery_web/live/tag_live/index.ex:27 +#: lib/cannery_web/live/tag_live/index.ex:36 #, elixir-autogen, elixir-format msgid "New Tag" msgstr "Neuer Tag" @@ -306,6 +306,7 @@ msgstr "Keine Einladung" #: lib/cannery_web/live/container_live/edit_tags_component.html.heex:31 #: lib/cannery_web/live/tag_live/index.html.heex:10 +#: lib/cannery_web/live/tag_live/index.html.heex:44 #, elixir-autogen, elixir-format msgid "No tags" msgstr "Keine Tags" @@ -394,7 +395,8 @@ msgstr "Gelagert in" #: lib/cannery_web/components/container_table_component.ex:52 #: lib/cannery_web/components/topbar.ex:49 -#: lib/cannery_web/live/tag_live/index.ex:32 +#: lib/cannery_web/live/tag_live/index.ex:44 +#: lib/cannery_web/live/tag_live/index.ex:54 #: lib/cannery_web/live/tag_live/index.html.heex:3 #, elixir-autogen, elixir-format msgid "Tags" @@ -1132,3 +1134,8 @@ msgstr "" #, elixir-autogen, elixir-format msgid "Search containers" msgstr "" + +#: lib/cannery_web/live/tag_live/index.html.heex:36 +#, elixir-autogen, elixir-format, fuzzy +msgid "Search tags" +msgstr "" diff --git a/priv/gettext/de/LC_MESSAGES/errors.po b/priv/gettext/de/LC_MESSAGES/errors.po index 05b6faf8..8f14637f 100644 --- a/priv/gettext/de/LC_MESSAGES/errors.po +++ b/priv/gettext/de/LC_MESSAGES/errors.po @@ -141,7 +141,7 @@ msgstr "ist nicht gültig" msgid "must have the @ sign and no spaces" msgstr "Muss ein @ Zeichen und keine Leerzeichen haben" -#: lib/cannery/tags.ex:39 +#: lib/cannery/tags.ex:66 #, elixir-autogen, elixir-format msgid "Tag not found" msgstr "Tag nicht gefunden" diff --git a/priv/gettext/de/LC_MESSAGES/prompts.po b/priv/gettext/de/LC_MESSAGES/prompts.po index bd434ef3..9314fa5a 100644 --- a/priv/gettext/de/LC_MESSAGES/prompts.po +++ b/priv/gettext/de/LC_MESSAGES/prompts.po @@ -35,7 +35,7 @@ msgstr "%{name} erfolgreich erstellt" #: lib/cannery_web/live/ammo_type_live/show.ex:55 #: lib/cannery_web/live/invite_live/index.ex:53 #: lib/cannery_web/live/invite_live/index.ex:133 -#: lib/cannery_web/live/tag_live/index.ex:38 +#: lib/cannery_web/live/tag_live/index.ex:64 #, elixir-autogen, elixir-format msgid "%{name} deleted succesfully" msgstr "%{name} erfolgreich gelöscht" @@ -85,7 +85,7 @@ msgstr "" #: lib/cannery_web/live/container_live/index.html.heex:93 #: lib/cannery_web/live/container_live/index.html.heex:138 #: lib/cannery_web/live/container_live/show.html.heex:59 -#: lib/cannery_web/live/tag_live/index.html.heex:39 +#: lib/cannery_web/live/tag_live/index.html.heex:65 #, elixir-autogen, elixir-format msgid "Are you sure you want to delete %{name}?" msgstr "Sind Sie sicher, dass sie %{name} löschen möchten?" diff --git a/priv/gettext/default.pot b/priv/gettext/default.pot index faea5dc1..f2658d46 100644 --- a/priv/gettext/default.pot +++ b/priv/gettext/default.pot @@ -147,7 +147,7 @@ msgstr "" msgid "Edit Invite" msgstr "" -#: lib/cannery_web/live/tag_live/index.ex:21 +#: lib/cannery_web/live/tag_live/index.ex:28 #, elixir-autogen, elixir-format msgid "Edit Tag" msgstr "" @@ -262,7 +262,7 @@ msgstr "" msgid "New Invite" msgstr "" -#: lib/cannery_web/live/tag_live/index.ex:27 +#: lib/cannery_web/live/tag_live/index.ex:36 #, elixir-autogen, elixir-format msgid "New Tag" msgstr "" @@ -291,6 +291,7 @@ msgstr "" #: lib/cannery_web/live/container_live/edit_tags_component.html.heex:31 #: lib/cannery_web/live/tag_live/index.html.heex:10 +#: lib/cannery_web/live/tag_live/index.html.heex:44 #, elixir-autogen, elixir-format msgid "No tags" msgstr "" @@ -377,7 +378,8 @@ msgstr "" #: lib/cannery_web/components/container_table_component.ex:52 #: lib/cannery_web/components/topbar.ex:49 -#: lib/cannery_web/live/tag_live/index.ex:32 +#: lib/cannery_web/live/tag_live/index.ex:44 +#: lib/cannery_web/live/tag_live/index.ex:54 #: lib/cannery_web/live/tag_live/index.html.heex:3 #, elixir-autogen, elixir-format msgid "Tags" @@ -1115,3 +1117,8 @@ msgstr "" #, elixir-autogen, elixir-format msgid "Search containers" msgstr "" + +#: lib/cannery_web/live/tag_live/index.html.heex:36 +#, elixir-autogen, elixir-format +msgid "Search tags" +msgstr "" diff --git a/priv/gettext/en/LC_MESSAGES/default.po b/priv/gettext/en/LC_MESSAGES/default.po index de579776..ed289104 100644 --- a/priv/gettext/en/LC_MESSAGES/default.po +++ b/priv/gettext/en/LC_MESSAGES/default.po @@ -148,7 +148,7 @@ msgstr "" msgid "Edit Invite" msgstr "" -#: lib/cannery_web/live/tag_live/index.ex:21 +#: lib/cannery_web/live/tag_live/index.ex:28 #, elixir-autogen, elixir-format msgid "Edit Tag" msgstr "" @@ -263,7 +263,7 @@ msgstr "" msgid "New Invite" msgstr "" -#: lib/cannery_web/live/tag_live/index.ex:27 +#: lib/cannery_web/live/tag_live/index.ex:36 #, elixir-autogen, elixir-format msgid "New Tag" msgstr "" @@ -292,6 +292,7 @@ msgstr "" #: lib/cannery_web/live/container_live/edit_tags_component.html.heex:31 #: lib/cannery_web/live/tag_live/index.html.heex:10 +#: lib/cannery_web/live/tag_live/index.html.heex:44 #, elixir-autogen, elixir-format msgid "No tags" msgstr "" @@ -378,7 +379,8 @@ msgstr "" #: lib/cannery_web/components/container_table_component.ex:52 #: lib/cannery_web/components/topbar.ex:49 -#: lib/cannery_web/live/tag_live/index.ex:32 +#: lib/cannery_web/live/tag_live/index.ex:44 +#: lib/cannery_web/live/tag_live/index.ex:54 #: lib/cannery_web/live/tag_live/index.html.heex:3 #, elixir-autogen, elixir-format msgid "Tags" @@ -1116,3 +1118,8 @@ msgstr "" #, elixir-autogen, elixir-format msgid "Search containers" msgstr "" + +#: lib/cannery_web/live/tag_live/index.html.heex:36 +#, elixir-autogen, elixir-format, fuzzy +msgid "Search tags" +msgstr "" diff --git a/priv/gettext/en/LC_MESSAGES/errors.po b/priv/gettext/en/LC_MESSAGES/errors.po index 6fe8c69b..e82fc948 100644 --- a/priv/gettext/en/LC_MESSAGES/errors.po +++ b/priv/gettext/en/LC_MESSAGES/errors.po @@ -128,7 +128,7 @@ msgstr "" msgid "must have the @ sign and no spaces" msgstr "" -#: lib/cannery/tags.ex:39 +#: lib/cannery/tags.ex:66 #, elixir-autogen, elixir-format msgid "Tag not found" msgstr "" diff --git a/priv/gettext/en/LC_MESSAGES/prompts.po b/priv/gettext/en/LC_MESSAGES/prompts.po index 642fcb55..8c53e523 100644 --- a/priv/gettext/en/LC_MESSAGES/prompts.po +++ b/priv/gettext/en/LC_MESSAGES/prompts.po @@ -23,7 +23,7 @@ msgstr "" #: lib/cannery_web/live/ammo_type_live/show.ex:55 #: lib/cannery_web/live/invite_live/index.ex:53 #: lib/cannery_web/live/invite_live/index.ex:133 -#: lib/cannery_web/live/tag_live/index.ex:38 +#: lib/cannery_web/live/tag_live/index.ex:64 #, elixir-autogen, elixir-format msgid "%{name} deleted succesfully" msgstr "" @@ -71,7 +71,7 @@ msgstr "" #: lib/cannery_web/live/container_live/index.html.heex:93 #: lib/cannery_web/live/container_live/index.html.heex:138 #: lib/cannery_web/live/container_live/show.html.heex:59 -#: lib/cannery_web/live/tag_live/index.html.heex:39 +#: lib/cannery_web/live/tag_live/index.html.heex:65 #, elixir-autogen, elixir-format msgid "Are you sure you want to delete %{name}?" msgstr "" diff --git a/priv/gettext/errors.pot b/priv/gettext/errors.pot index 53ce57b2..1f05b890 100644 --- a/priv/gettext/errors.pot +++ b/priv/gettext/errors.pot @@ -127,7 +127,7 @@ msgstr "" msgid "must have the @ sign and no spaces" msgstr "" -#: lib/cannery/tags.ex:39 +#: lib/cannery/tags.ex:66 #, elixir-autogen, elixir-format msgid "Tag not found" msgstr "" diff --git a/priv/gettext/es/LC_MESSAGES/default.po b/priv/gettext/es/LC_MESSAGES/default.po index 13e5d807..b06d7c60 100644 --- a/priv/gettext/es/LC_MESSAGES/default.po +++ b/priv/gettext/es/LC_MESSAGES/default.po @@ -162,7 +162,7 @@ msgstr "" msgid "Edit Invite" msgstr "" -#: lib/cannery_web/live/tag_live/index.ex:21 +#: lib/cannery_web/live/tag_live/index.ex:28 #, elixir-autogen, elixir-format msgid "Edit Tag" msgstr "" @@ -277,7 +277,7 @@ msgstr "" msgid "New Invite" msgstr "" -#: lib/cannery_web/live/tag_live/index.ex:27 +#: lib/cannery_web/live/tag_live/index.ex:36 #, elixir-autogen, elixir-format msgid "New Tag" msgstr "" @@ -306,6 +306,7 @@ msgstr "" #: lib/cannery_web/live/container_live/edit_tags_component.html.heex:31 #: lib/cannery_web/live/tag_live/index.html.heex:10 +#: lib/cannery_web/live/tag_live/index.html.heex:44 #, elixir-autogen, elixir-format msgid "No tags" msgstr "" @@ -392,7 +393,8 @@ msgstr "" #: lib/cannery_web/components/container_table_component.ex:52 #: lib/cannery_web/components/topbar.ex:49 -#: lib/cannery_web/live/tag_live/index.ex:32 +#: lib/cannery_web/live/tag_live/index.ex:44 +#: lib/cannery_web/live/tag_live/index.ex:54 #: lib/cannery_web/live/tag_live/index.html.heex:3 #, elixir-autogen, elixir-format msgid "Tags" @@ -1130,3 +1132,8 @@ msgstr "" #, elixir-autogen, elixir-format msgid "Search containers" msgstr "" + +#: lib/cannery_web/live/tag_live/index.html.heex:36 +#, elixir-autogen, elixir-format, fuzzy +msgid "Search tags" +msgstr "" diff --git a/priv/gettext/es/LC_MESSAGES/errors.po b/priv/gettext/es/LC_MESSAGES/errors.po index 78010b50..4fbd6b57 100644 --- a/priv/gettext/es/LC_MESSAGES/errors.po +++ b/priv/gettext/es/LC_MESSAGES/errors.po @@ -143,7 +143,7 @@ msgstr "no es válido" msgid "must have the @ sign and no spaces" msgstr "debe tener el signo @ y no contener espacios" -#: lib/cannery/tags.ex:39 +#: lib/cannery/tags.ex:66 #, elixir-autogen, elixir-format msgid "Tag not found" msgstr "Etiqueta no encontrada" diff --git a/priv/gettext/es/LC_MESSAGES/prompts.po b/priv/gettext/es/LC_MESSAGES/prompts.po index 6ceb62e5..eac6ab16 100644 --- a/priv/gettext/es/LC_MESSAGES/prompts.po +++ b/priv/gettext/es/LC_MESSAGES/prompts.po @@ -35,7 +35,7 @@ msgstr "%{name} creado exitosamente" #: lib/cannery_web/live/ammo_type_live/show.ex:55 #: lib/cannery_web/live/invite_live/index.ex:53 #: lib/cannery_web/live/invite_live/index.ex:133 -#: lib/cannery_web/live/tag_live/index.ex:38 +#: lib/cannery_web/live/tag_live/index.ex:64 #, elixir-autogen, elixir-format msgid "%{name} deleted succesfully" msgstr "%{name} borrado exitosamente" @@ -85,7 +85,7 @@ msgstr "Está seguro que desea eliminar %{email}? Esta acción es permanente!" #: lib/cannery_web/live/container_live/index.html.heex:93 #: lib/cannery_web/live/container_live/index.html.heex:138 #: lib/cannery_web/live/container_live/show.html.heex:59 -#: lib/cannery_web/live/tag_live/index.html.heex:39 +#: lib/cannery_web/live/tag_live/index.html.heex:65 #, elixir-autogen, elixir-format msgid "Are you sure you want to delete %{name}?" msgstr "Está seguro que desea eliminar %{name}?" diff --git a/priv/gettext/fr/LC_MESSAGES/default.po b/priv/gettext/fr/LC_MESSAGES/default.po index 4094642f..874e1e60 100644 --- a/priv/gettext/fr/LC_MESSAGES/default.po +++ b/priv/gettext/fr/LC_MESSAGES/default.po @@ -162,7 +162,7 @@ msgstr "Simple à utiliser :" msgid "Edit Invite" msgstr "Modifier l’invitation" -#: lib/cannery_web/live/tag_live/index.ex:21 +#: lib/cannery_web/live/tag_live/index.ex:28 #, elixir-autogen, elixir-format msgid "Edit Tag" msgstr "Modifier le tag" @@ -277,7 +277,7 @@ msgstr "Nouveau conteneur" msgid "New Invite" msgstr "Nouvelle invitation" -#: lib/cannery_web/live/tag_live/index.ex:27 +#: lib/cannery_web/live/tag_live/index.ex:36 #, elixir-autogen, elixir-format msgid "New Tag" msgstr "Nouveau tag" @@ -306,6 +306,7 @@ msgstr "Aucune invitation" #: lib/cannery_web/live/container_live/edit_tags_component.html.heex:31 #: lib/cannery_web/live/tag_live/index.html.heex:10 +#: lib/cannery_web/live/tag_live/index.html.heex:44 #, elixir-autogen, elixir-format msgid "No tags" msgstr "Aucun tag" @@ -394,7 +395,8 @@ msgstr "Est stocké dans" #: lib/cannery_web/components/container_table_component.ex:52 #: lib/cannery_web/components/topbar.ex:49 -#: lib/cannery_web/live/tag_live/index.ex:32 +#: lib/cannery_web/live/tag_live/index.ex:44 +#: lib/cannery_web/live/tag_live/index.ex:54 #: lib/cannery_web/live/tag_live/index.html.heex:3 #, elixir-autogen, elixir-format msgid "Tags" @@ -1135,3 +1137,8 @@ msgstr "" #, elixir-autogen, elixir-format msgid "Search containers" msgstr "" + +#: lib/cannery_web/live/tag_live/index.html.heex:36 +#, elixir-autogen, elixir-format, fuzzy +msgid "Search tags" +msgstr "" diff --git a/priv/gettext/fr/LC_MESSAGES/errors.po b/priv/gettext/fr/LC_MESSAGES/errors.po index 897b74c1..9407d5f4 100644 --- a/priv/gettext/fr/LC_MESSAGES/errors.po +++ b/priv/gettext/fr/LC_MESSAGES/errors.po @@ -142,7 +142,7 @@ msgstr "n’est pas valide" msgid "must have the @ sign and no spaces" msgstr "doit contenir le symbole @ et aucune espace" -#: lib/cannery/tags.ex:39 +#: lib/cannery/tags.ex:66 #, elixir-autogen, elixir-format msgid "Tag not found" msgstr "Tag pas trouvé" diff --git a/priv/gettext/fr/LC_MESSAGES/prompts.po b/priv/gettext/fr/LC_MESSAGES/prompts.po index 6d553de1..ae939b5d 100644 --- a/priv/gettext/fr/LC_MESSAGES/prompts.po +++ b/priv/gettext/fr/LC_MESSAGES/prompts.po @@ -35,7 +35,7 @@ msgstr "%{name} créé· avec succès" #: lib/cannery_web/live/ammo_type_live/show.ex:55 #: lib/cannery_web/live/invite_live/index.ex:53 #: lib/cannery_web/live/invite_live/index.ex:133 -#: lib/cannery_web/live/tag_live/index.ex:38 +#: lib/cannery_web/live/tag_live/index.ex:64 #, elixir-autogen, elixir-format msgid "%{name} deleted succesfully" msgstr "%{name} supprimé· avec succès" @@ -86,7 +86,7 @@ msgstr "" #: lib/cannery_web/live/container_live/index.html.heex:93 #: lib/cannery_web/live/container_live/index.html.heex:138 #: lib/cannery_web/live/container_live/show.html.heex:59 -#: lib/cannery_web/live/tag_live/index.html.heex:39 +#: lib/cannery_web/live/tag_live/index.html.heex:65 #, elixir-autogen, elixir-format msgid "Are you sure you want to delete %{name}?" msgstr "Êtes-vous certain·e de supprimer %{name} ?" diff --git a/priv/gettext/ga/LC_MESSAGES/default.po b/priv/gettext/ga/LC_MESSAGES/default.po index c6cf8f68..56d6eb6d 100644 --- a/priv/gettext/ga/LC_MESSAGES/default.po +++ b/priv/gettext/ga/LC_MESSAGES/default.po @@ -158,7 +158,7 @@ msgstr "" msgid "Edit Invite" msgstr "" -#: lib/cannery_web/live/tag_live/index.ex:21 +#: lib/cannery_web/live/tag_live/index.ex:28 #, elixir-autogen, elixir-format msgid "Edit Tag" msgstr "" @@ -273,7 +273,7 @@ msgstr "" msgid "New Invite" msgstr "" -#: lib/cannery_web/live/tag_live/index.ex:27 +#: lib/cannery_web/live/tag_live/index.ex:36 #, elixir-autogen, elixir-format msgid "New Tag" msgstr "" @@ -302,6 +302,7 @@ msgstr "" #: lib/cannery_web/live/container_live/edit_tags_component.html.heex:31 #: lib/cannery_web/live/tag_live/index.html.heex:10 +#: lib/cannery_web/live/tag_live/index.html.heex:44 #, elixir-autogen, elixir-format msgid "No tags" msgstr "" @@ -388,7 +389,8 @@ msgstr "" #: lib/cannery_web/components/container_table_component.ex:52 #: lib/cannery_web/components/topbar.ex:49 -#: lib/cannery_web/live/tag_live/index.ex:32 +#: lib/cannery_web/live/tag_live/index.ex:44 +#: lib/cannery_web/live/tag_live/index.ex:54 #: lib/cannery_web/live/tag_live/index.html.heex:3 #, elixir-autogen, elixir-format msgid "Tags" @@ -1126,3 +1128,8 @@ msgstr "" #, elixir-autogen, elixir-format msgid "Search containers" msgstr "" + +#: lib/cannery_web/live/tag_live/index.html.heex:36 +#, elixir-autogen, elixir-format, fuzzy +msgid "Search tags" +msgstr "" diff --git a/priv/gettext/ga/LC_MESSAGES/errors.po b/priv/gettext/ga/LC_MESSAGES/errors.po index 46148894..c75c772c 100644 --- a/priv/gettext/ga/LC_MESSAGES/errors.po +++ b/priv/gettext/ga/LC_MESSAGES/errors.po @@ -143,7 +143,7 @@ msgstr "" msgid "must have the @ sign and no spaces" msgstr "" -#: lib/cannery/tags.ex:39 +#: lib/cannery/tags.ex:66 #, elixir-autogen, elixir-format msgid "Tag not found" msgstr "" diff --git a/priv/gettext/ga/LC_MESSAGES/prompts.po b/priv/gettext/ga/LC_MESSAGES/prompts.po index 52d8d209..c1f4f122 100644 --- a/priv/gettext/ga/LC_MESSAGES/prompts.po +++ b/priv/gettext/ga/LC_MESSAGES/prompts.po @@ -33,7 +33,7 @@ msgstr "" #: lib/cannery_web/live/ammo_type_live/show.ex:55 #: lib/cannery_web/live/invite_live/index.ex:53 #: lib/cannery_web/live/invite_live/index.ex:133 -#: lib/cannery_web/live/tag_live/index.ex:38 +#: lib/cannery_web/live/tag_live/index.ex:64 #, elixir-autogen, elixir-format msgid "%{name} deleted succesfully" msgstr "" @@ -81,7 +81,7 @@ msgstr "" #: lib/cannery_web/live/container_live/index.html.heex:93 #: lib/cannery_web/live/container_live/index.html.heex:138 #: lib/cannery_web/live/container_live/show.html.heex:59 -#: lib/cannery_web/live/tag_live/index.html.heex:39 +#: lib/cannery_web/live/tag_live/index.html.heex:65 #, elixir-autogen, elixir-format msgid "Are you sure you want to delete %{name}?" msgstr "" diff --git a/priv/gettext/prompts.pot b/priv/gettext/prompts.pot index 78dfc924..87adeac3 100644 --- a/priv/gettext/prompts.pot +++ b/priv/gettext/prompts.pot @@ -22,7 +22,7 @@ msgstr "" #: lib/cannery_web/live/ammo_type_live/show.ex:55 #: lib/cannery_web/live/invite_live/index.ex:53 #: lib/cannery_web/live/invite_live/index.ex:133 -#: lib/cannery_web/live/tag_live/index.ex:38 +#: lib/cannery_web/live/tag_live/index.ex:64 #, elixir-autogen, elixir-format msgid "%{name} deleted succesfully" msgstr "" @@ -70,7 +70,7 @@ msgstr "" #: lib/cannery_web/live/container_live/index.html.heex:93 #: lib/cannery_web/live/container_live/index.html.heex:138 #: lib/cannery_web/live/container_live/show.html.heex:59 -#: lib/cannery_web/live/tag_live/index.html.heex:39 +#: lib/cannery_web/live/tag_live/index.html.heex:65 #, elixir-autogen, elixir-format msgid "Are you sure you want to delete %{name}?" msgstr "" diff --git a/test/cannery/tags_test.exs b/test/cannery/tags_test.exs index 748f476e..da315ebd 100644 --- a/test/cannery/tags_test.exs +++ b/test/cannery/tags_test.exs @@ -31,10 +31,28 @@ defmodule Cannery.TagsTest do [tag: tag_fixture(current_user), current_user: current_user] end - test "list_tags/0 returns all tags", %{tag: tag, current_user: current_user} do + test "list_tags/1 returns all tags", %{tag: tag, current_user: current_user} do assert Tags.list_tags(current_user) == [tag] end + test "list_tags/2 returns relevant tags for a user", %{current_user: current_user} do + tag_a = tag_fixture(%{"name" => "bullets"}, current_user) + tag_b = tag_fixture(%{"name" => "hollows"}, current_user) + + _shouldnt_return = + %{ + "name" => "bullet", + "desc" => "pews brass shell" + } + |> tag_fixture(user_fixture()) + + # name + assert Tags.list_tags("bullet", current_user) == [tag_a] + assert Tags.list_tags("bullets", current_user) == [tag_a] + assert Tags.list_tags("hollow", current_user) == [tag_b] + assert Tags.list_tags("hollows", current_user) == [tag_b] + end + test "get_tag!/1 returns the tag with given id", %{tag: tag, current_user: current_user} do assert Tags.get_tag!(tag.id, current_user) == tag end diff --git a/test/cannery_web/live/tag_live_test.exs b/test/cannery_web/live/tag_live_test.exs index 70747d1a..17b98073 100644 --- a/test/cannery_web/live/tag_live_test.exs +++ b/test/cannery_web/live/tag_live_test.exs @@ -41,6 +41,32 @@ defmodule CanneryWeb.TagLiveTest do assert html =~ tag.bg_color end + test "can search for tag", %{conn: conn, tag: tag} do + {:ok, index_live, html} = live(conn, Routes.tag_index_path(conn, :index)) + + assert html =~ tag.name + + assert index_live + |> form("[data-qa=\"tag_search\"]", + search: %{search_term: tag.name} + ) + |> render_change() =~ tag.name + + assert_patch(index_live, Routes.tag_index_path(conn, :search, tag.name)) + + refute index_live + |> form("[data-qa=\"tag_search\"]", search: %{search_term: "something_else"}) + |> render_change() =~ tag.name + + assert_patch(index_live, Routes.tag_index_path(conn, :search, "something_else")) + + assert index_live + |> form("[data-qa=\"tag_search\"]", search: %{search_term: ""}) + |> render_change() =~ tag.name + + assert_patch(index_live, Routes.tag_index_path(conn, :index)) + end + test "saves new tag", %{conn: conn} do {:ok, index_live, _html} = live(conn, Routes.tag_index_path(conn, :index))