diff --git a/app/components/sidenav_component/sidenav_component.html.erb b/app/components/sidenav_component/sidenav_component.html.erb index 8285f0a..2a82d41 100644 --- a/app/components/sidenav_component/sidenav_component.html.erb +++ b/app/components/sidenav_component/sidenav_component.html.erb @@ -95,8 +95,8 @@ diff --git a/app/components/subject_accordion_component.rb b/app/components/subject_accordion_component.rb index ab8a2a9..e4bd1cb 100644 --- a/app/components/subject_accordion_component.rb +++ b/app/components/subject_accordion_component.rb @@ -22,7 +22,9 @@ class SubjectAccordionComponent < BaseComponent end def accordion_body_id - ["subjectsAccordionBody", search_result["id"]].join + accordion_body = opts[:accordionFor].present? && opts[:accordionFor].to_s.eql?("subjects") ? "subjectsAccordionBody" : "doctrinesAccordionBody" + + [accordion_body, search_result["id"]].join end def custom_url diff --git a/app/components/subject_accordion_component/subject_accordion_component.html.erb b/app/components/subject_accordion_component/subject_accordion_component.html.erb index 993700d..7b21f52 100644 --- a/app/components/subject_accordion_component/subject_accordion_component.html.erb +++ b/app/components/subject_accordion_component/subject_accordion_component.html.erb @@ -1,10 +1,10 @@
- <% if search_result["parent_id"].present? %> + <% if search_result["has_children?"].present? %> diff --git a/app/components/subjects_offcanvas_component/subjects_offcanvas_component.html.erb b/app/components/subjects_offcanvas_component/subjects_offcanvas_component.html.erb index 666b076..31069b7 100644 --- a/app/components/subjects_offcanvas_component/subjects_offcanvas_component.html.erb +++ b/app/components/subjects_offcanvas_component/subjects_offcanvas_component.html.erb @@ -1,9 +1,9 @@ -
+
Subjects
-
+
diff --git a/app/controllers/concerns/subject_search.rb b/app/controllers/concerns/subject_search.rb index 750ef99..72ef811 100644 --- a/app/controllers/concerns/subject_search.rb +++ b/app/controllers/concerns/subject_search.rb @@ -11,7 +11,7 @@ module SubjectSearch with :parent_id, search_params[:parent_id].to_i if search_params[:parent_id].present? - without :parent_id if search_params[:is_root].present? && search_params[:is_root].to_s.eql?("true") + with :parent_id, nil if search_params[:is_root].present? && search_params[:is_root].to_s.eql?("true") without(:id).any_of(search_params[:exclude_ids]) if search_params[:exclude_ids].present? diff --git a/app/javascript/controllers/subjects_controller.js b/app/javascript/controllers/subjects_controller.js index 655cd75..8e8f893 100644 --- a/app/javascript/controllers/subjects_controller.js +++ b/app/javascript/controllers/subjects_controller.js @@ -15,6 +15,8 @@ export default class extends ApplicationController { params.is_root = true } + console.log(opts) + $.get("/api/subjects.json", params, function (search_results, status) { if (status === "success") { $this.stimulate("SubjectsReflex#render_subjects_accordion", search_results, opts) diff --git a/app/views/api/subjects/index.json.jbuilder b/app/views/api/subjects/index.json.jbuilder index b204507..7946bdb 100644 --- a/app/views/api/subjects/index.json.jbuilder +++ b/app/views/api/subjects/index.json.jbuilder @@ -2,4 +2,5 @@ json.array!(@subjects) do |subject| json.extract! subject, *%i[id name parent_id state doctrine_ids created_at updated_at] json.text subject.lineage_name json.heirarchy_level subject.ancestors.count + json.has_children? subject.has_children? end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 5b6c8db..fae4f92 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -14,7 +14,8 @@ <%= render(SidenavComponent.new(current_user: current_user, opts: { is_nav_bar: true }))%> - <%= render(SubjectsOffcanvasComponent.new(current_user: current_user, opts: { is_render: true })) %> + <%= render(SubjectsOffcanvasComponent.new(current_user: current_user, opts: { is_render: true, element_id: "subjectsOffCanvas", accordion_body_id: "subjectsAccordionBody" })) %> + <%= render(SubjectsOffcanvasComponent.new(current_user: current_user, opts: { is_render: true, element_id: "doctrinesOffCanvas", accordion_body_id: "doctrinesAccordionBody" })) %>