Browse Source

Merge pull request #131 from lexintegritastech/improve-main-ui

Improve `grouping` for `doctrines#search`
pull/132/head
Alexander D. Bondoc 4 years ago committed by GitHub
parent
commit
7ec5ad0bb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 33
      app/components/doctrine_index_component.rb
  2. 34
      app/components/doctrine_index_component/doctrine_index_component.html.erb
  3. 18
      app/controllers/concerns/doctrine_search.rb
  4. 4
      app/controllers/doctrines_controller.rb
  5. 5
      app/models/doctrine.rb
  6. 18
      app/views/doctrines/search.html.erb

33
app/components/doctrine_index_component.rb

@ -1,22 +1,14 @@
class DoctrineIndexComponent < BaseComponent
with_collection_parameter :doctrine
attr_reader :doctrine, :opts
attr_reader :search_results, :opts
include AnnotationSearch
include DoctrineSearch
def initialize(doctrine:, current_user:, opts: {})
@doctrine = doctrine
def initialize(search_results:, current_user:, opts: {})
@search_results = search_results
@opts = opts
end
delegate :id, to: :doctrine
delegate :subject_ids, to: :doctrine
delegate :content, to: :doctrine
delegate :subjects, to: :doctrine
delegate :headnote, to: :doctrine
delegate :doctrine_jurisprudences, to: :doctrine
delegate :jurisprudences, to: :doctrine
def annotation_form_url
doctrine_annotations_path(doctrine_id: id)
end
@ -25,12 +17,6 @@ class DoctrineIndexComponent < BaseComponent
"(No Subjects Provided)"
end
def jurisprudence
return nil if doctrine_jurisprudences.blank?
jurisprudences.first
end
def document_title(annotation)
return annotation.document.short_title if annotation.document.short_title.present?
@ -55,8 +41,8 @@ class DoctrineIndexComponent < BaseComponent
annotation.phil_rep.gsub(/(PhilRep|Phil)\.?,?/i, "Phil")
end
def annotations
search = annotation_search(doctrine_id: id)
def search_annotations(search_params)
search = annotation_search(search_params)
search.results
end
@ -68,7 +54,12 @@ class DoctrineIndexComponent < BaseComponent
contents.join(" citing ")
end
def search_doctrines(search_params)
search = doctrine_search(search_params)
search
end
def render?
doctrine.present? && doctrine.persisted?
search_results.present?
end
end

34
app/components/doctrine_index_component/doctrine_index_component.html.erb

@ -1,9 +1,25 @@
<div class="container-fluid p-0">
<% document_title = jurisprudence.short_title || jurisprudence.title %>
<% date_or_year = jurisprudence.doc_date.present? ? jurisprudence.doc_date.strftime("%B %d, %Y") : jurisprudence.year %>
<div class="row-flex m-3 mt-0 doctrine-content-body">
<div class="container-sm <%= params[:is_subjects_index].present? ? 'm-0 ps-0' : '' %>">
<% search_results.uniq(&:headnote).each do |uniq_by_headnote| %>
<h5> <%= uniq_by_headnote.headnote %> </h5>
<h5 class="clickable-link" style="color: darkred;" href="<%= document_path(jurisprudence.document.id, is_index_table: false, subject_ids: params[:subject_ids]) %>"> <%= [document_title, jurisprudence.clean_reference_number, date_or_year].join(", ") %> </h5>
<% annotations.each do |annotation| %>
<% grouped_by_content_search_params = { subject_ids: opts[:subject_ids], headnote: uniq_by_headnote.headnote, is_grouped_by_content: true } %>
<% search_doctrines(grouped_by_content_search_params).group(:content).groups.each do |group_by_content| %>
<% group_by_content.results.each do |content_result| %>
<div class="mb-0"> <%= raw content_result.content.html_safe %> </div>
<% grouped_by_juris_search_params = { subject_ids: opts[:subject_ids], content: content_result.content, is_grouped_by_juris_id: true } %>
<% search_doctrines(grouped_by_juris_search_params).group(:jurisprudence_id).groups.each do |grouped_by_juris| %>
<% grouped_by_juris.results.each do |juris_result| %>
<h5 class="clickable-link" style="color: darkred;" href="<%= document_path(juris_result.jurisprudence.document.id, is_index_table: false, subject_ids: params[:subject_ids]) %>">
<% document_title = juris_result.jurisprudence.short_title || juris_result.jurisprudence.title %>
<% date_or_year = juris_result.jurisprudence.doc_date.present? ? juris_result.jurisprudence.doc_date.strftime("%B, %d, %Y") : doctrine.jurisprudence.year %>
<%= [document_title, juris_result.jurisprudence.clean_reference_number, date_or_year].join(", ") %>
</h5>
<% search_params = { subject_ids: opts[:subject_ids], headnote: uniq_by_headnote.headnote, content: content_result.content, jurisprudence_id: juris_result.jurisprudence.id } %>
<% search_doctrines(search_params).results.each do |doctrine| %>
<% search_annotations({ doctrine_id: doctrine.id }).each do |annotation| %>
<% annotated_documents_title = [] %>
<% annotation.documents.each do |annotated_document| %>
<% ad_title = annotated_document.short_title || annotated_document.title %>
@ -29,4 +45,12 @@
</div>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
</div>
<hr/>
</div>

18
app/controllers/concerns/doctrine_search.rb

@ -9,6 +9,12 @@ module DoctrineSearch
with(:user_ids).any_of(search_params[:user_ids].map(&:to_i)) if search_params[:user_ids].present?
with(:jurisprudence_id, search_params[:jurisprudence_id]) if search_params[:jurisprudence_id].present?
%i[headnote content].each do |field|
with(field, search_params[field]) if search_params[field].present?
end
if search_params[:created_at].present?
with(:created_at).between(Date.parse(search_params[:created_at])..Time.zone.today.to_date)
end
@ -23,6 +29,18 @@ module DoctrineSearch
without(:id).any_of(search_params[:exclude_ids]) if search_params[:exclude_ids].present?
if search_params[:is_grouped_by_headnote].to_s.eql?("true")
group :headnote
end
if search_params[:is_grouped_by_content].to_s.eql?("true")
group :content
end
if search_params[:is_grouped_by_juris_id].to_s.eql?("true")
group :jurisprudence_id
end
order_by :search_year, :desc
order_by :search_doc_date, :desc

4
app/controllers/doctrines_controller.rb

@ -19,9 +19,7 @@ class DoctrinesController < ApplicationController
def search
@search = doctrine_search(search_params)
@results = @search.results
@uniq_by_headnotes = @results.uniq(&:headnote)
@search_results = @search.results
respond_to do |format|
format.html

5
app/models/doctrine.rb

@ -181,6 +181,10 @@ class Doctrine < ApplicationRecord
integer :id
integer :jurisprudence_id do
jurisprudence.id
end
integer :subject_ids, multiple: true
integer :user_ids, multiple: true do
@ -198,5 +202,6 @@ class Doctrine < ApplicationRecord
date :created_at
string :headnote
string :content
end
end

18
app/views/doctrines/search.html.erb

@ -1,20 +1,6 @@
<div class="container-fluid mt-1 p-0 doctrine-index-body">
<div class="container-fluid m-2 p-0"> <%= render PaginationComponent.new(data: @results, opts: { is_subject_breadcrums: true, subject_ids: params[:subject_ids], is_index_table: params[:is_index_table] }) %> </div>
<div class="container-fluid m-2 p-0"> <%= render PaginationComponent.new(data: @search_results, opts: { is_subject_breadcrums: true, subject_ids: params[:subject_ids], is_index_table: params[:is_index_table] }) %> </div>
<hr class="mt-0"/>
<% @uniq_by_headnotes.each do |uniq_by_headnote| %>
<div class="row-flex m-3 mt-0 doctrine-content-body">
<div class="container-sm <%= params[:is_subjects_index].present? ? 'm-0 ps-0' : '' %>">
<h5> <%= uniq_by_headnote.headnote %> </h5>
<% uniq_by_contents = @results.map { |doctrine| doctrine if doctrine.headnote.eql?(uniq_by_headnote.headnote) }.uniq(&:content) %>
<% uniq_by_contents.each do |uniq_by_content| %>
<div class="mb-0"> <%= raw uniq_by_content.content.html_safe %> </div>
<% doctrines = @results.map { |doctrine| doctrine if doctrine.headnote.eql?(uniq_by_headnote.headnote) && doctrine.content.eql?(uniq_by_content.content) } %>
<%= render(DoctrineIndexComponent.with_collection(doctrines, current_user: current_user, opts: { is_index_table: false, subject_ids: params[:subject_ids].map(&:to_i) })) %>
<% end %>
</div>
<hr/>
</div>
<% end %>
<%= render(DoctrineIndexComponent.new(search_results: @search_results, current_user: current_user, opts: { is_index_table: false, subject_ids: params[:subject_ids].map(&:to_i) })) %>
</div>

Loading…
Cancel
Save