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

Added Support page feature to Assignment CMS and participant views #520

Merged
merged 1 commit into from
Dec 12, 2023
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
20 changes: 20 additions & 0 deletions core/priv/gettext/en/LC_MESSAGES/eyra-assignment.po
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,23 @@ msgstr "Introduction"
#, elixir-autogen, elixir-format, fuzzy
msgid "onboarding.intro.title"
msgstr "Introduction"

#, elixir-autogen, elixir-format, fuzzy
msgid "settings.support.body"
msgstr "Use the text field below to give support to your participants about this assignment."

#, elixir-autogen, elixir-format, fuzzy
msgid "settings.support.title"
msgstr "Support"

#, elixir-autogen, elixir-format, fuzzy
msgid "support.page.title"
msgstr "Support"

#, elixir-autogen, elixir-format, fuzzy
msgid "support_form.off.label"
msgstr "Withhold support"

#, elixir-autogen, elixir-format, fuzzy
msgid "support_form.on.label"
msgstr "Give support"
20 changes: 20 additions & 0 deletions core/priv/gettext/eyra-assignment.pot
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,23 @@ msgstr ""
#, elixir-autogen, elixir-format
msgid "onboarding.intro.title"
msgstr ""

#, elixir-autogen, elixir-format
msgid "settings.support.body"
msgstr ""

#, elixir-autogen, elixir-format
msgid "settings.support.title"
msgstr ""

#, elixir-autogen, elixir-format
msgid "support.page.title"
msgstr ""

#, elixir-autogen, elixir-format
msgid "support_form.off.label"
msgstr ""

#, elixir-autogen, elixir-format
msgid "support_form.on.label"
msgstr ""
20 changes: 20 additions & 0 deletions core/priv/gettext/nl/LC_MESSAGES/eyra-assignment.po
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,23 @@ msgstr "Introductie"
#, elixir-autogen, elixir-format, fuzzy
msgid "onboarding.intro.title"
msgstr "Introductie"

#, elixir-autogen, elixir-format, fuzzy
msgid "settings.support.body"
msgstr "Gebruik het tekstvak hieronder om ondersteuning te bieden voor jouw deelnemers over deze opdracht."

#, elixir-autogen, elixir-format, fuzzy
msgid "settings.support.title"
msgstr "Ondersteuning"

#, elixir-autogen, elixir-format, fuzzy
msgid "support.page.title"
msgstr "Ondersteuning"

#, elixir-autogen, elixir-format, fuzzy
msgid "support_form.off.label"
msgstr "Geen ondersteuning bieden"

#, elixir-autogen, elixir-format, fuzzy
msgid "support_form.on.label"
msgstr "Bied ondersteuning"
5 changes: 5 additions & 0 deletions core/systems/assignment/_private.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ defmodule Systems.Assignment.Private do
}

def page_title_default(:assignment_intro), do: dgettext("eyra-assignment", "intro.page.title")

def page_title_default(:assignment_support),
do: dgettext("eyra-assignment", "support.page.title")

def page_body_default(:assignment_intro), do: ""
def page_body_default(:assignment_support), do: ""

def allowed_external_panel_ids() do
Keyword.get(config(), :external_panels, [])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Systems.Assignment.IntroForm do
defmodule Systems.Assignment.ContentPageForm do
use CoreWeb, :live_component_fabric
use Fabric.LiveComponent

Expand All @@ -7,33 +7,54 @@ defmodule Systems.Assignment.IntroForm do
alias Systems.Content

@impl true
def update(%{id: id, assignment: assignment}, socket) do
def update(
%{
id: id,
assignment: assignment,
page_key: page_key,
opt_in?: opt_in?,
on_text: on_text,
off_text: off_text
},
socket
) do
{
:ok,
socket
|> assign(
id: id,
assignment: assignment
assignment: assignment,
page_key: page_key,
opt_in?: opt_in?,
on_text: on_text,
off_text: off_text
)
|> update_page_ref()
|> compose_child(:switch)
|> compose_child(:content_page_form)
}
end

def update_page_ref(%{assigns: %{assignment: %{page_refs: page_refs}}} = socket) do
page_ref = Enum.find(page_refs, &(&1.key == :assignment_intro))
def update_page_ref(
%{assigns: %{assignment: %{page_refs: page_refs}, page_key: page_key}} = socket
) do
page_ref = Enum.find(page_refs, &(&1.key == page_key))
socket |> assign(page_ref: page_ref)
end

@impl true
def compose(:switch, %{page_ref: page_ref}) do
def compose(:switch, %{
page_ref: page_ref,
opt_in?: opt_in?,
on_text: on_text,
off_text: off_text
}) do
%{
module: Pixel.Switch,
params: %{
opt_in?: false,
on_text: dgettext("eyra-assignment", "intro_form.on.label"),
off_text: dgettext("eyra-assignment", "intro_form.off.label"),
opt_in?: opt_in?,
on_text: on_text,
off_text: off_text,
status:
if page_ref do
:on
Expand Down Expand Up @@ -68,9 +89,9 @@ defmodule Systems.Assignment.IntroForm do
def handle_event(
"update",
%{status: :on},
%{assigns: %{assignment: assignment}} = socket
%{assigns: %{assignment: assignment, page_key: page_key}} = socket
) do
page_ref = Assignment.Public.create_page_ref(assignment, :assignment_intro)
page_ref = Assignment.Public.create_page_ref(assignment, page_key)

{
:noreply,
Expand Down
44 changes: 28 additions & 16 deletions core/systems/assignment/crew_page_builder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ defmodule Systems.Assignment.CrewPageBuilder do
consent_view(assignment, assigns, is_tester?),
work_view(assignment, assigns, is_tester?)
]
|> Enum.filter(&(&1 != nil))
|> Enum.filter(&(not is_nil(&1)))
end

defp current_flow(%{fabric: %{children: children}}), do: children
Expand Down Expand Up @@ -87,34 +87,46 @@ defmodule Systems.Assignment.CrewPageBuilder do
context_menu_items = context_menu_items(assignment, assigns)

intro_page_ref = Enum.find(page_refs, &(&1.key == :assignment_intro))
support_page_ref = Enum.find(page_refs, &(&1.key == :assignment_support))

Fabric.prepare_child(fabric, :work_view, Assignment.CrewWorkView, %{
work_items: work_items,
consent_agreement: consent_agreement,
context_menu_items: context_menu_items,
intro_page_ref: intro_page_ref,
support_page_ref: support_page_ref,
user: user
})
end

defp context_menu_items(%{consent_agreement: consent_agreement, page_refs: page_refs}, _assigns) do
items = []
defp context_menu_items(assignment, _assigns) do
[:consent, :assignment_intro, :assignment_support]
|> Enum.map(&context_menu_item(&1, assignment))
|> Enum.filter(&(not is_nil(&1)))
end

items =
if Enum.find(page_refs, &(&1.key == :assignment_intro)) != nil do
items ++ [%{id: :intro, label: dgettext("eyra-assignment", "onboarding.intro.title")}]
else
items
end
defp context_menu_item(:consent = key, %{consent_agreement: consent_agreement}) do
if consent_agreement do
%{id: key, label: "Consent"}
else
nil
end
end

items =
if consent_agreement do
items ++ [%{id: :consent, label: "Consent"}]
else
items
end
defp context_menu_item(:assignment_intro = key, %{page_refs: page_refs}) do
if Enum.find(page_refs, &(&1.key == :assignment_intro)) != nil do
%{id: key, label: dgettext("eyra-assignment", "onboarding.intro.title")}
else
nil
end
end

items
defp context_menu_item(:assignment_support = key, %{page_refs: page_refs}) do
if Enum.find(page_refs, &(&1.key == key)) != nil do
%{id: key, label: dgettext("eyra-assignment", "support.page.title")}
else
nil
end
end

defp work_items(%{status: status, crew: crew} = assignment, %{current_user: user} = assigns) do
Expand Down
26 changes: 24 additions & 2 deletions core/systems/assignment/crew_work_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ defmodule Systems.Assignment.CrewWorkView do
consent_agreement: consent_agreement,
context_menu_items: context_menu_items,
intro_page_ref: intro_page_ref,
support_page_ref: support_page_ref,
user: user
},
socket
Expand All @@ -31,6 +32,7 @@ defmodule Systems.Assignment.CrewWorkView do
consent_agreement: consent_agreement,
context_menu_items: context_menu_items,
intro_page_ref: intro_page_ref,
support_page_ref: support_page_ref,
user: user
)
|> update_selected_item_id()
Expand Down Expand Up @@ -142,7 +144,17 @@ defmodule Systems.Assignment.CrewWorkView do
%{
module: Content.PageView,
params: %{
title: dgettext("eyra-assignment", "onboarding.intro.title"),
title: dgettext("eyra-assignment", "intro.page.title"),
page: page
}
}
end

def compose(:support_page, %{support_page_ref: %{page: page}}) do
%{
module: Content.PageView,
params: %{
title: dgettext("eyra-assignment", "support.page.title"),
page: page
}
}
Expand Down Expand Up @@ -211,7 +223,7 @@ defmodule Systems.Assignment.CrewWorkView do
end

@impl true
def handle_event("show", %{page: :intro}, socket) do
def handle_event("show", %{page: :assignment_intro}, socket) do
{
:noreply,
socket
Expand All @@ -220,6 +232,16 @@ defmodule Systems.Assignment.CrewWorkView do
}
end

@impl true
def handle_event("show", %{page: :assignment_support}, socket) do
{
:noreply,
socket
|> compose_child(:support_page)
|> show_modal(:support_page, :sheet)
}
end

@impl true
def handle_event("close", %{source: %{name: :consent_page}}, socket) do
{:noreply, socket |> hide_popup(:consent_page)}
Expand Down
34 changes: 32 additions & 2 deletions core/systems/assignment/settings_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ defmodule Systems.Assignment.SettingsView do
|> compose_child(:info)
|> compose_child(:intro)
|> compose_child(:consent)
|> compose_child(:support)
|> compose_child(:panel_connector)
|> compose_child(:storage_connector)
}
Expand All @@ -50,9 +51,13 @@ defmodule Systems.Assignment.SettingsView do
@impl true
def compose(:intro, %{entity: assignment}) do
%{
module: Assignment.IntroForm,
module: Assignment.ContentPageForm,
params: %{
assignment: assignment
assignment: assignment,
page_key: :assignment_intro,
opt_in?: false,
on_text: dgettext("eyra-assignment", "intro_form.on.label"),
off_text: dgettext("eyra-assignment", "intro_form.off.label")
}
}
end
Expand All @@ -67,6 +72,20 @@ defmodule Systems.Assignment.SettingsView do
}
end

@impl true
def compose(:support, %{entity: assignment}) do
%{
module: Assignment.ContentPageForm,
params: %{
assignment: assignment,
page_key: :assignment_support,
opt_in?: false,
on_text: dgettext("eyra-assignment", "support_form.on.label"),
off_text: dgettext("eyra-assignment", "support_form.off.label")
}
}
end

@impl true
def compose(:panel_connector, %{entity: assignment, uri_origin: uri_origin}) do
%{
Expand Down Expand Up @@ -135,6 +154,17 @@ defmodule Systems.Assignment.SettingsView do
</:footer>
</.child>

<.child name={:support} fabric={@fabric} >
<:header>
<Text.title3><%= dgettext("eyra-assignment", "settings.support.title") %></Text.title3>
<Text.body><%= dgettext("eyra-assignment", "settings.support.body") %></Text.body>
<.spacing value="M" />
</:header>
<:footer>
<.spacing value="L" />
</:footer>
</.child>

<.child name={:panel_connector} fabric={@fabric}>
<:header>
<Text.title3><%= dgettext("eyra-assignment", "settings.panel.title") %></Text.title3>
Expand Down
Loading
Loading