Skip to content

Commit

Permalink
Refactor Participant Finished View
Browse files Browse the repository at this point in the history
  • Loading branch information
mellelieuwes committed Oct 3, 2024
1 parent 765d694 commit e81fa50
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 61 deletions.
4 changes: 4 additions & 0 deletions core/priv/gettext/de/LC_MESSAGES/eyra-assignment.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 0 additions & 4 deletions core/priv/gettext/de/LC_MESSAGES/eyra-ui.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand Down
6 changes: 5 additions & 1 deletion core/priv/gettext/en/LC_MESSAGES/eyra-assignment.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
4 changes: 0 additions & 4 deletions core/priv/gettext/en/LC_MESSAGES/eyra-ui.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions core/priv/gettext/eyra-assignment.pot
Original file line number Diff line number Diff line change
Expand Up @@ -455,3 +455,7 @@ msgstr ""
#, elixir-autogen, elixir-format
msgid "progress.yes"
msgstr ""

#, elixir-autogen, elixir-format
msgid "retry.button"
msgstr ""
4 changes: 0 additions & 4 deletions core/priv/gettext/eyra-ui.pot
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand Down
4 changes: 4 additions & 0 deletions core/priv/gettext/nl/LC_MESSAGES/eyra-assignment.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 0 additions & 4 deletions core/priv/gettext/nl/LC_MESSAGES/eyra-ui.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
107 changes: 72 additions & 35 deletions core/systems/assignment/crew_work_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -592,26 +624,31 @@ defmodule Systems.Assignment.CrewWorkView do
def render(assigns) do
~H"""
<div class="w-full h-full flex flex-row">
<%= if exists?(@fabric, :work_list_view) do %>
<div class="w-left-column flex-shrink-0 flex flex-col py-6 gap-6">
<div class="px-6">
<Text.title2 margin=""><%= dgettext("eyra-assignment", "work.list.title") %></Text.title2>
</div>
<div>
<.line />
</div>
<div class="flex-grow">
<div class="px-6 h-full overflow-y-scroll">
<.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 %>
<div class="w-left-column flex-shrink-0 flex flex-col py-6 gap-6">
<div class="px-6">
<Text.title2 margin=""><%= dgettext("eyra-assignment", "work.list.title") %></Text.title2>
</div>
<div>
<.line />
</div>
<div class="flex-grow">
<div class="px-6 h-full overflow-y-scroll">
<.child name={:work_list_view} fabric={@fabric} />
</div>
</div>
</div>
</div>
<div class="border-l border-grey4">
<div class="border-l border-grey4">
</div>
<% end %>
<div class="h-full w-full">
<.child name={:start_view} fabric={@fabric} />
</div>
<% end %>
<div class="h-full w-full">
<.child name={:start_view} fabric={@fabric} />
</div>
<%!-- floating button --%>
<.child name={:context_menu} fabric={@fabric} />
Expand Down
39 changes: 31 additions & 8 deletions core/systems/assignment/finished_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
<div>
<div class="flex flex-row w-full h-full">
<div class="flex-grow" />
<div class="flex flex-col gap-8 items-center w-full h-full">
<div class="wysiwyg text-center">
<%= raw @body %>
</div>
<div class="flex flex-col items-center w-full h-full">
<div class="flex-grow" />
<div class="flex-grow" />
<Text.title1 margin="">Done</Text.title1>
<Text.body_large><%= @body %></Text.body_large>
<div class="flex flex-col items-center w-full pt-4">
<div class="flex-none">
<img src={~p"/images/illustrations/finished.svg"} id="zero-todos" alt="All tasks done">
</div>
<div class="flex-grow" />
</div>
<div class="pb-4">
<Button.dynamic {@retry_button} />
</div>
<div class="flex-grow" />
</div>
<div class="flex-grow" />
</div>
"""
end
Expand Down
2 changes: 1 addition & 1 deletion core/test/systems/assignment/crew_page_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down

0 comments on commit e81fa50

Please sign in to comment.