Skip to content

Commit

Permalink
Made platforms dynamic and refactored content page so it is live upda…
Browse files Browse the repository at this point in the history
…table
  • Loading branch information
mellelieuwes committed Jul 5, 2023
1 parent e7467a2 commit 8f2c0bb
Show file tree
Hide file tree
Showing 28 changed files with 407 additions and 113 deletions.
11 changes: 11 additions & 0 deletions core/assets/static/images/icons/ready.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions core/frameworks/signal/_public.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ defmodule Frameworks.Signal.Public do
Core.WebPush.SignalHandlers,
Core.APNS.SignalHandlers,
Systems.Observatory.Switch,
Systems.Project.Switch,
Systems.Assignment.Switch,
Systems.Pool.Switch,
Systems.Student.Switch,
Expand Down
16 changes: 15 additions & 1 deletion core/lib/core/enums/base.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,22 @@ defmodule Core.Enums.Base do
unquote(values)
end

def contains(atom) when is_atom(atom) do
contains(Atom.to_string(atom))
end

def contains(binary) when is_binary(binary) do
values()
|> Enum.map(&Atom.to_string/1)
|> Enum.member?(binary)
end

def translate(value) do
Gettext.dgettext(CoreWeb.Gettext, "eyra-enums", "#{unquote(name)}.#{value}")
if contains(value) do
Gettext.dgettext(CoreWeb.Gettext, "eyra-enums", "#{unquote(name)}.#{value}")
else
value
end
end

def labels() do
Expand Down
16 changes: 16 additions & 0 deletions core/priv/gettext/en/LC_MESSAGES/eyra-project.po
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,19 @@ msgstr ""
#, elixir-autogen, elixir-format, fuzzy
msgid "create.item.title"
msgstr "Select item type"

#, elixir-autogen, elixir-format, fuzzy
msgid "item.form.name.label"
msgstr "Name"

#, elixir-autogen, elixir-format
msgid "item.form.title"
msgstr ""

#, elixir-autogen, elixir-format, fuzzy
msgid "tabbar.item.support"
msgstr "Support"

#, elixir-autogen, elixir-format, fuzzy
msgid "tabbar.item.support.forward"
msgstr "Support"
4 changes: 4 additions & 0 deletions core/priv/gettext/en/LC_MESSAGES/eyra-support.po
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ msgstr "Report is received"
#, elixir-autogen, elixir-format
msgid "ticket.type"
msgstr "Form"

#, elixir-autogen, elixir-format
msgid "content.form.title"
msgstr "Support"
16 changes: 16 additions & 0 deletions core/priv/gettext/eyra-project.pot
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,19 @@ msgstr ""
#, elixir-autogen, elixir-format
msgid "create.item.title"
msgstr ""

#, elixir-autogen, elixir-format
msgid "item.form.name.label"
msgstr ""

#, elixir-autogen, elixir-format
msgid "item.form.title"
msgstr ""

#, elixir-autogen, elixir-format
msgid "tabbar.item.support"
msgstr ""

#, elixir-autogen, elixir-format
msgid "tabbar.item.support.forward"
msgstr ""
4 changes: 4 additions & 0 deletions core/priv/gettext/eyra-support.pot
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ msgstr ""
#, elixir-autogen, elixir-format
msgid "ticket.type"
msgstr ""

#, elixir-autogen, elixir-format
msgid "content.form.title"
msgstr ""
16 changes: 16 additions & 0 deletions core/priv/gettext/nl/LC_MESSAGES/eyra-project.po
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,19 @@ msgstr ""
#, elixir-autogen, elixir-format, fuzzy
msgid "create.item.title"
msgstr "Kies type item"

#, elixir-autogen, elixir-format, fuzzy
msgid "item.form.name.label"
msgstr "Naam"

#, elixir-autogen, elixir-format
msgid "item.form.title"
msgstr ""

#, elixir-autogen, elixir-format, fuzzy
msgid "tabbar.item.support"
msgstr "Support"

#, elixir-autogen, elixir-format, fuzzy
msgid "tabbar.item.support.forward"
msgstr "Support"
4 changes: 4 additions & 0 deletions core/priv/gettext/nl/LC_MESSAGES/eyra-support.po
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ msgstr "Melding ontvangen"
#, elixir-autogen, elixir-format
msgid "ticket.type"
msgstr "Formulier"

#, elixir-autogen, elixir-format
msgid "content.form.title"
msgstr "Support"
62 changes: 50 additions & 12 deletions core/systems/data_donation/_public.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ defmodule Systems.DataDonation.Public do

alias Ecto.Multi
alias Core.Authorization
alias Frameworks.Signal

alias Systems.{
DataDonation
Expand Down Expand Up @@ -43,13 +44,23 @@ defmodule Systems.DataDonation.Public do
|> Repo.get!(id)
end

def get_task(tool_id, position, preload \\ []) do
from(task in DataDonation.TaskModel,
where: task.tool_id == ^tool_id,
where: task.position == ^position,
preload: ^preload
)
|> Repo.one()
def get_task_by_special!(field, special_id, preload \\ [])

def get_task_by_special!(field, special_id, preload) when is_atom(field) do
get_task_by_special!([field], special_id, preload)
end

def get_task_by_special!([hd | tl], special_id, preload) when is_integer(special_id) do
query =
from(task in DataDonation.TaskModel,
where: field(task, ^hd) == ^special_id,
preload: ^preload
)

Enum.reduce(tl, query, fn key, query ->
query |> or_where([task], field(task, ^key) == ^special_id)
end)
|> Repo.one!()
end

def get_document_task!(id, preload \\ []) do
Expand All @@ -68,11 +79,16 @@ defmodule Systems.DataDonation.Public do
|> Ecto.Changeset.put_assoc(:auth_node, auth_node)
end

def add_task(tool, task_type) when is_binary(task_type) do
def add_task(tool_id, task_type) when is_integer(tool_id) do
get_tool!(tool_id)
|> add_task(task_type)
end

def add_task(%DataDonation.ToolModel{} = tool, task_type) when is_binary(task_type) do
add_task(tool, String.to_existing_atom(task_type))
end

def add_task(%DataDonation.ToolModel{} = tool, task_type) do
def add_task(%DataDonation.ToolModel{id: tool_id} = tool, task_type) do
Multi.new()
|> Multi.run(:position, fn _, _ ->
{:ok, task_count(tool)}
Expand All @@ -81,6 +97,7 @@ defmodule Systems.DataDonation.Public do
|> Multi.insert(:task, fn %{position: position, task_special: task_special} ->
create_task(tool, position, task_type, task_special)
end)
|> Signal.Public.multi_dispatch(:data_donation_tasks, %{tool_id: tool_id})
|> Repo.transaction()
end

Expand Down Expand Up @@ -119,9 +136,10 @@ defmodule Systems.DataDonation.Public do
|> DataDonation.DonateTaskModel.changeset(%{})
end

def update(changeset) do
def update(changeset, key) do
Multi.new()
|> Repo.multi_update(:data_donation_tool, changeset)
|> Repo.multi_update(key, changeset)
|> Signal.Public.multi_dispatch(key, %{changeset: changeset})
|> Repo.transaction()
end

Expand All @@ -140,6 +158,7 @@ defmodule Systems.DataDonation.Public do
|> Multi.run(:order_and_update, fn _, %{tasks: tasks} ->
{:ok, rearrange(tasks)}
end)
|> Signal.Public.multi_dispatch(:data_donation_tasks, %{tool_id: tool_id})
|> Repo.transaction()
end

Expand All @@ -161,6 +180,7 @@ defmodule Systems.DataDonation.Public do
|> Multi.run(:order_and_update, fn _, %{tasks: tasks} ->
{:ok, rearrange(tasks, old, new)}
end)
|> Signal.Public.multi_dispatch(:data_donation_tasks, %{tool_id: tool_id})
|> Repo.transaction()
end

Expand Down Expand Up @@ -221,9 +241,27 @@ end

defimpl Core.Persister, for: Systems.DataDonation.ToolModel do
def save(_tool, changeset) do
case Systems.DataDonation.Public.update(changeset) do
case Systems.DataDonation.Public.update(changeset, :data_donation_tool) do
{:ok, %{data_donation_tool: tool}} -> {:ok, tool}
_ -> {:error, changeset}
end
end
end

defimpl Core.Persister, for: Systems.DataDonation.TaskModel do
def save(_task, changeset) do
case Systems.DataDonation.Public.update(changeset, :data_donation_task) do
{:ok, %{data_donation_task: task}} -> {:ok, task}
_ -> {:error, changeset}
end
end
end

defimpl Core.Persister, for: Systems.DataDonation.DocumentTaskModel do
def save(_task, changeset) do
case Systems.DataDonation.Public.update(changeset, :data_donation_document_task) do
{:ok, %{data_donation_document_task: task}} -> {:ok, task}
_ -> {:error, changeset}
end
end
end
12 changes: 2 additions & 10 deletions core/systems/data_donation/document_task_form.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ defmodule Systems.DataDonation.DocumentTaskForm do
def update(
%{
id: id,
parent: parent,
entity_id: entity_id
entity: entity
},
socket
) do
Expand All @@ -33,22 +32,15 @@ defmodule Systems.DataDonation.DocumentTaskForm do
socket
|> assign(
id: id,
parent: parent,
placeholder: placeholder,
select_button: select_button,
replace_button: replace_button,
entity_id: entity_id
entity: entity
)
|> init_file_uploader(:pdf)
|> update_entity()
}
end

defp update_entity(%{assigns: %{entity_id: entity_id}} = socket) do
entity = DataDonation.Public.get_document_task!(entity_id)
assign(socket, entity: entity)
end

@impl true
def handle_event("change", _params, socket) do
{:noreply, socket}
Expand Down
14 changes: 14 additions & 0 deletions core/systems/data_donation/document_task_model.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,23 @@ defmodule Systems.DataDonation.DocumentTaskModel do
end

@fields ~w(document_name document_ref)a
@required_fields @fields

def changeset(model, params) do
model
|> cast(params, @fields)
end

def validate(changeset) do
changeset
|> validate_required(@required_fields)
end

def ready?(task) do
changeset =
changeset(task, %{})
|> validate()

changeset.valid?()
end
end
14 changes: 14 additions & 0 deletions core/systems/data_donation/donate_task_model.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,23 @@ defmodule Systems.DataDonation.DonateTaskModel do
end

@fields ~w()a
@required_fields @fields

def changeset(model, params) do
model
|> cast(params, @fields)
end

def validate(changeset) do
changeset
|> validate_required(@required_fields)
end

def ready?(task) do
changeset =
changeset(task, %{})
|> validate()

changeset.valid?()
end
end
14 changes: 14 additions & 0 deletions core/systems/data_donation/survey_task_model.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,23 @@ defmodule Systems.DataDonation.SurveyTaskModel do
end

@fields ~w()a
@required_fields @fields

def changeset(model, params) do
model
|> cast(params, @fields)
end

def validate(changeset) do
changeset
|> validate_required(@required_fields)
end

def ready?(task) do
changeset =
changeset(task, %{})
|> validate()

changeset.valid?()
end
end
Loading

0 comments on commit 8f2c0bb

Please sign in to comment.