Browse Source

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

Fix search for `annotations` and `doctrines`
pull/123/head
Alexander D. Bondoc 4 years ago committed by GitHub
parent
commit
c9abc3411b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      app/components/doctrine_index_component.rb
  2. 4
      app/components/doctrine_index_component/doctrine_index_component.html.erb
  3. 8
      app/components/document_doctrine_index_component.rb
  4. 2
      app/components/document_doctrine_index_component/document_doctrine_index_component.html.erb
  5. 4
      app/components/document_doctrine_show_component/document_doctrine_show_component.html.erb
  6. 6
      app/controllers/concerns/doctrine_search.rb
  7. 14
      app/models/annotation.rb
  8. 6
      app/models/doctrine.rb
  9. 9
      app/models/doctrine_jurisprudence.rb

11
app/components/doctrine_index_component.rb

@ -2,6 +2,8 @@ class DoctrineIndexComponent < BaseComponent
with_collection_parameter :doctrine with_collection_parameter :doctrine
attr_reader :doctrine, :opts attr_reader :doctrine, :opts
include AnnotationSearch
def initialize(doctrine:, current_user:, opts: {}) def initialize(doctrine:, current_user:, opts: {})
@doctrine = doctrine @doctrine = doctrine
@opts = opts @opts = opts
@ -10,10 +12,10 @@ class DoctrineIndexComponent < BaseComponent
delegate :id, to: :doctrine delegate :id, to: :doctrine
delegate :subject_ids, to: :doctrine delegate :subject_ids, to: :doctrine
delegate :content, to: :doctrine delegate :content, to: :doctrine
delegate :annotations, to: :doctrine
delegate :subjects, to: :doctrine delegate :subjects, to: :doctrine
delegate :headnote, to: :doctrine delegate :headnote, to: :doctrine
delegate :doctrine_jurisprudences, to: :doctrine delegate :doctrine_jurisprudences, to: :doctrine
delegate :jurisprudences, to: :doctrine
def annotation_form_url def annotation_form_url
doctrine_annotations_path(doctrine_id: id) doctrine_annotations_path(doctrine_id: id)
@ -26,7 +28,7 @@ class DoctrineIndexComponent < BaseComponent
def jurisprudence def jurisprudence
return nil if doctrine_jurisprudences.blank? return nil if doctrine_jurisprudences.blank?
doctrine_jurisprudences.first.jurisprudence jurisprudences.first
end end
def document_title(annotation) def document_title(annotation)
@ -53,6 +55,11 @@ class DoctrineIndexComponent < BaseComponent
annotation.phil_rep.gsub(/(PhilRep|Phil)\.?,?/i, "Phil") annotation.phil_rep.gsub(/(PhilRep|Phil)\.?,?/i, "Phil")
end end
def annotations
search = annotation_search(doctrine_id: id)
search.results
end
def render? def render?
doctrine.present? && doctrine.persisted? doctrine.present? && doctrine.persisted?
end end

4
app/components/doctrine_index_component/doctrine_index_component.html.erb

@ -8,13 +8,13 @@
<% date_or_year = jurisprudence.docdate.present? ? jurisprudence.docdate.to_date.strftime("%B %d, %Y") : jurisprudence.year %> <% date_or_year = jurisprudence.docdate.present? ? jurisprudence.docdate.to_date.strftime("%B %d, %Y") : jurisprudence.year %>
<h5 class="clickable-link" style="color: darkred;" href="<%= document_path(jurisprudence, is_index_table: false, subject_ids: params[:subject_ids]) %>"> <%= [document_title, jurisprudence.reference_number, date_or_year].join(", ") %> </h5> <h5 class="clickable-link" style="color: darkred;" href="<%= document_path(jurisprudence, is_index_table: false, subject_ids: params[:subject_ids]) %>"> <%= [document_title, jurisprudence.reference_number, date_or_year].join(", ") %> </h5>
<% annotations.sort_by { |a| [a.document.library.rank, -a.document.year, -a.document.doc_date.strftime("%Y-%m-%d")] }.each do |annotation| %> <% annotations.each do |annotation| %>
<p class="mb-2 ms-3 clickable-link" href="<%= show_url %>"> <p class="mb-2 ms-3 clickable-link" href="<%= show_url %>">
<% annotated_documents_title = [] %> <% annotated_documents_title = [] %>
<% annotation.documents.each do |annotated_document| %> <% annotation.documents.each do |annotated_document| %>
<% ad_title = annotated_document.short_title || annotated_document.title %> <% ad_title = annotated_document.short_title || annotated_document.title %>
<% ad_date_or_year = annotated_document.docdate.present? ? annotated_document.docdate.strftime("%B %d, %Y") : annotated_document.year %> <% ad_date_or_year = annotated_document.docdate.present? ? annotated_document.docdate.strftime("%B %d, %Y") : annotated_document.year %>
<% annotated_documents_title << [" citing #{ad_title}", annotated_document.reference_number, ad_date_or_year].join(", ") %> <% annotated_documents_title << [" citing #{ad_title}", annotated_document.clean_reference_number, ad_date_or_year].join(", ") %>
<% end %> <% end %>
<strong> <%= "#{annotation.annomarks.map { |annomark| "(#{annomark.code})" }.join(" ")}" %> </strong> <strong> <%= "#{annotation.annomarks.map { |annomark| "(#{annomark.code})" }.join(" ")}" %> </strong>

8
app/components/document_doctrine_index_component.rb

@ -2,6 +2,8 @@ class DocumentDoctrineIndexComponent < BaseComponent
with_collection_parameter :doctrine with_collection_parameter :doctrine
attr_reader :doctrine, :opts attr_reader :doctrine, :opts
include AnnotationSearch
def initialize(doctrine:, current_user:, opts: {}) def initialize(doctrine:, current_user:, opts: {})
@doctrine = doctrine @doctrine = doctrine
@opts = opts @opts = opts
@ -10,7 +12,6 @@ class DocumentDoctrineIndexComponent < BaseComponent
delegate :id, to: :doctrine delegate :id, to: :doctrine
delegate :subject_ids, to: :doctrine delegate :subject_ids, to: :doctrine
delegate :content, to: :doctrine delegate :content, to: :doctrine
delegate :annotations, to: :doctrine
delegate :subjects, to: :doctrine delegate :subjects, to: :doctrine
delegate :headnote, to: :doctrine delegate :headnote, to: :doctrine
delegate :doctrine_jurisprudences, to: :doctrine delegate :doctrine_jurisprudences, to: :doctrine
@ -47,6 +48,11 @@ class DocumentDoctrineIndexComponent < BaseComponent
annotation.phil_rep.gsub(/(PhilRep|Phil)\.?,?/i, "Phil") annotation.phil_rep.gsub(/(PhilRep|Phil)\.?,?/i, "Phil")
end end
def annotations
search = annotation_search(doctrine_id: id)
search.results
end
def render? def render?
doctrine.present? && doctrine.persisted? doctrine.present? && doctrine.persisted?
end end

2
app/components/document_doctrine_index_component/document_doctrine_index_component.html.erb

@ -10,7 +10,7 @@
<h5 style="color: darkred;"> <%= [document_title, jurisprudence.reference_number, date_or_year].join(", ") %> </h5> <h5 style="color: darkred;"> <%= [document_title, jurisprudence.reference_number, date_or_year].join(", ") %> </h5>
<% end %> <% end %>
<% annotations.sort_by { |a| [a.document.library.rank, -a.document.year, -a.document.doc_date.strftime('%Y-%m-%d')] }.each do |annotation| %> <% annotations.each do |annotation| %>
<p class="mb-2 ms-3"> <p class="mb-2 ms-3">
<% annotated_documents_title = [] %> <% annotated_documents_title = [] %>
<% annotation.documents.each do |annotated_document| %> <% annotation.documents.each do |annotated_document| %>

4
app/components/document_doctrine_show_component/document_doctrine_show_component.html.erb

@ -6,7 +6,7 @@
</div> </div>
<div class="col-sm-2 d-flex justify-content-end pe-0" data-controller="doctrines" data-document-id="<%= document_id %>" data-doctrine-id="<%= id %>" > <div class="col-sm-2 d-flex justify-content-end pe-0" data-controller="doctrines" data-document-id="<%= document_id %>" data-doctrine-id="<%= id %>" >
<a class="btn btn-success me-3 for-selectize-edit"data-action="click->doctrines#renderForm" data-bs-toggle="modal" data-bs-target="#doctrineModal"> Edit </a> <a class="btn btn-success me-3 for-selectize-edit" href="<%= edit_doctrine_path(id, jurisprudence_id: document_id) %>"> Edit </a>
<a class="btn btn-danger " data-action="click->doctrines#delete" > Delete </a> <a class="btn btn-danger " data-action="click->doctrines#delete" > Delete </a>
</div> </div>
</div> </div>
@ -85,7 +85,7 @@
<div class="row-flex"> <div class="row-flex">
<div class="annot-header"> <h5> Annotations </h5> </div> <div class="annot-header"> <h5> Annotations </h5> </div>
<div class="" id="annotationsIndexView"> <div class="" id="annotationsIndexView">
<% doctrine.annotations.sort_by { |a| [a.document.library.rank, -a.document.year, -a.document.doc_date.strftime("%Y-%m-%d")] }.each do |annotation| %> <% annotations.each do |annotation| %>
<% document_title = annotation.document.short_title || annotation.document.title %> <% document_title = annotation.document.short_title || annotation.document.title %>
<% date_or_year = annotation.document.docdate.present? ? annotation.document.docdate.strftime("%B %d, %Y") : annotation.document.year %> <% date_or_year = annotation.document.docdate.present? ? annotation.document.docdate.strftime("%B %d, %Y") : annotation.document.year %>
<% annotated_documents_title = [] %> <% annotated_documents_title = [] %>

6
app/controllers/concerns/doctrine_search.rb

@ -23,10 +23,8 @@ module DoctrineSearch
without(:id).any_of(search_params[:exclude_ids]) if search_params[:exclude_ids].present? without(:id).any_of(search_params[:exclude_ids]) if search_params[:exclude_ids].present?
if search_params[:sort_by].blank? if search_params[:is_group_by_headnote].to_s.eql?("true")
order_by :search_year, :desc group :headnote
order_by :search_doc_date, :desc
order_by :reference_number, :desc
end end
paginate page: search_params[:page] || 1, per_page: search_params[:per_page] || 20 paginate page: search_params[:page] || 1, per_page: search_params[:per_page] || 20

14
app/models/annotation.rb

@ -13,6 +13,8 @@ class Annotation < ApplicationRecord
validates :content, presence: true validates :content, presence: true
before_save :parse_content
def documents def documents
annotation_documents.collect(&:document) annotation_documents.collect(&:document)
end end
@ -31,6 +33,18 @@ class Annotation < ApplicationRecord
documents.map(&:id) documents.map(&:id)
end end
def parse_content
pr = phil_rep.gsub(/(PhilRep|Phil)\.?,?/i, "Phil")
pr = pr.gsub(/(PhilRep|Phil)\.?,?/i, "Phil")
annotated_doc_title = document.short_title || document.title
annotated_doc_date = document.doc_date.present? ? document.doc_date.try(:strftime, "%B %d, %Y") : document.year
contents = content.split(" citing ")
contents[0] = [annotated_doc_title, document.clean_reference_number, annotated_doc_date, pr].join(", ")
self.content = contents.join(" citing ")
end
searchable do searchable do
integer :document_id integer :document_id
integer :doctrine_id integer :doctrine_id

6
app/models/doctrine.rb

@ -183,10 +183,8 @@ class Doctrine < ApplicationRecord
paper_trail.originator.to_i paper_trail.originator.to_i
end end
join(:search_doc_date, :target => DoctrineJurisprudence, :type => :date, :join => { :from => :doctrine_id, :to => :id })
join(:search_year, :target => DoctrineJurisprudence, :type => :integer, :join => { :from => :doctrine_id, :to => :id })
join(:reference_number, :target => DoctrineJurisprudence, :type => :string, :join => { :from => :doctrine_id, :to => :id })
date :created_at date :created_at
string :headnote
end end
end end

9
app/models/doctrine_jurisprudence.rb

@ -4,13 +4,4 @@ class DoctrineJurisprudence < ApplicationRecord
belongs_to :doctrine, optional: false belongs_to :doctrine, optional: false
belongs_to :jurisprudence, class_name: "Cdao::Jurisprudence", optional: false belongs_to :jurisprudence, class_name: "Cdao::Jurisprudence", optional: false
searchable do
integer :doctrine_id
integer :jurisprudence_id
join(:search_doc_date, :target => Cdao::Jurisprudence, :type => :date, :join => { :from => :id, :to => :jurisprudence_id })
join(:search_year, :target => Cdao::Jurisprudence, :type => :integer, :join => { :from => :id, :to => :jurisprudence_id })
join(:reference_number, :target => Cdao::Jurisprudence, :type => :string, :join => { :from => :id, :to => :jurisprudence_id })
join(:subject_ids, :target => Doctrine, :type => :integer, :multiple => true, :join => { :from => :id, :to => :doctrine_id })
end
end end

Loading…
Cancel
Save