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

Feature/579 #965

Merged
merged 12 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 9 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

## \#2 unreleased

* Added: Confirmation dialog when skipping content pages or consent pages in assignment configuration.
* Added: Project breadcrumbs for easy navigation and hierarchy overview.
* Changed: Format of the filenames in Storages. Also no folders used anymore. This has impact on Data Donation studies.
* Changed: Assignment does not have a Storage association anymore. Projects can have one Storage that is shared between all the project items.
Expand Down
66 changes: 66 additions & 0 deletions core/frameworks/pixel/components/confirmation_modal.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
defmodule Frameworks.Pixel.ConfirmationModal do
use CoreWeb, :live_component

@impl true
def update(%{assigns: assigns}, socket) do
{
:ok,
socket
|> assign_new(:title, fn ->
Map.get(assigns, :title, dgettext("eyra-ui", "confirmation_modal.title"))
end)
|> assign_new(:body, fn ->
Map.get(assigns, :body, dgettext("eyra-ui", "confirmation_modal.body"))
end)
|> update_buttons()
}
end

defp update_buttons(%{assigns: %{myself: myself}} = socket) do
confirm = %{
action: %{type: :send, target: myself, event: "confirm"},
face: %{type: :primary, label: dgettext("eyra-ui", "confirm.button")}
}

cancel = %{
action: %{type: :send, target: myself, event: "cancel"},
face: %{type: :secondary, label: dgettext("eyra-ui", "cancel.button")}
}

assign(socket, buttons: [confirm, cancel])
end

def handle_event("confirm", _, socket) do
{:noreply, socket |> send_event(:parent, "confirmed")}
end

def handle_event("cancel", _, socket) do
{:noreply, socket |> send_event(:parent, "cancelled")}
end

@impl true
@spec render(any()) :: Phoenix.LiveView.Rendered.t()
def render(assigns) do
~H"""
<div>
<Text.title2>
<%= @title %>
</Text.title2>

<.spacing value="M" />

<Text.body_large>
<%= @body %>
</Text.body_large>

<.spacing value="M" />

<div class="flex flex-row gap-4">
<%= for button <- @buttons do %>
<Button.dynamic {button} />
<% end %>
</div>
</div>
"""
end
end
9 changes: 8 additions & 1 deletion core/frameworks/pixel/components/modal_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,14 @@ defmodule Frameworks.Pixel.ModalView do
attr(:style, :atom, required: true)
attr(:live_component, :map, required: true)

def container(assigns) do
def container(%{style: style} = assigns) do
allowed_styles = [:page, :sheet, :dialog, :notification]

unless style in allowed_styles do
raise ArgumentError,
"Invalid style: #{style}. Allowed styles are: #{Enum.join(allowed_styles, ", ")}"
end

~H"""
<%= if @style == :page do %>
<.page live_component={@live_component} />
Expand Down
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 @@ -428,3 +428,7 @@ msgstr[1] ""
#, elixir-autogen, elixir-format
msgid "atom.tag"
msgstr ""

#, elixir-autogen, elixir-format
msgid "gdpr_form.confirmation_modal.body"
msgstr ""
12 changes: 12 additions & 0 deletions core/priv/gettext/de/LC_MESSAGES/eyra-ui.po
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,15 @@ msgstr ""
#, elixir-autogen, elixir-format
msgid "menu.item.workspace"
msgstr ""

#, elixir-autogen, elixir-format, fuzzy
msgid "confirm.button"
msgstr ""

#, elixir-autogen, elixir-format
msgid "confirmation_modal.body"
msgstr ""

#, elixir-autogen, elixir-format
msgid "confirmation_modal.title"
msgstr ""
4 changes: 4 additions & 0 deletions core/priv/gettext/en/LC_MESSAGES/eyra-assignment.po
Original file line number Diff line number Diff line change
Expand Up @@ -427,3 +427,7 @@ msgstr[1] "%{count} participants"
#, elixir-autogen, elixir-format
msgid "atom.tag"
msgstr "Assignment"

#, elixir-autogen, elixir-format
msgid "gdpr_form.confirmation_modal.body"
msgstr "By skipping the consent, not only will the text be deleted, but the underlying consent agreement and all associated signatures will also be removed."
12 changes: 12 additions & 0 deletions core/priv/gettext/en/LC_MESSAGES/eyra-ui.po
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,15 @@ msgstr "Desktop"
#, elixir-autogen, elixir-format, fuzzy
msgid "menu.item.workspace"
msgstr "My workspace"

#, elixir-autogen, elixir-format, fuzzy
msgid "confirm.button"
msgstr "Confirm"

#, elixir-autogen, elixir-format
msgid "confirmation_modal.body"
msgstr "Are you sure you would like to skip this page? Your text will be deleted."

#, elixir-autogen, elixir-format
msgid "confirmation_modal.title"
msgstr "Are you sure?"
4 changes: 4 additions & 0 deletions core/priv/gettext/eyra-assignment.pot
Original file line number Diff line number Diff line change
Expand Up @@ -427,3 +427,7 @@ msgstr[1] ""
#, elixir-autogen, elixir-format
msgid "atom.tag"
msgstr ""

#, elixir-autogen, elixir-format
msgid "gdpr_form.confirmation_modal.body"
msgstr ""
12 changes: 12 additions & 0 deletions core/priv/gettext/eyra-ui.pot
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,15 @@ msgstr ""
#, elixir-autogen, elixir-format
msgid "menu.item.workspace"
msgstr ""

#, elixir-autogen, elixir-format
msgid "confirm.button"
msgstr ""

#, elixir-autogen, elixir-format
msgid "confirmation_modal.body"
msgstr ""

#, elixir-autogen, elixir-format
msgid "confirmation_modal.title"
msgstr ""
5 changes: 4 additions & 1 deletion core/priv/gettext/nl/LC_MESSAGES/eyra-assignment.po
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,6 @@ msgstr ""
#, elixir-autogen, elixir-format
msgid "storage.not_available.warning"
msgstr ""

#, elixir-autogen, elixir-format, fuzzy
msgid "1 participant"
msgid_plural "* participants"
Expand All @@ -427,3 +426,7 @@ msgstr[1] ""
#, elixir-autogen, elixir-format
msgid "atom.tag"
msgstr ""

#, elixir-autogen, elixir-format
msgid "gdpr_form.confirmation_modal.body"
msgstr ""
12 changes: 12 additions & 0 deletions core/priv/gettext/nl/LC_MESSAGES/eyra-ui.po
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,15 @@ msgstr "To-do"
#, elixir-autogen, elixir-format, fuzzy
msgid "menu.item.workspace"
msgstr "Mijn werkplek"

#, elixir-autogen, elixir-format, fuzzy
msgid "confirm.button"
msgstr "Klaar"

#, elixir-autogen, elixir-format
msgid "confirmation_modal.body"
msgstr ""

#, elixir-autogen, elixir-format
msgid "confirmation_modal.title"
msgstr ""
47 changes: 41 additions & 6 deletions core/systems/assignment/content_page_form.ex
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ defmodule Systems.Assignment.ContentPageForm do
}
end

@impl true
def compose(:confirmation_modal, %{page_ref: page_ref}) do
%{
module: Pixel.ConfirmationModal,
params: %{
assigns: %{
page_ref: page_ref
}
}
}
end

@impl true
def compose(:content_page_form, %{page_ref: nil}) do
%{
Expand Down Expand Up @@ -99,16 +111,39 @@ defmodule Systems.Assignment.ContentPageForm do
end

@impl true
def handle_event("update", %{status: :off}, %{assigns: %{page_ref: page_ref}} = socket) do
{:ok, _} = Assignment.Public.delete_page_ref(page_ref)
def handle_event("update", %{status: :off}, socket) do
if socket.assigns.page_ref.page.body != nil do
{
:noreply,
socket
|> compose_child(:confirmation_modal)
|> show_modal(:confirmation_modal, :dialog)
}
else
{:ok, _} = Assignment.Public.delete_page_ref(socket.assigns.page_ref)
{:noreply, socket}
end
end

{
:noreply,
socket |> assign(page_ref: page_ref)
MelchiorKokernoot marked this conversation as resolved.
Show resolved Hide resolved
}
@impl true
def handle_event("cancelled", %{source: %{name: :confirmation_modal}}, socket) do
{:noreply,
socket
|> hide_modal(:confirmation_modal)}
end

@impl true
def handle_event(
"confirmed",
%{source: %{name: :confirmation_modal}},
%{assigns: %{page_ref: page_ref}} = socket
) do
{:ok, _} = Assignment.Public.delete_page_ref(page_ref)
{:noreply, socket |> hide_modal(:confirmation_modal)}
end

@impl true
@spec render(any()) :: Phoenix.LiveView.Rendered.t()
def render(assigns) do
~H"""
<div>
Expand Down
43 changes: 40 additions & 3 deletions core/systems/assignment/gdpr_form.ex
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,26 @@ defmodule Systems.Assignment.GdprForm do
}
end

@impl true
def compose(:confirmation_modal, %{entity: %{consent_agreement: consent_agreement}}) do
assigns = %{consent_agreement: consent_agreement}
signatures = Consent.Public.list_signatures(consent_agreement)

assigns =
if signatures != [] do
Map.put(assigns, :body, dgettext("eyra-assignment", "gdpr_form.confirmation_modal.body"))
else
assigns
end

%{
module: Pixel.ConfirmationModal,
MelchiorKokernoot marked this conversation as resolved.
Show resolved Hide resolved
params: %{
assigns: assigns
}
}
end

@impl true
def handle_event(
"update",
Expand All @@ -71,15 +91,32 @@ defmodule Systems.Assignment.GdprForm do
end

@impl true
def handle_event("update", %{status: :off}, %{assigns: %{entity: assignment}} = socket) do
{:ok, _} = Assignment.Public.update_consent_agreement(assignment, nil)

def handle_event("update", %{status: :off}, socket) do
{
:noreply,
MelchiorKokernoot marked this conversation as resolved.
Show resolved Hide resolved
socket
|> compose_child(:confirmation_modal)
|> show_modal(:confirmation_modal, :dialog)
}
end

@impl true
def handle_event("cancelled", %{source: %{name: :confirmation_modal}}, socket) do
{:noreply,
socket
|> hide_modal(:confirmation_modal)}
end

@impl true
def handle_event(
"confirmed",
%{source: %{name: :confirmation_modal}},
%{assigns: %{entity: assignment}} = socket
) do
{:ok, _} = Assignment.Public.update_consent_agreement(assignment, nil)
{:noreply, socket |> hide_modal(:confirmation_modal)}
end

@impl true
def render(assigns) do
~H"""
Expand Down
6 changes: 6 additions & 0 deletions core/systems/consent/_public.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
defmodule Systems.Consent.Public do
import CoreWeb.Gettext
import Ecto.Query
import Systems.Consent.Queries

alias Ecto.Multi
alias Core.Repo
Expand Down Expand Up @@ -183,6 +184,11 @@ defmodule Systems.Consent.Public do
|> Signal.Public.multi_dispatch({:consent_revision, :updated})
|> Repo.transaction()
end

def list_signatures(%Consent.AgreementModel{} = consent_agreement) do
signature_query(consent_agreement)
|> Repo.all()
end
end

defimpl Core.Persister, for: Systems.Consent.RevisionModel do
Expand Down
23 changes: 23 additions & 0 deletions core/systems/consent/_queries.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
defmodule Systems.Consent.Queries do
require Ecto.Query
require Frameworks.Utility.Query

import Ecto.Query, warn: false
import Frameworks.Utility.Query, only: [build: 3]

alias Systems.Consent

def signature_query() do
from(Consent.SignatureModel, as: :signature)
end

def signature_query(%Consent.AgreementModel{id: consent_agreement_id}) do
build(signature_query(), :signature,
revision: [
agreement: [
id == ^consent_agreement_id
]
]
)
end
end
Loading