Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: allow deletion of all cards in a brainstorming #271 #272

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/mindwendel/brainstormings.ex
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,13 @@ defmodule Mindwendel.Brainstormings do
end)
end

def empty(%Brainstorming{} = brainstorming) do
# we only delete ideas - labels and users should be left intact:
Repo.delete_all(from idea in Idea, where: idea.brainstorming_id == ^brainstorming.id)

broadcast({:ok, brainstorming}, :brainstorming_updated)
end

@doc """
Deletes all brainstormings, older than 30 days since creation

Expand Down
12 changes: 12 additions & 0 deletions lib/mindwendel_web/live/admin/brainstorming_live/edit.ex
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,18 @@ defmodule MindwendelWeb.Admin.BrainstormingLive.Edit do
end
end

def handle_event("empty", %{"value" => brainstorming_admin_url_id}, socket)
when brainstorming_admin_url_id == socket.assigns.brainstorming.admin_url_id do
brainstorming = socket.assigns.brainstorming

Brainstormings.empty(brainstorming)

{:noreply,
redirect(socket,
to: Routes.brainstorming_show_path(socket, :show, brainstorming)
)}
end

defp cancel_changeset_timer(socket) do
if socket.assigns[:reset_changeset_timer_ref],
do: Process.cancel_timer(socket.assigns.reset_changeset_timer_ref)
Expand Down
25 changes: 25 additions & 0 deletions lib/mindwendel_web/live/admin/brainstorming_live/edit.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,31 @@
</div>
</div>

<div class="card border-danger mb-3">
<div class="card-header">
<h4><%= gettext("Empty brainstorming") %></h4>
</div>
<div class="card-body">
<div class="row mb-3">
<div class="col">
<p>
<%= gettext(
"Attention: This will delete all ideas in this brainstorming. The brainstorming itself and labels will be left unchanged. This cant be undone."
) %>
</p>
<button
class="btn btn-danger"
phx-click="empty"
value={@brainstorming.admin_url_id}
data-confirm={gettext("Brainstorming will be emptied - are you sure")}
>
<%= gettext("Empty brainstorming") %>
</button>
</div>
</div>
</div>
</div>

<div class="card border-danger mb-3">
<div class="card-header">
<h4><%= gettext("Delete Brainstorming") %></h4>
Expand Down
1 change: 1 addition & 0 deletions lib/mindwendel_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ defmodule MindwendelWeb.Router do
delete("/brainstormings/:id", BrainstormingController, :delete)
get("/brainstormings/:id/export", BrainstormingController, :export)
live("/brainstormings/:id/edit", BrainstormingLive.Edit, :edit)
live("/brainstormings/:id/empty", BrainstormingLive.Edit, :empty)
end

post("/brainstormings", BrainstormingController, :create)
Expand Down
24 changes: 20 additions & 4 deletions priv/gettext/de/LC_MESSAGES/default.po
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ msgstr "%{name} - Neue Idee"
msgid "Are you sure you want to delete this idea?"
msgstr "Möchtest du die Idee löschen?"

#: lib/mindwendel_web/live/admin/brainstorming_live/edit.html.heex:195
#: lib/mindwendel_web/live/admin/brainstorming_live/edit.html.heex:220
#, elixir-autogen, elixir-format
msgid "Attention: This will delete the brainstorming with all belonging ideas and other associated records to it. This cant be undone"
msgstr "Achtung: Hiermit löschst du das Brainstorming und alle dazugehörigen Ideen. Diese Aktion kann nicht rückgängig gemacht werden."
Expand All @@ -67,12 +67,12 @@ msgstr "Erstelle ein Brainstorming."
msgid "Create!"
msgstr "Erstellen!"

#: lib/mindwendel_web/live/admin/brainstorming_live/edit.html.heex:199
#: lib/mindwendel_web/live/admin/brainstorming_live/edit.html.heex:224
#, elixir-autogen, elixir-format
msgid "Delete"
msgstr "Löschen"

#: lib/mindwendel_web/live/admin/brainstorming_live/edit.html.heex:189
#: lib/mindwendel_web/live/admin/brainstorming_live/edit.html.heex:214
#, elixir-autogen, elixir-format
msgid "Delete Brainstorming"
msgstr "Lösche Brainstorming"
Expand Down Expand Up @@ -343,7 +343,7 @@ msgstr "Download als PNG"
msgid "Download as svg"
msgstr "Download als SVG"

#: lib/mindwendel_web/live/admin/brainstorming_live/edit.html.heex:200
#: lib/mindwendel_web/live/admin/brainstorming_live/edit.html.heex:225
#, elixir-autogen, elixir-format, fuzzy
msgid "Brainstorming delete are you sure"
msgstr "Bist du sicher, dass das Brainstorming gelöscht werden soll?"
Expand All @@ -367,3 +367,19 @@ msgstr ""
#, elixir-autogen, elixir-format, fuzzy
msgid "Brainstorming will be deleted in %{days}"
msgstr "Brainstorming wird gelöscht in "

#: lib/mindwendel_web/live/admin/brainstorming_live/edit.html.heex:195
#, elixir-autogen, elixir-format, fuzzy
msgid "Attention: This will delete all ideas in this brainstorming. The brainstorming itself and labels will be left unchanged. This cant be undone."
msgstr "Achtung: Hiermit löscht Du alle Ideen in diesem Brainstorming. Das Brainstorming und die Labels bleiben unverändert. Diese Aktion kann nicht rückgängig gemacht werden."

#: lib/mindwendel_web/live/admin/brainstorming_live/edit.html.heex:203
#, elixir-autogen, elixir-format, fuzzy
msgid "Brainstorming will be emptied - are you sure"
msgstr "Bist du sicher, dass das Brainstorming geleert werden soll?"

#: lib/mindwendel_web/live/admin/brainstorming_live/edit.html.heex:189
#: lib/mindwendel_web/live/admin/brainstorming_live/edit.html.heex:205
#, elixir-autogen, elixir-format, fuzzy
msgid "Empty brainstorming"
msgstr "Leere das Brainstorming"
24 changes: 20 additions & 4 deletions priv/gettext/default.pot
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ msgstr ""
msgid "Are you sure you want to delete this idea?"
msgstr ""

#: lib/mindwendel_web/live/admin/brainstorming_live/edit.html.heex:195
#: lib/mindwendel_web/live/admin/brainstorming_live/edit.html.heex:220
#, elixir-autogen, elixir-format
msgid "Attention: This will delete the brainstorming with all belonging ideas and other associated records to it. This cant be undone"
msgstr ""
Expand All @@ -66,12 +66,12 @@ msgstr ""
msgid "Create!"
msgstr ""

#: lib/mindwendel_web/live/admin/brainstorming_live/edit.html.heex:199
#: lib/mindwendel_web/live/admin/brainstorming_live/edit.html.heex:224
#, elixir-autogen, elixir-format
msgid "Delete"
msgstr ""

#: lib/mindwendel_web/live/admin/brainstorming_live/edit.html.heex:189
#: lib/mindwendel_web/live/admin/brainstorming_live/edit.html.heex:214
#, elixir-autogen, elixir-format
msgid "Delete Brainstorming"
msgstr ""
Expand Down Expand Up @@ -342,7 +342,7 @@ msgstr ""
msgid "Download as svg"
msgstr ""

#: lib/mindwendel_web/live/admin/brainstorming_live/edit.html.heex:200
#: lib/mindwendel_web/live/admin/brainstorming_live/edit.html.heex:225
#, elixir-autogen, elixir-format
msgid "Brainstorming delete are you sure"
msgstr ""
Expand All @@ -366,3 +366,19 @@ msgstr ""
#, elixir-autogen, elixir-format
msgid "Brainstorming will be deleted in %{days}"
msgstr ""

#: lib/mindwendel_web/live/admin/brainstorming_live/edit.html.heex:195
#, elixir-autogen, elixir-format
msgid "Attention: This will delete all ideas in this brainstorming. The brainstorming itself and labels will be left unchanged. This cant be undone."
msgstr ""

#: lib/mindwendel_web/live/admin/brainstorming_live/edit.html.heex:203
#, elixir-autogen, elixir-format
msgid "Brainstorming will be emptied - are you sure"
msgstr ""

#: lib/mindwendel_web/live/admin/brainstorming_live/edit.html.heex:189
#: lib/mindwendel_web/live/admin/brainstorming_live/edit.html.heex:205
#, elixir-autogen, elixir-format
msgid "Empty brainstorming"
msgstr ""
24 changes: 20 additions & 4 deletions priv/gettext/en/LC_MESSAGES/default.po
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ msgstr ""
msgid "Are you sure you want to delete this idea?"
msgstr ""

#: lib/mindwendel_web/live/admin/brainstorming_live/edit.html.heex:195
#: lib/mindwendel_web/live/admin/brainstorming_live/edit.html.heex:220
#, elixir-autogen, elixir-format
msgid "Attention: This will delete the brainstorming with all belonging ideas and other associated records to it. This cant be undone"
msgstr ""
Expand All @@ -67,12 +67,12 @@ msgstr ""
msgid "Create!"
msgstr ""

#: lib/mindwendel_web/live/admin/brainstorming_live/edit.html.heex:199
#: lib/mindwendel_web/live/admin/brainstorming_live/edit.html.heex:224
#, elixir-autogen, elixir-format
msgid "Delete"
msgstr ""

#: lib/mindwendel_web/live/admin/brainstorming_live/edit.html.heex:189
#: lib/mindwendel_web/live/admin/brainstorming_live/edit.html.heex:214
#, elixir-autogen, elixir-format
msgid "Delete Brainstorming"
msgstr ""
Expand Down Expand Up @@ -343,7 +343,7 @@ msgstr "Download as png"
msgid "Download as svg"
msgstr "Download as svg"

#: lib/mindwendel_web/live/admin/brainstorming_live/edit.html.heex:200
#: lib/mindwendel_web/live/admin/brainstorming_live/edit.html.heex:225
#, elixir-autogen, elixir-format, fuzzy
msgid "Brainstorming delete are you sure"
msgstr "Are you sure that you want to delete this brainstorming?"
Expand All @@ -367,3 +367,19 @@ msgstr ""
#, elixir-autogen, elixir-format, fuzzy
msgid "Brainstorming will be deleted in %{days}"
msgstr ""

#: lib/mindwendel_web/live/admin/brainstorming_live/edit.html.heex:195
#, elixir-autogen, elixir-format, fuzzy
msgid "Attention: This will delete all ideas in this brainstorming. The brainstorming itself and labels will be left unchanged. This cant be undone."
msgstr ""

#: lib/mindwendel_web/live/admin/brainstorming_live/edit.html.heex:203
#, elixir-autogen, elixir-format, fuzzy
msgid "Brainstorming will be emptied - are you sure"
msgstr "Are you sure that you want to delete this brainstorming?"

#: lib/mindwendel_web/live/admin/brainstorming_live/edit.html.heex:189
#: lib/mindwendel_web/live/admin/brainstorming_live/edit.html.heex:205
#, elixir-autogen, elixir-format, fuzzy
msgid "Empty brainstorming"
msgstr ""
58 changes: 58 additions & 0 deletions test/mindwendel/brainstormings_test.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule Mindwendel.BrainstormingsTest do
alias Mindwendel.Brainstormings.IdeaIdeaLabel
use Mindwendel.DataCase
alias Mindwendel.Brainstormings.BrainstormingModeratingUser
alias Mindwendel.Factory
Expand Down Expand Up @@ -311,4 +312,61 @@ defmodule Mindwendel.BrainstormingsTest do
assert Repo.exists?(from(b in Brainstorming, where: b.id == ^brainstorming.id))
end
end

describe "empty/1 brainstormings" do
test "empty/1 removes all ideas from a brainstorming", %{brainstorming: brainstorming} do
brainstorming = brainstorming |> Repo.preload([:ideas])
assert Enum.count(brainstorming.ideas) == 1
Brainstormings.empty(brainstorming)
# reload brainstorming:
brainstorming = Brainstormings.get_brainstorming!(brainstorming.id)
brainstorming = brainstorming |> Repo.preload([:ideas])
assert Enum.count(brainstorming.ideas) == 0
end

test "empty/1 also clears likes and labels from ideas", %{brainstorming: brainstorming} do
idea =
Factory.insert!(:idea,
brainstorming: brainstorming,
inserted_at: ~N[2021-01-01 15:04:30]
)

like = Factory.insert!(:like, idea: idea)

{:ok, idea} =
Brainstormings.add_idea_label_to_idea(idea, Enum.at(brainstorming.labels, 0))

idea = idea |> Repo.preload([:idea_labels])

Brainstormings.empty(brainstorming)
# reload brainstorming:
brainstorming = Brainstormings.get_brainstorming!(brainstorming.id)

assert Enum.count(brainstorming.ideas) == 0
assert Repo.get_by(Idea, id: idea.id) == nil
assert Repo.get_by(IdeaIdeaLabel, idea_id: idea.id) == nil
assert Repo.get_by(Like, id: like.id) == nil
end

test "empty/1 does not removes all ideas from other brainstormings", %{
brainstorming: brainstorming
} do
other_brainstorming = Factory.insert!(:brainstorming)

Factory.insert!(:idea,
brainstorming: other_brainstorming
)

other_brainstorming = other_brainstorming |> Repo.preload([:ideas])

assert Enum.count(other_brainstorming.ideas) == 1
Brainstormings.empty(brainstorming)
# reload brainstorming:
brainstorming = Brainstormings.get_brainstorming!(brainstorming.id)
brainstorming = brainstorming |> Repo.preload([:ideas])
other_brainstorming = other_brainstorming |> Repo.preload([:ideas])
assert Enum.count(brainstorming.ideas) == 0
assert Enum.count(other_brainstorming.ideas) == 1
end
end
end
32 changes: 31 additions & 1 deletion test/mindwendel_web/live/admin/brainstorming_live/edit_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@ defmodule MindwendelWeb.Admin.BrainstormingLive.EditTest do

alias Mindwendel.Factory

alias Mindwendel.Brainstormings

setup do
%{brainstorming: Factory.insert!(:brainstorming)}
brainstorming = Factory.insert!(:brainstorming)

%{
brainstorming: brainstorming,
idea:
Factory.insert!(:idea, brainstorming: brainstorming, inserted_at: ~N[2021-01-01 15:04:30])
}
end

test "connected mount", %{
Expand Down Expand Up @@ -130,6 +138,28 @@ defmodule MindwendelWeb.Admin.BrainstormingLive.EditTest do
assert edit_live_view |> element("input#brainstorming_labels_4_name") |> has_element?
end

describe "empty brainstorming" do
test "handles empty event to delete brainstorming content", %{
conn: conn,
brainstorming: brainstorming
} do
{:ok, edit_live_view, _html} =
live(conn, Routes.admin_brainstorming_edit_path(conn, :edit, brainstorming.admin_url_id))

# reload brainstorming to check for changes:
brainstorming = Brainstormings.get_brainstorming!(brainstorming.id)
assert Enum.count(brainstorming.ideas) == 1

edit_live_view
|> element("button", "Empty")
|> render_click()

# reload brainstorming to check for changes:
brainstorming = Brainstormings.get_brainstorming!(brainstorming.id)
assert Enum.count(brainstorming.ideas) == 0
end
end

defp html_selector_remove_idea_label_button(idea_label) do
"button[value=\"#{idea_label.id}\"]"
end
Expand Down
20 changes: 0 additions & 20 deletions test/mindwendel_web/live/live_helpers_test.ex

This file was deleted.

Loading