From 71cc5d6f63444d17d4294605cd8cf6e482ac2490 Mon Sep 17 00:00:00 2001 From: alexdbondoc17 Date: Mon, 7 Feb 2022 07:25:23 +0000 Subject: [PATCH] Enhancement of `documents`, `doctrines`, and `annotations` --- .../doctrine_index_table_component.rb | 24 +++++++++++++++++++ .../doctrine_index_table_component.html.erb | 19 +++++++++++++++ .../doctrine_modal_form_component.html.erb | 9 ++++++- .../document_doctrine_show_component.rb | 4 ++++ .../document_doctrine_show_component.html.erb | 2 +- .../subjects_sidenav_sub_menu_component.rb | 4 ++-- .../concerns/jurisprudence_search.rb | 4 +++- app/controllers/documents_controller.rb | 2 +- .../controllers/document_controller.js | 14 +---------- .../controllers/selectize_controller.js | 17 +++++++++++++ app/javascript/packs/application.js | 14 ----------- app/models/cdao/jurisprudence.rb | 2 +- app/views/doctrines/search.html.erb | 9 ++++++- app/views/documents/index.html.erb | 6 ++--- app/views/layouts/application.html.erb | 2 +- 15 files changed, 93 insertions(+), 39 deletions(-) create mode 100644 app/components/doctrine_index_table_component.rb create mode 100644 app/components/doctrine_index_table_component/doctrine_index_table_component.html.erb diff --git a/app/components/doctrine_index_table_component.rb b/app/components/doctrine_index_table_component.rb new file mode 100644 index 0000000..be454d2 --- /dev/null +++ b/app/components/doctrine_index_table_component.rb @@ -0,0 +1,24 @@ +class DoctrineIndexTableComponent < BaseComponent + attr_reader :search_results, :opts + + def initialize(current_user:, search_results:, opts: {}) + @search_results = search_results + @opts = opts + end + + def document_reference_number(document) + document.reference_number + end + + def document_title(document) + return document.short_title if document.short_title.present? + + document.title + end + + def date_or_year(document) + return document.docdate.strftime("%m/%d/%Y") if document.docdate.present? + + document.year + end +end diff --git a/app/components/doctrine_index_table_component/doctrine_index_table_component.html.erb b/app/components/doctrine_index_table_component/doctrine_index_table_component.html.erb new file mode 100644 index 0000000..81af1cb --- /dev/null +++ b/app/components/doctrine_index_table_component/doctrine_index_table_component.html.erb @@ -0,0 +1,19 @@ + + + + + + + + + + <% search_results.each do |search_result| %> + + + + + + + <% end %> + +
Reference Number Title Date PhilRep
<%= document_reference_number(search_result.document) %> <%= document_title(search_result.document) %> <%= date_or_year(search_result.document) %> <%= search_result.annotations.map(&:phil_rep).join(", ") %>
\ No newline at end of file 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 f55fe6f..04624ba 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 @@ -15,10 +15,17 @@ +
+
+ <%= label_tag :doctine_content_suggestions %> + <%= select_tag :doctine_content_suggestions, options_from_collection_for_select(Doctrine.all, :content, :content), class: "form-select", prompt: "Please select" %> +
+
+
<%= label_tag :content %> - <%= rich_text_area_tag :content, doctrine.content, placeholder: "Doctrine Content", data: { controller: "document", target: "document.input", action: "keyup->document#suggestDoctrine" } %> + <%= rich_text_area_tag :content, doctrine.content, placeholder: "Doctrine Content" %>
diff --git a/app/components/document_doctrine_show_component.rb b/app/components/document_doctrine_show_component.rb index cfe2b35..010b971 100644 --- a/app/components/document_doctrine_show_component.rb +++ b/app/components/document_doctrine_show_component.rb @@ -33,6 +33,10 @@ class DocumentDoctrineShowComponent < BaseComponent annotation.document.title end + def all_subjects + Cdao::Subject.all + end + def date_or_year(annotation) return annotation.document.docdate.to_date.strftime("%B %d, %Y") if annotation.document.docdate.present? 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 b499c8e..f15a08c 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 @@ -12,7 +12,7 @@
- <%= render(DoctrineModalFormComponent.new(current_user: current_user, doctrine: doctrine, subjects: subjects, opts: { form_url: jurisprudence_doctrine_path(jurisprudence_id: document_id, id: doctrine.id), form_method: "PUT" })) %> + <%= render(DoctrineModalFormComponent.new(current_user: current_user, doctrine: doctrine, subjects: all_subjects, opts: { form_url: jurisprudence_doctrine_path(jurisprudence_id: document_id, id: doctrine.id), form_method: "PUT" })) %>
diff --git a/app/components/subjects_sidenav_sub_menu_component.rb b/app/components/subjects_sidenav_sub_menu_component.rb index cb3e738..661ff86 100644 --- a/app/components/subjects_sidenav_sub_menu_component.rb +++ b/app/components/subjects_sidenav_sub_menu_component.rb @@ -6,8 +6,8 @@ class SubjectsSidenavSubMenuComponent < BaseComponent end def index_url(subject_id) - return search_doctrines_path(subject_ids: [subject_id]) if opts[:is_doctrines_index].present? + return search_doctrines_path(subject_ids: [subject_id], is_index_table: false) if opts[:is_doctrines_index].present? - search_documents_path(subject_ids: subject_id) + search_doctrines_path(subject_ids: [subject_id], is_index_table: true) end end diff --git a/app/controllers/concerns/jurisprudence_search.rb b/app/controllers/concerns/jurisprudence_search.rb index 4418b46..2cd8868 100644 --- a/app/controllers/concerns/jurisprudence_search.rb +++ b/app/controllers/concerns/jurisprudence_search.rb @@ -13,7 +13,9 @@ 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? + with(:phil_rep, search_params[:phil_rep]) if search_params[:phil_rep].present? + + with(:phil_rep, search_params[:scra]) if search_params[:scra].present? without(:id).any_of(search_params[:exclude_ids]) if search_params[:exclude_ids].present? diff --git a/app/controllers/documents_controller.rb b/app/controllers/documents_controller.rb index 64c4814..eb9ab50 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, :phil_rep, :year) + :subject_ids, :phil_rep, :scra, :year) end end diff --git a/app/javascript/controllers/document_controller.js b/app/javascript/controllers/document_controller.js index 1456409..5bdd1c0 100644 --- a/app/javascript/controllers/document_controller.js +++ b/app/javascript/controllers/document_controller.js @@ -48,8 +48,7 @@ export default class extends ApplicationController { } addCitingDocument () { - var document_id = "", document_ref_no = "", $modal = $("#newAnnotationModal"), $doc_title = $modal.find("#document_title"), - $doc_id = $modal.find("#document_id") + var document_id = "", document_ref_no = "", $modal = $("#newAnnotationModal"), $doc_title = $modal.find("#document_title") document_id = this.element.dataset["documentId"] document_ref_no = this.element.dataset["documentReferenceNumber"] @@ -71,15 +70,4 @@ export default class extends ApplicationController { $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/controllers/selectize_controller.js b/app/javascript/controllers/selectize_controller.js index e564f7b..f147161 100644 --- a/app/javascript/controllers/selectize_controller.js +++ b/app/javascript/controllers/selectize_controller.js @@ -16,5 +16,22 @@ export default class extends ApplicationController { } $(".default-selectize").selectize(default_opts) + + var $doctrine_content = $("#doctrineModal").find("input[name='content']") + var $trix_content = $("#doctrineModal").find(".trix-content") + + var doctrine_content_suggestions_opts = { + onChange: function (value) { + if(value === null || value === undefined || value === "") { + $doctrine_content.val("") + $trix_content.val("") + } else { + $doctrine_content.val(value) + $trix_content.val(value) + } + } + }; + + $("#doctine_content_suggestions").selectize($.extend(doctrine_content_suggestions_opts, default_opts)) } } diff --git a/app/javascript/packs/application.js b/app/javascript/packs/application.js index d2a499e..9a92045 100644 --- a/app/javascript/packs/application.js +++ b/app/javascript/packs/application.js @@ -44,24 +44,10 @@ $(document).on("ready turbolinks:load", function () { $(".clickable-tr").on("click", function () { let $href = $(this).attr("href"); - console.log("$href") if ($href !== undefined) { 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/models/cdao/jurisprudence.rb b/app/models/cdao/jurisprudence.rb index f8e627f..0079c12 100644 --- a/app/models/cdao/jurisprudence.rb +++ b/app/models/cdao/jurisprudence.rb @@ -97,6 +97,6 @@ class Cdao::Jurisprudence < Cdao::Base boolean :edited - join(:phil_rep, :target => Doctrine, :type => :string, :join => { :from => :document_id, :to => :id }) + join(:phil_rep, :target => Annotation, :type => :string, :join => { :from => :document_id, :to => :id }) end end diff --git a/app/views/doctrines/search.html.erb b/app/views/doctrines/search.html.erb index 16fc0b6..8c71a3f 100644 --- a/app/views/doctrines/search.html.erb +++ b/app/views/doctrines/search.html.erb @@ -1,4 +1,11 @@
<%= render PaginationComponent.new(data: @doctrines) %>
- <%= render(DocumentDoctrineIndexComponent.with_collection(@doctrines, current_user: current_user, opts: { is_doctrines_index: true, subject_ids: params[:subject_ids] })) %> + + <% if params[:is_index_table].to_s.eql?("true") %> +
+ <%= render(DoctrineIndexTableComponent.new(current_user: current_user, search_results: @doctrines)) %> +
+ <% else %> + <%= render(DocumentDoctrineIndexComponent.with_collection(@doctrines, current_user: current_user, opts: { is_doctrines_index: true, subject_ids: params[:subject_ids] })) %> + <% end %>
diff --git a/app/views/documents/index.html.erb b/app/views/documents/index.html.erb index 40457d9..08bfaff 100644 --- a/app/views/documents/index.html.erb +++ b/app/views/documents/index.html.erb @@ -22,13 +22,13 @@