diff --git a/lib/mindwendel/brainstormings.ex b/lib/mindwendel/brainstormings.ex index cc393982..80567d80 100644 --- a/lib/mindwendel/brainstormings.ex +++ b/lib/mindwendel/brainstormings.ex @@ -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 diff --git a/lib/mindwendel_web/live/admin/brainstorming_live/edit.ex b/lib/mindwendel_web/live/admin/brainstorming_live/edit.ex index 51c0fb1e..71b756fc 100644 --- a/lib/mindwendel_web/live/admin/brainstorming_live/edit.ex +++ b/lib/mindwendel_web/live/admin/brainstorming_live/edit.ex @@ -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) diff --git a/lib/mindwendel_web/live/admin/brainstorming_live/edit.html.heex b/lib/mindwendel_web/live/admin/brainstorming_live/edit.html.heex index 34d58572..024333a9 100644 --- a/lib/mindwendel_web/live/admin/brainstorming_live/edit.html.heex +++ b/lib/mindwendel_web/live/admin/brainstorming_live/edit.html.heex @@ -184,6 +184,31 @@ +
+ <%= gettext( + "Attention: This will delete all ideas in this brainstorming. The brainstorming itself and labels will be left unchanged. This cant be undone." + ) %> +
+ +