diff --git a/app/components/annotation_marks_modal_form_component/annotation_marks_modal_form_component.html.erb b/app/components/annotation_marks_modal_form_component/annotation_marks_modal_form_component.html.erb index 604eff7..a08efc7 100644 --- a/app/components/annotation_marks_modal_form_component/annotation_marks_modal_form_component.html.erb +++ b/app/components/annotation_marks_modal_form_component/annotation_marks_modal_form_component.html.erb @@ -27,26 +27,26 @@ -
-
- <%= text_field_tag :q, nil, class: "form-control", placeholder: "Search GR Number", data: { target: "annotations.q" } %> -
-
- +
+
+
+ <%= text_field_tag :q, nil, class: "form-control", placeholder: "Search GR Number", data: { target: "annotations.q" } %> +
+
+ +
-
-
- - - - - - - - - -
Reference No. Title Date
+
+ + + + + + + +
Reference No. Title Date
+
diff --git a/app/components/document_doctrine_show_component.rb b/app/components/document_doctrine_show_component.rb index 6576047..9808d52 100644 --- a/app/components/document_doctrine_show_component.rb +++ b/app/components/document_doctrine_show_component.rb @@ -1,7 +1,8 @@ class DocumentDoctrineShowComponent < BaseComponent - attr_reader :current_user, :document_id, :doctrine, :subjects + attr_reader :current_user, :annotations, :document_id, :doctrine, :subjects - def initialize(current_user:, doctrine:, document_id:, subjects:, opts: {}) + def initialize(current_user:, annotations:, doctrine:, document_id:, subjects:, opts: {}) + @annotations = annotations @doctrine = doctrine @document_id = document_id @current_user = current_user @@ -13,7 +14,6 @@ class DocumentDoctrineShowComponent < BaseComponent delegate :headnote, to: :doctrine delegate :subject_ids, to: :doctrine delegate :content, to: :doctrine - delegate :annotations, to: :doctrine delegate :subjects, to: :doctrine def annotation_form_url 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 1ea7ef0..6bbf831 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 @@ -74,8 +74,6 @@ Date - -
@@ -83,8 +81,9 @@
Annotations
-
- <% doctrine.annotations.order(rank: :asc).each do |annotation| %> +
+ <%= render(partial: "/shared/annotations_pagination", locals: { annotations: annotations, opts: { current_page: 1 } }) %> + <% annotations.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 = [] %> @@ -108,7 +107,7 @@ data-controller="annotations" data-doctrine-id="<%= id %>" data-annotation-id="<%= annotation.id %>" data-document-title="<%= citing_document_title %>" data-action="click->annotations#renderForm"> Edit - Delete + Delete
diff --git a/app/controllers/api/doctrine/annotations_controller.rb b/app/controllers/api/doctrine/annotations_controller.rb index 7718622..7a542d6 100644 --- a/app/controllers/api/doctrine/annotations_controller.rb +++ b/app/controllers/api/doctrine/annotations_controller.rb @@ -1,10 +1,22 @@ module Api module Doctrine class AnnotationsController < ::Api::BaseController + include AnnotationSearch + load_and_authorize_resource :doctrine, class: "Doctrine" load_and_authorize_resource :annotation, class: "Annotation", through: :doctrine def index + search = annotation_search(search_params) + @annotations = search.results + + respond_with @annotations + end + + def search + search = annotation_search(search_params) + @annotations = search.results + respond_with @annotations end @@ -14,12 +26,21 @@ module Api def create attrs = resource_params.to_unsafe_h.deep_symbolize_keys - subject_ids = attrs.delete(:subject_ids) - + document_id = attrs.delete(:document_id) + document_ids = params[:document_ids].split(",") + @annotation = @doctrine.annotations.new(attrs) + + if document_id.present? + @annotation.document = Cdao::Document.find(document_id) + end + + if document_ids.present? + @documents = Cdao::Document.where(id: document_ids) + end if @annotation.save - @annotation.subject_ids = subject_ids if subject_ids.present? + @documents.each { |document| @annotation.add_document(document) } if @documents.present? respond_with @annotation else @@ -29,10 +50,21 @@ module Api def update attrs = resource_params.to_unsafe_h.deep_symbolize_keys - subject_ids = attrs.delete(:subject_ids) + document_id = attrs.delete(:document_id) + document_ids = params[:document_ids].split(",") + + if document_ids.present? + @documents = Cdao::Jurisprudence.where(id: document_ids) + end + + attrs[:document] = Cdao::Jurisprudence.find(document_id) if document_id.present? if @annotation.update(attrs) - @annotation.subject_ids = subject_ids if subject_ids.present? + @annotation.annotation_documents.each do |annotation_document| + @annotation.remove_document(annotation_document.document) + end + + @documents.each { |document| @annotation.add_document(document) } if @documents.present? respond_with @annotation else @@ -49,7 +81,11 @@ module Api private def resource_params - params.permit(:content, subject_ids: []) + params.permit(:document_id, :phil_rep, :editor_notes, :rank, annomark_ids: []) + end + + def search_params + params.permit(:doctrine_id, :document_id, :phil_rep, :q, :page, :per_page) end end end diff --git a/app/controllers/api/doctrines_controller.rb b/app/controllers/api/doctrines_controller.rb index 7979c65..0e86a8d 100644 --- a/app/controllers/api/doctrines_controller.rb +++ b/app/controllers/api/doctrines_controller.rb @@ -20,12 +20,17 @@ module Api def create attrs = resource_params.to_unsafe_h.deep_symbolize_keys subject_ids = attrs.delete(:subject_ids) + jurisprudence_ids = attrs.delete(:jurisprudence_ids) @doctrine = ::Doctrine.new(attrs) if @doctrine.save @doctrine.subject_ids = subject_ids if subject_ids.present? + jurisprudence_ids.each do |jurisprudence_id| + @doctrine.doctrine_jurisprudences.create(jurisprudence_id: jurisprudence_id) + end + respond_with @doctrine else render errors: @doctrine.errors, status: 422 diff --git a/app/controllers/concerns/annotation_search.rb b/app/controllers/concerns/annotation_search.rb new file mode 100644 index 0000000..5f77f6e --- /dev/null +++ b/app/controllers/concerns/annotation_search.rb @@ -0,0 +1,17 @@ +module AnnotationSearch + def annotation_search(search_params) + fulltext_fields = %i[phil_rep].freeze + + search = ::Annotation.search do + fulltext search_params[:q], fields: fulltext_fields if search_params[:q].present? + + %i[doctrine_id document_id].each do |field| + with field, search_params[field] if search_params[field].present? + end + + paginate page: search_params[:page] || 1, per_page: search_params[:per_page] || 20 + end + + search + end +end diff --git a/app/controllers/doctrines_controller.rb b/app/controllers/doctrines_controller.rb index 91ef2d3..5d8a2fa 100644 --- a/app/controllers/doctrines_controller.rb +++ b/app/controllers/doctrines_controller.rb @@ -1,5 +1,6 @@ class DoctrinesController < ApplicationController include DoctrineSearch + include AnnotationSearch load_and_authorize_resource :doctrine, class: "Doctrine" @@ -23,6 +24,9 @@ class DoctrinesController < ApplicationController def show @jurisprudence = @doctrine.doctrine_jurisprudences.present? ? @doctrine.doctrine_jurisprudences.first.jurisprudence : nil + + search = annotation_search(params.permit(:page, :per_page)) + @annotations = search.results end def create diff --git a/app/controllers/document/doctrines_controller.rb b/app/controllers/document/doctrines_controller.rb index e6df65f..14f4349 100644 --- a/app/controllers/document/doctrines_controller.rb +++ b/app/controllers/document/doctrines_controller.rb @@ -1,7 +1,12 @@ class Document::DoctrinesController < ApplicationController + include AnnotationSearch + load_and_authorize_resource :document, class: "Cdao::Jurisprudence" load_and_authorize_resource :doctrine, class: "Doctrine", through: :document - def show; end + def show + search = annotation_search(params.permit(:page, :per_page)) + @annotations = search.results + end end diff --git a/app/javascript/controllers/annotations_controller.js b/app/javascript/controllers/annotations_controller.js index 825023d..7663531 100644 --- a/app/javascript/controllers/annotations_controller.js +++ b/app/javascript/controllers/annotations_controller.js @@ -7,8 +7,12 @@ export default class extends ApplicationController { super.connect() } - searchDocument () { - this.stimulate("AnnotationReflex#render_document_search_results", { q: this.qTarget.value }) + searchDocuments () { + this.stimulate("AnnotationReflex#render_document_search_results", { q: this.qTarget.value, page: 1 }) + } + + paginateDocuments () { + this.stimulate("AnnotationReflex#render_document_search_results", { q: this.element.dataset["q"], page: this.element.dataset["page"] }) } renderForm () { @@ -40,7 +44,7 @@ export default class extends ApplicationController { } } - addCitingDocument () { + addAnnotatedDocument () { var document_id = "", document_ref_no = "", document_date = "", document_title = "", $modal = $("#annotationModal"), $doc_title = $modal.find("#document_title"), $citing_document_ids = $modal.find("#document_ids") @@ -71,12 +75,41 @@ export default class extends ApplicationController { if (annotation_id !== null && annotation_id !== undefined && annotation_id !== "") { $.ajax({ - url: "/doctrines/" + doctrine_id + "/annotations/" + annotation_id, + url: "/api/doctrines/" + doctrine_id + "/annotations/" + annotation_id, type: 'PUT', - data: params + data: params, + success: function() { + $(".btn-close-x").trigger("click") + $this.stimulate("AnnotationReflex#render_annotations_views", { page: 1 }) + } }) } else { - $.post("/doctrines/" + doctrine_id + "/annotations", params) + $.post("/api/doctrines/" + doctrine_id + "/annotations", params, function(result, status) { + if(status === "success") { + $(".btn-close-x").trigger("click") + $this.stimulate("AnnotationReflex#render_annotations_views", { page: 1 }) + } + }) } } + + delete(ev) { + var $this = this, doctrine_id = $this.element.dataset["doctrineId"], annotation_id = this.element.dataset["annotationId"] + + ev.preventDefault(); + const contrim_alert = confirm("Are you sure to delete this record?") + if (contrim_alert) { + $.ajax({ + url: "/api/doctrines/" + doctrine_id + "/annotations/" + annotation_id, + type: 'DELETE', + success: function() { + $this.stimulate("AnnotationReflex#render_annotations_views", { page: 1 }) + } + }) + } + } + + paginate () { + this.stimulate("AnnotationReflex#render_annotations_views", { page: this.element.dataset["page"] }) + } } diff --git a/app/javascript/controllers/document_controller.js b/app/javascript/controllers/document_controller.js index 1b35a96..5432551 100644 --- a/app/javascript/controllers/document_controller.js +++ b/app/javascript/controllers/document_controller.js @@ -7,10 +7,15 @@ export default class extends ApplicationController { } search () { - this.stimulate("DocumentReflex#render_index_table", - { q: this.inputTarget.value }, - this.element.dataset["documentId"], - this.element.dataset["doctrineId"]) + this.stimulate("DocumentReflex#render_case_lists_search_results", + { q: this.inputTarget.value, page: 1 }, + this.element.dataset["doctrineId"]) + } + + paginate () { + this.stimulate("DocumentReflex#render_case_lists_search_results", + { q: this.element.dataset["q"], page: this.element.dataset["page"] }, + this.element.dataset["doctrineId"]) } loadYears () { diff --git a/app/javascript/src/application.scss b/app/javascript/src/application.scss index da0d9bc..ec15119 100644 --- a/app/javascript/src/application.scss +++ b/app/javascript/src/application.scss @@ -26,7 +26,7 @@ left: 0; } -.clickable-link, .clickable-tr, .accordion-button { +.clickable-link, .clickable-tr, .accordion-button, .page-item, .page-link { cursor: pointer; } diff --git a/app/reflexes/annotation_reflex.rb b/app/reflexes/annotation_reflex.rb index 21ace61..88b5386 100644 --- a/app/reflexes/annotation_reflex.rb +++ b/app/reflexes/annotation_reflex.rb @@ -2,11 +2,18 @@ class AnnotationReflex < ApplicationReflex include DocumentSearch + include AnnotationSearch def render_document_search_results(search_params) search = document_search(search_params) @documents = search.results - opts = { is_citing_document: true } - morph "tbody#documentSearchResultTable", render(partial: "document_search_results_table", locals: { search_results: @documents, opts: opts }) + opts = { current_page: search_params[:page], q: search_params[:q] } + morph "#annotatedDocumentsSearchResults", render(partial: "/shared/annotated_documents_search_results", locals: { documents: @documents, opts: opts }) + end + + def render_annotations_views(search_params) + search = annotation_search(search_params) + @annotations = search.results + morph "#annotationsIndexView", render(partial: "/shared/annotations_index_view", locals: { annotations: @annotations, opts: { current_page: search_params[:page] } }) end end diff --git a/app/reflexes/document_reflex.rb b/app/reflexes/document_reflex.rb index 3d26a11..6d1c624 100644 --- a/app/reflexes/document_reflex.rb +++ b/app/reflexes/document_reflex.rb @@ -3,11 +3,11 @@ class DocumentReflex < ApplicationReflex include DocumentSearch - def render_index_table(search_params, document_id, doctrine_id) + def render_case_lists_search_results(search_params, doctrine_id) search = document_search(search_params) @documents = search.results - opts = { is_case_lists: true, doctrine_id: doctrine_id } - morph "tbody#documentIndexTable", render(partial: "document_search_results_table", locals: { search_results: @documents, opts: opts }) + opts = { doctrine_id: doctrine_id, current_page: search_params[:page], q: search_params[:q] } + morph "#caseListsCollapse", render(partial: "/shared/case_lists_search_results", locals: { documents: @documents, opts: opts }) end def render_years(results) diff --git a/app/views/api/doctrine/annotations/create.json.jbuilder b/app/views/api/doctrine/annotations/create.json.jbuilder new file mode 100644 index 0000000..7c978c7 --- /dev/null +++ b/app/views/api/doctrine/annotations/create.json.jbuilder @@ -0,0 +1,2 @@ +json.(@annotation, *%i[id doctrine_id document_id phil_rep editor_notes annomark_ids citing_document_ids]) +json.doctrine_jurisprudence @annotation.doctrine.doctrine_jurisprudences.first.jurisprudence diff --git a/app/views/api/doctrine/annotations/destroy.json.jbuilder b/app/views/api/doctrine/annotations/destroy.json.jbuilder new file mode 100644 index 0000000..7c978c7 --- /dev/null +++ b/app/views/api/doctrine/annotations/destroy.json.jbuilder @@ -0,0 +1,2 @@ +json.(@annotation, *%i[id doctrine_id document_id phil_rep editor_notes annomark_ids citing_document_ids]) +json.doctrine_jurisprudence @annotation.doctrine.doctrine_jurisprudences.first.jurisprudence diff --git a/app/views/api/doctrine/annotations/edit.json.jbuilder b/app/views/api/doctrine/annotations/edit.json.jbuilder new file mode 100644 index 0000000..7c978c7 --- /dev/null +++ b/app/views/api/doctrine/annotations/edit.json.jbuilder @@ -0,0 +1,2 @@ +json.(@annotation, *%i[id doctrine_id document_id phil_rep editor_notes annomark_ids citing_document_ids]) +json.doctrine_jurisprudence @annotation.doctrine.doctrine_jurisprudences.first.jurisprudence diff --git a/app/views/api/doctrine/annotations/index.json.jbuilder b/app/views/api/doctrine/annotations/index.json.jbuilder new file mode 100644 index 0000000..dce92a2 --- /dev/null +++ b/app/views/api/doctrine/annotations/index.json.jbuilder @@ -0,0 +1,3 @@ +json.array!(@annotations) do |annotation| + json.extract! annotation, *%i[id doctrine_id document_id phil_rep editor_notes annomark_ids created_at updated_at] +end diff --git a/app/views/api/doctrine/annotations/search.json.jbuilder b/app/views/api/doctrine/annotations/search.json.jbuilder new file mode 100644 index 0000000..dce92a2 --- /dev/null +++ b/app/views/api/doctrine/annotations/search.json.jbuilder @@ -0,0 +1,3 @@ +json.array!(@annotations) do |annotation| + json.extract! annotation, *%i[id doctrine_id document_id phil_rep editor_notes annomark_ids created_at updated_at] +end diff --git a/app/views/doctrines/show.html.erb b/app/views/doctrines/show.html.erb index ee350fd..9b04d3d 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, doctrine: @doctrine, document_id: @jurisprudence.present? ? @jurisprudence.id : @jurisprudence, subjects: @subjects)) %> + <%= render(DocumentDoctrineShowComponent.new(current_user: current_user, annotations: @annotations, doctrine: @doctrine, document_id: @jurisprudence.present? ? @jurisprudence.id : @jurisprudence, subjects: @subjects)) %>
diff --git a/app/views/document/doctrines/show.html.erb b/app/views/document/doctrines/show.html.erb index a9229ec..ab57f60 100644 --- a/app/views/document/doctrines/show.html.erb +++ b/app/views/document/doctrines/show.html.erb @@ -25,7 +25,7 @@
- <%= render(DocumentDoctrineShowComponent.new(current_user: current_user, doctrine: @doctrine, document_id: @document.id, subjects: @subjects)) %> + <%= render(DocumentDoctrineShowComponent.new(current_user: current_user, annotations: @annotations, doctrine: @doctrine, document_id: @document.id, subjects: @subjects)) %>
diff --git a/app/views/shared/_annotated_documents_search_results.html.erb b/app/views/shared/_annotated_documents_search_results.html.erb new file mode 100644 index 0000000..5a9b69c --- /dev/null +++ b/app/views/shared/_annotated_documents_search_results.html.erb @@ -0,0 +1,96 @@ +
+
+ <%= text_field_tag :q, opts[:q], class: "form-control", placeholder: "Search GR Number", data: { target: "annotations.input" } %> +
+
+ <%= button_tag "Search", class: "btn btn-success", data: { action: "click->annotations#searchDocuments" } %> +
+
+ +
+
+
"> +

Search Results

+ + <%= page_entries_info documents, entry_name: 'records' if documents.present? %> + +
+
"> + +
+
+
+ +
+ + + + + + + + + + <% documents.each do |document| %> + + + + + + + <% end %> + +
Reference No. Title Date
<%= document.clean_reference_number %> <%= document.short_title || document.title %> <%= document.doc_date.present? ? document.doc_date : document.year %> + + Add + +
+
diff --git a/app/views/shared/_annotations_index_view.html.erb b/app/views/shared/_annotations_index_view.html.erb new file mode 100644 index 0000000..914824d --- /dev/null +++ b/app/views/shared/_annotations_index_view.html.erb @@ -0,0 +1,42 @@ +<%= render(partial: "/shared/annotations_pagination", locals: { annotations: annotations, opts: opts }) %> +<% annotations.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 = [] %> + <% 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 %> + <% annotated_documents_title << [" citing #{ad_title}", annotated_document.reference_number, ad_date_or_year].join(", ") %> + <% end %> + <% citing_document_title = [document_title, annotation.document.reference_number, date_or_year, annotation.phil_rep, annotated_documents_title].reject(&:blank?).join(', ').html_safe %> + +
+
+

+ <%= "#{annotation.annomarks.map { |annomark| "(#{annomark.code})" }.join(" ")}" %> + <%= raw citing_document_title %> +

+
+ +
+ Edit + Delete +
+
+ + <% if annotation.editor_notes.present? %> +
+
+ Editors Note: +
+ +
+ <%= raw annotation.editor_notes %> +
+
+
+ <% end %> +<% end %> diff --git a/app/views/shared/_annotations_pagination.html.erb b/app/views/shared/_annotations_pagination.html.erb new file mode 100644 index 0000000..3697169 --- /dev/null +++ b/app/views/shared/_annotations_pagination.html.erb @@ -0,0 +1,58 @@ +
+
+
"> + + <%= page_entries_info annotations, entry_name: 'records' if annotations.present? %> + +
+
"> + +
+
+
diff --git a/app/views/shared/_case_lists_search_results.html.erb b/app/views/shared/_case_lists_search_results.html.erb new file mode 100644 index 0000000..837e301 --- /dev/null +++ b/app/views/shared/_case_lists_search_results.html.erb @@ -0,0 +1,104 @@ +
+
+ <%= text_field_tag :q, opts[:q], class: "form-control", placeholder: "Search GR Number", + data: { target: "document.input" } %> +
+
+ <%= button_tag "Search", class: "btn btn-success", data: { action: "click->document#search" } %> +
+
+ +
+
+
"> +

Search Results

+ + <%= page_entries_info documents, entry_name: 'records' if documents.present? %> + +
+
"> + +
+
+
+ +
+ + + + + + + + + + <% documents.each do |document| %> + + + + + + + <% end %> + +
Reference No. Title Date
<%= document.clean_reference_number %> <%= document.short_title || document.title %> <%= document.doc_date.present? ? document.doc_date : document.year %> + <% date_or_year = document.doc_date || document.year %> + <% title = document.short_title || document.title %> + + Add Annotations + +
+
diff --git a/config/routes.rb b/config/routes.rb index 729b481..f43fd07 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -30,7 +30,9 @@ Rails.application.routes.draw do namespace :api, defaults: { format: :json } do resources :doctrines do scope module: :doctrine do - resources :annotations + resources :annotations do + get :search, on: :collection + end end end