From 499da5604d135e7b42ec0c3bc09a47d31e219c06 Mon Sep 17 00:00:00 2001 From: alexdbondoc17 Date: Mon, 7 Feb 2022 02:41:04 +0000 Subject: [PATCH] Implement Fixes --- .../annotation_marks_modal_form_component.rb | 12 ++++++++ ...tation_marks_modal_form_component.html.erb | 14 +++------ .../doctrine_modal_form_component.html.erb | 2 +- .../document_doctrine_index_component.rb | 12 ++++++++ ...document_doctrine_index_component.html.erb | 2 +- .../document_doctrine_show_component.rb | 12 ++++++++ .../document_doctrine_show_component.html.erb | 21 ++++++++++---- .../subject_accordion_component.html.erb | 22 +++++++------- .../concerns/jurisprudence_search.rb | 2 ++ .../doctrine/annotations_controller.rb | 20 +++++++++++++ app/controllers/doctrines_controller.rb | 2 +- app/controllers/documents_controller.rb | 2 +- .../controllers/document_controller.js | 29 +++++++++++++++++-- app/javascript/packs/application.js | 13 +++++++++ app/javascript/src/application.scss | 12 ++++++-- app/models/annotation.rb | 9 ++++++ app/models/cdao/jurisprudence.rb | 2 ++ app/models/doctrine.rb | 2 ++ app/views/documents/index.html.erb | 8 ++--- app/views/layouts/application.html.erb | 2 +- app/views/subject_indexes/index.html.erb | 6 ++-- app/views/subject_indexes/show.html.erb | 2 +- 22 files changed, 164 insertions(+), 44 deletions(-) diff --git a/app/components/annotation_marks_modal_form_component.rb b/app/components/annotation_marks_modal_form_component.rb index de475c8..ce2e379 100644 --- a/app/components/annotation_marks_modal_form_component.rb +++ b/app/components/annotation_marks_modal_form_component.rb @@ -17,6 +17,18 @@ class AnnotationMarksModalFormComponent < BaseComponent [document.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 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 094bd72..73677f7 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 @@ -11,6 +11,7 @@
<%= label_tag :annotation_marks %> <%= hidden_field_tag :document_id, document.id %> + <%= hidden_field_tag :document_ids, citing_document_ids %> <%= select_tag "annomark_ids[]", options_from_collection_for_select(Annomark.all, :id, :name, annotation.annomark_ids), class: "form-select default-selectize", multiple: true, prompt: "Please select" %>
@@ -18,14 +19,7 @@
<%= label_tag :document_title %> - <%= text_area_tag :document_title, document_title, class: "form-control selected-citing-docs" %> -
-
- -
-
- Selected Citing Documents - <%= select_tag "document_ids[]", [], class: "form-select selected-citing-docs default-selectize", multiple: true %> + <%= text_area_tag :document_title, [document_title, citing_documents_reference_numbers].reject(&:blank?).join(" "), class: "form-control selected-citing-docs" %>
@@ -54,8 +48,8 @@
-
- <%= label_tag :phil_rep %> +
+ <%= label_tag :phil_rep %> <%= text_field_tag :phil_rep, annotation.phil_rep, class: "form-control" %>
diff --git a/app/components/doctrine_modal_form_component/doctrine_modal_form_component.html.erb b/app/components/doctrine_modal_form_component/doctrine_modal_form_component.html.erb index 6f31dce..f55fe6f 100644 --- a/app/components/doctrine_modal_form_component/doctrine_modal_form_component.html.erb +++ b/app/components/doctrine_modal_form_component/doctrine_modal_form_component.html.erb @@ -18,7 +18,7 @@
<%= label_tag :content %> - <%= rich_text_area_tag :content, doctrine.content, placeholder: "Doctrine Content" %> + <%= rich_text_area_tag :content, doctrine.content, placeholder: "Doctrine Content", data: { controller: "document", target: "document.input", action: "keyup->document#suggestDoctrine" } %>
diff --git a/app/components/document_doctrine_index_component.rb b/app/components/document_doctrine_index_component.rb index 3a84c62..2e182ac 100644 --- a/app/components/document_doctrine_index_component.rb +++ b/app/components/document_doctrine_index_component.rb @@ -26,6 +26,18 @@ class DocumentDoctrineIndexComponent < BaseComponent "(No Subjects Provided)" end + def document_title(annotation) + return annotation.document.short_title if annotation.document.short_title.present? + + annotation.document.title + end + + def date_or_year(annotation) + return annotation.document.docdate.to_date.strftime("%B %d, %Y") if annotation.document.docdate.present? + + annotation.document.year + end + def render? doctrine.present? && doctrine.persisted? end 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 2a9b7f4..53c8f85 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 @@ -18,7 +18,7 @@ <% annotations.each do |annotation| %>

<%= "#{annotation.annomarks.map { |annomark| "(#{annomark.code})" }.join(" ")}" %> - <%= raw [annotation.document.title, annotation.document.reference_number, annotation.document.docdate.strftime("%B %d, %Y"), annotation.phil_rep].reject(&:blank?).join(', ') %> + <%= raw [document_title(annotation), annotation.document.reference_number, date_or_year(annotation), annotation.phil_rep].reject(&:blank?).join(', ') %>

<% if annotation.editor_notes.present? %> diff --git a/app/components/document_doctrine_show_component.rb b/app/components/document_doctrine_show_component.rb index 8a45818..cfe2b35 100644 --- a/app/components/document_doctrine_show_component.rb +++ b/app/components/document_doctrine_show_component.rb @@ -26,4 +26,16 @@ class DocumentDoctrineShowComponent < BaseComponent def annotation_form_url doctrine_annotations_path(doctrine_id: id,) end + + def document_title(annotation) + return annotation.document.short_title if annotation.document.short_title.present? + + annotation.document.title + end + + def date_or_year(annotation) + return annotation.document.docdate.to_date.strftime("%B %d, %Y") if annotation.document.docdate.present? + + annotation.document.year + end end \ No newline at end of file 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 cd34042..b499c8e 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 @@ -18,14 +18,22 @@
- <%= label_tag :subjects %> - <%= select_tag "subjects_ids[]", options_from_collection_for_select(Cdao::Subject.all, :id, :lineage_name, subject_ids), class: "form-select default-selectize", multiple: true, prompt: "Please select", readonly: true %> +
+ Subjects: +
+ +
+ <%= subjects.map(&:lineage_name).join(" & ") %> +
-
- <%= label_tag :content %> - <%= rich_text_area_tag :content, content, placeholder: "Doctrine Content", readonly: true %> +
+ Content: +
+ +
+ <%= raw content %>
@@ -72,6 +80,7 @@
<%= label_tag :annotation_marks %> <%= hidden_field_tag :document_id, nil %> + <%= hidden_field_tag :document_ids, nil %> <%= select_tag "annomark_ids[]", options_from_collection_for_select(Annomark.all, :id, :name), class: "form-select default-selectize", multiple: true, prompt: "Please select" %>
@@ -117,7 +126,7 @@
<%= label_tag :editor_notes %> - +
diff --git a/app/components/subject_accordion_component/subject_accordion_component.html.erb b/app/components/subject_accordion_component/subject_accordion_component.html.erb index 045cfc6..047c6af 100644 --- a/app/components/subject_accordion_component/subject_accordion_component.html.erb +++ b/app/components/subject_accordion_component/subject_accordion_component.html.erb @@ -1,15 +1,15 @@ <% parent.children.each do |sub1| %>
-
+
<% if sub1.children.present? %> <% else %> <%= link_to sub1.name, subject_index_path(sub1.id), class: "accordion-link text-decoration-none text-dark d-block sub2 clickable-link" %> - <%= link_to "Add Sub Subject", new_subject_index_path(parent_id: sub1.id), class: "btn btn-sm btn-primary text-decoration-none d-block sub1 clickable-link position-absolute end-0 me-2" %> + <%= link_to "Add Sub Subject", new_subject_index_path(parent_id: sub1.id), class: "btn btn-sm btn-primary text-decoration-none d-block sub1 clickable-link position-absolute end-0 accordion-action-button-margin" %> <% end %>
@@ -18,15 +18,15 @@ <% sub1.children.each do |sub2| %>
-
+
<% if sub1.children.present? %> <% else %> <%= link_to sub2.name, subject_index_path(sub2.id), class: "accordion-link text-decoration-none text-dark d-block sub3 clickable-link" %> - <%= link_to "Add Sub Subject", new_subject_index_path(parent_id: sub2.id), class: "btn btn-sm btn-primary text-decoration-none d-block sub1 clickable-link position-absolute end-0 me-2" %> + <%= link_to "Add Sub Subject", new_subject_index_path(parent_id: sub2.id), class: "btn btn-sm btn-primary text-decoration-none d-block sub1 clickable-link position-absolute end-0 accordion-action-button-margin" %> <% end %>
@@ -35,15 +35,15 @@ <% sub2.children.each do |sub3| %>
-
+
<% if sub3.children.present? %> <% else %> <%= link_to sub3.name, subject_index_path(sub3.id), class: "accordion-link text-decoration-none text-dark d-block sub4 clickable-link" %> - <%= link_to "Add Sub Subject", new_subject_index_path(parent_id: sub3.id), class: "btn btn-sm btn-primary text-decoration-none d-block sub1 clickable-link position-absolute end-0 me-2" %> + <%= link_to "Add Sub Subject", new_subject_index_path(parent_id: sub3.id), class: "btn btn-sm btn-primary text-decoration-none d-block sub1 clickable-link position-absolute end-0 accordion-action-button-margin" %> <% end %>
@@ -51,10 +51,10 @@
<% sub3.children.each do |sub4| %>
-
+
<%= link_to sub4.name, subject_index_path(sub4.id), class: "accordion-link text-decoration-none text-dark d-block sub5 clickable-link" %> - <%= link_to "Add Sub Subject", new_subject_index_path(parent_id: sub4.id), class: "btn btn-sm btn-primary text-decoration-none d-block sub1 clickable-link position-absolute end-0 me-2" %> + <%= link_to "Add Sub Subject", new_subject_index_path(parent_id: sub4.id), class: "btn btn-sm btn-primary text-decoration-none d-block sub1 clickable-link position-absolute end-0 accordion-action-button-margin" %>
diff --git a/app/controllers/concerns/jurisprudence_search.rb b/app/controllers/concerns/jurisprudence_search.rb index 55393d4..4418b46 100644 --- a/app/controllers/concerns/jurisprudence_search.rb +++ b/app/controllers/concerns/jurisprudence_search.rb @@ -13,6 +13,8 @@ module JurisprudenceSearch with(:subject_ids).any_of(search_params[:subject_ids].split(",").map(&:strip).map(&:to_i)) if search_params[:subject_ids].present? + with(:doctrine_phil_rep, search_params[:phil_rep]) if search_params[:phil_rep].present? + without(:id).any_of(search_params[:exclude_ids]) if search_params[:exclude_ids].present? order_by :doc_date, :desc diff --git a/app/controllers/doctrine/annotations_controller.rb b/app/controllers/doctrine/annotations_controller.rb index 5c6d087..391540e 100644 --- a/app/controllers/doctrine/annotations_controller.rb +++ b/app/controllers/doctrine/annotations_controller.rb @@ -5,6 +5,7 @@ class Doctrine::AnnotationsController < ApplicationController def create attrs = resource_params.to_unsafe_h.deep_symbolize_keys document_id = attrs.delete(:document_id) + document_ids = params[:document_ids].split(",") @annotation = @doctrine.annotations.new(attrs) @@ -12,8 +13,15 @@ class Doctrine::AnnotationsController < ApplicationController @annotation.document = Cdao::Jurisprudence.find(document_id) end + if document_ids.present? + @documents = Cdao::Jurisprudence.where(id: document_ids) + end + respond_to do |format| if @annotation.save + @documents.each do |document| + @annotation.add_document(document) + end format.html { redirect_to document_doctrine_path(@doctrine.document, @doctrine), notice: "Doctrine Annotation was successfully created." } else @@ -25,11 +33,23 @@ class Doctrine::AnnotationsController < ApplicationController def update attrs = resource_params.to_unsafe_h.deep_symbolize_keys 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? respond_to do |format| if @annotation.update(attrs) + @annotation.annotation_documents.each do |annotation_document| + @annotation.remove_document(annotation_document.document) + end + + @documents.each do |document| + @annotation.add_document(document) + end format.html { redirect_to document_doctrine_path(@doctrine.document, @doctrine), notice: "Doctrine Annotation was successfully updated." } else diff --git a/app/controllers/doctrines_controller.rb b/app/controllers/doctrines_controller.rb index 11c9cc3..b943d91 100644 --- a/app/controllers/doctrines_controller.rb +++ b/app/controllers/doctrines_controller.rb @@ -13,7 +13,7 @@ class DoctrinesController < ApplicationController end def search - @search = search_doctrines(search_params) + @search = doctrine_search(search_params) @doctrines = @search.results respond_to do |format| diff --git a/app/controllers/documents_controller.rb b/app/controllers/documents_controller.rb index 8a3d67d..64c4814 100644 --- a/app/controllers/documents_controller.rb +++ b/app/controllers/documents_controller.rb @@ -34,6 +34,6 @@ class DocumentsController < ApplicationController private def search_params params.permit(:reference_number, :title, :short_title, :q, :page, :per_page, - :subject_ids, :year) + :subject_ids, :phil_rep, :year) end end diff --git a/app/javascript/controllers/document_controller.js b/app/javascript/controllers/document_controller.js index ba6ffc4..1456409 100644 --- a/app/javascript/controllers/document_controller.js +++ b/app/javascript/controllers/document_controller.js @@ -54,7 +54,32 @@ export default class extends ApplicationController { document_id = this.element.dataset["documentId"] document_ref_no = this.element.dataset["documentReferenceNumber"] - console.log($doc_id.val()) - console.log($doc_title.val()) + var document_ids = [] + + console.log($("#document_ids").val() === "") + + if ($("#document_ids").val() === "") { + document_ids.push(document_id) + } else { + document_ids = $("#document_ids").val().split(",") + document_ids.push(document_id) + } + + $("#document_ids").val(document_ids.join(",")) + + var doc_title = $doc_title.val() + + $doc_title.val(doc_title + " citing " + document_ref_no) + } + + suggestDoctrine () { + var $this = this + + $.get("/api/doctrines.json", { q: $this.inputTarget.value }, function (data, status) { + if (status === "success") { + console.log(data) + console.log(data[0]) + } + }); } } diff --git a/app/javascript/packs/application.js b/app/javascript/packs/application.js index 2cb160a..d2a499e 100644 --- a/app/javascript/packs/application.js +++ b/app/javascript/packs/application.js @@ -49,6 +49,19 @@ $(document).on("ready turbolinks:load", function () { window.open($href); } }) + + var default_opts = { + plugins: ['restore_on_backspace', 'remove_button'], + searchField: ['text', 'optgroup'], + valueField: "id", + allowEmptyOption: false, + showEmptyOptionInDropdown: true, + emptyOptionLabel: true, + hideSelected: true, + placeholder: "Please Select" + } + + $(".default-selectize").selectize(default_opts) }); import "channels" diff --git a/app/javascript/src/application.scss b/app/javascript/src/application.scss index 1af5fdd..53ca036 100644 --- a/app/javascript/src/application.scss +++ b/app/javascript/src/application.scss @@ -22,6 +22,14 @@ cursor: pointer; } -.current { - background-color: #535353 !important; +.current, .nav-link.active { + background-color: #e6e6e6 !important; +} + +.accordion-action-button-margin { + margin: 7px 65px 0px 0px; +} + +.accordion-button::after { + margin-right: 10px; } diff --git a/app/models/annotation.rb b/app/models/annotation.rb index 30129e8..acbe809 100644 --- a/app/models/annotation.rb +++ b/app/models/annotation.rb @@ -24,4 +24,13 @@ class Annotation < ApplicationRecord def remove_document(document) annotation_documents.find_by(document_id: document.id).destroy end + + searchable do + integer :document_id + integer :doctrine_id + + text :phil_rep + + string :phil_rep + end end diff --git a/app/models/cdao/jurisprudence.rb b/app/models/cdao/jurisprudence.rb index 294b7a5..2077193 100644 --- a/app/models/cdao/jurisprudence.rb +++ b/app/models/cdao/jurisprudence.rb @@ -96,5 +96,7 @@ class Cdao::Jurisprudence < Cdao::Base integer :subject_ids, multiple: true boolean :edited + + join(:phil_rep, :target => Doctrine, :type => :string, :join => { :from => :document_id, :to => :id }) end end diff --git a/app/models/doctrine.rb b/app/models/doctrine.rb index 987cdea..f7a5efe 100644 --- a/app/models/doctrine.rb +++ b/app/models/doctrine.rb @@ -55,6 +55,8 @@ class Doctrine < ApplicationRecord paper_trail.originator.to_i end + join(:phil_rep, :target => Annotation, :type => :string, :join => { :from => :annotation_doctrine_id, :to => :id }) + date :created_at end end diff --git a/app/views/documents/index.html.erb b/app/views/documents/index.html.erb index 94bd593..40457d9 100644 --- a/app/views/documents/index.html.erb +++ b/app/views/documents/index.html.erb @@ -22,18 +22,18 @@ @@ -46,7 +46,7 @@
- <% if @search_params.reject { |k, v| v.blank? }.present? %> + <% if @search_params.present? %>
<%= render PaginationComponent.new(data: @jurisprudences) %>
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index ae1eb79..76b8fb8 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -11,7 +11,7 @@ <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %> - +
<% if current_user.present? %> diff --git a/app/views/subject_indexes/index.html.erb b/app/views/subject_indexes/index.html.erb index 0f15c59..a1c425e 100644 --- a/app/views/subject_indexes/index.html.erb +++ b/app/views/subject_indexes/index.html.erb @@ -7,15 +7,15 @@ <% Cdao::Subject.roots.all.each do |root| %>
-
+
<% if root.children.present? %> <% else %> <%= link_to root.name, subject_index_path(root.id), class: "accordion-link text-decoration-none text-dark d-block sub1 clickable-link" %> - <%= link_to "Add Sub Subject", new_subject_index_path(parent_id: root.id), class: "btn btn-sm btn-primary text-decoration-none d-block sub1 clickable-link position-absolute end-0 me-2" %> + <%= link_to "Add Sub Subject", new_subject_index_path(parent_id: root.id), class: "btn btn-sm btn-primary text-decoration-none d-block sub1 clickable-link position-absolute end-0 accordion-action-button-margin" %> <% end %>
diff --git a/app/views/subject_indexes/show.html.erb b/app/views/subject_indexes/show.html.erb index 7f40bca..67abd45 100644 --- a/app/views/subject_indexes/show.html.erb +++ b/app/views/subject_indexes/show.html.erb @@ -16,7 +16,7 @@
- +
Name: <%= @subject_index.name %> Parent Subject: <%= @subject_index.parent.lineage_name %> <%= @subject_index.is_root? ? "N/A" : @subject_index.parent.lineage_name %>