32 changed files with 355 additions and 346 deletions
@ -1,36 +1,4 @@ |
|||||||
class AnnotationMarksModalFormComponent < BaseComponent |
class AnnotationMarksModalFormComponent < BaseComponent |
||||||
attr_reader :document, :annotation, :opts |
|
||||||
|
|
||||||
def initialize(current_user:, document:, annotation:, opts:) |
def initialize(current_user:); end |
||||||
@document = document |
|
||||||
@annotation = annotation |
|
||||||
@opts = opts |
|
||||||
end |
|
||||||
|
|
||||||
def document_date_or_year |
|
||||||
return document.year if document.docdate.blank? |
|
||||||
|
|
||||||
document.docdate.strftime("%B %d, %Y") |
|
||||||
end |
|
||||||
|
|
||||||
def document_title |
|
||||||
title = document.short_title || document.title |
|
||||||
[title, document.reference_number, document_date_or_year].reject(&:blank?).join(", ") |
|
||||||
end |
|
||||||
|
|
||||||
def citing_documents_reference_numbers |
|
||||||
return if annotation.documents.blank? |
|
||||||
|
|
||||||
annotation.documents.map(&:reference_number).join(" citing ") |
|
||||||
end |
|
||||||
|
|
||||||
def citing_document_ids |
|
||||||
return if annotation.documents.blank? |
|
||||||
|
|
||||||
annotation.documents.map(&:id).join(",") |
|
||||||
end |
|
||||||
|
|
||||||
def render? |
|
||||||
opts[:form_url].present? && opts[:form_method].present? |
|
||||||
end |
|
||||||
end |
end |
||||||
@ -1,13 +1,3 @@ |
|||||||
class DoctrineModalFormComponent < BaseComponent |
class DoctrineModalFormComponent < BaseComponent |
||||||
attr_reader :doctrine, :subjects, :opts |
def initialize(current_user:); end |
||||||
|
|
||||||
def initialize(current_user:, doctrine:, subjects:, opts:) |
|
||||||
@doctrine = doctrine |
|
||||||
@subjects = subjects |
|
||||||
@opts = opts |
|
||||||
end |
|
||||||
|
|
||||||
def render? |
|
||||||
opts[:form_url].present? && opts[:form_method].present? |
|
||||||
end |
|
||||||
end |
end |
||||||
|
|||||||
@ -1,35 +1,33 @@ |
|||||||
<div class="modal fade modal-doctrine-body" id="doctrineModal" tabindex="-1" aria-labelledby="doctrineModal" aria-hidden="true"> |
<div class="modal fade modal-doctrine-body" id="doctrineModal" tabindex="-1" aria-labelledby="doctrineModal" aria-hidden="true" data-controller="doctrines"> |
||||||
<%= form_tag(opts[:form_url], method: opts[:form_method]) do %> |
<div class="modal-dialog modal-lg modal-dialog-scrollable"> |
||||||
<div class="modal-dialog modal-lg modal-dialog-scrollable"> |
<div class="modal-content"> |
||||||
<div class="modal-content"> |
<div class="modal-header"> |
||||||
<div class="modal-header"> |
<h5 class="modal-title"></h5> |
||||||
<h5 class="modal-title"> <%= opts[:form_method].eql?(:post) ? "New Doctrine" : "Update Doctrine" %> </h5> |
<button type="button" class="btn-close-x" data-bs-dismiss="modal" aria-label="Close">x</button> |
||||||
<button type="button" class="btn-close-x" data-bs-dismiss="modal" aria-label="Close">x</button> |
</div> |
||||||
</div> |
|
||||||
|
|
||||||
<div class="modal-body"> |
|
||||||
<div class="mb-3"> |
|
||||||
<label for="subject-name" class="col-form-label">Subjects</label> |
|
||||||
<%= select_tag "subject_ids[]", options_from_collection_for_select(subjects.sort_by { |sub| sub.lineage_name }, :id, :lineage_name, doctrine.subject_ids), class: "form-control subject-ids-selectize ps-0", multiple: true, prompt: "Please select" %> |
|
||||||
</div> |
|
||||||
|
|
||||||
<% if doctrine.new_record? %> |
|
||||||
<div class="mb-3"> |
|
||||||
<label for="subject-name" class="col-form-label">Doctine content suggestions</label> |
|
||||||
<select id="doctine_content_suggestions" class="form-control ps-0"> </select> |
|
||||||
</div> |
|
||||||
<% end %> |
|
||||||
|
|
||||||
|
<div class="modal-body"> |
||||||
<div class="mb-3"> |
<div class="mb-3"> |
||||||
<label for="subject-name" class="col-form-label">Content</label> |
<label for="subject-name" class="col-form-label"> Subjects </label> |
||||||
<%= rich_text_area_tag :content, doctrine.content, placeholder: "Doctrine Content" %> |
<%= hidden_field_tag :document_id, nil, data: { target: "doctrines.document_id" } %> |
||||||
|
<%= hidden_field_tag :doctrine_id, nil, data: { target: "doctrines.doctrine_id" } %> |
||||||
|
<select class="form-control subject-ids-selectize ps-0" name="subject_ids[]" id="subject_ids_" multiple="true"> </select> |
||||||
</div> |
</div> |
||||||
|
|
||||||
|
<div class="mb-3" id="doctine_content_suggestions_div"> |
||||||
|
<label for="subject-name" class="col-form-label">Doctine content suggestions</label> |
||||||
|
<select id="doctine_content_suggestions" class="form-control ps-0"> </select> |
||||||
</div> |
</div> |
||||||
<div class="modal-footer"> |
|
||||||
<button type="submit" class="btn btn-primary">Save</button> |
<div class="mb-3"> |
||||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button> |
<label for="subject-name" class="col-form-label">Content</label> |
||||||
|
<%= rich_text_area_tag :content, nil, placeholder: "Doctrine Content", data: { target: "doctrines.content" } %> |
||||||
</div> |
</div> |
||||||
</div> |
</div> |
||||||
|
<div class="modal-footer"> |
||||||
|
<button type="button" class="btn btn-primary" data-action="click->doctrines#save">Save</button> |
||||||
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button> |
||||||
|
</div> |
||||||
</div> |
</div> |
||||||
<% end %> |
</div> |
||||||
</div> |
</div> |
||||||
|
|||||||
@ -1,5 +1,5 @@ |
|||||||
<tr href="<%= document_path(search_result.id) %>" class="<%= opts.reject{ |k, v| v.blank? }.blank? ? 'clickable-tr' : ''%>" target="_blank"> |
<tr href="<%= document_path(search_result.id) %>" class="<%= opts.reject{ |k, v| v.blank? }.blank? ? 'clickable-tr' : ''%>" target="_blank"> |
||||||
<td> <%= reference_number %> </td> |
<td> <%= clean_reference_number %> </td> |
||||||
<td> <%= short_title || title %> </td> |
<td> <%= short_title || title %> </td> |
||||||
<td> <%= date_or_year %> </td> |
<td> <%= date_or_year %> </td> |
||||||
</tr> |
</tr> |
||||||
|
|||||||
@ -0,0 +1,87 @@ |
|||||||
|
import ApplicationController from './application_controller' |
||||||
|
export default class extends ApplicationController { |
||||||
|
static targets = ["q", "annotation_id", "doctrine_id", "document_id", "document_ids", |
||||||
|
"annomark_ids", "phil_rep", "editor_notes"] |
||||||
|
|
||||||
|
connect () { |
||||||
|
super.connect() |
||||||
|
} |
||||||
|
|
||||||
|
searchDocument () { |
||||||
|
var $this = this |
||||||
|
$.get("/api/documents.json", { q: $this.qTarget.value }, function (data, status) { |
||||||
|
if (status === "success") { |
||||||
|
$this.stimulate("AnnotationReflex#render_document_search_results", data) |
||||||
|
} |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
renderForm () { |
||||||
|
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") |
||||||
|
|
||||||
|
if(annotation_id !== null && annotation_id !== undefined && annotation_id !== "") { |
||||||
|
$modal.find(".modal-title").text("Edit Annotation") |
||||||
|
$.get("/api/doctrines/" + doctrine_id + "/annotations/" + annotation_id + ".json", {}, function(result, status) { |
||||||
|
$modal.find("#annotation_id").val(annotation_id) |
||||||
|
$modal.find("#doctrine_id").val(doctrine_id) |
||||||
|
$modal.find("#document_id").val(result.citing_document_ids) |
||||||
|
$modal.find("#document_ids").val(result.document_id) |
||||||
|
$modal.find("#phil_rep").val(result.phil_rep) |
||||||
|
$modal.find("#document_title").val($this.element.dataset["documentTitle"]) |
||||||
|
$modal.find("select[name='annomark_ids[]']")[0].selectize.setValue(result.annomark_ids) |
||||||
|
$modal.find(".trix-content").val(result.editor_notes) |
||||||
|
}); |
||||||
|
} else { |
||||||
|
$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("#doctrine_id").val(doctrine_id) |
||||||
|
$modal.find("#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"]) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
addCitingDocument () { |
||||||
|
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") |
||||||
|
|
||||||
|
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(", ")) |
||||||
|
} |
||||||
|
|
||||||
|
save () { |
||||||
|
var $this = this, $modal = $("#annotationModal"), annotation_id = $this.annotation_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 || "" } |
||||||
|
|
||||||
|
if (annotation_id !== null && annotation_id !== undefined && annotation_id !== "") { |
||||||
|
$.ajax({ |
||||||
|
url: "/doctrines/" + doctrine_id + "/annotations/" + annotation_id, |
||||||
|
type: 'PUT', |
||||||
|
data: params |
||||||
|
}) |
||||||
|
} else { |
||||||
|
$.post("/doctrines/" + doctrine_id + "/annotations", params) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,62 @@ |
|||||||
|
import ApplicationController from './application_controller' |
||||||
|
export default class extends ApplicationController { |
||||||
|
static targets = ["input", "document_id", "doctrine_id", "content"] |
||||||
|
|
||||||
|
connect () { |
||||||
|
super.connect() |
||||||
|
} |
||||||
|
|
||||||
|
renderForm () { |
||||||
|
var document_id = this.element.dataset["documentId"], doctrine_id = this.element.dataset["doctrineId"], |
||||||
|
$modal = $("#doctrineModal"), $subject_ids_el = $modal.find(".subject-ids-selectize"),
|
||||||
|
$subject_ids_selectize = $subject_ids_el[0].selectize |
||||||
|
|
||||||
|
console.log(this.element.dataset) |
||||||
|
|
||||||
|
if (doctrine_id !== null && doctrine_id !== undefined && doctrine_id !== "") { |
||||||
|
$modal.find("#doctine_content_suggestions_div").hide() |
||||||
|
$.get("/api/doctrines/" + doctrine_id + ".json", {}, function (doctrine, status) { |
||||||
|
$modal.find("#document_id").val(doctrine.document_id) |
||||||
|
$modal.find("#doctrine_id").val(doctrine.id) |
||||||
|
if (status === "success") { |
||||||
|
$.get("/api/subjects.json?doctrine_ids=" + doctrine.id, { per_page: 100 }, function (subjects, status) { |
||||||
|
if (status === "success") { |
||||||
|
$.each(subjects, function(i, subject) { |
||||||
|
$subject_ids_selectize.addOption(subject) |
||||||
|
}) |
||||||
|
|
||||||
|
$subject_ids_selectize.refreshOptions() |
||||||
|
$subject_ids_selectize.setValue(doctrine.subject_ids) |
||||||
|
} |
||||||
|
}); |
||||||
|
|
||||||
|
$modal.find(".trix-content").val(doctrine.content) |
||||||
|
} |
||||||
|
}) |
||||||
|
|
||||||
|
$modal.find(".modal-title").text("Update Doctrine") |
||||||
|
$(".selectize-dropdown").hide() |
||||||
|
} else { |
||||||
|
$modal.find("#doctine_content_suggestions_div").show() |
||||||
|
$modal.find(".modal-title").text("New Doctrine") |
||||||
|
$modal.find(".trix-content").val("") |
||||||
|
$subject_ids_selectize.setValue([]) |
||||||
|
$modal.find("#document_id").val(document_id) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
save () { |
||||||
|
var $modal = $("#doctrineModal"), document_id = this.document_idTarget.value, doctrine_id = this.doctrine_idTarget.value |
||||||
|
const params = { subject_ids: $modal.find("select[name='subject_ids[]']").val(), content: this.contentTarget.value } |
||||||
|
|
||||||
|
if (doctrine_id !== null && doctrine_id !== undefined && doctrine_id !== "") { |
||||||
|
$.ajax({ |
||||||
|
url: "/jurisprudences/" + document_id + "/doctrines/" + doctrine_id, |
||||||
|
type: 'PUT', |
||||||
|
data: params |
||||||
|
}) |
||||||
|
} else { |
||||||
|
$.post("/jurisprudences/" + document_id + "/doctrines", params) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -1,13 +0,0 @@ |
|||||||
import ApplicationController from './application_controller' |
|
||||||
|
|
||||||
export default class extends ApplicationController { |
|
||||||
connect() { |
|
||||||
super.connect() |
|
||||||
|
|
||||||
$("#cdao_subject_parent_id").select2({ tags: true, width: "100%" }) |
|
||||||
$(".subjects-select2").select2({ tags: true, width: "100%" }) |
|
||||||
$(".annomark-ids-select2").select2({ width: "100%", dropdownParent: $("#edit-annotation-modal") }) |
|
||||||
$(".new-annotation-annomark-ids").select2({ width: "100%", dropdownParent: $("#new-annotation-modal") }) |
|
||||||
$(".subject-ids-modal-select2").select2({ width: "100%", dropdownParent: $("#doctrineModal") }) |
|
||||||
} |
|
||||||
} |
|
||||||
@ -0,0 +1,8 @@ |
|||||||
|
# frozen_string_literal: true |
||||||
|
|
||||||
|
class AnnotationReflex < ApplicationReflex |
||||||
|
def render_document_search_results(results) |
||||||
|
opts = { is_citing_document: true } |
||||||
|
morph "tbody#documentSearchResultTable", render(partial: "document_search_results_table", locals: { search_results: results, opts: opts }) |
||||||
|
end |
||||||
|
end |
||||||
@ -1,7 +1,7 @@ |
|||||||
# frozen_string_literal: true |
# frozen_string_literal: true |
||||||
|
|
||||||
class SubjectsReflex < ApplicationReflex |
class SubjectsReflex < ApplicationReflex |
||||||
def load_roots |
def load_sidenav_accordion(search_results, opts = {}) |
||||||
@roots = "Hello!!!" |
morph "#" |
||||||
end |
end |
||||||
end |
end |
||||||
|
|||||||
@ -0,0 +1 @@ |
|||||||
|
json.(@annotation, *%i[id doctrine_id document_id phil_rep editor_notes annomark_ids citing_document_ids]) |
||||||
@ -1 +1 @@ |
|||||||
json.(@doctrine, *%i[id subject_ids content plain_content created_at updated_at]) |
json.(@doctrine, *%i[id document_id subject_ids content plain_content created_at updated_at]) |
||||||
|
|||||||
@ -1,3 +1,3 @@ |
|||||||
json.array!(@documents) do |document| |
json.array!(@documents) do |document| |
||||||
json.extract! document, *%i[id reference_number title short_title doc_date year phil_rep scra] |
json.extract! document, *%i[id reference_number clean_reference_number title short_title doc_date year phil_rep scra] |
||||||
end |
end |
||||||
|
|||||||
@ -1,4 +1,4 @@ |
|||||||
json.array!(@subjects) do |subject| |
json.array!(@subjects) do |subject| |
||||||
json.extract! subject, *%i[id name parent_id state doctrine_ids created_at updated_at] |
json.extract! subject, *%i[id name parent_id state doctrine_ids created_at updated_at] |
||||||
json.text [subject.lineage_name].join(" - ") |
json.text subject.lineage_name |
||||||
end |
end |
||||||
|
|||||||
Loading…
Reference in new issue