From b93ebc0ae69f0215d63a28ab938ef9cf0751f370 Mon Sep 17 00:00:00 2001 From: Angel Aviel Domaoan Date: Mon, 7 Feb 2022 09:45:02 +0000 Subject: [PATCH] Implement CDAO citation finders --- .../doctrine_modal_form_component.html.erb | 2 +- app/controllers/api/documents_controller.rb | 5 +- .../api/jurisprudences_controller.rb | 3 +- .../concerns/jurisprudence_search.rb | 4 +- app/controllers/documents_controller.rb | 5 +- app/models/cdao/citation_finder.rb | 8 ++ app/models/cdao/document.rb | 20 +++++ app/models/cdao/jurisprudence.rb | 83 ++++++++++--------- app/views/api/documents/index.json.jbuilder | 2 +- app/views/api/documents/show.json.jbuilder | 2 +- .../api/jurisprudences/index.json.jbuilder | 2 +- .../api/jurisprudences/show.json.jbuilder | 2 +- 12 files changed, 86 insertions(+), 52 deletions(-) diff --git a/app/components/doctrine_modal_form_component/doctrine_modal_form_component.html.erb b/app/components/doctrine_modal_form_component/doctrine_modal_form_component.html.erb index 04624ba..38abe31 100644 --- a/app/components/doctrine_modal_form_component/doctrine_modal_form_component.html.erb +++ b/app/components/doctrine_modal_form_component/doctrine_modal_form_component.html.erb @@ -18,7 +18,7 @@
<%= label_tag :doctine_content_suggestions %> - <%= 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" %>
diff --git a/app/controllers/api/documents_controller.rb b/app/controllers/api/documents_controller.rb index 162ba41..64dc988 100644 --- a/app/controllers/api/documents_controller.rb +++ b/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 diff --git a/app/controllers/api/jurisprudences_controller.rb b/app/controllers/api/jurisprudences_controller.rb index 370bd0a..326ee28 100644 --- a/app/controllers/api/jurisprudences_controller.rb +++ b/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 diff --git a/app/controllers/concerns/jurisprudence_search.rb b/app/controllers/concerns/jurisprudence_search.rb index 2cd8868..f90681c 100644 --- a/app/controllers/concerns/jurisprudence_search.rb +++ b/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? diff --git a/app/controllers/documents_controller.rb b/app/controllers/documents_controller.rb index eb9ab50..f5b03b9 100644 --- a/app/controllers/documents_controller.rb +++ b/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 diff --git a/app/models/cdao/citation_finder.rb b/app/models/cdao/citation_finder.rb index 9161f36..cce8f54 100644 --- a/app/models/cdao/citation_finder.rb +++ b/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 diff --git a/app/models/cdao/document.rb b/app/models/cdao/document.rb index cd9db3a..1df1ffa 100644 --- a/app/models/cdao/document.rb +++ b/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 diff --git a/app/models/cdao/jurisprudence.rb b/app/models/cdao/jurisprudence.rb index eb579d7..5b8a032 100644 --- a/app/models/cdao/jurisprudence.rb +++ b/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 diff --git a/app/views/api/documents/index.json.jbuilder b/app/views/api/documents/index.json.jbuilder index f438ec5..d745307 100644 --- a/app/views/api/documents/index.json.jbuilder +++ b/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 diff --git a/app/views/api/documents/show.json.jbuilder b/app/views/api/documents/show.json.jbuilder index 196f2a4..4ea13c7 100644 --- a/app/views/api/documents/show.json.jbuilder +++ b/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]) diff --git a/app/views/api/jurisprudences/index.json.jbuilder b/app/views/api/jurisprudences/index.json.jbuilder index 9bc37fe..f69b801 100644 --- a/app/views/api/jurisprudences/index.json.jbuilder +++ b/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 diff --git a/app/views/api/jurisprudences/show.json.jbuilder b/app/views/api/jurisprudences/show.json.jbuilder index d272685..12bc032 100644 --- a/app/views/api/jurisprudences/show.json.jbuilder +++ b/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])