From e81fa50701656176ecc8c9e8a34c8b8849733339 Mon Sep 17 00:00:00 2001 From: Emiel Date: Thu, 3 Oct 2024 22:26:22 +0200 Subject: [PATCH] Refactor Participant Finished View --- .../gettext/de/LC_MESSAGES/eyra-assignment.po | 4 + core/priv/gettext/de/LC_MESSAGES/eyra-ui.po | 4 - .../gettext/en/LC_MESSAGES/eyra-assignment.po | 6 +- core/priv/gettext/en/LC_MESSAGES/eyra-ui.po | 4 - core/priv/gettext/eyra-assignment.pot | 4 + core/priv/gettext/eyra-ui.pot | 4 - .../gettext/nl/LC_MESSAGES/eyra-assignment.po | 4 + core/priv/gettext/nl/LC_MESSAGES/eyra-ui.po | 4 - core/systems/assignment/crew_work_view.ex | 107 ++++++++++++------ core/systems/assignment/finished_view.ex | 39 +++++-- .../systems/assignment/crew_page_test.exs | 2 +- 11 files changed, 121 insertions(+), 61 deletions(-) diff --git a/core/priv/gettext/de/LC_MESSAGES/eyra-assignment.po b/core/priv/gettext/de/LC_MESSAGES/eyra-assignment.po index a06e5f59e..01f1eb78e 100644 --- a/core/priv/gettext/de/LC_MESSAGES/eyra-assignment.po +++ b/core/priv/gettext/de/LC_MESSAGES/eyra-assignment.po @@ -456,3 +456,7 @@ msgstr "" #, elixir-autogen, elixir-format msgid "progress.yes" msgstr "" + +#, elixir-autogen, elixir-format, fuzzy +msgid "retry.button" +msgstr "Zurück zu den Aufgaben" diff --git a/core/priv/gettext/de/LC_MESSAGES/eyra-ui.po b/core/priv/gettext/de/LC_MESSAGES/eyra-ui.po index d4517340a..665710114 100644 --- a/core/priv/gettext/de/LC_MESSAGES/eyra-ui.po +++ b/core/priv/gettext/de/LC_MESSAGES/eyra-ui.po @@ -159,10 +159,6 @@ msgstr "" msgid "submit.button" msgstr "" -#, elixir-autogen, elixir-format -msgid "close.button" -msgstr "Schließen" - #, elixir-autogen, elixir-format msgid "done.button" msgstr "" diff --git a/core/priv/gettext/en/LC_MESSAGES/eyra-assignment.po b/core/priv/gettext/en/LC_MESSAGES/eyra-assignment.po index 927d35011..30335aa72 100644 --- a/core/priv/gettext/en/LC_MESSAGES/eyra-assignment.po +++ b/core/priv/gettext/en/LC_MESSAGES/eyra-assignment.po @@ -252,7 +252,7 @@ msgstr "Consent declined" #, elixir-autogen, elixir-format msgid "finished_view.body" -msgstr "You have finished. Thank you for your participation. You can now close your browser or close this popup to revisit the page." +msgstr "You have finished. Thank you for your participation." #, elixir-autogen, elixir-format msgid "finished_view.title" @@ -455,3 +455,7 @@ msgstr "n/a" #, elixir-autogen, elixir-format msgid "progress.yes" msgstr "yes" + +#, elixir-autogen, elixir-format, fuzzy +msgid "retry.button" +msgstr "Back to the tasks" diff --git a/core/priv/gettext/en/LC_MESSAGES/eyra-ui.po b/core/priv/gettext/en/LC_MESSAGES/eyra-ui.po index 6c153f882..3fdccf1b1 100644 --- a/core/priv/gettext/en/LC_MESSAGES/eyra-ui.po +++ b/core/priv/gettext/en/LC_MESSAGES/eyra-ui.po @@ -158,10 +158,6 @@ msgstr "Copy" msgid "submit.button" msgstr "Save" -#, elixir-autogen, elixir-format, fuzzy -msgid "close.button" -msgstr "Close" - #, elixir-autogen, elixir-format, fuzzy msgid "done.button" msgstr "Done" diff --git a/core/priv/gettext/eyra-assignment.pot b/core/priv/gettext/eyra-assignment.pot index 28778b880..0b007f588 100644 --- a/core/priv/gettext/eyra-assignment.pot +++ b/core/priv/gettext/eyra-assignment.pot @@ -455,3 +455,7 @@ msgstr "" #, elixir-autogen, elixir-format msgid "progress.yes" msgstr "" + +#, elixir-autogen, elixir-format +msgid "retry.button" +msgstr "" diff --git a/core/priv/gettext/eyra-ui.pot b/core/priv/gettext/eyra-ui.pot index e7b873e4f..a5331a53a 100644 --- a/core/priv/gettext/eyra-ui.pot +++ b/core/priv/gettext/eyra-ui.pot @@ -158,10 +158,6 @@ msgstr "" msgid "submit.button" msgstr "" -#, elixir-autogen, elixir-format -msgid "close.button" -msgstr "" - #, elixir-autogen, elixir-format msgid "done.button" msgstr "" diff --git a/core/priv/gettext/nl/LC_MESSAGES/eyra-assignment.po b/core/priv/gettext/nl/LC_MESSAGES/eyra-assignment.po index 91d1af64a..ab050ca3a 100644 --- a/core/priv/gettext/nl/LC_MESSAGES/eyra-assignment.po +++ b/core/priv/gettext/nl/LC_MESSAGES/eyra-assignment.po @@ -455,3 +455,7 @@ msgstr "" #, elixir-autogen, elixir-format msgid "progress.yes" msgstr "" + +#, elixir-autogen, elixir-format, fuzzy +msgid "retry.button" +msgstr "Terug naar de taken" diff --git a/core/priv/gettext/nl/LC_MESSAGES/eyra-ui.po b/core/priv/gettext/nl/LC_MESSAGES/eyra-ui.po index 5151af3a0..2e22db9d7 100644 --- a/core/priv/gettext/nl/LC_MESSAGES/eyra-ui.po +++ b/core/priv/gettext/nl/LC_MESSAGES/eyra-ui.po @@ -158,10 +158,6 @@ msgstr "Kopieer" msgid "submit.button" msgstr "Opslaan" -#, elixir-autogen, elixir-format, fuzzy -msgid "close.button" -msgstr "Sluiten" - #, elixir-autogen, elixir-format, fuzzy msgid "done.button" msgstr "Klaar" diff --git a/core/systems/assignment/crew_work_view.ex b/core/systems/assignment/crew_work_view.ex index 566728183..44a52bcee 100644 --- a/core/systems/assignment/crew_work_view.ex +++ b/core/systems/assignment/crew_work_view.ex @@ -26,17 +26,18 @@ defmodule Systems.Assignment.CrewWorkView do crew: crew, user: user, timezone: timezone, - panel_info: panel_info, + panel_info: %{embedded?: embedded?} = panel_info, tester?: tester? }, socket ) do + retry? = Map.get(socket.assigns, :retry?, false) tool_started = Map.get(socket.assigns, :tool_started, false) tool_initialized = Map.get(socket.assigns, :tool_initialized, false) - tasks_finished? = Map.get(socket.assigns, :tasks_finished?, tasks_finished?(work_items)) + initial? = Map.get(socket.assigns, :work_items) == nil + tasks_finished? = tasks_finished?(work_items) - { - :ok, + socket = socket |> assign( work_items: work_items, @@ -52,16 +53,40 @@ defmodule Systems.Assignment.CrewWorkView do panel_info: panel_info, tool_started: tool_started, tool_initialized: tool_initialized, - tasks_finished?: tasks_finished? + retry?: retry? ) - |> update_selected_item_id() - |> update_selected_item() - |> compose_child(:work_list_view) - |> compose_child(:start_view) - |> compose_child(:context_menu) - |> update_tool_ref_view() - |> update_child(:finished_view) - } + + socket = + if initial? do + if tasks_finished? and not embedded? do + socket |> compose_child(:finished_view) + else + socket |> initialize() + end + else + socket |> update() + end + + {:ok, socket} + end + + defp initialize(socket) do + socket + |> hide_child(:finished_view) + |> update_selected_item_id() + |> update_selected_item() + |> compose_child(:work_list_view) + |> compose_child(:start_view) + |> compose_child(:context_menu) + |> compose_tool_ref_view() + end + + defp update(socket) do + socket + |> update_child(:work_list_view) + |> update_child(:start_view) + |> update_child(:context_menu) + |> update_child(:tool_ref_view) end defp tasks_finished?(work_items) do @@ -77,7 +102,7 @@ defmodule Systems.Assignment.CrewWorkView do tool_started and tool_initialized end - defp update_tool_ref_view(%{assigns: %{selected_item_id: selected_item_id}} = socket) do + defp compose_tool_ref_view(%{assigns: %{selected_item_id: selected_item_id}} = socket) do case Fabric.get_child(socket, :tool_ref_view) do %{params: %{work_item: {%{id: id}, _}}} when id == selected_item_id -> socket @@ -281,6 +306,16 @@ defmodule Systems.Assignment.CrewWorkView do # Events + def handle_event("retry", _, socket) do + { + :noreply, + socket + |> assign(retry?: true) + |> hide_child(:finished_view) + |> initialize() + } + end + def handle_event("tool_initialized", _, socket) do { :noreply, @@ -539,17 +574,14 @@ defmodule Systems.Assignment.CrewWorkView do socket end - defp handle_finished_state(%{assigns: %{tasks_finished?: true}} = socket) do - socket - end + defp handle_finished_state(%{assigns: %{retry?: true}} = socket), do: socket defp handle_finished_state(%{assigns: %{work_items: work_items}} = socket) do if tasks_finished?(work_items) do socket - |> assign(tasks_finished?: true) + |> hide_modal(:tool_ref_view) |> signal_tasks_finished() |> compose_child(:finished_view) - |> show_modal(:finished_view, :sheet) else socket end @@ -592,26 +624,31 @@ defmodule Systems.Assignment.CrewWorkView do def render(assigns) do ~H"""
- <%= if exists?(@fabric, :work_list_view) do %> -
-
- <%= dgettext("eyra-assignment", "work.list.title") %> -
-
- <.line /> -
-
-
- <.child name={:work_list_view} fabric={@fabric} /> + <%= if exists?(@fabric, :finished_view) do %> + <.child name={:finished_view} fabric={@fabric} /> + <% else %> + <%= if exists?(@fabric, :work_list_view) do %> +
+
+ <%= dgettext("eyra-assignment", "work.list.title") %> +
+
+ <.line /> +
+
+
+ <.child name={:work_list_view} fabric={@fabric} /> +
-
-
+
+
+ <% end %> + +
+ <.child name={:start_view} fabric={@fabric} />
<% end %> -
- <.child name={:start_view} fabric={@fabric} /> -
<%!-- floating button --%> <.child name={:context_menu} fabric={@fabric} /> diff --git a/core/systems/assignment/finished_view.ex b/core/systems/assignment/finished_view.ex index 8b46a0b2b..f5623f2bc 100644 --- a/core/systems/assignment/finished_view.ex +++ b/core/systems/assignment/finished_view.ex @@ -9,26 +9,49 @@ defmodule Systems.Assignment.FinishedView do { :ok, - socket |> assign(body: body) + socket + |> assign(body: body) + |> update_retry_button() } end + defp update_retry_button(socket) do + retry_button = %{ + action: %{type: :send, event: "retry"}, + face: %{ + type: :plain, + icon: :forward, + label: dgettext("eyra-assignment", "retry.button") + } + } + + assign(socket, retry_button: retry_button) + end + + def handle_event("retry", _, socket) do + {:noreply, socket |> send_event(:parent, "retry")} + end + @impl true def render(assigns) do ~H""" -
+
+
-
- <%= raw @body %> -
-
-
+
+ Done + <%= @body %> +
All tasks done
-
+
+ +
+
+
""" end diff --git a/core/test/systems/assignment/crew_page_test.exs b/core/test/systems/assignment/crew_page_test.exs index c25a38f6a..fc2b57a25 100644 --- a/core/test/systems/assignment/crew_page_test.exs +++ b/core/test/systems/assignment/crew_page_test.exs @@ -31,7 +31,7 @@ defmodule Systems.Assignment.CrewPageTest do describe "render an assignment crew page" do test "renders page", %{conn: conn, assignment: assignment, user: user} do - conn = put_session(conn, :panel_info, %{}) + conn = put_session(conn, :panel_info, %{embedded?: false}) Assignment.Public.add_participant!(assignment, user) {:ok, _view, html} = live(conn, ~p"/assignment/#{assignment.id}")