diff --git a/lib/app/item.ex b/lib/app/item.ex index 5fdb282d..a156a2c5 100644 --- a/lib/app/item.ex +++ b/lib/app/item.ex @@ -3,6 +3,7 @@ defmodule App.Item do import Ecto.Changeset import Ecto.Query alias App.{Repo, Tag, ItemTag, Person} + alias App.List, as: L alias __MODULE__ schema "items" do @@ -11,12 +12,13 @@ defmodule App.Item do belongs_to :people, Person, references: :person_id, foreign_key: :person_id many_to_many(:tags, Tag, join_through: ItemTag, on_replace: :delete) + many_to_many(:lists, L, join_through: "items_lists", on_replace: :delete) timestamps() end @doc false - def changeset(item, attrs) do + def changeset(item, attrs \\ %{}) do item |> cast(attrs, [:person_id, :status, :text]) |> validate_required([:text, :person_id]) @@ -69,6 +71,7 @@ defmodule App.Item do Item |> Repo.get!(id) |> Repo.preload(tags: from(t in Tag, order_by: t.text)) + |> Repo.preload(lists: from(l in L, order_by: l.name)) end @doc """ diff --git a/lib/app_web/controllers/item_controller.ex b/lib/app_web/controllers/item_controller.ex new file mode 100644 index 00000000..505e8a58 --- /dev/null +++ b/lib/app_web/controllers/item_controller.ex @@ -0,0 +1,15 @@ +defmodule AppWeb.ItemController do + use AppWeb, :controller + alias App.{Item, List} + # plug :permission_tag when action in [:edit, :update, :delete] + + def edit(conn, %{"id" => id}) do + person_id = conn.assigns[:person][:id] || 0 + + item = Item.get_item!(id) + lists = List.list_person_lists(person_id) + + changeset = Item.changeset(item) + render(conn, "edit.html", item: item, lists: lists, changeset: changeset) + end +end diff --git a/lib/app_web/live/app_live.html.heex b/lib/app_web/live/app_live.html.heex index d013a74a..bb9f87f2 100644 --- a/lib/app_web/live/app_live.html.heex +++ b/lib/app_web/live/app_live.html.heex @@ -258,6 +258,10 @@ <%= live_patch tag.text, to: Routes.live_path(@socket, AppWeb.AppLive, %{filter_by: @filter, filter_by_tag: tag.text}), style: "background-color:#{tag.color}", class: " text-white font-bold py-1 px-2 rounded-full" %> <% end %> + +
Oops, something went wrong! Please check the errors below.
+