Skip to content

Commit

Permalink
invoke App.ListItems.add_all_items_to_all_list_for_person_id/1 in mou…
Browse files Browse the repository at this point in the history
…nt to ensure All items on "all" list #145 #356
  • Loading branch information
nelsonic committed Aug 31, 2023
1 parent 7f91403 commit 7ef0509
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
10 changes: 8 additions & 2 deletions lib/app/cid.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ defmodule App.Cid do
This is done transparently so nobody needs to _think_ about cids.
"""
def put_cid(changeset) do
# don't add a cid to a changeset that already has one
if Map.has_key?(changeset.changes, :cid) do
changeset
else
cid = Cid.cid(changeset.changes)
%{changeset | changes: Map.put(changeset.changes, :cid, cid)}
# Only add cid to changeset that has :name i.e. list.name or :text i.e. item.text
if Map.has_key?(changeset.changes, :name) || Map.has_key?(changeset.changes, :text) do
cid = Cid.cid(changeset.changes)
%{changeset | changes: Map.put(changeset.changes, :cid, cid)}
else
changeset
end
end
end
end
4 changes: 1 addition & 3 deletions lib/app/item.ex
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ defmodule App.Item do
all_list = App.List.get_all_list_for_person(person_id)
# dbg(all_list)
seq = App.ListItems.get_list_items(all_list.cid)
dbg(seq)
# dbg(seq)

sql = """
SELECT i.id, i.cid, i.text, i.status, i.person_id, i.updated_at,
Expand All @@ -245,8 +245,6 @@ defmodule App.Item do
Ecto.Adapters.SQL.query!(Repo, sql, [seq])
|> map_columns_to_values()

dbg(values)

items_tags =
list_person_items(person_id)
|> Enum.reduce(%{}, fn i, acc -> Map.put(acc, i.id, i) end)
Expand Down
11 changes: 8 additions & 3 deletions lib/app_web/live/app_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ defmodule AppWeb.AppLive do
all_list = App.List.get_all_list_for_person(person_id)
# dbg(all_list)
# Temporary function to add All *existing* items to the "All" list:
# App.ListItems.add_all_items_to_all_list_for_person_id(person_id)
App.ListItems.add_all_items_to_all_list_for_person_id(person_id)

items = Item.items_with_timers(person_id)
tags = Tag.list_person_tags(person_id)
Expand Down Expand Up @@ -98,7 +98,7 @@ defmodule AppWeb.AppLive do

# need to restrict getting items to the people who own or have rights to access them!
item = Item.get_item!(Map.get(data, "id"))
Item.update_item(item, %{status: status, person_id: person_id})
Item.update_item(item, %{status: status, person_id: person_id, cid: item.cid})
Timer.stop_timer_for_item_id(item.id)

AppWeb.Endpoint.broadcast(@topic, "update", :toggle)
Expand Down Expand Up @@ -401,7 +401,11 @@ defmodule AppWeb.AppLive do

# 2: uncategorised (when item are created), 3: active
def status?(item), do: not is_nil(item) && Map.has_key?(item, :status)
def active?(item), do: status?(item) && item.status == 2 || status?(item) && item.status == 3

def active?(item),
do:
(status?(item) && item.status == 2) || (status?(item) && item.status == 3)

def done?(item), do: status?(item) && item.status == 4
def archived?(item), do: status?(item) && item.status == 6

Expand Down Expand Up @@ -483,6 +487,7 @@ defmodule AppWeb.AppLive do
defp filter_items(items, filter, filter_tag) do
# avoid nil items mvp#412
items = Enum.reject(items, &is_nil/1)

items =
case filter do
"active" ->
Expand Down

0 comments on commit 7ef0509

Please sign in to comment.