- <% doctrine.annotations.order(created_at: :desc).each do |annotation| %>
+ <% annotations.sort_by { |a| [a.document.library.rank, -a.document.year, -a.document.doc_date.strftime("%Y-%m-%d")] }.each do |annotation| %>
<% 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 %>
<% annotated_documents_title = [] %>
@@ -100,14 +100,14 @@
<%= "#{annotation.annomarks.map { |annomark| "(#{annomark.code})" }.join(" ")}" %>
- <%= raw citing_document_title %>
+ <%= raw annotation.content.present? ? annotation.content : citing_document_title %>
diff --git a/app/controllers/api/doctrine/annotations_controller.rb b/app/controllers/api/doctrine/annotations_controller.rb
index 654d3ab..a2aaaee 100644
--- a/app/controllers/api/doctrine/annotations_controller.rb
+++ b/app/controllers/api/doctrine/annotations_controller.rb
@@ -81,7 +81,7 @@ module Api
private
def resource_params
- params.permit(:document_id, :phil_rep, :editor_notes, :rank, annomark_ids: [])
+ params.permit(:document_id, :content, :phil_rep, :editor_notes, :rank, annomark_ids: [])
end
def search_params
diff --git a/app/controllers/concerns/annotation_search.rb b/app/controllers/concerns/annotation_search.rb
index 8545c9f..2aea88f 100644
--- a/app/controllers/concerns/annotation_search.rb
+++ b/app/controllers/concerns/annotation_search.rb
@@ -9,7 +9,9 @@ module AnnotationSearch
with field, search_params[field] if search_params[field].present?
end
- order_by :created_at, :desc
+ order_by :library_rank, :asc
+ order_by :search_year, :desc
+ order_by :search_doc_date, :desc
paginate page: search_params[:page] || 1, per_page: search_params[:per_page] || 20
end
diff --git a/app/controllers/concerns/doctrine_search.rb b/app/controllers/concerns/doctrine_search.rb
index efa4e22..8205d54 100644
--- a/app/controllers/concerns/doctrine_search.rb
+++ b/app/controllers/concerns/doctrine_search.rb
@@ -23,6 +23,12 @@ module DoctrineSearch
without(:id).any_of(search_params[:exclude_ids]) if search_params[:exclude_ids].present?
+ if search_params[:sort_by].blank?
+ order_by :search_year, :desc
+ order_by :search_doc_date, :desc
+ order_by :reference_number, :desc
+ end
+
paginate page: search_params[:page] || 1, per_page: search_params[:per_page] || 20
end
diff --git a/app/javascript/controllers/annotations_controller.js b/app/javascript/controllers/annotations_controller.js
index 67f1156..7129d6f 100644
--- a/app/javascript/controllers/annotations_controller.js
+++ b/app/javascript/controllers/annotations_controller.js
@@ -19,7 +19,6 @@ export default class extends ApplicationController {
var $this = this, annotation_id = $this.element.dataset["annotationId"], doctrine_id = $this.element.dataset["doctrineId"],
document_title = "", document_ref_no = "", document_date_or_year = "", $modal = $("#annotationModal")
- console.log($this.element.dataset["currentDocumentId"])
$modal.find("#current_document_id").val($this.element.dataset["currentDocumentId"])
if(annotation_id !== null && annotation_id !== undefined && annotation_id !== "") {
$modal.find(".modal-title").text("Edit Annotation")
@@ -74,7 +73,7 @@ export default class extends ApplicationController {
current_document_id = $this.current_document_idTarget.value, doctrine_id = $this.doctrine_idTarget.value
const params = { annomark_ids: $modal.find("select[name='annomark_ids[]']").val(), document_id: $this.document_idTarget.value,
document_ids: $this.document_idsTarget.value || "", phil_rep: $this.phil_repTarget.value || "",
- editor_notes: $this.editor_notesTarget.value || "" }
+ editor_notes: $this.editor_notesTarget.value || "", content: $modal.find("#document_title").val() }
if (annotation_id !== null && annotation_id !== undefined && annotation_id !== "") {
$.ajax({
diff --git a/app/models/annotation.rb b/app/models/annotation.rb
index c8071e8..1f64a95 100644
--- a/app/models/annotation.rb
+++ b/app/models/annotation.rb
@@ -11,6 +11,8 @@ class Annotation < ApplicationRecord
has_many :annotation_annomarks, dependent: :destroy
has_many :annomarks, through: :annotation_annomarks
+ validates :content, presence: true
+
def documents
annotation_documents.collect(&:document)
end
@@ -33,6 +35,10 @@ class Annotation < ApplicationRecord
integer :document_id
integer :doctrine_id
+ join(:library_rank, target: Cdao::Document, type: :integer, join: { from: :id, to: :document_id })
+ join(:search_year, target: Cdao::Document, type: :integer, join: { from: :id, to: :document_id })
+ join(:search_doc_date, target: Cdao::Document, type: :date, join: { from: :id, to: :document_id })
+
date :created_at
date :updated_at
diff --git a/app/models/cdao/document.rb b/app/models/cdao/document.rb
index 3d9deb6..29bcd6c 100644
--- a/app/models/cdao/document.rb
+++ b/app/models/cdao/document.rb
@@ -1,6 +1,8 @@
class Cdao::Document < Cdao::Base
self.table_name = "documents"
+ belongs_to :library, class_name: "Cdao::Library", optional: false
+
alias_attribute :docdate, :doc_date
alias_attribute :short_title, :title
@@ -69,6 +71,11 @@ class Cdao::Document < Cdao::Base
integer :id
integer :year
+
+ integer :library_rank do
+ library.rank
+ end
+
integer :search_year do
year.present? && year > 0 ? year : (doc_date.try :year)
end
diff --git a/app/models/cdao/jurisprudence.rb b/app/models/cdao/jurisprudence.rb
index 1ebaa2f..78c935d 100644
--- a/app/models/cdao/jurisprudence.rb
+++ b/app/models/cdao/jurisprudence.rb
@@ -163,7 +163,5 @@ class Cdao::Jurisprudence < Cdao::Base
boolean :is_only_in_premium_libraries do
is_only_in_premium_libraries?
end
-
- join(:phil_rep, :target => Annotation, :type => :string, :join => { :from => :document_id, :to => :id })
end
end
diff --git a/app/models/doctrine.rb b/app/models/doctrine.rb
index d5505aa..d3baf04 100644
--- a/app/models/doctrine.rb
+++ b/app/models/doctrine.rb
@@ -179,7 +179,9 @@ class Doctrine < ApplicationRecord
paper_trail.originator.to_i
end
- join(:phil_rep, :target => Annotation, :type => :string, :join => { :from => :annotation_doctrine_id, :to => :id })
+ 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
end
diff --git a/app/models/doctrine_jurisprudence.rb b/app/models/doctrine_jurisprudence.rb
index d2749b6..cbc9d73 100644
--- a/app/models/doctrine_jurisprudence.rb
+++ b/app/models/doctrine_jurisprudence.rb
@@ -3,4 +3,14 @@ class DoctrineJurisprudence < ApplicationRecord
belongs_to :doctrine, 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
diff --git a/db/migrate/20220307043427_add_content_in_annotation.rb b/db/migrate/20220307043427_add_content_in_annotation.rb
new file mode 100644
index 0000000..ac45a3e
--- /dev/null
+++ b/db/migrate/20220307043427_add_content_in_annotation.rb
@@ -0,0 +1,5 @@
+class AddContentInAnnotation < ActiveRecord::Migration[6.1]
+ def change
+ add_column :annotations, :content, :text, default: "", null: false
+ end
+end