diff --git a/app/components/sidenav_component/sidenav_component.html.erb b/app/components/sidenav_component/sidenav_component.html.erb index 2a1cab6..8285f0a 100644 --- a/app/components/sidenav_component/sidenav_component.html.erb +++ b/app/components/sidenav_component/sidenav_component.html.erb @@ -88,12 +88,16 @@ <%= link_to 'Search'.html_safe, documents_path, class: "nav-link" %> @@ -112,7 +116,5 @@ - - <% end %> <% end %> diff --git a/app/components/subject_accordion_component.rb b/app/components/subject_accordion_component.rb index 187ae62..ab8a2a9 100644 --- a/app/components/subject_accordion_component.rb +++ b/app/components/subject_accordion_component.rb @@ -1,10 +1,35 @@ class SubjectAccordionComponent < BaseComponent - attr_reader :parent, :subjects, :opts + with_collection_parameter :search_result + attr_reader :search_result, :opts + + def initialize(search_result:, current_user:, opts: {}) + @search_result = search_result + @opts = opts + end - def initialize(current_user:, parent:, subjects: nil, opts: {}) - @parent = parent - @subjects = subjects - @opts = opts - end + def parent_accordion_id + return "subjectsAccordion" if search_result["parent_id"].blank? + + ["subjectsAccordion", search_result["parent_id"]].join + end + + def children_accordion_id + ["subjectsAccordion", search_result["id"]].join + end + + def accordion_id + ["subjectsAccordion", search_result["id"]].join + end + + def accordion_body_id + ["subjectsAccordionBody", search_result["id"]].join + end + + def custom_url + return search_doctrines_path(subject_ids: [search_result["id"]], is_index_table: false) if opts[:accordionFor].present? && opts[:accordionFor].to_s.eql?("subjects") + return search_doctrines_path(subject_ids: [search_result["id"]], is_index_table: true) if opts[:accordionFor].present? && opts[:accordionFor].to_s.eql?("doctrines") + + return subject_index_path(search_result["id"]).blank? end +end \ No newline at end of file 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 6fa8b33..9ab9123 100644 --- a/app/components/subject_accordion_component/subject_accordion_component.html.erb +++ b/app/components/subject_accordion_component/subject_accordion_component.html.erb @@ -1,168 +1,21 @@ -<% if opts[:is_offcanvas].present? %> - <% Cdao::Subject.roots.order(name: :asc).each do |root| %> -
-
-
- <% if root.children.present? %> - - <% else %> - <%= link_to root.name, subject_index_path(root.id), class: "accordion-link text-decoration-none text-dark d-block sub1 clickable-link" %> - <% end %> +
+
+
+ <% if search_result["parent_id"].present? %> + - -
" data-bs-parent="#mainPanel<%= root.id %>"> -
- <% root.children.order(name: :asc).each do |sub1| %> -
-
-
- <% if sub1.children.present? %> - - <% else %> - <%= link_to sub1.name, subject_index_path(sub1.id), class: "accordion-link text-decoration-none text-dark d-block sub2 clickable-link" %> - <% end %> -
- -
" data-bs-parent="#secondLevelPanel<%= sub1.id %>"> -
- <% sub1.children.order(name: :asc).each do |sub2| %> -
-
-
- <% if sub1.children.present? %> - - <% else %> - <%= link_to sub2.name, subject_index_path(sub2.id), class: "accordion-link text-decoration-none text-dark d-block sub3 clickable-link" %> - <% end %> -
- -
" data-bs-parent="#thirdLevelPanel<%= sub2.id %>"> -
- <% sub2.children.order(name: :asc).each do |sub3| %> -
-
-
- <% if sub3.children.present? %> - - <% else %> - <%= link_to sub3.name, subject_index_path(sub3.id), class: "accordion-link text-decoration-none text-dark d-block sub4 clickable-link" %> - <% end %> -
- -
" data-bs-parent="#fourthLevelPanel<%= sub3.id %>"> -
- <% sub3.children.order(name: :asc).each do |sub4| %> -
-
-
- <%= link_to sub4.name, subject_index_path(sub4.id), class: "accordion-link text-decoration-none text-dark d-block sub5 clickable-link" %> -
-
-
- <% end %> -
-
-
-
- <% end %> -
-
-
-
- <% end %> -
-
-
-
- <% end %> -
-
-
+ <% else %> + <%= link_to search_result["name"], custom_url, class: "accordion-link text-decoration-none text-dark d-block sub1 clickable-link" %> + <% end %>
- <% end %> -<% else %> - <% parent.children.order(name: :asc).each do |sub1| %> -
-
-
- <% if sub1.children.present? %> - - <% else %> - <%= link_to sub1.name, subject_index_path(sub1.id), class: "accordion-link text-decoration-none text-dark d-block sub2 clickable-link" %> - <%= link_to "Add Sub Level", new_subject_index_path(parent_id: sub1.id), class: "btn btn-sm btn-primary text-decoration-none d-block sub1 clickable-link position-absolute end-0 accordion-action-button-margin" %> - <% end %> -
- -
" data-bs-parent="#secondLevelPanel<%= sub1.id %>"> -
- <% sub1.children.order(name: :asc).each do |sub2| %> -
-
-
- <% if sub1.children.present? %> - - <% else %> - <%= link_to sub2.name, subject_index_path(sub2.id), class: "accordion-link text-decoration-none text-dark d-block sub3 clickable-link" %> - <%= link_to "Add Sub Level", new_subject_index_path(parent_id: sub2.id), class: "btn btn-sm btn-primary text-decoration-none d-block sub1 clickable-link position-absolute end-0 accordion-action-button-margin" %> - <% end %> -
-
" data-bs-parent="#thirdLevelPanel<%= sub2.id %>"> -
- <% sub2.children.order(name: :asc).each do |sub3| %> -
-
-
- <% if sub3.children.present? %> - - <% else %> - <%= link_to sub3.name, subject_index_path(sub3.id), class: "accordion-link text-decoration-none text-dark d-block sub4 clickable-link" %> - <%= link_to "Add Sub Level", new_subject_index_path(parent_id: sub3.id), class: "btn btn-sm btn-primary text-decoration-none d-block sub1 clickable-link position-absolute end-0 accordion-action-button-margin" %> - <% end %> -
- -
" data-bs-parent="#fourthLevelPanel<%= sub3.id %>"> -
- <% sub3.children.order(name: :asc).each do |sub4| %> -
-
-
- <%= link_to sub4.name, subject_index_path(sub4.id), class: "accordion-link text-decoration-none text-dark d-block sub5 clickable-link" %> - <%= link_to "Add Sub Level", new_subject_index_path(parent_id: sub4.id), class: "btn btn-sm btn-primary text-decoration-none d-block sub1 clickable-link position-absolute end-0 accordion-action-button-margin" %> -
-
-
- <% end %> -
-
-
-
- <% end %> -
-
-
-
- <% end %> -
-
+
+
- <% end %> -<% end %> +
+
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 e1d8f00..666b076 100644 --- a/app/components/subjects_offcanvas_component/subjects_offcanvas_component.html.erb +++ b/app/components/subjects_offcanvas_component/subjects_offcanvas_component.html.erb @@ -1,31 +1,9 @@ -
+
-
Subjects
+
Subjects
-
- <% Cdao::Subject.roots.order(name: :asc).each do |root| %> -
-
-
- <% if root.children.present? %> - - <% else %> - <%= link_to root.name, subject_index_path(root.id), class: "accordion-link text-decoration-none text-dark d-block sub1 clickable-link" %> - <% end %> -
- -
" data-bs-parent="#mainPanel<%= root.id %>"> -
- - <%= render(SubjectAccordionComponent.new(current_user: current_user, parent: root)) %> -
-
-
-
- <% end %> +
diff --git a/app/controllers/api/subjects_controller.rb b/app/controllers/api/subjects_controller.rb index f639175..52e34d1 100644 --- a/app/controllers/api/subjects_controller.rb +++ b/app/controllers/api/subjects_controller.rb @@ -14,7 +14,7 @@ module Api private def search_params - params.permit(:q, :name, :parent_id, :state, :doctrine_ids, :page, :per_page, exclude_ids: []) + params.permit(:q, :name, :parent_id, :state, :doctrine_ids, :is_root, :page, :per_page, exclude_ids: []) end end end diff --git a/app/javascript/controllers/subjects_controller.js b/app/javascript/controllers/subjects_controller.js index 7c0d38d..655cd75 100644 --- a/app/javascript/controllers/subjects_controller.js +++ b/app/javascript/controllers/subjects_controller.js @@ -4,18 +4,20 @@ export default class extends ApplicationController { super.connect() } - renderSidenavAccordion () { - var parent_id = this.element.dataset["subjectParentId"], $this = this, params = {} + loadSubjectsAccordion () { + var $this = this, params = { per_page: 200 }, parent_id = $this.element.dataset["subjectParentId"], + opts = { parent_accordion_id: $this.element.dataset["accordionId"], accordionTarget: $this.element.dataset["accordionTarget"], + accordionFor: $this.element.dataset["accordionFor"] } if (parent_id !== null && parent_id !== undefined && parent_id !== "") { params.parent_id = parent_id } else { - params.is_root_only = true + params.is_root = true } - $.get("/api/subjects.json", params, function (results, status) { + $.get("/api/subjects.json", params, function (search_results, status) { if (status === "success") { - $this.stimulate("SubjectsReflex#render_sidenav_accordion", results) + $this.stimulate("SubjectsReflex#render_subjects_accordion", search_results, opts) } }) } diff --git a/app/reflexes/subjects_reflex.rb b/app/reflexes/subjects_reflex.rb index d118bf7..96a619f 100644 --- a/app/reflexes/subjects_reflex.rb +++ b/app/reflexes/subjects_reflex.rb @@ -1,17 +1,7 @@ # frozen_string_literal: true class SubjectsReflex < ApplicationReflex - def load_sidenav_accordion(search_results, opts = {}) - morph "#" + def render_subjects_accordion(search_results, opts = {}) + morph opts[:accordionTarget], render(partial: "/shared/subjects_accordion", locals: { search_results: search_results, opts: opts }) end - - def save - raise @subject_index.inspect - end - - private - - def resource_params - params.permit(:name, :parent_id, library_ids: []) - end end diff --git a/app/views/api/subjects/index.json.jbuilder b/app/views/api/subjects/index.json.jbuilder index 54d0973..b204507 100644 --- a/app/views/api/subjects/index.json.jbuilder +++ b/app/views/api/subjects/index.json.jbuilder @@ -1,4 +1,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 end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 73be0e1..5b6c8db 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -14,20 +14,11 @@ <%= render(SidenavComponent.new(current_user: current_user, opts: { is_nav_bar: true }))%> -
-
-
Backdrop with scrolling
- -
- -
- <%= render(SubjectAccordionComponent.new(current_user: current_user, parent: nil, opts: { is_offcanvas: true })) %> -
-
+ <%= render(SubjectsOffcanvasComponent.new(current_user: current_user, opts: { is_render: true })) %>
- <%= render(SubjectAccordionComponent.new(current_user: current_user, parent: @subject_index)) %>