From 91ec1e2d37e831fec8108c197409ea1f9a342acd Mon Sep 17 00:00:00 2001 From: alexdbondoc17 Date: Thu, 27 Jan 2022 12:31:45 +0000 Subject: [PATCH] Add form `doctrines` and `annotations` --- app/components/analysis_form_component.rb | 12 ++++ .../analysis_form_component.html.erb | 54 ++++++++++++++++ app/components/doctrine_index_component.rb | 25 ++++++++ .../doctrine_index_component.html.erb | 62 ++++++++++++++++++ .../doctrine_modal_form_component.rb | 11 ++++ .../doctrine_modal_form_component.html.erb | 30 +++++++++ app/components/doctrine_show_component.rb | 9 +++ .../doctrine_show_component.html.erb | 64 +++++++++++++++++++ .../document_index_table_component.rb | 3 +- .../document_index_table_component.html.erb | 54 +++++++++++++++- .../doctrine/annotations_controller.rb | 2 +- .../jurisprudence/doctrines_controller.rb | 2 +- app/javascript/packs/application.js | 4 ++ app/views/documents/index.html.erb | 3 +- app/views/documents/show.html.erb | 14 +++- package.json | 1 + yarn.lock | 5 ++ 17 files changed, 346 insertions(+), 9 deletions(-) create mode 100644 app/components/analysis_form_component.rb create mode 100644 app/components/analysis_form_component/analysis_form_component.html.erb create mode 100644 app/components/doctrine_index_component.rb create mode 100644 app/components/doctrine_index_component/doctrine_index_component.html.erb create mode 100644 app/components/doctrine_modal_form_component.rb create mode 100644 app/components/doctrine_modal_form_component/doctrine_modal_form_component.html.erb create mode 100644 app/components/doctrine_show_component.rb create mode 100644 app/components/doctrine_show_component/doctrine_show_component.html.erb diff --git a/app/components/analysis_form_component.rb b/app/components/analysis_form_component.rb new file mode 100644 index 0000000..8e0f855 --- /dev/null +++ b/app/components/analysis_form_component.rb @@ -0,0 +1,12 @@ +class AnalysisFormComponent < BaseComponent + attr_reader :doctrine, :opts + + def initialize(current_user:, doctrine:, opts:) + @doctrine = doctrine + @opts = opts + end + + def render? + doctrine.present? && opts[:form_url].present? && opts[:form_method].present? + end +end diff --git a/app/components/analysis_form_component/analysis_form_component.html.erb b/app/components/analysis_form_component/analysis_form_component.html.erb new file mode 100644 index 0000000..d784ef1 --- /dev/null +++ b/app/components/analysis_form_component/analysis_form_component.html.erb @@ -0,0 +1,54 @@ +
+
+
+ <%= form_for(doctrine, url: opts[:form_url], method: opts[:form_method]) do |doctrine_form| %> + <%= fields_for :annotation, doctrine.annotations.build do |annotation_form| %> +
+
+ <%= doctrine_form.select :subject_ids, options_from_collection_for_select(Cdao::Subject.all, :id, :lineage_name), {}, class: "form-select i-chosen", multiple: true, prompt: "Please select" %> +
+
+ +
+
+ <%= doctrine_form.text_area :content, class: "i-ckeditor form-control", placeholder: "Doctrine" %> +
+
+ +
+
+ +
+ +
+
+
+ <%= text_field_tag :q, nil, class: "form-control", placeholder: "Search GR Number" %> +
+ +
+ <%= button_tag "search", class: "btn btn-primary" %> +
+
+ +
+ + + + + + + + + + <%= render(DocumentIndexTableComponent.with_collection(Cdao::Jurisprudence.first(5), current_user: current_user, opts: { is_case_lists: true, form: annotation_form })) %> + +
Reference No. Date Title
+
+
+ <% end %> + <% end %> +
+
+
\ No newline at end of file diff --git a/app/components/doctrine_index_component.rb b/app/components/doctrine_index_component.rb new file mode 100644 index 0000000..9978825 --- /dev/null +++ b/app/components/doctrine_index_component.rb @@ -0,0 +1,25 @@ +class DoctrineIndexComponent < BaseComponent + with_collection_parameter :doctrine + attr_reader :doctrine + + def initialize(doctrine:, current_user:) + @doctrine = doctrine + end + + delegate :id, to: :doctrine + delegate :subject_ids, to: :doctrine + delegate :content, to: :doctrine + delegate :document_id, to: :doctrine + + def doctrine_form_url + jurisprudence_doctrines_path(jurisprudence_id: document_id) + end + + def annotation_form_url + doctrine_annotations_path(doctrine_id: id) + end + + def doctrine_subjects + doctrine_subjects.group(:subject_id) + end +end \ No newline at end of file diff --git a/app/components/doctrine_index_component/doctrine_index_component.html.erb b/app/components/doctrine_index_component/doctrine_index_component.html.erb new file mode 100644 index 0000000..a46f281 --- /dev/null +++ b/app/components/doctrine_index_component/doctrine_index_component.html.erb @@ -0,0 +1,62 @@ +
+
+
+ <%= form_tag(doctrine_form_url, method: :patch) do %> +
+ <%= label_tag :subject_indexes %> + <%= select_tag "subject_ids[]", options_from_collection_for_select(Cdao::Subject.all, :id, :lineage_name, subject_ids), class: "form-select i-chosen", multiple: true, prompt: "Please select" %> +
+ +
+
+ <%= label_tag :content %> + <%= text_area_tag :content, content, class: "i-ckeditor form-control", placeholder: "Doctrine" %> +
+
+ <% end %> + +
+
+ +
+ +
+
+
+ <%= text_field_tag :q, nil, class: "form-control", placeholder: "Search GR Number" %> +
+ +
+ <%= button_tag "search", class: "btn btn-primary" %> +
+
+ +
+ + + + + + + + + + <%= render(DocumentIndexTableComponent.with_collection(Cdao::Jurisprudence.first(5), current_user: current_user, opts: { is_case_lists: true, form_url: annotation_form_url, document_id: document_id })) %> + +
Reference No. Date Title
+
+
+ + <% doctrine.annotations.each do |annotation| %> +
+
+
+
<%= "#{annotation.annomarks.map { |annomark| "(#{annomark.code})" }.join(" ")} #{[annotation.document.title, annotation.document.reference_number, annotation.document.docdate.strftime("%B %d, %Y"), annotation.phil_rep].join(', ')}" %>
+ Editors Note: <%= annotation.editor_notes %> +
+
+
+ <% end %> +
+
\ No newline at end of file diff --git a/app/components/doctrine_modal_form_component.rb b/app/components/doctrine_modal_form_component.rb new file mode 100644 index 0000000..a5a5c96 --- /dev/null +++ b/app/components/doctrine_modal_form_component.rb @@ -0,0 +1,11 @@ +class DoctrineModalFormComponent < BaseComponent + attr_reader :opts + + def initialize(current_user:, opts:) + @opts = opts + end + + def render? + opts[:form_url].present? && opts[:form_method].present? + end +end \ 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 new file mode 100644 index 0000000..09a6d3f --- /dev/null +++ b/app/components/doctrine_modal_form_component/doctrine_modal_form_component.html.erb @@ -0,0 +1,30 @@ + \ No newline at end of file diff --git a/app/components/doctrine_show_component.rb b/app/components/doctrine_show_component.rb new file mode 100644 index 0000000..9939351 --- /dev/null +++ b/app/components/doctrine_show_component.rb @@ -0,0 +1,9 @@ +class DoctrineShowComponent < BaseComponent + with_collection_parameter :search_result + attr_reader :doctrine, :current_user + + def initialize(doctrine:, current_user:) + @doctrine = doctrine + @current_user = current_user + end +end \ No newline at end of file diff --git a/app/components/doctrine_show_component/doctrine_show_component.html.erb b/app/components/doctrine_show_component/doctrine_show_component.html.erb new file mode 100644 index 0000000..7dee1f8 --- /dev/null +++ b/app/components/doctrine_show_component/doctrine_show_component.html.erb @@ -0,0 +1,64 @@ +
+
+ <%= form_tag(doctrine_form_url, method: :patch) do %> +
+ <%= label_tag :subject_indexes %> + <%= select_tag "subject_ids[]", options_from_collection_for_select(Cdao::Subject.all, :id, :lineage_name, subject_ids), class: "form-select i-chosen", multiple: true, prompt: "Please select" %> +
+ +
+
+ <%= label_tag :content %> + <%= text_area_tag :content, content, class: "i-ckeditor form-control", placeholder: "Doctrine" %> +
+
+ +
+
+ <%= submit_tag "Update Doctrine", class: "btn btn-primary" %> +
+
+ <% end %> + +
+
+ +
+ +
+
+
+ <%= text_field_tag :q, nil, class: "form-control", placeholder: "Search GR Number" %> +
+ +
+ <%= button_tag "search", class: "btn btn-primary" %> +
+
+ +
+ + + + + + + + + + <%= render(DocumentIndexTableComponent.with_collection(Cdao::Jurisprudence.first(5), current_user: current_user, opts: { is_case_lists: true, form_url: annotation_form_url, document_id: document_id })) %> + +
Reference No. Date Title
+
+
+ + <%= form_tag(annotation_form_url, method: :patch) do %> +
+ <%= label_tag :annotation %> + <%%= hidden_tag :document_id, doctrine > + <%= text_area_tag :content, content, class: "i-ckeditor form-control", placeholder: "Doctrine" %> +
+ <%end%> +
+
\ No newline at end of file diff --git a/app/components/document_index_table_component.rb b/app/components/document_index_table_component.rb index 0e7dd2c..3acb933 100644 --- a/app/components/document_index_table_component.rb +++ b/app/components/document_index_table_component.rb @@ -2,8 +2,9 @@ class DocumentIndexTableComponent < BaseComponent with_collection_parameter :search_result attr_reader :search_result, :opts - def initialize(search_result:, current_user:) + def initialize(search_result:, current_user:, opts:) @search_result = search_result + @opts = opts end delegate :reference_number, to: :search_result diff --git a/app/components/document_index_table_component/document_index_table_component.html.erb b/app/components/document_index_table_component/document_index_table_component.html.erb index 8dd4d3e..d1d0b71 100644 --- a/app/components/document_index_table_component/document_index_table_component.html.erb +++ b/app/components/document_index_table_component/document_index_table_component.html.erb @@ -1,6 +1,56 @@ - + <%= reference_number %> <%= title %> <%= date_or_year %> - + <% if opts[:is_case_lists].present? && opts[:form_url].present? && opts[:document_id].present? %> + + + + + + + + <% end %> diff --git a/app/controllers/doctrine/annotations_controller.rb b/app/controllers/doctrine/annotations_controller.rb index 992f805..f607911 100644 --- a/app/controllers/doctrine/annotations_controller.rb +++ b/app/controllers/doctrine/annotations_controller.rb @@ -9,7 +9,7 @@ class Doctrine::AnnotationsController < ApplicationController @annotation = @doctrine.annotations.new(attrs) if document_id.present? - @annotation.document = Cdao::Jurisprudence.find(attrs.delete(:document_id)) + @annotation.document = Cdao::Jurisprudence.find(document_id) end respond_to do |format| diff --git a/app/controllers/jurisprudence/doctrines_controller.rb b/app/controllers/jurisprudence/doctrines_controller.rb index b7b7646..0e99435 100644 --- a/app/controllers/jurisprudence/doctrines_controller.rb +++ b/app/controllers/jurisprudence/doctrines_controller.rb @@ -6,7 +6,7 @@ class Jurisprudence::DoctrinesController < ApplicationController attrs = resource_params.to_unsafe_h.deep_symbolize_keys subject_ids = attrs.delete(:subject_ids) - @doctrine = @jurisprudence.doctrines(attrs) + @doctrine = @jurisprudence.doctrines.new(attrs) respond_to do |format| if @doctrine.save diff --git a/app/javascript/packs/application.js b/app/javascript/packs/application.js index e690518..1528cea 100644 --- a/app/javascript/packs/application.js +++ b/app/javascript/packs/application.js @@ -16,6 +16,7 @@ import "@fortawesome/fontawesome-free/js/all.min"; import "@fortawesome/fontawesome-free/css/all.min"; import "moment"; import "select2"; +import "chosen-js" window.jQuery = $; window.$ = $; @@ -40,8 +41,11 @@ $(document).ready(function () { $(".clickable-tr").on("click", function () { let $href = $(this).attr("href"); + console.log("$href") if ($href !== undefined) { window.open($href); } }) + + $(".i-chosen").chosen({width: "100%"}); }); diff --git a/app/views/documents/index.html.erb b/app/views/documents/index.html.erb index 90890a7..b81b0be 100644 --- a/app/views/documents/index.html.erb +++ b/app/views/documents/index.html.erb @@ -21,8 +21,9 @@ Title Date + - <%= render(DocumentIndexTableComponent.with_collection(@jurisprudences, current_user: current_user)) %> + <%= render(DocumentIndexTableComponent.with_collection(@jurisprudences, current_user: current_user, opts: {})) %>
diff --git a/app/views/documents/show.html.erb b/app/views/documents/show.html.erb index aeff621..165c134 100644 --- a/app/views/documents/show.html.erb +++ b/app/views/documents/show.html.erb @@ -31,11 +31,19 @@ -