Browse Source

Implement CDAO citation finders

pull/20/head
Angel Aviel Domaoan 4 years ago committed by Angel Aviel Domaoan
parent
commit
6dbc2c3f16
  1. 2
      app/components/doctrine_modal_form_component/doctrine_modal_form_component.html.erb
  2. 5
      app/controllers/api/documents_controller.rb
  3. 3
      app/controllers/api/jurisprudences_controller.rb
  4. 4
      app/controllers/concerns/jurisprudence_search.rb
  5. 5
      app/controllers/documents_controller.rb
  6. 8
      app/models/cdao/citation_finder.rb
  7. 20
      app/models/cdao/document.rb
  8. 83
      app/models/cdao/jurisprudence.rb
  9. 2
      app/views/api/documents/index.json.jbuilder
  10. 2
      app/views/api/documents/show.json.jbuilder
  11. 2
      app/views/api/jurisprudences/index.json.jbuilder
  12. 2
      app/views/api/jurisprudences/show.json.jbuilder

2
app/components/doctrine_modal_form_component/doctrine_modal_form_component.html.erb

@ -18,7 +18,7 @@
<div class="row">
<div class="col-sm-12 p-2">
<strong> <%= label_tag :doctine_content_suggestions %> </strong>
<%= select_tag :doctine_content_suggestions, options_from_collection_for_select(Doctrine.all, :content, :content), class: "form-select", prompt: "Please select" %>
<%= select_tag :doctine_content_suggestions, options_from_collection_for_select(Doctrine.all, :content, :plain_content), class: "form-select", prompt: "Please select" %>
</div>
</div>

5
app/controllers/api/documents_controller.rb

@ -31,6 +31,8 @@ module Api
without(:id).any_of(search_params[:exclude_ids]) if search_params[:exclude_ids].present?
with(:citation_finders_names).any_of(search_params[:citation_finder]) if search_params[:citation_finder].present?
order_by :doc_date, :desc
order_by :year, :desc
@ -41,7 +43,8 @@ module Api
end
def search_params
params.permit(:reference_number, :title, :short_title, :year, :q, :page, :per_page,
params.permit(:reference_number, :title, :short_title, :year, :citation_finder,
:q, :page, :per_page,
exclude_ids: [])
end
end

3
app/controllers/api/jurisprudences_controller.rb

@ -27,7 +27,8 @@ module Api
private
def search_params
params.permit(:reference_number, :title, :short_title, :year, :q, :page, :per_page,
params.permit(:reference_number, :title, :short_title, :year, :citation_finder,
:q, :page, :per_page,
exclude_ids: [])
end
end

4
app/controllers/concerns/jurisprudence_search.rb

@ -13,9 +13,7 @@ module JurisprudenceSearch
with(:subject_ids).any_of(search_params[:subject_ids].split(",").map(&:strip).map(&:to_i)) if search_params[:subject_ids].present?
with(:phil_rep, search_params[:phil_rep]) if search_params[:phil_rep].present?
with(:phil_rep, search_params[:scra]) if search_params[:scra].present?
with(:citation_finders_names).any_of(search_params[:citation_finder]) if search_params[:citation_finder].present?
without(:id).any_of(search_params[:exclude_ids]) if search_params[:exclude_ids].present?

5
app/controllers/documents_controller.rb

@ -33,7 +33,8 @@ class DocumentsController < ApplicationController
private
def search_params
params.permit(:reference_number, :title, :short_title, :q, :page, :per_page,
:subject_ids, :phil_rep, :scra, :year)
params.permit(:reference_number, :title, :short_title,
:year, :citation_finder, :subject_ids,
:q, :page, :per_page)
end
end

8
app/models/cdao/citation_finder.rb

@ -5,4 +5,12 @@ class Cdao::CitationFinder < Cdao::Base
belongs_to :jurisprudence, class_name: "Cdao::Jurisprudence", optional: false
delegate :title, :content, :ponente, :syllabus, :reference_number, :docdate, to: :jurisprudence
def display_name
@display_name || set_display_name
end
def set_display_name
@display_name = "#{volume} #{%w(SCRA PHIL)[citation_source_id]} #{[first_page, last_page].join('-')}"
end
end

20
app/models/cdao/document.rb

@ -23,6 +23,24 @@ class Cdao::Document < Cdao::Base
end
end
def citation_finders_names
return [] unless doc_type.match?("Jurisprudence")
Cdao::Jurisprudence.find(doc_id).citation_finders_names
end
def phil_rep
return "" unless doc_type.match?("Jurisprudence")
Cdao::Jurisprudence.find(doc_id).phil_rep
end
def scra
return "" unless doc_type.match?("Jurisprudence")
Cdao::Jurisprudence.find(doc_id).scra
end
searchable do
text :reference_number, stored: true
text :title, stored: true
@ -46,5 +64,7 @@ class Cdao::Document < Cdao::Base
integer :search_year do
year.present? && year > 0 ? year : (doc_date.try :year)
end
string :citation_finders_names, multiple: true
end
end

83
app/models/cdao/jurisprudence.rb

@ -72,46 +72,6 @@ class Cdao::Jurisprudence < Cdao::Base
subjects.map(&:id)
end
searchable do
text :reference_number, stored: true
text :title, stored: true
text :short_title, stored: true
string :reference_number
string :title do
(title.present? ? title.first(32760).strip : short_title || "").titleize
end
string :short_title do
(short_title.presence || title.first(32760).strip || "").titleize
end
date :doc_date
date :search_doc_date do
doc_date.presence || Date.new(year.presence || 0)
end
integer :id
integer :year
integer :search_year do
year.present? && year > 0 ? year : (doc_date.try :year)
end
integer :subject_ids, multiple: true
boolean :edited
join(:phil_rep, :target => Annotation, :type => :string, :join => { :from => :document_id, :to => :id })
end
def phil_rep
names = citation_finders_names.keep_if { |a| a.match?("Phil") }
end
def scra
names = citation_finders_names.keep_if { |a| a.match?(Cdao::CitationFinder::TYPES[0]) }
names
end
def citation_finders_names
return [] if citation_finders.blank?
@ -146,4 +106,47 @@ class Cdao::Jurisprudence < Cdao::Base
names
end
def phil_rep
return "" if citation_finders.blank?
citation_finders.where(citation_source_id: 1).map(&:display_name).join(' | ')
end
def scra
return "" if citation_finders.blank?
citation_finders.where(citation_source_id: 0).map(&:display_name).join(' | ')
end
searchable include: [:citation_finders] do
text :reference_number, stored: true
text :title, stored: true
text :short_title, stored: true
string :reference_number
string :title do
(title.present? ? title.first(32760).strip : short_title || "").titleize
end
string :short_title do
(short_title.presence || title.first(32760).strip || "").titleize
end
string :citation_finders_names, multiple: true
date :doc_date
date :search_doc_date do
doc_date.presence || Date.new(year.presence || 0)
end
integer :id
integer :year
integer :search_year do
year.present? && year > 0 ? year : (doc_date.try :year)
end
integer :subject_ids, multiple: true
boolean :edited
join(:phil_rep, :target => Annotation, :type => :string, :join => { :from => :document_id, :to => :id })
end
end

2
app/views/api/documents/index.json.jbuilder

@ -1,3 +1,3 @@
json.array!(@documents) do |document|
json.extract! document, *%i[id reference_number title short_title doc_date year]
json.extract! document, *%i[id reference_number title short_title doc_date year phil_rep scra]
end

2
app/views/api/documents/show.json.jbuilder

@ -1 +1 @@
json.(@document, *%i[id reference_number title short_title doc_date year])
json.(@document, *%i[id reference_number title short_title doc_date year phil_rep scra])

2
app/views/api/jurisprudences/index.json.jbuilder

@ -1,3 +1,3 @@
json.array!(@jurisprudences) do |jurisprudence|
json.extract! jurisprudence, *%i[id reference_number title docdate ponente edited short_title year]
json.extract! jurisprudence, *%i[id reference_number title docdate ponente edited short_title year phil_rep scra]
end

2
app/views/api/jurisprudences/show.json.jbuilder

@ -1 +1 @@
json.(@jurisprudence, *%i[id reference_number title docdate ponente edited short_title year content])
json.(@jurisprudence, *%i[id reference_number title docdate ponente edited short_title year content phil_rep scra])

Loading…
Cancel
Save