Skip to content

Commit

Permalink
Merge pull request #514 from eyra/context-menu
Browse files Browse the repository at this point in the history
Context menu
  • Loading branch information
mellelieuwes authored Dec 7, 2023
2 parents 59ac2de + 5c7907f commit e45458a
Show file tree
Hide file tree
Showing 24 changed files with 286 additions and 32 deletions.
10 changes: 5 additions & 5 deletions core/assets/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ module.exports = {
{ pattern: /border-./ },
],
theme: {
boxShadow: {
top4px: "inset 0 4px 0 0 rgba(0, 0, 0, 0.15)",
top2px: "inset 0 2px 0 0 rgba(0, 0, 0, 0.15)",
"2xl": "0 5px 20px 0px rgba(0, 0, 0, 0.08)",
},
colors: {
primary: "#4272EF",
primarylight: "#E3EAFD",
Expand All @@ -49,6 +44,11 @@ module.exports = {
surfconext: "#4DB2CF",
},
extend: {
boxShadow: {
top4px: "inset 0 4px 0 0 rgba(0, 0, 0, 0.15);",
top2px: "inset 0 2px 0 0 rgba(0, 0, 0, 0.15;);",
floating: "0px 5px 20px 0px rgba(0, 0, 0, 0.10);",
},
transitionDuration: {
2000: "2000ms",
},
Expand Down
2 changes: 1 addition & 1 deletion core/frameworks/pixel/components/radio_group.ex
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ defmodule Frameworks.Pixel.RadioGroup do
@impl true
def render(assigns) do
~H"""
<div>
<div class="ml-[6px]">
<.form id={"#{@id}_form"} for={@form} phx-change="change" phx-target={@myself}>
<div class="flex flex-row gap-8">
<%= for item <- @items do %>
Expand Down
36 changes: 36 additions & 0 deletions core/frameworks/pixel/components/takeover.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
defmodule Frameworks.Pixel.Takeover do
use CoreWeb, :html

alias Frameworks.Pixel.Button

attr(:title, :string, required: true)
attr(:target, :any, required: true)

slot(:inner_block)

def takeover(%{target: target} = assigns) do
close_button = %{
action: %{type: :send, event: "takeover_close", target: target},
face: %{type: :icon, icon: :close}
}

assigns = assign(assigns, close_button: close_button)

~H"""
<div class="px-12 pt-6 pb-12 bg-white shadow-floating rounded relative">
<div class="sticky top-10">
<div class="flex flex-row">
<div class="flex-grow" />
<Button.dynamic {@close_button} />
</div>
</div>
<div class="flex flex-col">
<Text.title2><%= @title %></Text.title2>
<div class="">
<%= render_slot(@inner_block) %>
</div>
</div>
</div>
"""
end
end
2 changes: 1 addition & 1 deletion core/lib/core_web/controllers/layouts/error.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<script src="/js/app.js" defer></script>
</head>
<body class="font-body bg-grey5 scrollbar-hidden" x-data="{ overlay: false}" >
<div class="fixed z-10 w-full h-full bg-black bg-opacity-20" x-show="overlay"></div>
<div class="fixed z-10 w-full h-full bg-black bg-opacity-30" x-show="overlay"></div>
<div class="flex flex-row">
<div class="flex flex-col w-full">
<div class="flex-grow">
Expand Down
2 changes: 1 addition & 1 deletion core/lib/core_web/ui/dialog/dialog.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ defmodule CoreWeb.UI.Dialog do

def dialog(assigns) do
~H"""
<div class="p-8 bg-white shadow-2xl min-w-dialog-width sm:min-w-dialog-width-sm rounded">
<div class="h-full p-8 bg-white shadow-2xl min-w-dialog-width sm:min-w-dialog-width-sm rounded">
<div class="flex flex-col gap-4 sm:gap-8">
<div class="text-title5 font-title5 sm:text-title3 sm:font-title3">
<%= @title %>
Expand Down
2 changes: 1 addition & 1 deletion core/lib/core_web/ui/popup.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule CoreWeb.UI.Popup do

def popup(assigns) do
~H"""
<div class="fixed z-20 left-0 top-0 w-full h-full bg-black bg-opacity-20">
<div class="fixed z-20 left-0 top-0 w-full h-full bg-black bg-opacity-30">
<div class="flex flex-row items-center justify-center w-full h-full">
<%= render_slot(@inner_block) %>
</div>
Expand Down
4 changes: 4 additions & 0 deletions core/priv/gettext/en/LC_MESSAGES/eyra-consent.po
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ msgstr "Please not that this version of the consent text has already been signed
#, elixir-autogen, elixir-format
msgid "out_of_sync.error.message"
msgstr "The consent text has been changed. Please refresh the page to continue."

#, elixir-autogen, elixir-format
msgid "signature.view.title"
msgstr "Consent"
4 changes: 4 additions & 0 deletions core/priv/gettext/eyra-consent.pot
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ msgstr ""
#, elixir-autogen, elixir-format
msgid "out_of_sync.error.message"
msgstr ""

#, elixir-autogen, elixir-format
msgid "signature.view.title"
msgstr ""
4 changes: 4 additions & 0 deletions core/priv/gettext/nl/LC_MESSAGES/eyra-consent.po
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ msgstr "Deze versie van de tekst voor toestemming is al ondertekend door partici
#, elixir-autogen, elixir-format
msgid "out_of_sync.error.message"
msgstr "De toestemmingstekst is aangepast. Ververs de pagina om verder te gaan."

#, elixir-autogen, elixir-format
msgid "signature.view.title"
msgstr "Toestemming"
2 changes: 1 addition & 1 deletion core/systems/admin/config_page.ex
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ defmodule Systems.Admin.ConfigPage do
<.workspace title={dgettext("eyra-admin", "config.title")} menus={@menus}>
<%= if @popup do %>
<.popup>
<div class="p-8 w-popup-md bg-white shadow-2xl rounded">
<div class="p-8 w-popup-md bg-white shadow-floating rounded">
<.live_component id={:config_page_popup} module={@popup.module} {@popup} />
</div>
</.popup>
Expand Down
23 changes: 22 additions & 1 deletion core/systems/assignment/crew_page.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ defmodule Systems.Assignment.CrewPage do
|> assign(
id: id,
model: model,
image_info: nil
image_info: nil,
popup: nil
)
|> update_panel_info(session)
|> observe_view_model()
Expand Down Expand Up @@ -106,6 +107,17 @@ defmodule Systems.Assignment.CrewPage do
{:noreply, socket |> store(key, data)}
end

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

@impl true
def handle_event("hide_popup", _, socket) do
{:noreply, socket |> assign(popup: nil)}
end

def store(
%{assigns: %{panel_info: panel_info, model: assignment, remote_ip: remote_ip}} = socket,
key,
Expand Down Expand Up @@ -138,6 +150,15 @@ defmodule Systems.Assignment.CrewPage do
<% end %>
</div>
</:header>
<%= if @popup do %>
<.popup>
<div class="w-3/5 h-4/5 overflow-y-scroll">
<.live_component id={:page_popup} module={@popup.module} {@popup.params} />
</div>
</.popup>
<% end %>
<div id={:crew_page} class="w-full h-full flex flex-col" phx-hook="ViewportResize">
<.flow fabric={@fabric} />
</div>
Expand Down
25 changes: 23 additions & 2 deletions core/systems/assignment/crew_page_builder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,35 @@ defmodule Systems.Assignment.CrewPageBuilder do
end
end

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

Fabric.prepare_child(fabric, :work_view, Assignment.CrewWorkView, %{
work_items: work_items
work_items: work_items,
consent_agreement: consent_agreement,
context_menu_items: context_menu_items,
user: user
})
end

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

items =
if consent_agreement do
items ++ [%{id: :consent, label: "Consent"}]
else
items
end

items
end

defp work_items(%{status: status, crew: crew} = assignment, %{current_user: user} = assigns) do
if is_tester?(assignment, assigns) or status == :online do
member = Crew.Public.get_member(crew, user)
Expand Down
81 changes: 71 additions & 10 deletions core/systems/assignment/crew_work_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,34 @@ defmodule Systems.Assignment.CrewWorkView do
Assignment,
Crew,
Workflow,
Project
Project,
Content,
Consent
}

def update(%{work_items: work_items}, socket) do
def update(
%{
work_items: work_items,
consent_agreement: consent_agreement,
context_menu_items: context_menu_items,
user: user
},
socket
) do
{
:ok,
socket
|> assign(work_items: work_items)
|> assign(
work_items: work_items,
consent_agreement: consent_agreement,
context_menu_items: context_menu_items,
user: user
)
|> update_selected_item_id()
|> update_selected_item()
|> compose_child(:work_list_view)
|> compose_child(:start_view)
|> compose_child(:context_menu)
|> update_child(:tool_ref_view)
}
end
Expand Down Expand Up @@ -62,6 +78,8 @@ defmodule Systems.Assignment.CrewWorkView do
socket |> assign(selected_item: selected_item)
end

# Compose

@impl true
def compose(:start_view, %{selected_item: selected_item}) when not is_nil(selected_item) do
%{module: Assignment.StartView, params: %{work_item: selected_item}}
Expand Down Expand Up @@ -95,18 +113,30 @@ defmodule Systems.Assignment.CrewWorkView do
@impl true
def compose(:tool_ref_view, _assigns), do: nil

defp map_item({%{id: id, title: title, group: group}, task}) do
%{id: id, title: title, icon: group, status: task_status(task)}
def compose(:context_menu, %{context_menu_items: []}) do
nil
end

defp task_status(%{status: status}), do: status
defp task_status(_), do: :pending
def compose(:context_menu, %{context_menu_items: context_menu_items}) do
%{
module: Content.ContextMenu,
params: %{
items: context_menu_items
}
}
end

defp lock_task(socket, task) do
Crew.Public.lock_task(task)
socket
def compose(:consent_page, %{consent_agreement: consent_agreement, user: user}) do
%{
module: Consent.SignatureView,
params: %{
signature: Consent.Public.get_signature(consent_agreement, user)
}
}
end

# Events

@impl true
def handle_event(
"complete_task",
Expand Down Expand Up @@ -157,6 +187,23 @@ defmodule Systems.Assignment.CrewWorkView do
}
end

@impl true
def handle_event("show", %{page: :consent}, socket) do
{
:noreply,
socket
|> compose_child(:consent_page)
|> show_popup(:consent_page)
}
end

@impl true
def handle_event("close", %{source: %{name: :consent_page}}, socket) do
{:noreply, socket |> hide_popup(:consent_page)}
end

# Private

defp handle_feldspar_event(%{assigns: %{selected_item: {_, task}}} = socket, %{
"__type__" => "CommandSystemExit",
"code" => code,
Expand Down Expand Up @@ -188,6 +235,18 @@ defmodule Systems.Assignment.CrewWorkView do
socket |> Frameworks.Pixel.Flash.put_error("Unsupported event")
end

defp map_item({%{id: id, title: title, group: group}, task}) do
%{id: id, title: title, icon: group, status: task_status(task)}
end

defp task_status(%{status: status}), do: status
defp task_status(_), do: :pending

defp lock_task(socket, task) do
Crew.Public.lock_task(task)
socket
end

@impl true
def render(assigns) do
~H"""
Expand Down Expand Up @@ -216,6 +275,8 @@ defmodule Systems.Assignment.CrewWorkView do
<.child name={:start_view} fabric={@fabric} />
</div>
<% end %>
<%!-- floating button --%>
<.child name={:context_menu} fabric={@fabric} />
</div>
"""
end
Expand Down
2 changes: 1 addition & 1 deletion core/systems/assignment/ticket_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule Systems.Assignment.TicketView do

def normal(assigns) do
~H"""
<div class="flex flex-row gap-12 rounded-lg shadow-2xl p-8 h-full bg-tertiary">
<div class="flex flex-row gap-12 rounded-lg shadow-floating p-8 h-full bg-tertiary">
<Text.title4><%= dgettext("eyra-assignment", "ticket.title") %></Text.title4>
<Text.title4><%= @public_id %></Text.title4>
</div>
Expand Down
2 changes: 1 addition & 1 deletion core/systems/benchmark/tool_page.ex
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ defmodule Systems.Benchmark.ToolPage do
<.stripped title={@vm.hero_title} menus={@menus}>
<%= if @popup do %>
<.popup>
<div class="p-8 w-popup-md bg-white shadow-2xl rounded">
<div class="p-8 w-popup-md bg-white shadow-floating rounded">
<.live_component {@popup} />
</div>
</.popup>
Expand Down
2 changes: 1 addition & 1 deletion core/systems/budget/funding_page.ex
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ defmodule Systems.Budget.FundingPage do
<.workspace title={dgettext("eyra-budget", "funding.title")} menus={@menus}>
<%= if @popup do %>
<.popup>
<div class="p-8 w-popup-md bg-white shadow-2xl rounded">
<div class="p-8 w-popup-md bg-white shadow-floating rounded">
<.live_component id={:funding_popup} module={@popup.module} {@popup} />
</div>
</.popup>
Expand Down
2 changes: 1 addition & 1 deletion core/systems/campaign/overview_page.ex
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ defmodule Systems.Campaign.OverviewPage do
<%= if @popup do %>
<.popup>
<div class="p-8 w-popup-md bg-white shadow-2xl rounded">
<div class="p-8 w-popup-md bg-white shadow-floating rounded">
<.live_component id={:campaign_overview_popup} module={@popup.module} {@popup} />
</div>
</.popup>
Expand Down
3 changes: 2 additions & 1 deletion core/systems/consent/_public.ex
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ defmodule Systems.Consent.Public do
join: r in Consent.RevisionModel,
on: r.id == s.revision_id,
where: s.user_id == ^user_id,
where: r.agreement_id == ^agreement_id
where: r.agreement_id == ^agreement_id,
preload: [:revision]
)
|> Repo.all()
|> List.first()
Expand Down
Loading

0 comments on commit e45458a

Please sign in to comment.