Skip to content

Commit

Permalink
Merge pull request #519 from eyra/assignment-intro
Browse files Browse the repository at this point in the history
Added Content Page concept w/ Assignment Onboarding Introduction
  • Loading branch information
mellelieuwes authored Dec 12, 2023
2 parents 62d1636 + 3dd7061 commit 8fb0fc2
Show file tree
Hide file tree
Showing 21 changed files with 590 additions and 10 deletions.
26 changes: 25 additions & 1 deletion core/priv/gettext/en/LC_MESSAGES/eyra-assignment.po
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ msgid "retract.button"
msgstr "Take offline"

#, elixir-autogen, elixir-format
msgid "onboarding.consent.continue.button"
msgid "onboarding.continue.button"
msgstr "Continue"

#, elixir-autogen, elixir-format, fuzzy
Expand Down Expand Up @@ -221,3 +221,27 @@ msgstr "Branding"
#, elixir-autogen, elixir-format
msgid "work.list.title"
msgstr "Tasks"

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

#, elixir-autogen, elixir-format, fuzzy
msgid "intro_form.off.label"
msgstr "Skip introduction"

#, elixir-autogen, elixir-format, fuzzy
msgid "intro_form.on.label"
msgstr "Show introduction"

#, elixir-autogen, elixir-format, fuzzy
msgid "settings.intro.body"
msgstr "Use the text field below to write an introduction text for your participants about this assignment."

#, elixir-autogen, elixir-format, fuzzy
msgid "settings.intro.title"
msgstr "Introduction"

#, elixir-autogen, elixir-format, fuzzy
msgid "onboarding.intro.title"
msgstr "Introduction"
26 changes: 25 additions & 1 deletion core/priv/gettext/eyra-assignment.pot
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ msgid "retract.button"
msgstr ""

#, elixir-autogen, elixir-format
msgid "onboarding.consent.continue.button"
msgid "onboarding.continue.button"
msgstr ""

#, elixir-autogen, elixir-format
Expand Down Expand Up @@ -221,3 +221,27 @@ msgstr ""
#, elixir-autogen, elixir-format
msgid "work.list.title"
msgstr ""

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

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

#, elixir-autogen, elixir-format
msgid "intro_form.on.label"
msgstr ""

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

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

#, elixir-autogen, elixir-format
msgid "onboarding.intro.title"
msgstr ""
26 changes: 25 additions & 1 deletion core/priv/gettext/nl/LC_MESSAGES/eyra-assignment.po
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ msgid "retract.button"
msgstr "Offline halen"

#, elixir-autogen, elixir-format
msgid "onboarding.consent.continue.button"
msgid "onboarding.continue.button"
msgstr "Verder"

#, elixir-autogen, elixir-format, fuzzy
Expand Down Expand Up @@ -221,3 +221,27 @@ msgstr "Branding"
#, elixir-autogen, elixir-format
msgid "work.list.title"
msgstr "Taken"

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

#, elixir-autogen, elixir-format, fuzzy
msgid "intro_form.off.label"
msgstr "Introductie overslaan"

#, elixir-autogen, elixir-format, fuzzy
msgid "intro_form.on.label"
msgstr "Introductie tonen"

#, elixir-autogen, elixir-format, fuzzy
msgid "settings.intro.body"
msgstr "Gebruik het tekstvak hieronder om een introductie te schrijven voor jouw deelnemers over deze opdracht."

#, elixir-autogen, elixir-format, fuzzy
msgid "settings.intro.title"
msgstr "Introductie"

#, elixir-autogen, elixir-format, fuzzy
msgid "onboarding.intro.title"
msgstr "Introductie"
32 changes: 32 additions & 0 deletions core/priv/repo/migrations/20231211140124_add_pages.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
defmodule Core.Repo.Migrations.AddPages do
use Ecto.Migration

def up do
create table(:content_pages) do
add(:body, :text)
add(:auth_node_id, references(:authorization_nodes), null: false)
timestamps()
end

create table(:assignment_page_refs, primary_key: false) do
add(:key, :string)

add(:assignment_id, references(:assignments, on_delete: :delete_all),
null: false,
primary_key: true
)

add(:page_id, references(:content_pages, on_delete: :delete_all),
null: false,
primary_key: true
)

timestamps()
end
end

def down do
drop(table(:assignment_page_refs))
drop(table(:content_pages))
end
end
2 changes: 2 additions & 0 deletions core/systems/assignment/_assembly.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ defmodule Systems.Assignment.Assembly do
crew_auth_node = Authorization.prepare_node(auth_node)
crew = Crew.Public.prepare(crew_auth_node)
info = Assignment.Public.prepare_info(info_attrs(template, director))
page_refs = Assignment.Public.prepare_page_refs(template, auth_node)
workflow = prepare_workflow(template, auth_node)
consent_agreement = prepare_consent_agreement(auth_node)

Assignment.Public.prepare(
%{special: template},
crew,
info,
page_refs,
workflow,
budget,
consent_agreement,
Expand Down
5 changes: 5 additions & 0 deletions core/systems/assignment/_private.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
defmodule Systems.Assignment.Private do
use CoreWeb, :verified_routes

import CoreWeb.Gettext

require Logger

alias Systems.{
Expand All @@ -10,6 +12,9 @@ defmodule Systems.Assignment.Private do
Storage
}

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

def allowed_external_panel_ids() do
Keyword.get(config(), :external_panels, [])
end
Expand Down
52 changes: 51 additions & 1 deletion core/systems/assignment/_public.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ defmodule Systems.Assignment.Public do
alias Core.Authorization
alias Core.Accounts.User
alias Frameworks.Concept
alias Frameworks.Signal

alias Systems.{
Project,
Assignment,
Content,
Consent,
Budget,
Workflow,
Expand Down Expand Up @@ -45,6 +47,8 @@ defmodule Systems.Assignment.Public do
end

def get_by(association, preload \\ [])
def get_by(%Assignment.PageRefModel{assignment_id: id}, preload), do: get!(id, preload)

def get_by(%Assignment.InfoModel{id: id}, preload), do: get_by(:info_id, id, preload)

def get_by(%Storage.EndpointModel{id: id}, preload),
Expand Down Expand Up @@ -115,10 +119,11 @@ defmodule Systems.Assignment.Public do
|> Repo.all()
end

def prepare(%{} = attrs, crew, info, workflow, budget, consent_agreement, auth_node) do
def prepare(%{} = attrs, crew, info, page_refs, workflow, budget, consent_agreement, auth_node) do
%Assignment.Model{}
|> Assignment.Model.changeset(attrs)
|> Ecto.Changeset.put_assoc(:info, info)
|> Ecto.Changeset.put_assoc(:page_refs, page_refs)
|> Ecto.Changeset.put_assoc(:workflow, workflow)
|> Ecto.Changeset.put_assoc(:crew, crew)
|> Ecto.Changeset.put_assoc(:budget, budget)
Expand All @@ -143,6 +148,51 @@ defmodule Systems.Assignment.Public do
|> Ecto.Changeset.put_assoc(:tool_ref, tool_ref)
end

def prepare_page_refs(_template, auth_node) do
[
prepare_page_ref(auth_node, :assignment_intro)
]
end

def prepare_page_ref(auth_node, key) when is_atom(key) do
page_title = Assignment.Private.page_title_default(key)
page_body = Assignment.Private.page_body_default(key)
page_auth_node = Authorization.prepare_node(auth_node)
page = Content.Public.prepare_page(page_title, page_body, page_auth_node)

%Assignment.PageRefModel{}
|> Assignment.PageRefModel.changeset(%{key: key})
|> Ecto.Changeset.put_assoc(:page, page)
end

def create_page_ref(%Assignment.Model{auth_node: auth_node} = assignment, key) do
page_ref =
prepare_page_ref(auth_node, key)
|> Ecto.Changeset.put_assoc(:assignment, assignment)

Multi.new()
|> Multi.insert(:assignment_page_ref, page_ref)
|> Signal.Public.multi_dispatch({:assignment_page_ref, :inserted})
|> Repo.transaction()
end

def delete_page_ref(
%Assignment.PageRefModel{assignment_id: assignment_id, page_id: page_id} = page_ref
) do
page_refs =
from(pr in Assignment.PageRefModel,
where: pr.assignment_id == ^assignment_id,
where: pr.page_id == ^page_id
)

Multi.new()
|> Multi.delete_all(:assignment_page_refs, page_refs)
|> Signal.Public.multi_dispatch({:assignment_page_ref, :deleted}, %{
assignment_page_ref: page_ref
})
|> Repo.transaction()
end

def delete_storage_endpoint!(%{storage_endpoint_id: nil} = assignment) do
assignment
end
Expand Down
10 changes: 10 additions & 0 deletions core/systems/assignment/_switch.ex
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ defmodule Systems.Assignment.Switch do
end
end

@impl true
def intercept({:assignment_page_ref, _} = signal, %{assignment_page_ref: page_ref} = message) do
assignment = Assignment.Public.get_by(page_ref, Assignment.Model.preload_graph(:down))

dispatch!(
{:assignment, signal},
Map.merge(message, %{assignment: assignment})
)
end

@impl true
def intercept({:assignment, _} = signal, message) do
handle(signal, message)
Expand Down
1 change: 0 additions & 1 deletion core/systems/assignment/crew_page.ex
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ defmodule Systems.Assignment.CrewPage do

@impl true
def handle_event("show_modal", modal, socket) do
# popup = %{module: module, params: Map.put(params, :id, id)}
{:noreply, socket |> assign(modal: modal)}
end

Expand Down
33 changes: 30 additions & 3 deletions core/systems/assignment/crew_page_builder.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
defmodule Systems.Assignment.CrewPageBuilder do
import CoreWeb.Gettext

alias Systems.{
Assignment,
Crew,
Expand Down Expand Up @@ -34,6 +36,7 @@ defmodule Systems.Assignment.CrewPageBuilder do

defp full_flow(assignment, assigns, is_tester?) do
[
intro_view(assignment, assigns),
consent_view(assignment, assigns, is_tester?),
work_view(assignment, assigns, is_tester?)
]
Expand All @@ -42,6 +45,20 @@ defmodule Systems.Assignment.CrewPageBuilder do

defp current_flow(%{fabric: %{children: children}}), do: children

defp intro_view(
%{page_refs: page_refs},
%{fabric: fabric}
) do
if intro_page_ref = Enum.find(page_refs, &(&1.key == :assignment_intro)) do
Fabric.prepare_child(fabric, :onboarding_view_intro, Assignment.OnboardingView, %{
page_ref: intro_page_ref,
title: dgettext("eyra-assignment", "onboarding.intro.title")
})
else
nil
end
end

defp consent_view(%{consent_agreement: nil}, _, _), do: nil

defp consent_view(
Expand All @@ -54,32 +71,42 @@ defmodule Systems.Assignment.CrewPageBuilder do
else
revision = Consent.Public.latest_revision(consent_agreement, [:signatures])

Fabric.prepare_child(fabric, :onboarding_view, Assignment.OnboardingConsentView, %{
Fabric.prepare_child(fabric, :onboarding_view_consent, Assignment.OnboardingConsentView, %{
revision: revision,
user: user
})
end
end

defp work_view(
%{consent_agreement: consent_agreement} = assignment,
%{consent_agreement: consent_agreement, page_refs: page_refs} = assignment,
%{fabric: fabric, current_user: user} = assigns,
_
) do
work_items = work_items(assignment, assigns)
context_menu_items = context_menu_items(assignment, assigns)

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

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,
user: user
})
end

defp context_menu_items(%{consent_agreement: consent_agreement}, _assigns) do
defp context_menu_items(%{consent_agreement: consent_agreement, page_refs: page_refs}, _assigns) do
items = []

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

items =
if consent_agreement do
items ++ [%{id: :consent, label: "Consent"}]
Expand Down
Loading

0 comments on commit 8fb0fc2

Please sign in to comment.