Skip to content

Commit

Permalink
Merge branch 'Simon-Initiative:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
dtiwarATS committed Aug 2, 2024
2 parents d1d57c5 + b41a5c5 commit e13273f
Show file tree
Hide file tree
Showing 14 changed files with 512 additions and 37 deletions.
39 changes: 34 additions & 5 deletions lib/oli/delivery/hierarchy.ex
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ defmodule Oli.Delivery.Hierarchy do
),
join: p in Project,
on: p.id == spp.project_id,
where: rev.resource_type_id in ^[page_id, container_id],
where: rev.resource_type_id in ^[page_id, container_id] and not sr.hidden,
select: %{
"id" => rev.id,
"numbering" => %{"index" => sr.numbering_index, "level" => sr.numbering_level},
Expand Down Expand Up @@ -366,10 +366,9 @@ defmodule Oli.Delivery.Hierarchy do
end

defp build_updated_children(children_ids, nodes_by_sr_id) do
Enum.map(
children_ids,
&(Map.get(nodes_by_sr_id, &1) |> hierarchy_node_with_children(nodes_by_sr_id))
)
children_ids
|> Enum.filter(&Map.has_key?(nodes_by_sr_id, &1))
|> Enum.map(&(Map.get(nodes_by_sr_id, &1) |> hierarchy_node_with_children(nodes_by_sr_id)))
end

def reorder_children(
Expand Down Expand Up @@ -438,6 +437,36 @@ defmodule Oli.Delivery.Hierarchy do
end
end

@doc """
Toggles the hidden attribute of a node in the hierarchy with the given uuid
"""

def find_and_toggle_hidden(hierarchy, uuid) do
find_and_toggle_hidden_r(hierarchy, uuid)
|> mark_unfinalized()
end

defp find_and_toggle_hidden_r(hierarchy, uuid) do
if hierarchy.uuid == uuid do
updated_section_resource =
case hierarchy.section_resource do
nil -> nil
sr -> Map.put(sr, :hidden, !sr.hidden)
end

%HierarchyNode{
hierarchy
| section_resource: updated_section_resource
}
else
%HierarchyNode{
hierarchy
| children:
Enum.map(hierarchy.children, fn child -> find_and_toggle_hidden_r(child, uuid) end)
}
end
end

@doc """
Moves a node to a given container given by destination uuid
"""
Expand Down
7 changes: 5 additions & 2 deletions lib/oli/delivery/sections.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1839,6 +1839,7 @@ defmodule Oli.Delivery.Sections do
|> Enum.filter(fn section_resource ->
case section_resource do
%SectionResource{start_date: nil, end_date: nil} -> false
%SectionResource{hidden: true} -> false
_ -> true
end
end)
Expand Down Expand Up @@ -1924,6 +1925,7 @@ defmodule Oli.Delivery.Sections do
|> Enum.filter(fn section_resource ->
case section_resource do
%SectionResource{start_date: nil, end_date: nil} -> false
%SectionResource{hidden: true} -> false
_ -> true
end
end)
Expand Down Expand Up @@ -4335,7 +4337,8 @@ defmodule Oli.Delivery.Sections do
left_join: ra in assoc(r_att, :resource_access),
where:
ra.section_id == ^section.id and ra.user_id == ^user_id and rev.graded and
rev.resource_type_id == ^page_resource_type_id and last_att.row_number == 1,
rev.resource_type_id == ^page_resource_type_id and last_att.row_number == 1 and
not sr.hidden,
group_by: [
rev.id,
sr.numbering_index,
Expand Down Expand Up @@ -4416,7 +4419,7 @@ defmodule Oli.Delivery.Sections do
rev.resource_type_id == ^page_resource_type_id and
coalesce(se.start_date, se.end_date) |> coalesce(sr.start_date) |> coalesce(sr.end_date) >=
^today and coalesce(ra.progress, 0) == 0 and
is_nil(r_att.id),
is_nil(r_att.id) and not sr.hidden,
order_by: [
asc:
coalesce(se.start_date, se.end_date) |> coalesce(sr.start_date) |> coalesce(sr.end_date),
Expand Down
5 changes: 4 additions & 1 deletion lib/oli/delivery/sections/section_resource.ex
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ defmodule Oli.Delivery.Sections.SectionResource do
field :review_submission, Ecto.Enum, values: [:allow, :disallow], default: :allow
field :feedback_mode, Ecto.Enum, values: [:allow, :disallow, :scheduled], default: :allow
field :feedback_scheduled_date, :utc_datetime
field :hidden, :boolean, default: false

# an array of ids to other section resources
field :children, {:array, :id}, default: []
Expand Down Expand Up @@ -108,6 +109,7 @@ defmodule Oli.Delivery.Sections.SectionResource do
:review_submission,
:feedback_mode,
:feedback_scheduled_date,
:hidden,
:scoring_strategy_id,
:resource_id,
:project_id,
Expand Down Expand Up @@ -141,7 +143,8 @@ defmodule Oli.Delivery.Sections.SectionResource do
:delivery_policy_id,
:scoring_strategy_id,
:inserted_at,
:updated_at
:updated_at,
:hidden
]

def to_map(%SectionResource{} = section_resource) do
Expand Down
5 changes: 4 additions & 1 deletion lib/oli_web/components/delivery/layouts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ defmodule OliWeb.Components.Delivery.Layouts do
</div>
<div class="p-2 flex-col justify-center items-center gap-4 inline-flex">
<.tech_support_button id="tech-support" ctx={@ctx} sidebar_expanded={@sidebar_expanded} />
<.exit_course_button sidebar_expanded={@sidebar_expanded} />
<.exit_course_button
:if={is_independent_learner?(@ctx.user)}
sidebar_expanded={@sidebar_expanded}
/>
</div>
</nav>
<nav
Expand Down
30 changes: 17 additions & 13 deletions lib/oli_web/components/delivery/user_account.ex
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,7 @@ defmodule OliWeb.Components.Delivery.UserAccount do
~H"""
<.menu_item_maybe_linked_account user={@ctx.user} />
<.maybe_menu_item_edit_user_account user={@ctx.user} />
<.menu_item_link href={~p"/sections/workspace/student"}>
My Courses
</.menu_item_link>
<.menu_divider />
<.maybe_my_courses_menu_item_link user={@ctx.user} />
<.menu_item_dark_mode_selector id={"#{@id}-dark-mode-selector"} ctx={@ctx} />
<.menu_divider />
<.menu_item_timezone_selector id={"#{@id}-tz-selector"} ctx={@ctx} />
Expand Down Expand Up @@ -186,14 +183,6 @@ defmodule OliWeb.Components.Delivery.UserAccount do
end
end

def menu_item_my_courses_link(assigns) do
~H"""
<.menu_item_link href={~p"/sections/workspace/student"}>
My Courses
</.menu_item_link>
"""
end

attr(:user, User, required: true)

def menu_item_maybe_linked_account(assigns) do
Expand All @@ -204,6 +193,7 @@ defmodule OliWeb.Components.Delivery.UserAccount do
<.menu_item_link href={Routes.delivery_path(OliWeb.Endpoint, :link_account)}>
Link authoring account
</.menu_item_link>
<.menu_divider />
<% end %>
<% linked_author_account_email -> %>
Expand Down Expand Up @@ -237,7 +227,21 @@ defmodule OliWeb.Components.Delivery.UserAccount do
Edit Account
</.menu_item_link>
<.menu_divider />
<.menu_divider :if={is_independent_learner?(@user)} />
"""
end

attr(:user, User, required: true)

def maybe_my_courses_menu_item_link(assigns) do
~H"""
<%= if is_independent_learner?(@user) do %>
<.menu_item_link href={~p"/sections/workspace/student"}>
My Courses
</.menu_item_link>
<.menu_divider />
<% end %>
"""
end

Expand Down
12 changes: 12 additions & 0 deletions lib/oli_web/live/delivery/remix/actions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ defmodule OliWeb.Delivery.Remix.Actions do
"""

use OliWeb, :live_component
alias Oli.Resources.ResourceType

def render(assigns) do
~H"""
Expand All @@ -16,6 +17,17 @@ defmodule OliWeb.Delivery.Remix.Actions do
>
<i class="fas fa-arrow-circle-right"></i> Move
</button>
<button
:if={@resource_type == ResourceType.id_for_page()}
type="button"
class="btn btn-outline-primary btn-sm ml-2"
phx-click="show_hide_resource_modal"
phx-value-uuid={@uuid}
>
<i class={"fa-solid #{if @hidden, do: "fa-eye", else: "fa-eye-slash"}"}></i> <%= if @hidden,
do: "Show",
else: "Hide" %>
</button>
<button
type="button"
class="btn btn-danger btn-sm ml-2"
Expand Down
8 changes: 7 additions & 1 deletion lib/oli_web/live/delivery/remix/entry.ex
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,13 @@ defmodule OliWeb.Delivery.Remix.Entry do
</div>
<div draggable="true" ondragstart="event.preventDefault(); event.stopPropagation();">
<.live_component module={Actions} uuid={@node.uuid} id={"remix_actions_#{@node.uuid}"} />
<.live_component
module={Actions}
uuid={@node.uuid}
hidden={(@node.section_resource && @node.section_resource.hidden) || false}
resource_type={@node.revision.resource_type_id}
id={"remix_actions_#{@node.uuid}"}
/>
</div>
</div>
"""
Expand Down
58 changes: 58 additions & 0 deletions lib/oli_web/live/delivery/remix/hide_resource_modal.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
defmodule OliWeb.Delivery.Remix.HideResourceModal do
use Phoenix.LiveComponent
use Phoenix.HTML

import OliWeb.Components.Common

alias Oli.Delivery.Hierarchy.HierarchyNode

def render(%{node: %HierarchyNode{}} = assigns) do
~H"""
<div
class="modal fade show"
id={"hide_#{@node.uuid}"}
tabindex="-1"
role="dialog"
aria-hidden="true"
phx-hook="ModalLaunch"
>
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">
<%= get_label_action(@node) |> String.capitalize() %>
<%= @node.revision.title |> String.capitalize() %>
</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close">
</button>
</div>
<div class="modal-body">
Are you sure you want to <%= get_label_action(@node) %> <b><%= @node.revision.title %></b>?
</div>
<div class="modal-footer">
<.button
type="button"
variant={:info}
data-bs-dismiss="modal"
phx-click="HideResourceModal.cancel"
>
Cancel
</.button>
<.button
type="button"
variant={:danger}
phx-value-uuid={@node.uuid}
phx-key="enter"
phx-click="HideResourceModal.toggle"
>
<%= get_label_action(@node) |> String.capitalize() %>
</.button>
</div>
</div>
</div>
</div>
"""
end

defp get_label_action(node), do: if(node.section_resource.hidden, do: "show", else: "hide")
end
46 changes: 45 additions & 1 deletion lib/oli_web/live/delivery/remix_section.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ defmodule OliWeb.Delivery.RemixSection do
alias OliWeb.Common.Hierarchy.Publications.TableModel, as: PublicationsTableModel
alias OliWeb.Common.Breadcrumb
alias OliWeb.Common.Table.SortableTableModel
alias OliWeb.Delivery.Remix.{RemoveModal, AddMaterialsModal}
alias OliWeb.Delivery.Remix.{RemoveModal, AddMaterialsModal, HideResourceModal}
alias OliWeb.Common.Hierarchy.MoveModal
alias Oli.Publishing
alias Oli.Publishing.PublishedResource
Expand Down Expand Up @@ -848,6 +848,50 @@ defmodule OliWeb.Delivery.RemixSection do
{:noreply, hide_modal(socket, modal_assigns: nil)}
end

def handle_event("show_hide_resource_modal", %{"uuid" => uuid}, socket) do
%{hierarchy: hierarchy} = socket.assigns

node = Hierarchy.find_in_hierarchy(hierarchy, uuid)

modal_assigns = %{
id: "hide_#{uuid}",
node: node
}

modal = fn assigns ->
~H"""
<HideResourceModal.render {@modal_assigns} />
"""
end

{:noreply,
show_modal(
socket,
modal,
modal_assigns: modal_assigns
)}
end

def handle_event("HideResourceModal.toggle", %{"uuid" => uuid}, socket) do
%{hierarchy: hierarchy, active: active} = socket.assigns

hierarchy =
Hierarchy.find_and_toggle_hidden(hierarchy, uuid)
|> Hierarchy.finalize()

# refresh active node
active = Hierarchy.find_in_hierarchy(hierarchy, active.uuid)

{:noreply,
socket
|> assign(hierarchy: hierarchy, active: active, has_unsaved_changes: true)
|> hide_modal(modal_assigns: nil)}
end

def handle_event("HideResourceModal.cancel", _, socket) do
{:noreply, hide_modal(socket, modal_assigns: nil)}
end

defp maybe_filter_publications(publications, params) do
filtered_publications =
case params[:text_filter] do
Expand Down
Loading

0 comments on commit e13273f

Please sign in to comment.