Browse Source

Merge pull request #110 from lexintegritastech/improve-main-ui

Enhance UI for `jurisprudence`, `doctrine`, and `annotation`
pull/111/head
Alexander D. Bondoc 4 years ago committed by GitHub
parent
commit
1fc6ec5694
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      app/components/doctrine_index_component/doctrine_index_component.html.erb
  2. 4
      app/components/document_doctrine_index_component/document_doctrine_index_component.html.erb
  3. 6
      app/components/document_doctrine_show_component/document_doctrine_show_component.html.erb
  4. 2
      app/controllers/api/doctrine/annotations_controller.rb
  5. 4
      app/controllers/concerns/annotation_search.rb
  6. 6
      app/controllers/concerns/doctrine_search.rb
  7. 3
      app/javascript/controllers/annotations_controller.js
  8. 6
      app/models/annotation.rb
  9. 7
      app/models/cdao/document.rb
  10. 2
      app/models/cdao/jurisprudence.rb
  11. 4
      app/models/doctrine.rb
  12. 10
      app/models/doctrine_jurisprudence.rb
  13. 5
      db/migrate/20220307043427_add_content_in_annotation.rb

4
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 %>
<h5 class="clickable-link" style="color: darkred;" href="<%= document_path(jurisprudence, is_index_table: false, subject_ids: params[:subject_ids]) %>"> <%= [document_title, jurisprudence.reference_number, date_or_year].join(", ") %> </h5>
<% 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| %>
<p class="mb-2 ms-3 clickable-link" href="<%= show_url %>">
<% annotated_documents_title = [] %>
<% annotation.documents.each do |annotated_document| %>
@ -18,7 +18,7 @@
<% end %>
<strong> <%= "#{annotation.annomarks.map { |annomark| "(#{annomark.code})" }.join(" ")}" %> </strong>
<%= 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(', ') %>
</p>
<% if annotation.editor_notes.present? %>

4
app/components/document_doctrine_index_component/document_doctrine_index_component.html.erb

@ -25,7 +25,7 @@
<h5 style="color: darkred;"> <%= [document_title, jurisprudence.reference_number, date_or_year].join(", ") %> </h5>
<% 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| %>
<p class="mb-2 ms-3">
<% annotated_documents_title = [] %>
<% annotation.documents.each do |annotated_document| %>
@ -35,7 +35,7 @@
<% end %>
<strong> <%= "#{annotation.annomarks.map { |annomark| "(#{annomark.code})" }.join(" ")}" %> </strong>
<%= 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(', ') %>
</p>
<% if annotation.editor_notes.present? %>

6
app/components/document_doctrine_show_component/document_doctrine_show_component.html.erb

@ -85,7 +85,7 @@
<div class="row-flex">
<div class="annot-header"> <h5> Annotations </h5> </div>
<div class="" id="annotationsIndexView">
<% 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 @@
<div class="col-sm-10">
<p class="pb-0 ms-3">
<strong> <%= "#{annotation.annomarks.map { |annomark| "(#{annomark.code})" }.join(" ")}" %> </strong>
<%= raw citing_document_title %>
<%= raw annotation.content.present? ? annotation.content : citing_document_title %>
</p>
</div>
<div class="col-sm-2 d-flex justify-content-end align-items-baseline">
<a class="btn btn-secondary me-3" data-bs-toggle="modal" data-bs-target="#annotationModal"
data-controller="annotations" data-doctrine-id="<%= id %>" data-annotation-id="<%= annotation.id %>"
data-current-document-id="<%= document_id %>" data-document-title="<%= citing_document_title %>"
data-current-document-id="<%= document_id %>" data-document-title="<%= annotation.content.present? ? annotation.content : citing_document_title %>"
data-action="click->annotations#renderForm"> Edit </a>
<a class="btn btn-danger" data-controller="annotations" data-current-document-id="<%= document_id %>" data-doctrine-id="<%= id %>" data-annotation-id="<%= annotation.id %>" data-action="click->annotations#delete" > Delete </a>
</div>

2
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

4
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

6
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

3
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({

6
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

7
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

2
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

4
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

10
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

5
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
Loading…
Cancel
Save