diff --git a/app/components/annotation_form_component.rb b/app/components/annotation_form_component.rb
index 390a211..a1ef260 100644
--- a/app/components/annotation_form_component.rb
+++ b/app/components/annotation_form_component.rb
@@ -12,13 +12,34 @@ class AnnotationFormComponent < BaseComponent
Cdao::Document.find(opts[:document_id].to_i)
end
+ def clean_phil_rep(annotation)
+ return if annotation.phil_rep.blank?
+
+ annotation.phil_rep.gsub(/(PhilRep|Phil)\.?,?/i, "Phil")
+ end
+
def display_text
- return annotation.content if annotation.persisted?
+ return annotation.content if annotation.persisted? && annotation.content.present? && annotation.content.include?("Phil")
+ display_text = nil
title = document.short_title || document.title
year_or_date = document.doc_date.present? ? document.doc_date.strftime("%B %d, %Y") : document.year
- [title, document.clean_reference_number, year_or_date].join(", ")
+ if annotation.new_record?
+ display_text = [title, document.clean_reference_number, year_or_date].join(", ")
+ else
+ contents = [[title, document.clean_reference_number, year_or_date].reject(&:blank?).join(", ")]
+
+ annotation.documents.each do |citing_doc|
+ citing_doc_title = citing_doc.short_title || citing_doc.title
+ citing_doc_year_or_date = citing_doc.doc_date.present? ? citing_doc.doc_date.strftime("%B %d, %Y") : citing_doc.year
+ contents << [citing_doc_title, citing_doc.clean_reference_number, citing_doc_year_or_date].join(", ")
+ end
+
+ display_text = contents.reject(&:blank?).join(" citing ")
+ end
+
+ display_text
end
def phil_rep
diff --git a/app/components/doctrine_index_component.rb b/app/components/doctrine_index_component.rb
index 5f08712..2da5b0f 100644
--- a/app/components/doctrine_index_component.rb
+++ b/app/components/doctrine_index_component.rb
@@ -43,7 +43,7 @@ class DoctrineIndexComponent < BaseComponent
annotation.document.year
end
- def show_url
+ def doctrine_show_url
return document_doctrine_path(jurisprudence.id, id, is_index_table: false, subject_ids: opts[:subject_ids].reject(&:blank?)) if jurisprudence.present?
doctrine_path(id, is_index_table: false, subject_ids: opts[:subject_ids].reject(&:blank?))
diff --git a/app/components/doctrine_index_component/doctrine_index_component.html.erb b/app/components/doctrine_index_component/doctrine_index_component.html.erb
index 54c5054..8039be7 100644
--- a/app/components/doctrine_index_component/doctrine_index_component.html.erb
+++ b/app/components/doctrine_index_component/doctrine_index_component.html.erb
@@ -1,15 +1,13 @@
-
<%= raw content.html_safe %>
-
<% document_title = jurisprudence.short_title || jurisprudence.title %>
- <% date_or_year = jurisprudence.docdate.present? ? jurisprudence.docdate.to_date.strftime("%B %d, %Y") : jurisprudence.year %>
+ <% date_or_year = jurisprudence.doc_date.present? ? jurisprudence.doc_date.strftime("%B %d, %Y") : jurisprudence.year %>
-
<%= [document_title, jurisprudence.clean_reference_number, date_or_year].join(", ") %>
+ <%= [document_title, jurisprudence.clean_reference_number, date_or_year].join(", ") %>
<% annotations.each do |annotation| %>
<% annotated_documents_title = [] %>
<% annotation.documents.each do |annotated_document| %>
<% 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.doc_date.present? ? annotated_document.doc_date.strftime("%B %d, %Y") : annotated_document.year %>
<% annotated_documents_title << [" citing #{ad_title}", annotated_document.clean_reference_number, ad_date_or_year].join(", ") %>
<% end %>
<% citing_document_title = [document_title, annotation.document.clean_reference_number, date_or_year, clean_phil_rep(annotation), annotated_documents_title].reject(&:blank?).join(', ').html_safe %>
@@ -20,7 +18,7 @@
<% if annotation.editor_notes.present? %>
-
+
Editors Note:
diff --git a/app/components/document_doctrine_show_component.rb b/app/components/document_doctrine_show_component.rb
index 1404dce..6905ea7 100644
--- a/app/components/document_doctrine_show_component.rb
+++ b/app/components/document_doctrine_show_component.rb
@@ -1,12 +1,11 @@
class DocumentDoctrineShowComponent < BaseComponent
- attr_reader :current_user, :annotations, :jurisprudence_id, :doctrine, :subjects
+ attr_reader :current_user, :doctrine, :opts
- def initialize(current_user:, annotations:, doctrine:, jurisprudence_id:, subjects:, opts: {})
- @annotations = annotations
+ include AnnotationSearch
+
+ def initialize(current_user:, doctrine:, opts: {})
@doctrine = doctrine
- @jurisprudence_id = jurisprudence_id
@current_user = current_user
- @subjects = subjects
@opts = opts
end
@@ -49,4 +48,9 @@ class DocumentDoctrineShowComponent < BaseComponent
contents[0] = [contents[0], clean_phil_rep(annotation)].reject(&:blank?).join(", ")
contents.join(" citing ")
end
+
+ def annotations
+ search = annotation_search(doctrine_id: id)
+ search.results
+ end
end
\ No newline at end of file
diff --git a/app/components/document_doctrine_show_component/document_doctrine_show_component.html.erb b/app/components/document_doctrine_show_component/document_doctrine_show_component.html.erb
index 87c4674..00b58e7 100644
--- a/app/components/document_doctrine_show_component/document_doctrine_show_component.html.erb
+++ b/app/components/document_doctrine_show_component/document_doctrine_show_component.html.erb
@@ -5,8 +5,8 @@
Doctrine Details
-
@@ -56,7 +56,7 @@
-
+
<%= text_field_tag :q, nil, class: "form-control", placeholder: "Search GR Number, Title or Short Title", data: { target: "document.input" } %>
@@ -101,10 +101,10 @@
<%= raw annotation.content.present? ? content_diplay_text(annotation) : citing_document_title %>
diff --git a/app/components/document_index_table_component.rb b/app/components/document_index_table_component.rb
deleted file mode 100644
index fd379fd..0000000
--- a/app/components/document_index_table_component.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-class DocumentIndexTableComponent < BaseComponent
- with_collection_parameter :search_result
- attr_reader :search_result, :opts
-
- def initialize(search_result:, current_user:, opts: {})
- @search_result = search_result
- @opts = opts
- end
-
- delegate :id, to: :search_result
- delegate :clean_reference_number, to: :search_result
- delegate :title, to: :search_result
- delegate :short_title, to: :search_result
-
- def date_or_year
- return search_result.docdate.strftime("%m/%d/%Y") if search_result.docdate.present?
-
- search_result.year
- end
-
- def doctrine_annotations_path(doctrine_id)
- doctrine_annotations_path(doctrine_id: doctrine_id)
- end
-end
diff --git a/app/components/jurisprudences_index_table_component.rb b/app/components/jurisprudences_index_table_component.rb
new file mode 100644
index 0000000..92d2fda
--- /dev/null
+++ b/app/components/jurisprudences_index_table_component.rb
@@ -0,0 +1,25 @@
+class JurisprudencesIndexTableComponent < BaseComponent
+ with_collection_parameter :jurisprudence
+ attr_reader :jurisprudence, :opts
+
+ def initialize(jurisprudence:, current_user:, opts: {})
+ @jurisprudence = jurisprudence
+ @opts = opts
+ end
+
+ delegate :id, to: :jurisprudence
+ delegate :clean_reference_number, to: :jurisprudence
+ delegate :title, to: :jurisprudence
+ delegate :short_title, to: :jurisprudence
+ delegate :document, to: :jurisprudence
+
+ def date_or_year
+ return jurisprudence.docdate.strftime("%B %d, %Y") if jurisprudence.docdate.present?
+
+ jurisprudence.year
+ end
+
+ def doctrine_annotations_path(doctrine_id)
+ doctrine_annotations_path(doctrine_id: doctrine_id)
+ end
+end
diff --git a/app/components/document_index_table_component/document_index_table_component.html.erb b/app/components/jurisprudences_index_table_component/jurisprudences_index_table_component.html.erb
similarity index 59%
rename from app/components/document_index_table_component/document_index_table_component.html.erb
rename to app/components/jurisprudences_index_table_component/jurisprudences_index_table_component.html.erb
index 3a7b013..2e4db36 100644
--- a/app/components/document_index_table_component/document_index_table_component.html.erb
+++ b/app/components/jurisprudences_index_table_component/jurisprudences_index_table_component.html.erb
@@ -1,4 +1,4 @@
-
+
| <%= clean_reference_number %> |
<%= short_title || title %> |
<%= date_or_year %> |
diff --git a/app/controllers/doctrines_controller.rb b/app/controllers/doctrines_controller.rb
index ef6c4ef..d85366c 100644
--- a/app/controllers/doctrines_controller.rb
+++ b/app/controllers/doctrines_controller.rb
@@ -21,7 +21,7 @@ class DoctrinesController < ApplicationController
@search = doctrine_search(search_params)
@results = @search.results
- @uniq_doctrines = @results.uniq(&:headnote)
+ @uniq_by_headnotes = @results.uniq(&:headnote)
respond_to do |format|
format.html
diff --git a/app/controllers/documents_controller.rb b/app/controllers/documents_controller.rb
index 1083a9c..2f19794 100644
--- a/app/controllers/documents_controller.rb
+++ b/app/controllers/documents_controller.rb
@@ -2,7 +2,8 @@ class DocumentsController < ApplicationController
include JurisprudenceSearch
include DoctrineSearch
- load_and_authorize_resource :document, class: "Cdao::Jurisprudence"
+ load_and_authorize_resource :document, class: "Cdao::Jurisprudence", only: %i[index search]
+ load_and_authorize_resource :document, class: "Cdao::Document", only: %i[show]
def index
@search_params = search_params
@@ -16,11 +17,13 @@ class DocumentsController < ApplicationController
end
def show
- @doctrines = @document.doctrines.sort_by { |doctrine| [-doctrine.jurisprudences.first.year, -doctrine.jurisprudences.first.docdate.strftime("%Y-%m-%d")] }
+ if @document.library.document_type.eql?(Cdao::Library.first.document_type)
+ @jurisprudence = Cdao::Jurisprudence.find(@document.doc_id)
- where = { enabled: true, state: "published" }
- @cited_in_documents = @document.class.citing_docs_of(@document, where)
- @paginated_cited_in_documents = Kaminari.paginate_array(@cited_in_documents, total_count: @cited_in_documents.count).page(params[:page]).per(20)
+ where = { enabled: true, state: "published" }
+ @cited_in_documents = @jurisprudence.class.citing_docs_of(@jurisprudence, where)
+ @paginated_cited_in_documents = Kaminari.paginate_array(@cited_in_documents, total_count: @cited_in_documents.count).page(params[:page]).per(20)
+ end
# @cross_ref_documents = @document.class.cited_docs_of(document, where)
end
diff --git a/app/javascript/controllers/document_controller.js b/app/javascript/controllers/document_controller.js
index 7691ee0..90b60f0 100644
--- a/app/javascript/controllers/document_controller.js
+++ b/app/javascript/controllers/document_controller.js
@@ -7,7 +7,6 @@ export default class extends ApplicationController {
}
search () {
- console.log(this.element.dataset)
this.stimulate("DocumentReflex#render_case_lists_search_results",
{ q: this.inputTarget.value, citation_finder: this.citation_finderTarget.value, page: 1 },
this.element.dataset["doctrineId"], this.element.dataset["jurisprudenceId"])
diff --git a/app/jobs/parse_linkable_content_job.rb b/app/jobs/parse_linkable_content_job.rb
new file mode 100644
index 0000000..260fe57
--- /dev/null
+++ b/app/jobs/parse_linkable_content_job.rb
@@ -0,0 +1,66 @@
+class ParseLinkableContentJob < ActiveJob::Base
+ queue_as :default
+
+ def perform(annotation)
+ content = ""
+ document = annotation.document
+ citing_docs = annotation.documents
+
+ if annotation.content.present?
+ content = annotation.content.gsub("", "").gsub("
", "")
+
+ contents = content.split(" citing ")
+ contents.each_with_index do |content, i|
+ linkable_content = nil
+ if i.eql?(0)
+ linkable_content = add_linkable_content(document.id, [content[i], clean_phil_rep(annotation)].reject(&:blank?).join(", "))
+ else
+ citing_docs.each do |citing_doc|
+ old_content = contents[i]
+ next if !old_content.include?(citing_doc.clean_reference_number)
+
+ linkable_content = add_linkable_content(citing_doc.id, old_content)
+ end
+ end
+
+ contents[i] = linkable_content
+ end
+
+ content = contents.join(" citing ")
+ else
+ contents = []
+ doc_title = document.short_title || document.title
+ doc_date_or_year = document.doc_date.present? ? document.doc_date.strftime("%B %d, %Y") : document.year
+ doc_ref_num = document.clean_reference_number
+ contents << add_linkable_content(document.id, [doc_title, doc_ref_num, doc_date_or_year, clean_phil_rep(annotation)].reject(&:blank?).join(", "))
+
+ if citing_docs.present?
+ citing_docs.each do |citing_doc|
+ citing_doc_title = citing_doc.short_title || citing_doc.title
+ citing_doc_date_or_year = citing_doc.doc_date.present? ? citing_doc.doc_date.strftime("%B %d, %Y") : citing_doc.year
+ citing_doc_ref_num = citing_doc.clean_reference_number
+
+ citing_content = [citing_doc_title, citing_doc_date_or_year, citing_doc_ref_num].join(", ")
+ contents << ["citing", add_linkable_content(citing_doc, citing_content)].join(" ")
+ end
+ end
+ content = contents.join(", ")
+ end
+
+ annotation.update_column(:content, content) if content.present?
+ annotation.index!
+ end
+
+ private
+ def add_linkable_content(document_id, content)
+ document_route = Rails.application.routes.url_helpers.document_path(document_id)
+
+ " #{content} "
+ end
+
+ def clean_phil_rep(annotation)
+ return if annotation.phil_rep.blank?
+
+ annotation.phil_rep.gsub(/(PhilRep|Phil)\.?,?/i, "Phil")
+ end
+end
diff --git a/app/models/cdao/document.rb b/app/models/cdao/document.rb
index 893dd02..b5e859d 100644
--- a/app/models/cdao/document.rb
+++ b/app/models/cdao/document.rb
@@ -31,6 +31,13 @@ class Cdao::Document < Cdao::Base
libraries.all?(&:premium?)
end
+ def content
+ table_name = self.doc_type.tableize
+ sql = "select * from #{table_name} where id='#{self.doc_id}' LIMIT 1"
+ query = Cdao::Base.connection.execute(sql)
+ query.first.present? ? query.first["content"] : ""
+ end
+
def to_builder(ability = nil)
Jbuilder.new do |doc|
doc.(self, *%i[id title short_title])
diff --git a/app/models/cdao/jurisprudence.rb b/app/models/cdao/jurisprudence.rb
index 78c935d..f3e04e1 100644
--- a/app/models/cdao/jurisprudence.rb
+++ b/app/models/cdao/jurisprudence.rb
@@ -1,6 +1,7 @@
class Cdao::Jurisprudence < Cdao::Base
self.table_name = "jurisprudences"
+ has_one :document, as: :doc, class_name: "Jurisprudence", dependent: :destroy
has_many :annotations, as: :document, dependent: :restrict_with_error
has_many :doctrine_jurisprudences, dependent: :destroy
@@ -29,6 +30,10 @@ class Cdao::Jurisprudence < Cdao::Base
Cdao::Citation.where(cited_doc_id: self.id, cited_doc_type: self.class.name.gsub("Cdao::", ""))
end
+ def document
+ Cdao::Document.where(doc_id: self.id, doc_type: self.class.name.gsub("Cdao::", "")).first
+ end
+
def self.citing_docs_of(doc, where = {})
citing_docs = []
c_arel = Cdao::Citation.arel_table
diff --git a/app/views/doctrines/new.html.erb b/app/views/doctrines/new.html.erb
index 8017feb..597a381 100644
--- a/app/views/doctrines/new.html.erb
+++ b/app/views/doctrines/new.html.erb
@@ -13,7 +13,7 @@
-
+
<%= text_field_tag :q, nil, class: "form-control", placeholder: "Search GR Number, Title or Short Title", data: { target: "document.input" } %>
@@ -50,7 +50,7 @@
<% if params[:doctrine_id].present? %>
Back
<% else %>
-
Back
+
Back
<% end %>
@@ -59,6 +59,6 @@
<% if @doctrine.new_record? %>
- <%= render partial: "/shared/doctrine_form_annotation_modal_form", locals: { jurisprudence_id: params[:jurisprudence_id] } %>
+ <%= render partial: "/shared/doctrine_form_annotation_modal_form" %>
<% end %>
diff --git a/app/views/doctrines/search.html.erb b/app/views/doctrines/search.html.erb
index 1d93923..5e3c5da 100644
--- a/app/views/doctrines/search.html.erb
+++ b/app/views/doctrines/search.html.erb
@@ -1,14 +1,17 @@
<%= render PaginationComponent.new(data: @results, opts: { is_subject_breadcrums: true, subject_ids: params[:subject_ids], is_index_table: params[:is_index_table] }) %>
- <% @uniq_doctrines.each do |uniq_doctrine| %>
+ <% @uniq_by_headnotes.each do |uniq_by_headnote| %>
-
<%= uniq_doctrine.headnote %>
+
<%= uniq_by_headnote.headnote %>
-
- <% doctrines = @results.map { |doctrine| doctrine if doctrine.headnote.eql?(uniq_doctrine.headnote) } %>
- <%= render(DoctrineIndexComponent.with_collection(doctrines, current_user: current_user, opts: { is_index_table: false, subject_ids: params[:subject_ids].map(&:to_i) })) %>
+ <% 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| %>
+
<%= raw uniq_by_content.content.html_safe %>
+ <% 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 %>
diff --git a/app/views/doctrines/show.html.erb b/app/views/doctrines/show.html.erb
index 742d690..605afb1 100644
--- a/app/views/doctrines/show.html.erb
+++ b/app/views/doctrines/show.html.erb
@@ -20,7 +20,7 @@
- <%= render(DocumentDoctrineShowComponent.new(current_user: current_user, annotations: @annotations, doctrine: @doctrine, jurisprudence_id: @jurisprudence.present? ? @jurisprudence.id : @jurisprudence, subjects: @subjects)) %>
+ <%= render(DocumentDoctrineShowComponent.new(current_user: current_user, doctrine: @doctrine, jurisprudence_id: @jurisprudence.present? ? @jurisprudence.id : @jurisprudence)) %>
diff --git a/app/views/document/doctrines/show.html.erb b/app/views/document/doctrines/show.html.erb
index 87311dd..8e56d4e 100644
--- a/app/views/document/doctrines/show.html.erb
+++ b/app/views/document/doctrines/show.html.erb
@@ -8,7 +8,7 @@
<% if params[:is_index_table].present? %>
<% else %>
-
+
<% end %>
@@ -47,12 +47,12 @@
- <%= render(DocumentDoctrineShowComponent.new(current_user: current_user, annotations: @annotations, doctrine: @doctrine, jurisprudence_id: @document.id, subjects: @subjects)) %>
+ <%= render(DocumentDoctrineShowComponent.new(current_user: current_user, doctrine: @doctrine, opts: { jurisprudence_id: @document.id })) %>
diff --git a/app/views/documents/index.html.erb b/app/views/documents/index.html.erb
index bb031f2..79de665 100644
--- a/app/views/documents/index.html.erb
+++ b/app/views/documents/index.html.erb
@@ -20,7 +20,7 @@
- <%= render(DocumentIndexTableComponent.with_collection(@jurisprudences, current_user: current_user, opts: { search_params: @search_params.to_unsafe_h })) %>
+ <%= render(JurisprudencesIndexTableComponent.with_collection(@jurisprudences, current_user: current_user, opts: { search_params: @search_params.to_unsafe_h })) %>
diff --git a/app/views/documents/show.html.erb b/app/views/documents/show.html.erb
index 4c3ca3e..6cfd0be 100644
--- a/app/views/documents/show.html.erb
+++ b/app/views/documents/show.html.erb
@@ -50,75 +50,82 @@
+ <% if @jurisprudence.present? %>
+ -
+
+
+ <% end %>
+
-
-
-
- -
-
-
- -
-
+
+
+ <% if @jurisprudence.present? %>
+ -
+
+
+ <% end %>
-
-
-
-
- <%= render(DoctrineModalFormComponent.new(current_user: current_user)) %>
+ <% if @jurisprudence.present? %>
+
-
-
-
- <% @document.subjects.sort_by { |sub| sub.lineage_name }.each_with_index do |subject, i| %>
-
-
+ <% end %>
-
" id="documentTabContent" role="tabpanel">
+
<%= raw @document.content.html_safe%>
-
" id="citatonTabContent" role="tabpanel">
-
-
Cited In
-
<%= render PaginationComponent.new(data: @paginated_cited_in_documents, opts: { is_cited_in_doc: true}) %>
-
-
-
- | Reference No. |
- Title |
- Date |
-
+ <% if @jurisprudence.present? %>
+ " id="citatonTabContent" role="tabpanel">
+
+
Cited In
+
<%= render PaginationComponent.new(data: @paginated_cited_in_documents, opts: { is_cited_in_doc: true}) %>
+
+
+
+ | Reference No. |
+ Title |
+ Date |
+
-
- <%= render(CitationIndexTableComponent.with_collection(@cited_in_documents, current_user: current_user)) %>
-
-
-
+
+ <%= render(CitationIndexTableComponent.with_collection(@cited_in_documents, current_user: current_user)) %>
+
+
+
+ <% end %>