diff --git a/core/frameworks/concept/presenter.ex b/core/frameworks/concept/presenter.ex index 6b48acd50..5d535042f 100644 --- a/core/frameworks/concept/presenter.ex +++ b/core/frameworks/concept/presenter.ex @@ -1,9 +1,9 @@ defmodule Frameworks.Concept.Presenter do - @type model :: pos_integer() | map @type page :: atom() + @type model :: pos_integer() | map | nil @type assigns :: map - @callback view_model(model, page, assigns) :: map() + @callback view_model(page, model, assigns) :: map() defmacro __using__(_opts) do quote do diff --git a/core/frameworks/utililty/view_model_builder.ex b/core/frameworks/utililty/view_model_builder.ex index b4b383242..8af0c4a3e 100644 --- a/core/frameworks/utililty/view_model_builder.ex +++ b/core/frameworks/utililty/view_model_builder.ex @@ -1,6 +1,6 @@ defprotocol Frameworks.Utility.ViewModelBuilder do @type accumulator :: map - @type model :: map | list + @type model :: map | list | nil @type page :: atom() | tuple() @type assigns :: map diff --git a/core/lib/core_web/ui/dialog/dialog.ex b/core/lib/core_web/ui/dialog/dialog.ex index e8967ee77..24d4991a7 100644 --- a/core/lib/core_web/ui/dialog/dialog.ex +++ b/core/lib/core_web/ui/dialog/dialog.ex @@ -4,7 +4,7 @@ defmodule CoreWeb.UI.Dialog do alias Frameworks.Pixel.Button attr(:title, :string, required: true) - attr(:text, :string, required: true) + attr(:text, :string, default: nil) attr(:buttons, :list, default: []) slot(:inner_block) @@ -15,9 +15,11 @@ defmodule CoreWeb.UI.Dialog do
<%= @title %>
-
- <%= @text %> -
+ <%= if @text do %> +
+ <%= @text %> +
+ <% end %>
<%= render_slot(@inner_block) %>
diff --git a/core/lib/core_web/ui/empty.ex b/core/lib/core_web/ui/empty.ex index e39b44031..ec630ad6d 100644 --- a/core/lib/core_web/ui/empty.ex +++ b/core/lib/core_web/ui/empty.ex @@ -5,7 +5,8 @@ defmodule CoreWeb.UI.Empty do attr(:title, :string, required: true) attr(:body, :string, required: true) - attr(:illustration, :string, default: "cards") + attr(:illustration, :string) + attr(:button, :map, default: nil) def empty(assigns) do ~H""" @@ -15,18 +16,21 @@ defmodule CoreWeb.UI.Empty do
<%= @body %>
+ <%= if @button do %> +
+ <.spacing value="L" /> + <.wrap> + + +
+ <% end %> -
+
""" diff --git a/core/priv/gettext/en/LC_MESSAGES/eyra-consent.po b/core/priv/gettext/en/LC_MESSAGES/eyra-consent.po index 4434c6ee2..82b97ee77 100644 --- a/core/priv/gettext/en/LC_MESSAGES/eyra-consent.po +++ b/core/priv/gettext/en/LC_MESSAGES/eyra-consent.po @@ -11,10 +11,6 @@ msgstr "" "Language: en\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" -#, elixir-autogen, elixir-format -msgid "consent-out-of-sync-error" -msgstr "Someone made changes to the consent text. Please refresh the page to continue." - #, elixir-autogen, elixir-format msgid "default.consent.text" msgstr "
Write here your custom consent terms and conditions..
" diff --git a/core/priv/gettext/en/LC_MESSAGES/eyra-enums.po b/core/priv/gettext/en/LC_MESSAGES/eyra-enums.po index 5e5fe3ee1..1b2763b94 100644 --- a/core/priv/gettext/en/LC_MESSAGES/eyra-enums.po +++ b/core/priv/gettext/en/LC_MESSAGES/eyra-enums.po @@ -336,7 +336,7 @@ msgstr "Empty" #, elixir-autogen, elixir-format, fuzzy msgid "templates.data_donation" -msgstr "Online study" +msgstr "Data donation" #, elixir-autogen, elixir-format, fuzzy msgid "platforms.apple" diff --git a/core/priv/gettext/en/LC_MESSAGES/eyra-project.po b/core/priv/gettext/en/LC_MESSAGES/eyra-project.po index 8dd08bdc7..fee22cb74 100644 --- a/core/priv/gettext/en/LC_MESSAGES/eyra-project.po +++ b/core/priv/gettext/en/LC_MESSAGES/eyra-project.po @@ -49,7 +49,7 @@ msgstr "Here you will find an overview of all your projects. There are no projec #, elixir-autogen, elixir-format msgid "overview.empty.title" -msgstr "Welcome" +msgstr "Your journey starts here" #, elixir-autogen, elixir-format msgid "overview.title" @@ -158,3 +158,35 @@ msgstr "Settings" #, elixir-autogen, elixir-format, fuzzy msgid "tabbar.item.settings.forward" msgstr "Go to Settings" + +#, elixir-autogen, elixir-format +msgid "default.name" +msgstr "New project" + +#, elixir-autogen, elixir-format, fuzzy +msgid "add.first.item.button" +msgstr "Add first item" + +#, elixir-autogen, elixir-format +msgid "node.empty.description" +msgstr "Here you will find an overview your items. There are no items yet available. You can now add your first item." + +#, elixir-autogen, elixir-format, fuzzy +msgid "node.empty.title" +msgstr "Blank canvas" + +#, elixir-autogen, elixir-format +msgid "tool_ref.tag.benchmark" +msgstr "Benchmark" + +#, elixir-autogen, elixir-format +msgid "tool_ref.tag.default" +msgstr "Tool" + +#, elixir-autogen, elixir-format +msgid "tool_ref.tag.questionnaire" +msgstr "Questionnaire" + +#, elixir-autogen, elixir-format, fuzzy +msgid "form.text" +msgstr "Project settings" diff --git a/core/priv/gettext/en/LC_MESSAGES/eyra-ui.po b/core/priv/gettext/en/LC_MESSAGES/eyra-ui.po index 4ea109a7d..67f0d60b4 100644 --- a/core/priv/gettext/en/LC_MESSAGES/eyra-ui.po +++ b/core/priv/gettext/en/LC_MESSAGES/eyra-ui.po @@ -253,3 +253,7 @@ msgstr "Edit" #, elixir-autogen, elixir-format msgid "copy.clipboard.button" msgstr "Copy" + +#, elixir-autogen, elixir-format, fuzzy +msgid "submit.button" +msgstr "Save" diff --git a/core/priv/gettext/eyra-consent.pot b/core/priv/gettext/eyra-consent.pot index d789ea5e9..50e04738f 100644 --- a/core/priv/gettext/eyra-consent.pot +++ b/core/priv/gettext/eyra-consent.pot @@ -11,10 +11,6 @@ msgid "" msgstr "" -#, elixir-autogen, elixir-format -msgid "consent-out-of-sync-error" -msgstr "" - #, elixir-autogen, elixir-format msgid "default.consent.text" msgstr "" diff --git a/core/priv/gettext/eyra-project.pot b/core/priv/gettext/eyra-project.pot index 7fc0f4c9c..124f83057 100644 --- a/core/priv/gettext/eyra-project.pot +++ b/core/priv/gettext/eyra-project.pot @@ -158,3 +158,35 @@ msgstr "" #, elixir-autogen, elixir-format msgid "tabbar.item.settings.forward" msgstr "" + +#, elixir-autogen, elixir-format +msgid "default.name" +msgstr "" + +#, elixir-autogen, elixir-format +msgid "add.first.item.button" +msgstr "" + +#, elixir-autogen, elixir-format +msgid "node.empty.description" +msgstr "" + +#, elixir-autogen, elixir-format +msgid "node.empty.title" +msgstr "" + +#, elixir-autogen, elixir-format +msgid "tool_ref.tag.benchmark" +msgstr "" + +#, elixir-autogen, elixir-format +msgid "tool_ref.tag.default" +msgstr "" + +#, elixir-autogen, elixir-format +msgid "tool_ref.tag.questionnaire" +msgstr "" + +#, elixir-autogen, elixir-format +msgid "form.text" +msgstr "" diff --git a/core/priv/gettext/eyra-ui.pot b/core/priv/gettext/eyra-ui.pot index 6239d7106..1223c014d 100644 --- a/core/priv/gettext/eyra-ui.pot +++ b/core/priv/gettext/eyra-ui.pot @@ -253,3 +253,7 @@ msgstr "" #, elixir-autogen, elixir-format msgid "copy.clipboard.button" msgstr "" + +#, elixir-autogen, elixir-format +msgid "submit.button" +msgstr "" diff --git a/core/priv/gettext/nl/LC_MESSAGES/eyra-consent.po b/core/priv/gettext/nl/LC_MESSAGES/eyra-consent.po index ae40207e9..f871081f6 100644 --- a/core/priv/gettext/nl/LC_MESSAGES/eyra-consent.po +++ b/core/priv/gettext/nl/LC_MESSAGES/eyra-consent.po @@ -11,10 +11,6 @@ msgstr "" "Language: nl\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" -#, elixir-autogen, elixir-format -msgid "consent-out-of-sync-error" -msgstr "Iemand heeft de consent tekst is aangepast. Ververs de pagina om verder te gaan." - #, elixir-autogen, elixir-format msgid "default.consent.text" msgstr "
Beschrijf hier de consent voorwaarden
" diff --git a/core/priv/gettext/nl/LC_MESSAGES/eyra-enums.po b/core/priv/gettext/nl/LC_MESSAGES/eyra-enums.po index f501f2da2..91b635ec6 100644 --- a/core/priv/gettext/nl/LC_MESSAGES/eyra-enums.po +++ b/core/priv/gettext/nl/LC_MESSAGES/eyra-enums.po @@ -336,7 +336,7 @@ msgstr "Leeg" #, elixir-autogen, elixir-format, fuzzy msgid "templates.data_donation" -msgstr "Online studie" +msgstr "Data donatie" #, elixir-autogen, elixir-format, fuzzy msgid "platforms.apple" diff --git a/core/priv/gettext/nl/LC_MESSAGES/eyra-project.po b/core/priv/gettext/nl/LC_MESSAGES/eyra-project.po index 016c2cb50..8322ef702 100644 --- a/core/priv/gettext/nl/LC_MESSAGES/eyra-project.po +++ b/core/priv/gettext/nl/LC_MESSAGES/eyra-project.po @@ -49,7 +49,7 @@ msgstr "Hier kan vind je een overzicht van al je projecten. Op dit moment zijn e #, elixir-autogen, elixir-format msgid "overview.empty.title" -msgstr "Welkom" +msgstr "Here start je reis" #, elixir-autogen, elixir-format msgid "overview.title" @@ -158,3 +158,35 @@ msgstr "Instellingen" #, elixir-autogen, elixir-format, fuzzy msgid "tabbar.item.settings.forward" msgstr "Ga naar Instellingen" + +#, elixir-autogen, elixir-format +msgid "default.name" +msgstr "Nieuw project" + +#, elixir-autogen, elixir-format, fuzzy +msgid "add.first.item.button" +msgstr "Maak eerste item aan" + +#, elixir-autogen, elixir-format +msgid "node.empty.description" +msgstr "Hier vind je een overzicht van je items. Op dit moment zijn er nog geen items beschikbaar. Je kan nu je eerste item aanmaken." + +#, elixir-autogen, elixir-format, fuzzy +msgid "node.empty.title" +msgstr "Leeg canvas" + +#, elixir-autogen, elixir-format +msgid "tool_ref.tag.benchmark" +msgstr "Benchmark" + +#, elixir-autogen, elixir-format +msgid "tool_ref.tag.default" +msgstr "Tool" + +#, elixir-autogen, elixir-format +msgid "tool_ref.tag.questionnaire" +msgstr "Vragenlijst" + +#, elixir-autogen, elixir-format, fuzzy +msgid "form.text" +msgstr "Project instellingen" diff --git a/core/priv/gettext/nl/LC_MESSAGES/eyra-ui.po b/core/priv/gettext/nl/LC_MESSAGES/eyra-ui.po index 407f32385..2928996d8 100644 --- a/core/priv/gettext/nl/LC_MESSAGES/eyra-ui.po +++ b/core/priv/gettext/nl/LC_MESSAGES/eyra-ui.po @@ -253,3 +253,7 @@ msgstr "Bewerken" #, elixir-autogen, elixir-format msgid "copy.clipboard.button" msgstr "Kopieer" + +#, elixir-autogen, elixir-format, fuzzy +msgid "submit.button" +msgstr "Opslaan" diff --git a/core/systems/alliance/_presenter.ex b/core/systems/alliance/_presenter.ex index 7c29dfbd4..a7216e07c 100644 --- a/core/systems/alliance/_presenter.ex +++ b/core/systems/alliance/_presenter.ex @@ -4,7 +4,7 @@ defmodule Systems.Alliance.Presenter do alias Systems.Alliance @impl true - def view_model(%Alliance.ToolModel{director: director} = tool, page, assigns) do - Frameworks.Utility.Module.get(director, "Presenter").view_model(tool, page, assigns) + def view_model(page, %Alliance.ToolModel{director: director} = tool, assigns) do + Frameworks.Utility.Module.get(director, "Presenter").view_model(page, tool, assigns) end end diff --git a/core/systems/alliance/callback_page.ex b/core/systems/alliance/callback_page.ex index c6589ba61..5426ae8ab 100644 --- a/core/systems/alliance/callback_page.ex +++ b/core/systems/alliance/callback_page.ex @@ -44,8 +44,6 @@ defmodule Systems.Alliance.CallbackPage do defp activate_participant_task(socket), do: socket - defoverridable handle_view_model_updated: 1 - def handle_view_model_updated(socket), do: socket @impl true diff --git a/core/systems/assignment/_presenter.ex b/core/systems/assignment/_presenter.ex index 777558830..b210a8bb9 100644 --- a/core/systems/assignment/_presenter.ex +++ b/core/systems/assignment/_presenter.ex @@ -9,21 +9,21 @@ defmodule Systems.Assignment.Presenter do } @impl true - def view_model(%Alliance.ToolModel{} = tool, Alliance.CallbackPage = page, assigns) do + def view_model(Alliance.CallbackPage = page, %Alliance.ToolModel{} = tool, assigns) do builder(page).view_model(tool, assigns) end @impl true def view_model( - %Assignment.Model{director: director} = assignment, Assignment.LandingPage = page, + %Assignment.Model{director: director} = assignment, assigns ) do - Module.get(director, "Presenter").view_model(assignment, page, assigns) + Module.get(director, "Presenter").view_model(page, assignment, assigns) end @impl true - def view_model(%Assignment.Model{} = assignment, page, assigns) do + def view_model(page, %Assignment.Model{} = assignment, assigns) do builder(page).view_model(assignment, assigns) end diff --git a/core/systems/assignment/content_page_builder.ex b/core/systems/assignment/content_page_builder.ex index e1ed82102..3ded782c1 100644 --- a/core/systems/assignment/content_page_builder.ex +++ b/core/systems/assignment/content_page_builder.ex @@ -220,6 +220,12 @@ defmodule Systems.Assignment.ContentPageBuilder do title: dgettext("eyra-workflow", "item.library.title"), description: dgettext("eyra-workflow", "item.library.description"), items: [ + %{ + id: :donate, + type: :feldspar_tool, + title: dgettext("eyra-workflow", "item.donate.title"), + description: dgettext("eyra-workflow", "item.donate.description") + }, %{ id: :questionnaire, type: :alliance_tool, @@ -237,12 +243,6 @@ defmodule Systems.Assignment.ContentPageBuilder do type: :document_tool, title: dgettext("eyra-workflow", "item.download.title"), description: dgettext("eyra-workflow", "item.download.description") - }, - %{ - id: :donate, - type: :feldspar_tool, - title: dgettext("eyra-workflow", "item.donate.title"), - description: dgettext("eyra-workflow", "item.donate.description") } ] } diff --git a/core/systems/assignment/crew_page.ex b/core/systems/assignment/crew_page.ex index 0dc09ef26..365ce2156 100644 --- a/core/systems/assignment/crew_page.ex +++ b/core/systems/assignment/crew_page.ex @@ -38,8 +38,6 @@ defmodule Systems.Assignment.CrewPage do } end - defoverridable handle_view_model_updated: 1 - def handle_view_model_updated(socket) do socket |> update_flow() diff --git a/core/systems/assignment/gdpr_form.ex b/core/systems/assignment/gdpr_form.ex index fd60d3600..dd659b881 100644 --- a/core/systems/assignment/gdpr_form.ex +++ b/core/systems/assignment/gdpr_form.ex @@ -59,7 +59,7 @@ defmodule Systems.Assignment.GdprForm do %{status: :on}, %{assigns: %{entity: %{auth_node: auth_node} = assignment}} = socket ) do - consent_agreement = %Consent.AgreementModel{auth_node: auth_node} + consent_agreement = Consent.Public.prepare_agreement(auth_node: auth_node) Assignment.Public.update_consent_agreement(assignment, consent_agreement) { diff --git a/core/systems/assignment/landing_page.ex b/core/systems/assignment/landing_page.ex index 7009deefa..19e295dd4 100644 --- a/core/systems/assignment/landing_page.ex +++ b/core/systems/assignment/landing_page.ex @@ -44,8 +44,6 @@ defmodule Systems.Assignment.LandingPage do } end - defoverridable handle_view_model_updated: 1 - def handle_view_model_updated(socket) do socket |> update_task_view() diff --git a/core/systems/assignment/model.ex b/core/systems/assignment/model.ex index d709a8039..bbf99ded8 100644 --- a/core/systems/assignment/model.ex +++ b/core/systems/assignment/model.ex @@ -89,6 +89,10 @@ defmodule Systems.Assignment.Model do def tool(_), do: nil + def tag(%{special: special}) do + Assignment.Templates.translate(special) + end + def preload_graph(:down) do [ :excluded, diff --git a/core/systems/benchmark/_presenter.ex b/core/systems/benchmark/_presenter.ex index 51f3f8d91..d42e11579 100644 --- a/core/systems/benchmark/_presenter.ex +++ b/core/systems/benchmark/_presenter.ex @@ -6,7 +6,7 @@ defmodule Systems.Benchmark.Presenter do } @impl true - def view_model(%Benchmark.ToolModel{} = tool, page, assigns) do + def view_model(page, %Benchmark.ToolModel{} = tool, assigns) do builder(page).view_model(tool, assigns) end diff --git a/core/systems/campaign/_presenter.ex b/core/systems/campaign/_presenter.ex index 9335053d6..a122c8f55 100644 --- a/core/systems/campaign/_presenter.ex +++ b/core/systems/campaign/_presenter.ex @@ -1,33 +1,26 @@ defmodule Systems.Campaign.Presenter do @behaviour Frameworks.Concept.Presenter - alias Frameworks.Signal - alias Systems.{ Campaign, Promotion, Assignment } - def update(%Campaign.Model{} = campaign, id, page) do - Signal.Public.dispatch!({:page, page}, %{id: id, model: campaign}) - campaign - end - @impl true - def view_model(%Assignment.Model{} = assignment, page, assigns) do - Campaign.Public.get_by_promotable(assignment, Campaign.Model.preload_graph(:down)) - |> view_model(page, assigns) + def view_model(page, %Assignment.Model{} = assignment, assigns) do + campaign = Campaign.Public.get_by_promotable(assignment, Campaign.Model.preload_graph(:down)) + view_model(page, campaign, assigns) end @impl true - def view_model(%Promotion.Model{} = promotion, page, assigns) do - Campaign.Public.get_by_promotion(promotion, Campaign.Model.preload_graph(:down)) - |> view_model(page, assigns) + def view_model(page, %Promotion.Model{} = promotion, assigns) do + campaign = Campaign.Public.get_by_promotion(promotion, Campaign.Model.preload_graph(:down)) + view_model(page, campaign, assigns) end @impl true - def view_model(%Campaign.Model{} = campaign, page, assigns) do + def view_model(page, %Campaign.Model{} = campaign, assigns) do builder(page).view_model(campaign, assigns) end diff --git a/core/systems/campaign/_switch.ex b/core/systems/campaign/_switch.ex index dd22f2ce4..dc90b01b8 100644 --- a/core/systems/campaign/_switch.ex +++ b/core/systems/campaign/_switch.ex @@ -56,12 +56,15 @@ defmodule Systems.Campaign.Switch do if event == :created do Campaign.Public.assign_coordinators(campaign) else - campaign - |> Campaign.Presenter.update(promotion_id, Promotion.LandingPage) - |> Campaign.Presenter.update(assignment_id, Assignment.LandingPage) - |> Campaign.Presenter.update(id, Campaign.ContentPage) + update(Promotion.LandingPage, promotion_id, campaign) + update(Assignment.LandingPage, assignment_id, campaign) + update(Campaign.ContentPage, id, campaign) end end defp handle({_, _}, _), do: nil + + def update(page, id, %Campaign.Model{} = campaign) do + Signal.Public.dispatch!({:page, page}, %{id: id, model: campaign}) + end end diff --git a/core/systems/campaign/content_page.ex b/core/systems/campaign/content_page.ex index 98753dbb7..cca27a468 100644 --- a/core/systems/campaign/content_page.ex +++ b/core/systems/campaign/content_page.ex @@ -73,8 +73,6 @@ defmodule Systems.Campaign.ContentPage do super(socket) end - defoverridable handle_view_model_updated: 1 - def handle_view_model_updated(socket) do socket |> update_actions() diff --git a/core/systems/citizen/_presenter.ex b/core/systems/citizen/_presenter.ex index b4d7c512d..58582c490 100644 --- a/core/systems/citizen/_presenter.ex +++ b/core/systems/citizen/_presenter.ex @@ -7,12 +7,12 @@ defmodule Systems.Citizen.Presenter do } @impl true - def view_model(%Pool.SubmissionModel{} = submission, Pool.SubmissionPage, assigns) do + def view_model(Pool.SubmissionPage, %Pool.SubmissionModel{} = submission, assigns) do Citizen.Pool.SubmissionPageBuilder.view_model(submission, assigns) end @impl true - def view_model(%Pool.Model{} = pool, Pool.DetailPage, assigns) do + def view_model(Pool.DetailPage, %Pool.Model{} = pool, assigns) do Citizen.Pool.DetailPageBuilder.view_model(pool, assigns) end end diff --git a/core/systems/consent/_public.ex b/core/systems/consent/_public.ex index 87d95a68f..1084bda16 100644 --- a/core/systems/consent/_public.ex +++ b/core/systems/consent/_public.ex @@ -19,6 +19,7 @@ defmodule Systems.Consent.Public do %Consent.AgreementModel{} |> Consent.AgreementModel.changeset() |> Ecto.Changeset.put_assoc(:auth_node, auth_node) + |> Ecto.Changeset.put_assoc(:revisions, [prepare_revision(nil)]) end def bump_revision_if_needed(agreement_id) when is_integer(agreement_id) do @@ -31,7 +32,7 @@ defmodule Systems.Consent.Public do Multi.new() |> Multi.run(:revision, fn _, _ -> case latest_revision(agreement, [:signatures]) do - nil -> create_revision(agreement, dgettext("eyra-consent", "default.consent.text")) + nil -> create_revision(agreement, nil) %{source: source, signatures: [_ | _]} -> create_revision(agreement, source) revision -> {:ok, revision} end @@ -51,9 +52,18 @@ defmodule Systems.Consent.Public do |> Repo.insert() end - def prepare_revision(agreement, source) when is_binary(source) do + def prepare_revision(nil) do + dgettext("eyra-consent", "default.consent.text") + |> prepare_revision() + end + + def prepare_revision(source) when is_binary(source) do %Consent.RevisionModel{} |> Consent.RevisionModel.changeset(%{source: source}) + end + + def prepare_revision(agreement, source) do + prepare_revision(source) |> Ecto.Changeset.put_assoc(:agreement, agreement) end diff --git a/core/systems/content/page.ex b/core/systems/content/page.ex index 3db6591f6..8dbcd3073 100644 --- a/core/systems/content/page.ex +++ b/core/systems/content/page.ex @@ -127,8 +127,6 @@ defmodule Systems.Content.Page do super(socket) end - defoverridable handle_view_model_updated: 1 - def handle_view_model_updated(socket) do socket |> update_actions() diff --git a/core/systems/document/_presenter.ex b/core/systems/document/_presenter.ex index f9404f06e..552e446b9 100644 --- a/core/systems/document/_presenter.ex +++ b/core/systems/document/_presenter.ex @@ -6,7 +6,7 @@ defmodule Systems.Document.Presenter do } @impl true - def view_model(%Document.ToolModel{} = _tool, _page, _assigns) do + def view_model(_page, %Document.ToolModel{} = _tool, _assigns) do %{} end end diff --git a/core/systems/feldspar/_presenter.ex b/core/systems/feldspar/_presenter.ex index 7ba42cb44..967bf653b 100644 --- a/core/systems/feldspar/_presenter.ex +++ b/core/systems/feldspar/_presenter.ex @@ -6,7 +6,7 @@ defmodule Systems.Feldspar.Presenter do } @impl true - def view_model(%Feldspar.ToolModel{} = _tool, _page, _assigns) do + def view_model(_page, %Feldspar.ToolModel{} = _tool, _assigns) do %{} end end diff --git a/core/systems/lab/_presenter.ex b/core/systems/lab/_presenter.ex index fadef4ac8..28d7d0f25 100644 --- a/core/systems/lab/_presenter.ex +++ b/core/systems/lab/_presenter.ex @@ -6,7 +6,7 @@ defmodule Systems.Lab.Presenter do } @impl true - def view_model(%Lab.ToolModel{} = _tool, _page, _assigns) do + def view_model(_page, %Lab.ToolModel{} = _tool, _assigns) do %{} end end diff --git a/core/systems/next_action/_presenter.ex b/core/systems/next_action/_presenter.ex index 301debcef..d17097416 100644 --- a/core/systems/next_action/_presenter.ex +++ b/core/systems/next_action/_presenter.ex @@ -1,19 +1,10 @@ defmodule Systems.NextAction.Presenter do use Frameworks.Concept.Presenter - alias Frameworks.Signal - - alias Systems.{ - NextAction - } + alias Systems.NextAction @impl true - def view_model(%Core.Accounts.User{} = user, NextAction.OverviewPage, _) do + def view_model(NextAction.OverviewPage, %Core.Accounts.User{} = user, _) do %{next_actions: NextAction.Public.list_next_actions(user)} end - - def update(model, %Core.Accounts.User{id: id}, page) do - Signal.Public.dispatch!({:page, page}, %{id: id, model: model}) - model - end end diff --git a/core/systems/next_action/_switch.ex b/core/systems/next_action/_switch.ex index 9aa82a4ab..0492b06b6 100644 --- a/core/systems/next_action/_switch.ex +++ b/core/systems/next_action/_switch.ex @@ -6,10 +6,14 @@ defmodule Systems.NextAction.Switch do } def intercept({:next_action, :created}, %{user: user, action: _action}) do - NextAction.Presenter.update(user, user, NextAction.OverviewPage) + update(NextAction.OverviewPage, user) end def intercept({:next_action, :cleared}, %{user: user, action_type: _action_type}) do - NextAction.Presenter.update(user, user, NextAction.OverviewPage) + update(NextAction.OverviewPage, user) + end + + defp update(page, %{id: id} = model) do + Signal.Public.dispatch!({:page, page}, %{id: id, model: model}) end end diff --git a/core/systems/next_action/overview_page.ex b/core/systems/next_action/overview_page.ex index 9403f2111..880a6c65e 100644 --- a/core/systems/next_action/overview_page.ex +++ b/core/systems/next_action/overview_page.ex @@ -31,8 +31,6 @@ defmodule Systems.NextAction.OverviewPage do ) end - defoverridable handle_view_model_updated: 1 - def handle_view_model_updated(socket) do refresh_next_actions(socket) end diff --git a/core/systems/observatory/_public.ex b/core/systems/observatory/_public.ex index 2bf6a1bf4..76a7c1715 100644 --- a/core/systems/observatory/_public.ex +++ b/core/systems/observatory/_public.ex @@ -37,23 +37,20 @@ defmodule Systems.Observatory.Public do socket end - def update_view_model(socket, model, page, presenter) do - vm = - presenter - |> get_view_model(socket, model, page) + def update_view_model(socket, page, model, presenter) do + vm = get_view_model(socket, page, model, presenter) socket |> Phoenix.Component.assign(vm: vm) end defp get_view_model( - presenter, %{assigns: assigns} = _socket, + page, model, - page + presenter ) do - presenter - |> apply(:view_model, [model, page, assigns]) + apply(presenter, :view_model, [page, model, assigns]) end defmacro __using__(_opts \\ []) do @@ -61,6 +58,8 @@ defmodule Systems.Observatory.Public do import CoreWeb.Gettext alias Systems.Observatory.Public + require Logger + @presenter Frameworks.Concept.System.presenter(__MODULE__) def handle_info(%{auto_save: status}, socket) do @@ -74,7 +73,7 @@ defmodule Systems.Observatory.Public do { :noreply, socket - |> Public.update_view_model(model, __MODULE__, @presenter) + |> Public.update_view_model(__MODULE__, model, @presenter) |> handle_view_model_updated() |> put_updated_info_flash() } @@ -83,19 +82,21 @@ defmodule Systems.Observatory.Public do def observe_view_model(%{assigns: %{model: %{id: id} = model}} = socket) do socket |> Public.observe([{__MODULE__, [id]}]) - |> Public.update_view_model(model, __MODULE__, @presenter) + |> Public.update_view_model(__MODULE__, model, @presenter) end - def update_view_model(%{assigns: %{model: %{id: id} = model}} = socket) do + def update_view_model(%{assigns: %{model: model}} = socket) do socket - |> Public.update_view_model(model, __MODULE__, @presenter) + |> Public.update_view_model(__MODULE__, model, @presenter) end def handle_view_model_updated(socket) do - IO.puts("No handle_observation/1 implemented") + Logger.warn("handle_view_model_updated/1 not implemented") socket end + defoverridable handle_view_model_updated: 1 + def put_updated_info_flash(%{assigns: %{auto_save_status: :active}} = socket) do socket end diff --git a/core/systems/pool/_presenter.ex b/core/systems/pool/_presenter.ex index b127412a0..920f3252d 100644 --- a/core/systems/pool/_presenter.ex +++ b/core/systems/pool/_presenter.ex @@ -4,7 +4,7 @@ defmodule Systems.Pool.Presenter do alias Systems.Pool @impl true - def view_model(%Pool.Model{director: director} = pool, page, assigns) do - Frameworks.Concept.System.presenter(director).view_model(pool, page, assigns) + def view_model(page, %Pool.Model{director: director} = pool, assigns) do + Frameworks.Concept.System.presenter(director).view_model(page, pool, assigns) end end diff --git a/core/systems/pool/pages/detail_page.ex b/core/systems/pool/pages/detail_page.ex index e88e157c1..c9a6225c2 100644 --- a/core/systems/pool/pages/detail_page.ex +++ b/core/systems/pool/pages/detail_page.ex @@ -44,8 +44,6 @@ defmodule Systems.Pool.DetailPage do mount(%{"id" => pool_id, "tab" => nil}, session, socket) end - defoverridable handle_view_model_updated: 1 - def handle_view_model_updated(socket) do socket |> update_menus() end diff --git a/core/systems/pool/pages/submission_page.ex b/core/systems/pool/pages/submission_page.ex index d15cedd81..3dc99eb55 100644 --- a/core/systems/pool/pages/submission_page.ex +++ b/core/systems/pool/pages/submission_page.ex @@ -54,10 +54,7 @@ defmodule Systems.Pool.SubmissionPage do super(assign(socket, preview_path: preview_path)) end - defoverridable handle_view_model_updated: 1 - def handle_view_model_updated(socket) do - IO.puts("handle_view_model_updated") socket |> update_menus() end diff --git a/core/systems/project/_assembly.ex b/core/systems/project/_assembly.ex index 1979da06f..9d98d5b03 100644 --- a/core/systems/project/_assembly.ex +++ b/core/systems/project/_assembly.ex @@ -31,6 +31,7 @@ defmodule Systems.Project.Assembly do Multi.new() |> Multi.insert(:project, project) + |> EctoHelper.run(:auth, &update_auth/2) |> Repo.transaction() end diff --git a/core/systems/project/_presenter.ex b/core/systems/project/_presenter.ex index fb8d2ecc4..80da3f6a7 100644 --- a/core/systems/project/_presenter.ex +++ b/core/systems/project/_presenter.ex @@ -1,20 +1,15 @@ defmodule Systems.Project.Presenter do @behaviour Frameworks.Concept.Presenter - alias Systems.{ - Project - } + alias Systems.Project @impl true - def view_model(%Project.NodeModel{} = node, page, assigns) do - builder(page).view_model(node, assigns) + def view_model(Project.NodePage, %Project.NodeModel{} = node, assigns) do + Project.NodePageBuilder.view_model(node, assigns) end @impl true - def view_model(%Project.ItemModel{} = item, page, assigns) do - builder(page).view_model(item, assigns) + def view_model(Project.OverviewPage, %Core.Accounts.User{} = user, assigns) do + Project.OverviewPageBuilder.view_model(user, assigns) end - - defp builder(Project.NodePage), do: Project.NodePageBuilder - defp builder(Project.ItemContentPage), do: Project.ItemContentPageBuilder end diff --git a/core/systems/project/_public.ex b/core/systems/project/_public.ex index 420e87ca4..16113b1df 100644 --- a/core/systems/project/_public.ex +++ b/core/systems/project/_public.ex @@ -1,5 +1,7 @@ defmodule Systems.Project.Public do import Ecto.Query, warn: false + import CoreWeb.Gettext + alias Core.Repo alias Core.Accounts.User @@ -97,6 +99,31 @@ defmodule Systems.Project.Public do |> Repo.all() end + def exists?(user, name) do + list_owned_projects(user) + |> Enum.find(&(&1.name == name)) != nil + end + + def new_project_name(user) do + name = dgettext("eyra-project", "default.name") + + if exists?(user, name) do + new_project_name(user, name, 2) + else + name + end + end + + def new_project_name(user, name, attempt) do + new_name = "#{name} (#{attempt})" + + if exists?(user, new_name) do + new_project_name(user, name, attempt + 1) + else + new_name + end + end + def delete(id) when is_number(id) do get!(id, Project.Model.preload_graph(:down)) |> Project.Assembly.delete() @@ -199,3 +226,12 @@ defmodule Systems.Project.Public do from(u in User, where: u.id in ^owner_ids, preload: ^preload, order_by: u.id) |> Repo.all() end end + +defimpl Core.Persister, for: Systems.Project.Model do + def save(_project, changeset) do + case Frameworks.Utility.EctoHelper.update_and_dispatch(changeset, :project) do + {:ok, %{project: project}} -> {:ok, project} + _ -> {:error, changeset} + end + end +end diff --git a/core/systems/project/_switch.ex b/core/systems/project/_switch.ex index a5a5fc15a..3d18bb208 100644 --- a/core/systems/project/_switch.ex +++ b/core/systems/project/_switch.ex @@ -42,6 +42,11 @@ defmodule Systems.Project.Switch do update_pages(project_item) end + @impl true + def intercept({:project, _}, %{project: project}) do + update_pages(project) + end + defp handle({:tool, signal}, %{tool: tool} = message) do Project.Public.get_tool_ref_by_tool(tool) |> then(&dispatch!({:tool_ref, signal}, Map.merge(message, %{tool_ref: &1}))) @@ -52,6 +57,13 @@ defmodule Systems.Project.Switch do |> Enum.each(&update_page(&1, item)) end + defp update_pages(%Project.Model{} = project) do + Project.Public.list_owners(project) + |> Enum.each(fn user -> + update_page(Project.OverviewPage, user) + end) + end + defp update_page(page, %{id: id} = model) when is_atom(page) do dispatch!({:page, page}, %{id: id, model: model}) end diff --git a/core/systems/project/form.ex b/core/systems/project/form.ex index 9395e13c1..bd3a1d1cc 100644 --- a/core/systems/project/form.ex +++ b/core/systems/project/form.ex @@ -1,6 +1,8 @@ defmodule Systems.Project.Form do use CoreWeb.LiveForm + import CoreWeb.UI.Dialog + alias Systems.{ Project } @@ -8,29 +10,50 @@ defmodule Systems.Project.Form do # Handle initial update @impl true def update( - %{id: id, entity: project, target: target}, + %{id: id, project: project, target: target}, socket ) do changeset = Project.Model.changeset(project, %{}) - close_button = %{ - action: %{type: :send, event: "close"}, - face: %{type: :icon, icon: :close} - } - { :ok, socket |> assign( id: id, - entity: project, + project: project, target: target, - close_button: close_button, - changeset: changeset + changeset: changeset, + show_errors: false ) + |> update_title() + |> update_text() + |> update_buttons() } end + defp update_title(socket) do + assign(socket, title: dgettext("eyra-project", "form.title")) + end + + defp update_text(socket) do + assign(socket, text: dgettext("eyra-project", "form.text")) + end + + defp update_buttons(%{assigns: %{myself: myself}} = socket) do + buttons = [ + %{ + action: %{type: :send, target: myself, event: "submit"}, + face: %{type: :primary, label: dgettext("eyra-ui", "submit.button")} + }, + %{ + action: %{type: :send, target: myself, event: "cancel"}, + face: %{type: :label, label: dgettext("eyra-ui", "cancel.button")} + } + ] + + assign(socket, buttons: buttons) + end + # Handle Events @impl true def handle_event("close", _params, socket) do @@ -39,40 +62,55 @@ defmodule Systems.Project.Form do end @impl true - def handle_event("save", %{"model" => attrs}, %{assigns: %{entity: entity}} = socket) do + def handle_event("change", %{"model" => attrs}, %{assigns: %{project: project}} = socket) do + changeset = Project.Model.changeset(project, attrs) + { :noreply, - socket - |> save(entity, attrs) + socket |> assign(changeset: changeset) } end - # Saving + @impl true + def handle_event("submit", _, socket) do + {:noreply, socket |> submit_form()} + end + + @impl true + def handle_event("cancel", _, socket) do + {:noreply, socket |> finish()} + end - def save(socket, %{root: root} = entity, attrs) do - project_changeset = Project.Model.changeset(entity, attrs) - root_changeset = Project.NodeModel.changeset(root, attrs) + # Submit + defp submit_form(%{assigns: %{project: project, changeset: changeset}} = socket) do + case Core.Persister.save(project, changeset) do + {:ok, _} -> + socket |> finish() + + {:error, changeset} -> + socket + |> assign(show_errors: true) + |> assign(changeset: changeset) + end + end + + defp finish(socket) do + send(self(), %{module: __MODULE__, action: :close}) socket - |> save(root_changeset) - |> save(project_changeset) end @impl true def render(assigns) do ~H"""
-
-
- <%= dgettext("eyra-project", "form.title") %> -
-
- -
- - <.form id={@id} :let={form} for={@changeset} phx-change="save" phx-target={@myself} > - <.text_input form={form} field={:name} label_text={dgettext("eyra-project", "form.name.label")} /> - + <.dialog {%{title: @title, buttons: @buttons}}> +
+ <.form id={@id} :let={form} for={@changeset} phx-change="change" phx-target={@myself} > + <.text_input form={form} field={:name} label_text={dgettext("eyra-project", "form.name.label")} /> + +
+
""" end diff --git a/core/systems/project/item_model.ex b/core/systems/project/item_model.ex index fd208a82c..f3013eff9 100644 --- a/core/systems/project/item_model.ex +++ b/core/systems/project/item_model.ex @@ -70,6 +70,9 @@ defmodule Systems.Project.ItemModel do Enum.map(items, &auth_tree/1) end + def tag(%{tool_ref: %{id: _} = tool_ref}), do: Project.ToolRefModel.tag(tool_ref) + def tag(%{assignment: %{id: _} = assignment}), do: Assignment.Model.tag(assignment) + defimpl Frameworks.Utility.ViewModelBuilder do use CoreWeb, :verified_routes diff --git a/core/systems/project/model.ex b/core/systems/project/model.ex index 51b207655..5aae94a2f 100644 --- a/core/systems/project/model.ex +++ b/core/systems/project/model.ex @@ -83,7 +83,8 @@ defmodule Systems.Project.Model do tags = items - |> Enum.map(&tag/1) + |> Enum.map(&Project.ItemModel.tag/1) + |> Enum.filter(&(&1 != nil)) |> Enum.uniq() %{ @@ -99,10 +100,6 @@ defmodule Systems.Project.Model do } end - defp tag(%{tool_ref: %{data_donation_tool: %{id: _id}}}), do: "Data Donation" - defp tag(%{tool_ref: %{benchmark_tool: %{id: _id}}}), do: "Benchmark" - defp tag(_), do: nil - defp info([_item]), do: "1 item" defp info(items) when is_list(items), do: "#{Enum.count(items)} items" end diff --git a/core/systems/project/node_page.ex b/core/systems/project/node_page.ex index 4c8e1350d..8ee1ec5f4 100644 --- a/core/systems/project/node_page.ex +++ b/core/systems/project/node_page.ex @@ -176,6 +176,18 @@ defmodule Systems.Project.NodePage do <% end %> <.spacing value="L" /> + <% else %> +
+ <.empty + title={dgettext("eyra-project", "node.empty.title")} + body={dgettext("eyra-project", "node.empty.description")} + illustration="cards" + button={%{ + action: %{type: :send, event: "create_item"}, + face: %{type: :primary, label: dgettext("eyra-project", "add.first.item.button")} + }} + /> +
<% end %> diff --git a/core/systems/project/overview_page.ex b/core/systems/project/overview_page.ex index 47aa9ef44..ef9b0fccb 100644 --- a/core/systems/project/overview_page.ex +++ b/core/systems/project/overview_page.ex @@ -2,11 +2,11 @@ defmodule Systems.Project.OverviewPage do use CoreWeb, :live_view use CoreWeb.Layouts.Workspace.Component, :projects use CoreWeb.UI.PlainDialog + use Systems.Observatory.Public import CoreWeb.Layouts.Workspace.Component alias CoreWeb.UI.SelectorDialog - alias Frameworks.Utility.ViewModelBuilder alias Frameworks.Pixel.Button alias Frameworks.Pixel.Grid alias Frameworks.Pixel.Text @@ -17,34 +17,23 @@ defmodule Systems.Project.OverviewPage do Project } - def mount(_params, _session, socket) do + def mount(_params, _session, %{assigns: %{current_user: user}} = socket) do { :ok, socket |> assign( + model: user, dialog: nil, popup: nil, selector_dialog: nil ) - |> update_projects() - |> update_cards() + |> observe_view_model() |> update_menus() } end - defp update_projects(%{assigns: %{current_user: user}} = socket) do - preload = Project.Model.preload_graph(:down) - projects = Project.Public.list_owned_projects(user, preload: preload) - - socket - |> assign(projects: projects) - end - - defp update_cards(%{assigns: %{projects: projects} = assigns} = socket) do - cards = Enum.map(projects, &ViewModelBuilder.view_model(&1, {__MODULE__, :card}, assigns)) - - socket - |> assign(cards: cards) + def handle_view_model_updated(socket) do + socket |> update_menus() end def handle_auto_save_done(socket) do @@ -52,19 +41,27 @@ defmodule Systems.Project.OverviewPage do end @impl true - def handle_event("card_clicked", %{"item" => card_id}, %{assigns: %{cards: cards}} = socket) do + def handle_event( + "card_clicked", + %{"item" => card_id}, + %{assigns: %{vm: %{cards: cards}}} = socket + ) do card_id = String.to_integer(card_id) %{path: path} = Enum.find(cards, &(&1.id == card_id)) {:noreply, push_redirect(socket, to: path)} end @impl true - def handle_event("edit", %{"item" => project_id}, %{assigns: %{projects: projects}} = socket) do + def handle_event( + "edit", + %{"item" => project_id}, + %{assigns: %{vm: %{projects: projects}}} = socket + ) do project = Enum.find(projects, &(&1.id == String.to_integer(project_id))) popup = %{ module: Project.Form, - entity: project, + project: project, target: self() } @@ -97,8 +94,7 @@ defmodule Systems.Project.OverviewPage do project_id: nil, dialog: nil ) - |> update_projects() - |> update_cards() + |> update_view_model() |> update_menus() } end @@ -140,15 +136,14 @@ defmodule Systems.Project.OverviewPage do @impl true def handle_event("create_project", _params, %{assigns: %{current_user: user}} = socket) do - popup = %{ - module: Project.CreatePopup, - target: self(), - user: user - } + user + |> Project.Public.new_project_name() + |> Project.Assembly.create(user, :empty) { :noreply, - socket |> assign(popup: popup) + socket + |> update_view_model() } end @@ -165,19 +160,25 @@ defmodule Systems.Project.OverviewPage do { :noreply, socket - |> update_projects() - |> update_cards() } end @impl true def handle_info(%{selector: :cancel}, socket) do - {:noreply, socket |> assign(selector_dialog: nil)} + { + :noreply, + socket + |> assign(selector_dialog: nil) + } end @impl true def handle_info(%{module: _, action: :close}, socket) do - {:noreply, socket |> assign(popup: nil)} + { + :noreply, + socket + |> assign(popup: nil) + } end @impl true @@ -219,7 +220,7 @@ defmodule Systems.Project.OverviewPage do <%= if @popup do %> <.popup> -
+
<.live_component id={:project_overview_popup} module={@popup.module} {@popup} />
@@ -243,12 +244,12 @@ defmodule Systems.Project.OverviewPage do - <%= if Enum.count(@cards) > 0 do %> + <%= if Enum.count(@vm.cards) > 0 do %>
<%= dgettext("eyra-project", "overview.header.title") %> - <%= Enum.count(@cards) %> + <%= Enum.count(@vm.cards) %>
@@ -266,7 +267,7 @@ defmodule Systems.Project.OverviewPage do
- <%= for card <- @cards do %> + <%= for card <- @vm.cards do %> <% end %> @@ -276,11 +277,10 @@ defmodule Systems.Project.OverviewPage do title={dgettext("eyra-project", "overview.empty.title")} body={dgettext("eyra-project", "overview.empty.description")} illustration="cards" - /> - <.spacing value="L" /> - <% end %> diff --git a/core/systems/project/overview_page_builder.ex b/core/systems/project/overview_page_builder.ex new file mode 100644 index 000000000..f53370685 --- /dev/null +++ b/core/systems/project/overview_page_builder.ex @@ -0,0 +1,32 @@ +defmodule Systems.Project.OverviewPageBuilder do + alias Frameworks.Utility.ViewModelBuilder + + alias Systems.{ + Project + } + + def view_model( + user, + assigns + ) do + projects = projects(user) + cards = cards(projects, assigns) + + %{ + projects: projects, + cards: cards + } + end + + defp projects(user) do + preload = Project.Model.preload_graph(:down) + Project.Public.list_owned_projects(user, preload: preload) + end + + defp cards(projects, assigns) do + Enum.map( + projects, + &ViewModelBuilder.view_model(&1, {Systems.Project.OverviewPage, :card}, assigns) + ) + end +end diff --git a/core/systems/project/tool_ref_model.ex b/core/systems/project/tool_ref_model.ex index bf87337cf..1934d4539 100644 --- a/core/systems/project/tool_ref_model.ex +++ b/core/systems/project/tool_ref_model.ex @@ -3,6 +3,7 @@ defmodule Systems.Project.ToolRefModel do use Frameworks.Utility.Schema import Ecto.Changeset + import CoreWeb.Gettext alias Frameworks.Concept @@ -83,4 +84,14 @@ defmodule Systems.Project.ToolRefModel do def tool(%{document_tool: %{id: _id} = tool}), do: tool def tool(%{lab_tool: %{id: _id} = tool}), do: tool def tool(%{benchmark_tool: %{id: _id} = tool}), do: tool + + def tag(%Project.ToolRefModel{special: :questionnaire}), + do: dgettext("eyra-project", "tool_ref.tag.questionnaire") + + def tag(%Project.ToolRefModel{special: :benchmark}), + do: dgettext("eyra-project", "tool_ref.tag.benchmark") + + def tag(%Project.ToolRefModel{special: _special}) do + dgettext("eyra-project", "tool_ref.tag.default") + end end diff --git a/core/systems/promotion/_presenter.ex b/core/systems/promotion/_presenter.ex index cef338448..ca2920d5c 100644 --- a/core/systems/promotion/_presenter.ex +++ b/core/systems/promotion/_presenter.ex @@ -4,7 +4,8 @@ defmodule Systems.Promotion.Presenter do alias Systems.Promotion @impl true - def view_model(%Promotion.Model{director: director} = promotion, page, assigns) do - Frameworks.Concept.System.presenter(director).view_model(promotion, page, assigns) + def view_model(page, %Promotion.Model{director: director} = promotion, assigns) do + presenter = Frameworks.Concept.System.presenter(director) + apply(presenter, :view_model, [page, promotion, assigns]) end end diff --git a/core/systems/promotion/landing_page.ex b/core/systems/promotion/landing_page.ex index 4405ea6f1..e9390aa29 100644 --- a/core/systems/promotion/landing_page.ex +++ b/core/systems/promotion/landing_page.ex @@ -77,8 +77,6 @@ defmodule Systems.Promotion.LandingPage do |> assign(image_info: image_info) end - defoverridable handle_view_model_updated: 1 - def handle_view_model_updated(socket) do socket |> update_image_info() @@ -133,11 +131,6 @@ defmodule Systems.Promotion.LandingPage do defp grid_cols(2), do: "grid-cols-1 sm:grid-cols-2" defp grid_cols(_), do: "grid-cols-1 sm:grid-cols-3" - # data(preview, :boolean) - # data(model, :map) - # data(image_info, :map) - # data(back_path, :any) - @impl true def render(assigns) do ~H""" diff --git a/core/systems/student/_presenter.ex b/core/systems/student/_presenter.ex index 95681c1be..fbd212689 100644 --- a/core/systems/student/_presenter.ex +++ b/core/systems/student/_presenter.ex @@ -7,12 +7,12 @@ defmodule Systems.Student.Presenter do } @impl true - def view_model(%Pool.SubmissionModel{} = submission, Pool.SubmissionPage, assigns) do + def view_model(Pool.SubmissionPage, %Pool.SubmissionModel{} = submission, assigns) do Student.Pool.SubmissionPageBuilder.view_model(submission, assigns) end @impl true - def view_model(%Pool.Model{} = pool, Pool.DetailPage, assigns) do + def view_model(Pool.DetailPage, %Pool.Model{} = pool, assigns) do Student.Pool.DetailPageBuilder.view_model(pool, assigns) end end diff --git a/core/systems/test/_presenter.ex b/core/systems/test/_presenter.ex index 06503ed16..1ab3cd2bf 100644 --- a/core/systems/test/_presenter.ex +++ b/core/systems/test/_presenter.ex @@ -4,14 +4,12 @@ defmodule Systems.Test.Presenter do alias Systems.Observatory @impl true - def view_model(%Systems.Test.Model{} = model, page, assigns) do - model - |> Builder.view_model(page, assigns) + def view_model(page, %Systems.Test.Model{} = model, assigns) do + Builder.view_model(model, page, assigns) end - def view_model(id, page, assigns) when is_binary(id) do - Systems.Test.Public.get(id) - |> Builder.view_model(page, assigns) + def view_model(page, id, assigns) when is_binary(id) do + Builder.view_model(Systems.Test.Public.get(id), page, assigns) end def update(Systems.Test.Page = page, model) do diff --git a/core/systems/test/page.ex b/core/systems/test/page.ex index 5cfd3d3a9..c41c14c9e 100644 --- a/core/systems/test/page.ex +++ b/core/systems/test/page.ex @@ -20,7 +20,6 @@ defmodule Systems.Test.Page do } end - defoverridable handle_view_model_updated: 1 def handle_view_model_updated(socket), do: socket # data(model, :map) diff --git a/core/test/systems/consent/_public_test.exs b/core/test/systems/consent/_public_test.exs index b41ed419f..423e3f037 100644 --- a/core/test/systems/consent/_public_test.exs +++ b/core/test/systems/consent/_public_test.exs @@ -17,22 +17,25 @@ defmodule Systems.Consent.PublicTest do {:ok, _} = Multi.new() |> Multi.insert(:agreement, Consent.Public.prepare_agreement(Authorization.prepare_node())) - |> Multi.insert(:revision1, fn %{agreement: agreement} -> - Consent.Public.prepare_revision(agreement, "revision1") - end) |> Multi.insert(:revision2, fn %{agreement: agreement} -> Consent.Public.prepare_revision(agreement, "revision2") end) + |> Multi.insert(:revision3, fn %{agreement: agreement} -> + Consent.Public.prepare_revision(agreement, "revision3") + end) |> Repo.transaction() assert [ %Systems.Consent.AgreementModel{ revisions: [ %Systems.Consent.RevisionModel{ - source: "revision1" + source: _ }, %Systems.Consent.RevisionModel{ source: "revision2" + }, + %Systems.Consent.RevisionModel{ + source: "revision3" } ] } @@ -47,26 +50,26 @@ defmodule Systems.Consent.PublicTest do {:ok, _} = Multi.new() |> Multi.insert(:agreement, Consent.Public.prepare_agreement(Authorization.prepare_node())) - |> Multi.insert(:revision1, fn %{agreement: agreement} -> - Consent.Public.prepare_revision(agreement, "revision1") - end) - |> Multi.insert(:signatureA1, fn %{revision1: revision1} -> - Consent.Public.prepare_signature(revision1, user_a) - end) - |> Multi.insert(:signatureB1, fn %{revision1: revision1} -> - Consent.Public.prepare_signature(revision1, user_b) - end) |> Multi.insert(:revision2, fn %{agreement: agreement} -> Consent.Public.prepare_revision(agreement, "revision2") end) - |> Multi.insert(:signatureA2, fn %{revision2: revision2} -> + |> Multi.insert(:signatureA1, fn %{revision2: revision2} -> Consent.Public.prepare_signature(revision2, user_a) end) - |> Multi.insert(:signatureB2, fn %{revision2: revision2} -> + |> Multi.insert(:signatureB1, fn %{revision2: revision2} -> Consent.Public.prepare_signature(revision2, user_b) end) - |> Multi.insert(:signatureC2, fn %{revision2: revision2} -> - Consent.Public.prepare_signature(revision2, user_c) + |> Multi.insert(:revision3, fn %{agreement: agreement} -> + Consent.Public.prepare_revision(agreement, "revision3") + end) + |> Multi.insert(:signatureA2, fn %{revision3: revision3} -> + Consent.Public.prepare_signature(revision3, user_a) + end) + |> Multi.insert(:signatureB2, fn %{revision3: revision3} -> + Consent.Public.prepare_signature(revision3, user_b) + end) + |> Multi.insert(:signatureC2, fn %{revision3: revision3} -> + Consent.Public.prepare_signature(revision3, user_c) end) |> Repo.transaction() @@ -74,14 +77,18 @@ defmodule Systems.Consent.PublicTest do %Systems.Consent.AgreementModel{ revisions: [ %Systems.Consent.RevisionModel{ - source: "revision1", + source: _source, + signatures: [] + }, + %Systems.Consent.RevisionModel{ + source: "revision2", signatures: [ %Systems.Consent.SignatureModel{user_id: ^user_a_id}, %Systems.Consent.SignatureModel{user_id: ^user_b_id} ] }, %Systems.Consent.RevisionModel{ - source: "revision2", + source: "revision3", signatures: [ %Systems.Consent.SignatureModel{user_id: ^user_a_id}, %Systems.Consent.SignatureModel{user_id: ^user_b_id},