From f14998b01c8a94554439694adc7bb1b1010ea80d Mon Sep 17 00:00:00 2001 From: alexdbondoc17 Date: Mon, 7 Mar 2022 06:20:08 +0000 Subject: [PATCH 1/3] Enhance `searchable` for `jurisprudence`, `doctrine`, and `annotation` --- app/controllers/concerns/annotation_search.rb | 4 +++- app/controllers/concerns/doctrine_search.rb | 6 ++++++ app/models/annotation.rb | 6 ++++++ app/models/cdao/document.rb | 7 +++++++ app/models/cdao/jurisprudence.rb | 2 -- app/models/doctrine.rb | 4 +++- app/models/doctrine_jurisprudence.rb | 10 ++++++++++ 7 files changed, 35 insertions(+), 4 deletions(-) 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/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 From 099854f3adbcaef40ce52885ea6f1d64f07a7af7 Mon Sep 17 00:00:00 2001 From: alexdbondoc17 Date: Mon, 7 Mar 2022 06:20:58 +0000 Subject: [PATCH 2/3] Add `content` in `annotation` --- app/controllers/api/doctrine/annotations_controller.rb | 2 +- app/javascript/controllers/annotations_controller.js | 3 +-- db/migrate/20220307043427_add_content_in_annotation.rb | 5 +++++ 3 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20220307043427_add_content_in_annotation.rb 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/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/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 From 7b4d5481aeb1f665e693bd511372d8fdf92f4798 Mon Sep 17 00:00:00 2001 From: alexdbondoc17 Date: Mon, 7 Mar 2022 06:22:25 +0000 Subject: [PATCH 3/3] Enhance UI for `doctrines` and `annotations` --- .../doctrine_index_component.html.erb | 4 ++-- .../document_doctrine_index_component.html.erb | 4 ++-- .../document_doctrine_show_component.html.erb | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) 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 0c6d2a4..a6a0794 100644 --- a/app/components/doctrine_index_component/doctrine_index_component.html.erb +++ b/app/components/doctrine_index_component/doctrine_index_component.html.erb @@ -8,7 +8,7 @@ <% date_or_year = jurisprudence.docdate.present? ? jurisprudence.docdate.to_date.strftime("%B %d, %Y") : jurisprudence.year %> - <% 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| %> <% if annotation.editor_notes.present? %> diff --git a/app/components/document_doctrine_index_component/document_doctrine_index_component.html.erb b/app/components/document_doctrine_index_component/document_doctrine_index_component.html.erb index 0d559d0..ba7e5a7 100644 --- a/app/components/document_doctrine_index_component/document_doctrine_index_component.html.erb +++ b/app/components/document_doctrine_index_component/document_doctrine_index_component.html.erb @@ -25,7 +25,7 @@
<%= [document_title, jurisprudence.reference_number, date_or_year].join(", ") %>
<% end %> - <% 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| %>

<% annotated_documents_title = [] %> <% annotation.documents.each do |annotated_document| %> @@ -35,7 +35,7 @@ <% end %> <%= "#{annotation.annomarks.map { |annomark| "(#{annomark.code})" }.join(" ")}" %> - <%= raw [document_title(annotation), annotation.document.reference_number, date_or_year(annotation), annotation.phil_rep, annotated_documents_title].reject(&:blank?).join(', ') %> + <%= raw annotation.content.present? ? annotation.content : [document_title(annotation), annotation.document.reference_number, date_or_year(annotation), annotation.phil_rep, annotated_documents_title].reject(&:blank?).join(', ') %>

<% if annotation.editor_notes.present? %> 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 e87bacc..0a8c293 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 @@ -85,7 +85,7 @@
Annotations
- <% 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 %>