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 db593ad..76c737e 100644
--- a/app/components/doctrine_index_component/doctrine_index_component.html.erb
+++ b/app/components/doctrine_index_component/doctrine_index_component.html.erb
@@ -1,40 +1,33 @@
-
-
-
<%= headnote %>
-
<%= raw content.html_safe %>
+
<%= 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 %>
+
+ <% document_title = jurisprudence.short_title || jurisprudence.title %>
+ <% date_or_year = jurisprudence.docdate.present? ? jurisprudence.docdate.to_date.strftime("%B %d, %Y") : jurisprudence.year %>
-
<%= [document_title, jurisprudence.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 %>
- <% annotated_documents_title << [" citing #{ad_title}", annotated_document.clean_reference_number, ad_date_or_year].join(", ") %>
- <% end %>
-
- <%= "#{annotation.annomarks.map { |annomark| "(#{annomark.code})" }.join(" ")}" %>
- <%= raw annotation.content.present? ? annotation.content : [document_title(annotation), annotation.document.reference_number, date_or_year(annotation), clean_phil_rep(annotation), annotated_documents_title].reject(&:blank?).join(', ') %>
-
-
- <% if annotation.editor_notes.present? %>
-
-
- Editors Note:
-
-
-
- <%= raw annotation.editor_notes %>
-
-
- <% end %>
+
<%= [document_title, jurisprudence.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 %>
+ <% annotated_documents_title << [" citing #{ad_title}", annotated_document.clean_reference_number, ad_date_or_year].join(", ") %>
<% end %>
-
-
-
+
<%= "#{annotation.annomarks.map { |annomark| "(#{annomark.code})" }.join(" ")}" %>
+ <%= raw annotation.content.present? ? annotation.content : [document_title(annotation), annotation.document.reference_number, date_or_year(annotation), clean_phil_rep(annotation), annotated_documents_title].reject(&:blank?).join(', ') %>
+
+
+ <% if annotation.editor_notes.present? %>
+
+
+ Editors Note:
+
+
+
+ <%= raw annotation.editor_notes %>
+
+
+ <% end %>
+ <% end %>
diff --git a/app/controllers/api/doctrine/annotations_controller.rb b/app/controllers/api/doctrine/annotations_controller.rb
index a2aaaee..80bd7f3 100644
--- a/app/controllers/api/doctrine/annotations_controller.rb
+++ b/app/controllers/api/doctrine/annotations_controller.rb
@@ -42,6 +42,7 @@ module Api
if @annotation.save
@documents.each { |document| @annotation.add_document(document) } if @documents.present?
+ @annotation.index!
respond_with @annotation
else
render errors: @annotation.errors, status: 422
@@ -66,6 +67,7 @@ module Api
@documents.each { |document| @annotation.add_document(document) } if @documents.present?
+ @annotation.index!
respond_with @annotation
else
render errors: @annotation.errors, status: 422
diff --git a/app/javascript/controllers/doctrines_controller.js b/app/javascript/controllers/doctrines_controller.js
index 98ecbbf..205ecdb 100644
--- a/app/javascript/controllers/doctrines_controller.js
+++ b/app/javascript/controllers/doctrines_controller.js
@@ -1,6 +1,7 @@
import ApplicationController from './application_controller'
+var annotations_attributes = []
export default class extends ApplicationController {
- static targets = ["input", "document_id", "doctrine_id", "headnote", "content"]
+ static targets = ["input", "q", "document_id", "doctrine_id", "headnote", "content"]
connect () {
super.connect()
@@ -84,24 +85,31 @@ export default class extends ApplicationController {
}
})
} else {
- $.post("/api/doctrines", $.extend({ jurisprudence_ids: [document_id] }, params), function(data, status) {
+ $.post("/api/doctrines", $.extend({ jurisprudence_ids: [document_id] }, params), function(doctrine, status) {
if(status === 'success') {
$('.toast').addClass('bg-success').show();
- $( ".toast-body" ).html( "
Submitted Successfully " );
-
- const contrim_alert = confirm("Do you want to create an Annotation?")
-
- if (contrim_alert) {
- $this.stimulate("DoctrinesReflex#render_annotation_form", document_id, data.id)
- $('.toast').fadeOut(5000)
- } else {
- $(".btn-close-x").trigger("click")
- location.pathname = "/documents/" + document_id + "/doctrines/" + data.id
+ $( ".toast-body" ).html( "
Doctrine was successfully save " );
+ $('.toast').fadeOut(5000);
+
+ if (annotations_attributes.length > 0) {
+ $.each(annotations_attributes, function(index, annotation) {
+ $.post("/api/doctrines/" + doctrine.id + "/annotations", annotation, function(annotation, status) {
+ if(status === 'success') {
+ $('.toast').addClass('bg-success').show();
+ $( ".toast-body" ).html( "
Case Lists was successfully save " );
+ $('.toast').fadeOut(5000);
+
+ if ((index + 1) === annotations_attributes.length) {
+ location.pathname = "/documents/" + document_id + "/doctrines/" + doctrine.id
+ }
+ }
+ })
+ })
}
} else {
- $(".btn-close-x").trigger("click");
$('.toast').addClass('bg-danger').show();
$( ".toast-body" ).html( "
Unexpected Error Problem Occurred " );
+ $('.toast').fadeOut(5000);
}
})
}
@@ -120,41 +128,114 @@ export default class extends ApplicationController {
success: function() {
$('.toast').addClass('bg-danger').show();
$( ".toast-body" ).html( "
Deleted Successfully " );
+ $('.toast').fadeOut(5000);
location.pathname = "/documents/" + document_id
},
error: function () {
$('.toast').addClass('bg-danger').show();
$( ".toast-body" ).html( "
Unexpected Error Problem Occurred " );
+ $('.toast').fadeOut(5000);
}
})
}
}
+ searchCitingDocuments () {
+ this.stimulate("DoctrinesReflex#render_citing_documents_search_results", { q: this.qTarget.value, page: 1 })
+ }
+
+ paginateCitingDocuments () {
+ this.stimulate("AnnotationReflex#render_citing_documents_search_results", { q: this.element.dataset["q"], page: this.element.dataset["page"] })
+ }
+
+ addCitingDocument () {
+ var document_id = "", document_ref_no = "", document_date = "", document_title = "",
+ $modal = $("#annotationModal"), $doc_title = $modal.find("trix-editor[placeholder='Document Title']"),
+ $citing_document_ids = $modal.find("#document_ids")
+
+ document_id = this.element.dataset["documentId"]
+ document_ref_no = this.element.dataset["documentReferenceNumber"]
+ document_date = this.element.dataset["documentDate"]
+ document_title = this.element.dataset["documentTitle"]
+
+ var document_ids = []
+
+ if ($citing_document_ids.val() !== null && $citing_document_ids.val() !== undefined && $citing_document_ids.val() !== "") {
+ document_ids = $citing_document_ids.val().split(",")
+ }
+
+ document_ids.push(document_id)
+ $citing_document_ids.val(document_ids.join(","))
+
+ var doc_title = $doc_title.val()
+ $doc_title.val(doc_title + " citing " + [document_title, document_ref_no, document_date].join(", "))
+ }
+
+ removeAnnotation () {
+ var index = this.element.dataset["annotationsAttributesIndex"]
+ const contrim_alert = confirm("Are you sure that you want to remove this Case List?")
+
+ if (contrim_alert) {
+ annotations_attributes.splice(index, 1)
+ $('.toast').addClass('bg-success').show();
+ $( ".toast-body" ).html( "
Case List is successfully removed. " );
+ $('.toast').fadeOut(5000)
+ this.stimulate("DoctrinesReflex#render_doctrine_form_annotations_view", annotations_attributes)
+ }
+ }
+
saveAnnotation () {
- var $form = $("#doctrineForm")
- const params = { doctrine_id: $form.find("#doctrine_id").val(), document_id: $form.find("#document_id").val(),
- document_ids: $form.find("#document_ids").val().split(","), content: $form.find("#document_title").val(),
- phil_rep: $form.find("#phil_rep").val(), editor_notes: $form.find("#editor_notes").val(),
- annomark_ids: $form.find("select[name='annomark_ids[]']").val() }
+ var $modal = $("#annotationModal"), annotaitons_attributes_index = $modal.find("#annotaitons_attributes_index").val()
+ var params = { document_id: $modal.find("#document_id").val(), document_ids: $modal.find("#document_ids").val().split(","),
+ content: $modal.find("input[name='document_title']").val(), phil_rep: $modal.find("#phil_rep").val(),
+ editor_notes: $modal.find("input[name='editor_notes']").val(), annomark_ids: $modal.find("select[name='annomark_ids[]']").val() }
+
+ if (annotaitons_attributes_index.length) {
+ annotations_attributes.splice(annotaitons_attributes_index, 1, params)
+ $( ".toast-body" ).html( "
Case List is successfully updated. " );
+ } else {
+ annotations_attributes.push(params)
+ $( ".toast-body" ).html( "
Case List is successfully added. " );
+ }
- $.post("/api/doctrines/" + params.doctrine_id + "/annotations", params, function (result, status) {
- if(status === "success") {
- $(".btn-close-x").trigger("click");
- $('.toast').addClass('bg-success').show();
- $( ".toast-body" ).html( "
Submitted Successfully " );
- location.pathname = "/documents/" + $form.find("#current_document_id").val() + "/doctrines/" + params.doctrine_id
- } else {
- $(".btn-close-x").trigger("click")
- $('.toast').addClass('bg-danger').show()
- $( ".toast-body" ).html( "
Unexpected Error Problem Occurred " )
- }
- })
+ $(".btn-close-x").trigger("click");
+ $('.toast').addClass('bg-success').show();
+ $('.toast').fadeOut(5000);
+ this.stimulate("DoctrinesReflex#render_doctrine_form_annotations_view", annotations_attributes)
+ this.stimulate("DoctrinesReflex#render_default_citing_documents")
+ this.stimulate("DoctrinesReflex#render_default_case_lists")
}
- closeDoctrineAnnotationModalForm () {
- var $current_document_id = $("#doctrineModal").find("#current_document_id").val()
- var $doctrine_id = $("#doctrineModal").find("#doctrine_id").val()
- $(".btn-close-x").trigger("click");
- location.pathname = "/documents/" + $current_document_id + "/doctrines/" + $doctrine_id
+ newAnnotation () {
+ var document_title = "", document_ref_no = "", document_date_or_year = "", $modal = $("#annotationModal")
+
+ $modal.find(".modal-title").text("New Annotation")
+ document_title = this.element.dataset["documentTitle"]
+ document_ref_no = this.element.dataset["documentReferenceNumber"]
+ document_date_or_year = this.element.dataset["documentDateOrYear"]
+
+ $modal.find("select[name='annomark_ids[]']").val([])
+ $modal.find("#doctrine_id").val(null)
+ $modal.find("trix-editor[placeholder='Document Title']").val([document_title, document_ref_no, document_date_or_year].join(", "))
+ $modal.find("#document_id").val(this.element.dataset["documentId"])
+ $modal.find("#phil_rep").val(this.element.dataset["documentPhilRep"])
+ }
+
+ editAnnotation () {
+ var $modal = $("#annotationModal"), annotations_attributes_index = this.element.dataset["annotationsAttributesIndex"],
+ annotation = annotations_attributes[annotations_attributes_index]
+
+ $modal.find(".modal-title").text("Edit Annotation")
+
+ $modal.find("select[name='annomark_ids[]']").val(annotation.annomark_ids)
+ $modal.find("trix-editor[placeholder='Document Title']").val(annotation.content)
+ $modal.find("#document_id").val(annotation.document_id)
+ $modal.find("#annotaitons_attributes_index").val(annotations_attributes_index)
+
+ if (annotation.document_ids.length) {
+ $modal.find("#document_ids").val(annotation.document_ids.join(","))
+ }
+
+ $modal.find("#phil_rep").val(annotation.phil_rep)
}
}
diff --git a/app/javascript/controllers/document_controller.js b/app/javascript/controllers/document_controller.js
index ecda5ae..d9e49e9 100644
--- a/app/javascript/controllers/document_controller.js
+++ b/app/javascript/controllers/document_controller.js
@@ -12,6 +12,18 @@ export default class extends ApplicationController {
this.element.dataset["doctrineId"], this.element.dataset["currentDocumentId"])
}
+ searchDoctrineFormCaseLists () {
+ this.stimulate("DocumentReflex#render_doctrine_form_case_lists",
+ { q: this.inputTarget.value, citation_finder: this.citation_finderTarget.value, page: 1 },
+ this.element.dataset["jurisprudenceId"])
+ }
+
+ paginateDoctrineFormCaseLists () {
+ this.stimulate("DocumentReflex#render_doctrine_form_case_lists",
+ { q: this.element.dataset["q"], citation_finder: this.element.dataset["citation_finder"],
+ page: this.element.dataset["page"] }, this.element.dataset["jurisprudenceId"])
+ }
+
paginate () {
this.stimulate("DocumentReflex#render_case_lists_search_results",
{ q: this.element.dataset["q"], citation_finder: this.element.dataset["citation_finder"],
diff --git a/app/reflexes/doctrines_reflex.rb b/app/reflexes/doctrines_reflex.rb
index df77e8f..d23b16a 100644
--- a/app/reflexes/doctrines_reflex.rb
+++ b/app/reflexes/doctrines_reflex.rb
@@ -2,6 +2,7 @@
class DoctrinesReflex < ApplicationReflex
include DoctrineSearch
+ include DocumentSearch
def render_document_doctrines_index(search_params)
search = doctrine_search(search_params)
@@ -19,4 +20,23 @@ class DoctrinesReflex < ApplicationReflex
document = Cdao::Document.where(reference_number: jurisprudence.reference_number).first
morph "#doctrineForm", render(partial: "/shared/annotation_form", locals: { annotation: Annotation.new, document: document, doctrine_id: doctrine_id, jurisprudence: jurisprudence })
end
+
+ def render_doctrine_form_annotations_view(annotations)
+ morph "#doctrineAnnotationsView", render(partial: "/shared/doctrine_form_annotations_view", locals: { annotations: annotations })
+ end
+
+ def render_citing_documents_search_results(search_params)
+ search = document_search(search_params.merge(sort_by: %w[reference_number_texts title_texts short_title_texts]))
+ @documents = search.results
+ opts = { current_page: search_params[:page], q: search_params[:q] }
+ morph "#citingDocumentsSearchResults", render(partial: "/shared/doctrine_form_citing_documents_search_results", locals: { documents: @documents, opts: opts })
+ end
+
+ def render_default_citing_documents
+ morph "#citingDocumentsSearchResults", render(partial: "/shared/doctrine_form_citing_documents_search_results", locals: { documents: [], opts: {} })
+ end
+
+ def render_default_case_lists
+ morph "#caseListsCollapse", render(partial: "/shared/doctrine_form_default_case_lists", locals: { documents: @documents, opts: {} })
+ end
end
diff --git a/app/reflexes/document_reflex.rb b/app/reflexes/document_reflex.rb
index 0ca3e82..12d601f 100644
--- a/app/reflexes/document_reflex.rb
+++ b/app/reflexes/document_reflex.rb
@@ -19,4 +19,11 @@ class DocumentReflex < ApplicationReflex
@documents = search.results
morph "tbody#modalDocumentSearchTable", render(partial: "document_search_results_table", locals: { search_results: @documents, opts: { is_citing_document: true } })
end
+
+ def render_doctrine_form_case_lists(search_params, jurisprudence_id)
+ search = document_search(search_params.merge(sort_by: %i[reference_number_texts title_texts short_title_texts]))
+ @documents = search.results
+ opts = { jurisprudence_id: jurisprudence_id, current_page: search_params[:page], q: search_params[:q], citation_finder: search_params[:citation_finder] }
+ morph "#caseListsCollapse", render(partial: "/shared/doctrine_form_case_lists", locals: { documents: @documents, opts: opts })
+ end
end
diff --git a/app/views/doctrines/edit.html.erb b/app/views/doctrines/edit.html.erb
index 9ed4d71..af2a961 100644
--- a/app/views/doctrines/edit.html.erb
+++ b/app/views/doctrines/edit.html.erb
@@ -1,12 +1,12 @@
-
+
- <%= render(DoctrineFormComponent.new(current_user: current_user, doctrine: @doctrine)) %>
+ <%= render(DoctrineFormComponent.new(current_user: current_user, doctrine: @doctrine, jurisprudence_id: params[:jurisprudence_id])) %>
diff --git a/app/views/doctrines/new.html.erb b/app/views/doctrines/new.html.erb
index f0820f4..8017feb 100644
--- a/app/views/doctrines/new.html.erb
+++ b/app/views/doctrines/new.html.erb
@@ -3,7 +3,48 @@
<%= render(DoctrineFormComponent.new(current_user: current_user, doctrine: @doctrine, jurisprudence_id: params[:jurisprudence_id])) %>
+
+ <% if @doctrine.new_record? %>
+
+
+
+
+
+ <%= text_field_tag :q, nil, class: "form-control", placeholder: "Search GR Number, Title or Short Title", data: { target: "document.input" } %>
+
+
+ <%= button_tag "Search", class: "btn btn-success btn-sm me-2", data: { action: "click->document#searchDoctrineFormCaseLists" } %>
+ Citation finder
+
+
+ <%= text_field_tag :citation_finder, nil, class: "form-control", placeholder: "Citation Finder", data: { target: "document.citation_finder" } %>
+
+
+
+
+
+
+
+ Reference No.
+ Title
+ Date
+
+
+
+
+
+
+ <% end %>
+