diff --git a/core/bundles/next/lib/layouts/workspace/menu_builder.ex b/core/bundles/next/lib/layouts/workspace/menu_builder.ex index dd338bff5..def0c7b97 100644 --- a/core/bundles/next/lib/layouts/workspace/menu_builder.ex +++ b/core/bundles/next/lib/layouts/workspace/menu_builder.ex @@ -40,6 +40,6 @@ defmodule Next.Layouts.Workspace.MenuBuilder do def include_map(user), do: %{ console: Authorization.can_access?(user, Next.Console.Page), - projects: Systems.Admin.Public.admin?(user) + projects: Systems.Admin.Public.admin?(user) or user.researcher } end diff --git a/core/lib/core/factories.ex b/core/lib/core/factories.ex index 6f417dd9c..5f247163f 100644 --- a/core/lib/core/factories.ex +++ b/core/lib/core/factories.ex @@ -251,7 +251,15 @@ defmodule Core.Factories do end def build(:project_node) do - build(:project_node, %{name: Faker.Lorem.word(), project_path: [1, 2]}) + build(:project_node, %{name: Faker.Lorem.word(), project_path: []}) + end + + def build(:project_item) do + build(:project_item, %{name: Faker.Lorem.word(), project_path: []}) + end + + def build(:tool_ref) do + build(:tool_ref, %{}) end def build(:auth_node, %{} = attributes) do @@ -379,6 +387,34 @@ defmodule Core.Factories do |> struct!(attributes) end + def build(:project_item, %{} = attributes) do + {node, attributes} = Map.pop(attributes, :node, build(:project_node)) + {tool_ref, attributes} = Map.pop(attributes, :tool_ref, build(:tool_ref)) + + %Project.ItemModel{ + node: node, + tool_ref: tool_ref + } + |> struct!(attributes) + end + + def build(:tool_ref, %{} = attributes) do + {item, attributes} = Map.pop(attributes, :item, build(:project_item)) + {survey_tool, attributes} = Map.pop(attributes, :survey_tool, nil) + {lab_tool, attributes} = Map.pop(attributes, :lab_tool, nil) + {data_donation_tool, attributes} = Map.pop(attributes, :data_donation_tool, nil) + {benchmark_tool, attributes} = Map.pop(attributes, :benchmark_tool, nil) + + %Project.ToolRefModel{ + item: item, + survey_tool: survey_tool, + lab_tool: lab_tool, + data_donation_tool: data_donation_tool, + benchmark_tool: benchmark_tool + } + |> struct!(attributes) + end + def build(:assignment, %{} = attributes) do {auth_node, attributes} = Map.pop(attributes, :auth_node, build(:auth_node)) {budget, attributes} = Map.pop(attributes, :budget, build(:budget)) diff --git a/core/priv/gettext/en/LC_MESSAGES/eyra-enums.po b/core/priv/gettext/en/LC_MESSAGES/eyra-enums.po index afff9ba8d..28119c9cd 100644 --- a/core/priv/gettext/en/LC_MESSAGES/eyra-enums.po +++ b/core/priv/gettext/en/LC_MESSAGES/eyra-enums.po @@ -340,4 +340,4 @@ msgstr "Benchmark" #, elixir-autogen, elixir-format, fuzzy msgid "project_tools.data_donation" -msgstr "Data Donation Study" +msgstr "Data Donation" diff --git a/core/priv/gettext/en/LC_MESSAGES/eyra-project.po b/core/priv/gettext/en/LC_MESSAGES/eyra-project.po index cb8ee9e2b..42408ff3a 100644 --- a/core/priv/gettext/en/LC_MESSAGES/eyra-project.po +++ b/core/priv/gettext/en/LC_MESSAGES/eyra-project.po @@ -190,3 +190,7 @@ msgstr "Retract" #, elixir-autogen, elixir-format msgid "create.item.button.short" msgstr "" + +#, elixir-autogen, elixir-format, fuzzy +msgid "create.item.title" +msgstr "Select item type" diff --git a/core/priv/gettext/eyra-project.pot b/core/priv/gettext/eyra-project.pot index 06f26afc1..09d4237ef 100644 --- a/core/priv/gettext/eyra-project.pot +++ b/core/priv/gettext/eyra-project.pot @@ -190,3 +190,7 @@ msgstr "" #, elixir-autogen, elixir-format msgid "create.item.button.short" msgstr "" + +#, elixir-autogen, elixir-format +msgid "create.item.title" +msgstr "" diff --git a/core/priv/gettext/nl/LC_MESSAGES/eyra-enums.po b/core/priv/gettext/nl/LC_MESSAGES/eyra-enums.po index 75a753519..ff6c0e8bc 100644 --- a/core/priv/gettext/nl/LC_MESSAGES/eyra-enums.po +++ b/core/priv/gettext/nl/LC_MESSAGES/eyra-enums.po @@ -340,4 +340,4 @@ msgstr "Benchmark" #, elixir-autogen, elixir-format, fuzzy msgid "project_tools.data_donation" -msgstr "Data Donatie Studie" +msgstr "Data Donatie" diff --git a/core/priv/gettext/nl/LC_MESSAGES/eyra-project.po b/core/priv/gettext/nl/LC_MESSAGES/eyra-project.po index 07a565320..3d41e2200 100644 --- a/core/priv/gettext/nl/LC_MESSAGES/eyra-project.po +++ b/core/priv/gettext/nl/LC_MESSAGES/eyra-project.po @@ -190,3 +190,7 @@ msgstr "Terugtrekken" #, elixir-autogen, elixir-format msgid "create.item.button.short" msgstr "" + +#, elixir-autogen, elixir-format, fuzzy +msgid "create.item.title" +msgstr "Kies type item" diff --git a/core/priv/repo/seeds.exs b/core/priv/repo/seeds.exs index 6afff9d93..e9078d4e2 100644 --- a/core/priv/repo/seeds.exs +++ b/core/priv/repo/seeds.exs @@ -24,7 +24,7 @@ images = [ "raw_url=https%3A%2F%2Fimages.unsplash.com%2Fphoto-1515378791036-0648a3ef77b2%3Fixid%3DMnwyMTY0MzZ8MHwxfHNlYXJjaHw4fHx3b3JrfGVufDB8fHx8MTYyMTc3NjgwOQ%26ixlib%3Drb-1.2.1&username=christinhumephoto&name=Christin+Hume&blur_hash=LMF%3B%3Dw0LAJR%25~A9uT0nNRjxaW%3DIo" ] -data_donation_promotions = +_data_donation_promotions = Enum.map(images, fn image -> %{ title: Faker.Lorem.sentence(), @@ -52,15 +52,15 @@ data_donation_promotions = } end) -Enum.each(data_donation_promotions, fn promotion -> - data = %{ - script: File.read!(Path.join([:code.priv_dir(:core), "repo", "script.py"])), - subject_count: 400 - # promotion: promotion - } +# Enum.each(data_donation_promotions, fn promotion -> +# data = %{ +# script: File.read!(Path.join([:code.priv_dir(:core), "repo", "script.py"])), +# subject_count: 400 +# # promotion: promotion +# } - Core.Factories.insert!(:data_donation_tool, data) -end) +# Core.Factories.insert!(:data_donation_tool, data) +# end) # campaigns = # Enum.map(data_donation_tools, fn data_donation_tool -> diff --git a/core/systems/project/_assembly.ex b/core/systems/project/_assembly.ex index ba2d77388..cf73be93b 100644 --- a/core/systems/project/_assembly.ex +++ b/core/systems/project/_assembly.ex @@ -48,7 +48,8 @@ defmodule Systems.Project.Assembly do |> Repo.transaction() end - def create_item(%Project.NodeModel{id: node_id} = node, tool_special) do + def create_item(name, %Project.NodeModel{id: node_id} = node, tool_special) + when is_binary(name) do project = from(p in Project.Model, where: p.root_id == ^node_id, preload: [:auth_node]) |> Repo.one!() @@ -59,11 +60,12 @@ defmodule Systems.Project.Assembly do end) |> prepare_tool(tool_special) |> Multi.insert(:tool_ref, fn %{tool: tool} -> - Project.Public.create_tool_ref(tool_special, tool) + key = String.to_existing_atom("#{tool_special}_tool") + Project.Public.create_tool_ref(key, tool) end) |> Multi.insert(:item, fn %{tool_ref: tool_ref} -> Project.Public.create_item( - %{name: "Item", project_path: [project.id, node_id]}, + %{name: name, project_path: [project.id, node_id]}, node, tool_ref ) @@ -120,14 +122,14 @@ defmodule Systems.Project.Assembly do end) end - defp prepare_tool(multi, :data_donation_tool) do + defp prepare_tool(multi, :data_donation) do multi |> Multi.insert(:tool, fn %{auth_node: auth_node} -> DataDonation.Public.create(%{subject_count: 0, director: :project}, auth_node) end) end - defp prepare_tool(multi, :benchmark_tool) do + defp prepare_tool(multi, :benchmark) do multi |> Multi.insert(:tool, fn %{auth_node: auth_node} -> Benchmark.Public.create(%{title: "", director: :project}, auth_node) diff --git a/core/systems/project/create_item_popup.ex b/core/systems/project/create_item_popup.ex new file mode 100644 index 000000000..89d24870b --- /dev/null +++ b/core/systems/project/create_item_popup.ex @@ -0,0 +1,114 @@ +defmodule Systems.Project.CreateItemPopup do + use CoreWeb, :live_component + + alias Frameworks.Pixel.Selector + + alias Systems.{ + Project + } + + # Handle Tool Type Selector Update + @impl true + def update( + %{active_item_id: active_item_id, selector_id: :tool_selector}, + %{assigns: %{tool_labels: tool_labels}} = socket + ) do + %{id: selected_tool} = Enum.find(tool_labels, &(&1.id == active_item_id)) + + { + :ok, + socket + |> assign(selected_tool: selected_tool) + } + end + + # Initial Update + @impl true + def update(%{id: id, node: node, target: target}, socket) do + title = dgettext("eyra-project", "create.item.title") + + { + :ok, + socket + |> assign(id: id, node: node, target: target, title: title) + |> init_tools() + |> init_buttons() + } + end + + defp init_tools(socket) do + selected_tool = :empty + tool_labels = Project.Tools.labels(selected_tool) + socket |> assign(tool_labels: tool_labels, selected_tool: selected_tool) + end + + defp init_buttons(%{assigns: %{myself: myself}} = socket) do + socket + |> assign( + buttons: [ + %{ + action: %{type: :send, event: "proceed", target: myself}, + face: %{ + type: :primary, + label: dgettext("eyra-project", "create.proceed.button") + } + }, + %{ + action: %{type: :send, event: "cancel", target: myself}, + face: %{type: :label, label: dgettext("eyra-ui", "cancel.button")} + } + ] + ) + end + + @impl true + def handle_event( + "proceed", + _, + %{assigns: %{selected_tool: selected_tool}} = socket + ) do + create_item(socket, selected_tool) + + {:noreply, socket |> close()} + end + + @impl true + def handle_event("cancel", _, socket) do + {:noreply, socket |> close()} + end + + defp close(%{assigns: %{target: target}} = socket) do + update_target(target, %{module: __MODULE__, action: :close}) + socket + end + + defp create_item(%{assigns: %{node: node}}, tool) do + name = Project.Tools.translate(tool) + Project.Assembly.create_item(name, node, tool) + end + + @impl true + def render(assigns) do + ~H""" +