Skip to content

Commit

Permalink
Merge pull request #532 from eyra/feedback-niek
Browse files Browse the repository at this point in the history
Feedback Niek
  • Loading branch information
mellelieuwes authored Dec 22, 2023
2 parents f7a5cb6 + 88a2bdc commit 3837a76
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 134 deletions.
2 changes: 1 addition & 1 deletion core/frameworks/fabric/html.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ defmodule Fabric.Html do

def stack(assigns) do
~H"""
<div class={"flex flex-col #{@gap}"}>
<div class={"w-full h-full flex flex-col #{@gap}"}>
<%= for child <- @fabric.children do %>
<.live_child {Map.from_struct(child)} />
<% end %>
Expand Down
29 changes: 21 additions & 8 deletions core/systems/assignment/_private.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,27 @@ defmodule Systems.Assignment.Private do
Storage
}

def get_panel_url(%Assignment.Model{id: id, external_panel: external_panel}) do
case external_panel do
:liss -> ~p"/assignment/#{id}/liss"
:ioresearch -> ~p"/assignment/#{id}/ioresearch?participant={id}&language=nl"
:generic -> ~p"/assignment/#{id}/participate?participant={id}&language=nl"
end
end

def get_preview_url(%Assignment.Model{id: id, external_panel: external_panel}, participant) do
case external_panel do
:liss ->
~p"/assignment/#{id}/liss?respondent=#{participant}&quest=quest&varname1=varname1&token=token&page=page"

:ioresearch ->
~p"/assignment/#{id}/ioresearch?participant=#{participant}"

_ ->
~p"/assignment/#{id}/participate?participant=#{participant}"
end
end

def page_title_default(:assignment_intro), do: dgettext("eyra-assignment", "intro.page.title")

def page_title_default(:assignment_support),
Expand All @@ -28,14 +49,6 @@ defmodule Systems.Assignment.Private do
Application.get_env(:core, :assignment)
end

def panel_function_component(%Assignment.Model{external_panel: nil}), do: nil

def panel_function_component(%Assignment.Model{external_panel: :liss}),
do: &Assignment.PanelViews.liss/1

def panel_function_component(%Assignment.Model{external_panel: _}),
do: &Assignment.PanelViews.default/1

def connector_popup_module(:storage), do: Assignment.ConnectorPopupStorage
def connector_popup_module(:panel), do: Assignment.ConnectorPopupPanel

Expand Down
10 changes: 2 additions & 8 deletions core/systems/assignment/connection_view_panel.ex
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,12 @@ defmodule Systems.Assignment.ConnectionViewPanel do
defp update_url(
%{
assigns: %{
assignment: %{id: id, external_panel: external_panel},
assignment: assignment,
uri_origin: uri_origin
}
} = socket
) do
relative_url =
case external_panel do
:liss -> "/assignment/#{id}/liss"
:ioresearch -> "/assignment/#{id}/ioresearch?participant={id}&language=nl"
:generic -> "/assignment/#{id}/participate?participant={id}&language=nl"
end

relative_url = Assignment.Private.get_panel_url(assignment)
assign(socket, url: uri_origin <> relative_url)
end

Expand Down
8 changes: 5 additions & 3 deletions core/systems/assignment/content_page_builder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ defmodule Systems.Assignment.ContentPageBuilder do
title = get_title(special)
show_errors = show_errors(assignment, assigns)
tabs = create_tabs(assignment, show_errors, assigns)
action_map = action_map(assignment)
action_map = action_map(assignment, assigns)
actions = actions(assignment, action_map)

%{
Expand All @@ -43,8 +43,10 @@ defmodule Systems.Assignment.ContentPageBuilder do
false
end

defp action_map(%{id: id}) do
preview_action = %{type: :http_get, to: ~p"/assignment/#{id}", target: "_blank"}
defp action_map(assignment, %{current_user: %{id: user_id}}) do
preview_url = Assignment.Private.get_preview_url(assignment, user_id)

preview_action = %{type: :http_get, to: preview_url, target: "_blank"}
publish_action = %{type: :send, event: "action_click", item: :publish}
retract_action = %{type: :send, event: "action_click", item: :retract}
close_action = %{type: :send, event: "action_click", item: :close}
Expand Down
128 changes: 68 additions & 60 deletions core/systems/assignment/crew_work_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@ defmodule Systems.Assignment.CrewWorkView do
socket |> assign(selected_item_id: nil)
end

defp update_selected_item_id(%{assigns: %{work_items: [{%{id: id}, _}]}} = socket) do
socket |> assign(selected_item_id: id)
end

defp update_selected_item_id(%{assigns: %{work_items: work_items}} = socket) do
{%{id: selected_item_id}, _} =
Enum.find(work_items, List.first(work_items), fn {_, %{status: status}} ->
Expand Down Expand Up @@ -204,38 +200,20 @@ defmodule Systems.Assignment.CrewWorkView do

# Events

def handle_event("tool_initialized", _, %{assign: %{tool_started: true}} = socket) do
def handle_event("tool_initialized", _, socket) do
{
:noreply,
socket
|> assign(tool_initialized: true)
}
end

def handle_event("tool_initialized", _, socket) do
{:noreply, socket}
end

@impl true
def handle_event(
"complete_task",
_,
%{assigns: %{work_items: work_items, selected_item: {%{id: selected_item_id}, _}}} =
socket
) do
{_, task} = Enum.find(work_items, fn {%{id: id}, _} -> id == selected_item_id end)

Crew.Public.activate_task(task)

def handle_event("complete_task", _, socket) do
{
:noreply,
socket
|> assign(
tool_started: false,
tool_initialized: false
)
|> compose_child(:tool_ref_view)
|> handle_finished_state()
|> handle_complete_task()
}
end

Expand Down Expand Up @@ -317,49 +295,21 @@ defmodule Systems.Assignment.CrewWorkView do

# Private

defp handle_finished_state(%{assigns: %{crew: crew, user: user}} = socket) do
if Crew.Public.member_finised?(crew, user) do
socket
|> compose_child(:finished_view)
|> show_modal(:finished_view, :sheet)
else
socket
end
end

defp handle_feldspar_event(
%{
assigns: %{
selected_item: {_, task},
work_items: work_items,
panel_info: %{embedded?: embedded?}
}
} = socket,
socket,
%{
"__type__" => "CommandSystemExit",
"code" => code,
"info" => _info
"info" => info
}
) do
if code == 0 do
Crew.Public.activate_task(task)

socket =
if Enum.count(work_items) > 1 do
socket
|> assign(tool_started: false, tool_initialized: false)
|> hide_child(:tool_ref_view)
else
socket
end

if embedded? do
socket
else
handle_finished_state(socket)
end
handle_complete_task(socket)
else
Frameworks.Pixel.Flash.put_info(socket, "Application stopped")
Frameworks.Pixel.Flash.put_info(
socket,
"Application stopped unexpectedly [#{code}]: #{info}"
)
end
end

Expand Down Expand Up @@ -389,6 +339,64 @@ defmodule Systems.Assignment.CrewWorkView do
socket |> Frameworks.Pixel.Flash.put_error("Unsupported event")
end

defp handle_complete_task(%{assigns: %{selected_item: {_, task}}} = socket) do
{:ok, %{crew_task: updated_task}} = Crew.Public.activate_task(task)

socket
|> update_task(updated_task)
|> reset_selection()
|> handle_finished_state()
end

defp update_task(%{assigns: %{work_items: work_items}} = socket, updated_task) do
work_items =
Enum.map(work_items, fn {item, task} ->
if task.id == updated_task.id do
{item, updated_task}
else
{item, task}
end
end)

assign(socket, work_items: work_items)
end

defp reset_selection(%{assigns: %{work_items: work_items}} = socket)
when length(work_items) <= 1 do
socket
end

defp reset_selection(socket) do
socket
|> assign(
tool_started: false,
tool_initialized: false,
selected_item_id: nil
)
|> update_selected_item_id()
|> update_selected_item()
|> compose_child(:work_list_view)
|> compose_child(:start_view)
|> hide_child(:tool_ref_view)
end

defp handle_finished_state(%{assigns: %{panel_info: %{embedded?: true}}} = socket) do
# Dont show finished view when embedded in external panel UI
socket
end

defp handle_finished_state(%{assigns: %{work_items: work_items}} = socket) do
task_ids = Enum.map(work_items, fn {_, task} -> task.id end)

if Crew.Public.tasks_finised?(task_ids) do
socket
|> compose_child(:finished_view)
|> show_modal(:finished_view, :sheet)
else
socket
end
end

defp map_item({%{id: id, title: title, group: group}, task}) do
%{id: id, title: title, icon: group, status: task_status(task)}
end
Expand Down
20 changes: 16 additions & 4 deletions core/systems/assignment/external_panel_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,25 @@ defmodule Systems.Assignment.ExternalPanelController do

Logger.warn("[ExternalPanelController] create: #{inspect(params)}")

cond do
has_no_access?(assignment, params) -> forbidden(conn)
is_offline?(assignment) -> service_unavailable(conn)
true -> start(assignment, conn, params)
if is_tester?(assignment, conn) do
conn
|> add_panel_info(params)
|> redirect(to: path(params))
else
cond do
has_no_access?(assignment, params) -> forbidden(conn)
is_offline?(assignment) -> service_unavailable(conn)
true -> start(assignment, conn, params)
end
end
end

defp is_tester?(%{crew: crew}, %{assigns: %{current_user: user}}) do
Core.Authorization.user_has_role?(user, crew, :tester)
end

defp is_tester?(_, _), do: false

defp is_offline?(%{status: status}) do
status != :online
end
Expand Down
47 changes: 0 additions & 47 deletions core/systems/assignment/panel_views.ex

This file was deleted.

9 changes: 6 additions & 3 deletions core/systems/crew/_public.ex
Original file line number Diff line number Diff line change
Expand Up @@ -403,10 +403,13 @@ defmodule Systems.Crew.Public do
|> Repo.transaction()
end

def member_finised?(crew, user_ref) do
def tasks_finised?(task_ids) when is_list(task_ids) do
pending_tasks =
list_tasks_for_user(crew, user_ref)
|> Enum.filter(&(&1.status == :pending))
from(t in Crew.TaskModel,
where: t.id in ^task_ids,
where: t.status == :pending
)
|> Repo.all()

Enum.empty?(pending_tasks)
end
Expand Down

0 comments on commit 3837a76

Please sign in to comment.