Browse Source

Add form `doctrines` and `annotations`

pull/9/head
alexdbondoc17 4 years ago committed by Angel Aviel Domaoan
parent
commit
cd20805100
  1. 12
      app/components/analysis_form_component.rb
  2. 54
      app/components/analysis_form_component/analysis_form_component.html.erb
  3. 25
      app/components/doctrine_index_component.rb
  4. 62
      app/components/doctrine_index_component/doctrine_index_component.html.erb
  5. 11
      app/components/doctrine_modal_form_component.rb
  6. 30
      app/components/doctrine_modal_form_component/doctrine_modal_form_component.html.erb
  7. 9
      app/components/doctrine_show_component.rb
  8. 64
      app/components/doctrine_show_component/doctrine_show_component.html.erb
  9. 3
      app/components/document_index_table_component.rb
  10. 54
      app/components/document_index_table_component/document_index_table_component.html.erb
  11. 2
      app/controllers/doctrine/annotations_controller.rb
  12. 2
      app/controllers/jurisprudence/doctrines_controller.rb
  13. 4
      app/javascript/packs/application.js
  14. 3
      app/views/documents/index.html.erb
  15. 14
      app/views/documents/show.html.erb
  16. 1
      package.json
  17. 5
      yarn.lock

12
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

54
app/components/analysis_form_component/analysis_form_component.html.erb

@ -0,0 +1,54 @@
<div class="card">
<div class="card-body pd-0">
<div class="row">
<%= form_for(doctrine, url: opts[:form_url], method: opts[:form_method]) do |doctrine_form| %>
<%= fields_for :annotation, doctrine.annotations.build do |annotation_form| %>
<div class="row">
<div class="col-sm-11 p-2">
<%= 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" %>
</div>
</div>
<div class="row">
<div class="col-sm-11 p-2">
<%= doctrine_form.text_area :content, class: "i-ckeditor form-control", placeholder: "Doctrine" %>
</div>
</div>
<div class="row">
<div class="col-sm-11 p-2">
<button type="button" class="btn btn-primary" data-bs-toggle="collapse" data-bs-target="#caseListsCollapse" aria-expanded="false" aria-controls="collapseExample"> Case Lists </button
</div>
</div>
<div class="collapse" id="caseListsCollapse">
<div class="row">
<div class="col-sm-10 p-2">
<%= text_field_tag :q, nil, class: "form-control", placeholder: "Search GR Number" %>
</div>
<div class="col-sm-1 p-2">
<%= button_tag "search", class: "btn btn-primary" %>
</div>
</div>
<div class="row tab">
<table class="table table-striped table-hover mb-0">
<thead>
<th class="bg-light"> Reference No. </th>
<th class="bg-light"> Date </th>
<th class="bg-light"> Title </th>
<th class="bg-light"> </th>
</thead>
<tbody>
<%= render(DocumentIndexTableComponent.with_collection(Cdao::Jurisprudence.first(5), current_user: current_user, opts: { is_case_lists: true, form: annotation_form })) %>
</tbody>
</table>
</div>
</div>
<% end %>
<% end %>
</div>
</div>
</div>

25
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

62
app/components/doctrine_index_component/doctrine_index_component.html.erb

@ -0,0 +1,62 @@
<div class="card">
<div class="card-header"> </div>
<div class="card-body">
<%= form_tag(doctrine_form_url, method: :patch) do %>
<div class="row">
<%= 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" %>
</div>
<div class="row">
<div class="col-sm-12 p-2">
<%= label_tag :content %>
<%= text_area_tag :content, content, class: "i-ckeditor form-control", placeholder: "Doctrine" %>
</div>
</div>
<% end %>
<div class="row">
<div class="col-sm-12 p-2">
<button type="button" class="btn btn-primary" data-bs-toggle="collapse" data-bs-target="#caseListsCollapse" aria-expanded="false" aria-controls="collapseExample"> Case Lists </button
</div>
</div>
<div class="collapse" id="caseListsCollapse">
<div class="row">
<div class="col-sm-10 p-2">
<%= text_field_tag :q, nil, class: "form-control", placeholder: "Search GR Number" %>
</div>
<div class="col-sm-1 p-2">
<%= button_tag "search", class: "btn btn-primary" %>
</div>
</div>
<div class="row tab">
<table class="table table-striped table-hover mb-0">
<thead>
<th class="bg-light"> Reference No. </th>
<th class="bg-light"> Date </th>
<th class="bg-light"> Title </th>
<th class="bg-light"> </th>
</thead>
<tbody>
<%= 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 })) %>
</tbody>
</table>
</div>
</div>
<% doctrine.annotations.each do |annotation| %>
<div class="row">
<div class="card col-sm-12">
<div class="card-header p-1">
<h6> <%= "#{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(', ')}" %> </h6>
<span class="m-3"> Editors Note: <%= annotation.editor_notes %> </span>
</div>
</div>
</div>
<% end %>
</div>
</div>

11
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

30
app/components/doctrine_modal_form_component/doctrine_modal_form_component.html.erb

@ -0,0 +1,30 @@
<div class="modal fade" id="doctrineModal" tabindex="-1" aria-labelledby="doctrineModal" aria-hidden="true">
<div class="modal-dialog w-100">
<div class="modal-content w-100">
<%= form_tag(opts[:form_url], method: opts[:form_method]) do %>
<div class="modal-header">
<h4> Add New Doctrine </h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-sm-12 p-2">
<%= select_tag "subject_ids[]", options_from_collection_for_select(Cdao::Subject.all, :id, :lineage_name, params[:subject_ids]), class: "form-select i-chosen", multiple: true, prompt: "Please select" %>
</div>
</div>
<div class="row">
<div class="col-sm-12 p-2">
<%= text_area_tag :content, params[:content], class: "i-ckeditor form-control", placeholder: "Doctrine" %>
</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary">Save</button>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
</div>
<% end %>
</div>
</div>
</div>

9
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

64
app/components/doctrine_show_component/doctrine_show_component.html.erb

@ -0,0 +1,64 @@
<div class="card">
<div class="card-body">
<%= form_tag(doctrine_form_url, method: :patch) do %>
<div class="row">
<%= 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" %>
</div>
<div class="row">
<div class="col-sm-12 p-2">
<%= label_tag :content %>
<%= text_area_tag :content, content, class: "i-ckeditor form-control", placeholder: "Doctrine" %>
</div>
</div>
<div class="row">
<div class="col-sm-12 p-2">
<%= submit_tag "Update Doctrine", class: "btn btn-primary" %>
</div>
</div>
<% end %>
<div class="row">
<div class="col-sm-12 p-2">
<button type="button" class="btn btn-primary" data-bs-toggle="collapse" data-bs-target="#caseListsCollapse" aria-expanded="false" aria-controls="collapseExample"> Case Lists </button
</div>
</div>
<div class="collapse" id="caseListsCollapse">
<div class="row">
<div class="col-sm-10 p-2">
<%= text_field_tag :q, nil, class: "form-control", placeholder: "Search GR Number" %>
</div>
<div class="col-sm-1 p-2">
<%= button_tag "search", class: "btn btn-primary" %>
</div>
</div>
<div class="row tab">
<table class="table table-striped table-hover mb-0">
<thead>
<th class="bg-light"> Reference No. </th>
<th class="bg-light"> Date </th>
<th class="bg-light"> Title </th>
<th class="bg-light"> </th>
</thead>
<tbody>
<%= 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 })) %>
</tbody>
</table>
</div>
</div>
<%= form_tag(annotation_form_url, method: :patch) do %>
<div class="row">
<%= label_tag :annotation %>
<%%= hidden_tag :document_id, doctrine >
<%= text_area_tag :content, content, class: "i-ckeditor form-control", placeholder: "Doctrine" %>
</div>
<%end%>
</div>
</div>

3
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

54
app/components/document_index_table_component/document_index_table_component.html.erb

@ -1,6 +1,56 @@
<tr href="<%= document_path(search_result) %>" class="clickable-tr">
<tr href="<%= document_path(search_result) %>" class="<%= opts.reject{ |k, v| v.blank? }.blank? ? 'clickable-tr' : ''%>">
<td> <%= reference_number %> </td>
<td> <%= title %> </td>
<td> <%= date_or_year %> </td>
<td></td>
<% if opts[:is_case_lists].present? && opts[:form_url].present? && opts[:document_id].present? %>
<td>
<a class="btn btn-sm btn-primary" data-bs-toggle="modal" data-bs-target="#annotationModal">
<i class="fas fa-plus-circle" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Add"></i>
</a>
<div class="modal fade" id="annotationModal" tabindex="-1" aria-labelledby="annotationModal" aria-hidden="true">
<div class="modal-dialog modal-dialog-scrollable w-50">
<div class="modal-header"> Create Annotations </div>
<div class="modal-content">
<%= form_tag(opts[:form_url], method: :post) do%>
<div class="modal-body">
<div class="row">
<div class="col-sm-12 p-2">
<%= label_tag :annotation_marks %>
<%= hidden_field_tag :document_id, opts[:document_id] %>
<%= select_tag "annomark_ids[]", options_from_collection_for_select(Annomark.all, :id, :name, params[:annomark_ids]), class: "form-select i-chosen", multiple: true, prompt: "Please select" %>
</div>
</div>
<div class="row">
<div class="col-sm-12 p-2">
<%= label_tag :document_title %>
<%= text_area_tag :document_title, [title, reference_number, date_or_year].join(","), class: "form-control" %>
</div>
</div>
<div class="row">
<div class="col-sm-12 p-2">
<%= label_tag :phil_rep %>
<%= text_field_tag :phil_rep, params[:phil_rep], class: "form-control" %>
</div>
</div>
<div class="row">
<div class="col-sm-12 p-2">
<%= label_tag :editor_notes %>
<%= text_area_tag :editor_notes, params[:editors_note], class: "form-control i-ckeditor" %>
</div>
</div>
</div>
<div class="modal-footer">
<%= submit_tag "Save", class: "btn btn-primary" %>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
</div>
<% end %>
</div>
</div>
</div>
</td>
<% end %>
</tr>

2
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|

2
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

4
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%"});
});

3
app/views/documents/index.html.erb

@ -21,8 +21,9 @@
<th class="bg-light"> Title </th>
<th class="bg-light"> Date </th>
</thead>
<tbody>
<%= render(DocumentIndexTableComponent.with_collection(@jurisprudences, current_user: current_user)) %>
<%= render(DocumentIndexTableComponent.with_collection(@jurisprudences, current_user: current_user, opts: {})) %>
</tbody>
</table>
</div>

14
app/views/documents/show.html.erb

@ -31,11 +31,19 @@
</li>
</ul>
<div class="tab-content" id="menuTabContent">
<div class="tab-content">
<div class="tab-pane fade show active" id="analysisTabContent" role="tabpanel" aria-labelledby="home-tab">
<div class="container-fluid">
<div class="justify-content-end">
<a> <i class="fas fa-plus-circle"></i> </a>
<div class="row-flex col-sm-12 end-0">
<a class="btn btn-sm btn-primary" data-bs-toggle="modal" data-bs-target="#doctrineModal">
<i class="fas fa-plus-circle" data-toggle="tooltip" data-placement="bottom" title="New Doctrine"></i>
</a>
<%= render(DoctrineModalFormComponent.new(current_user: current_user, opts: { form_url: jurisprudence_doctrines_path(jurisprudence_id: @document.id), form_method: :post })) %>
</div>
<div class="row-flex col-sm-12 mt-2">
<%= render(DoctrineIndexComponent.with_collection(@doctrines, current_user: current_user)) %>
</div>
</div>
</div>

1
package.json

@ -9,6 +9,7 @@
"@rails/ujs": "^6.0.0",
"@rails/webpacker": "5.4.3",
"bootstrap": "^5.1.3",
"chosen-js": "^1.8.7",
"flatpickr": "^4.6.9",
"font-awesome": "^4.7.0",
"jquery": "^3.6.0",

5
yarn.lock generated

@ -1856,6 +1856,11 @@ chokidar@^2.1.8:
optionalDependencies:
fsevents "^1.2.7"
chosen-js@^1.8.7:
version "1.8.7"
resolved "https://registry.yarnpkg.com/chosen-js/-/chosen-js-1.8.7.tgz#9bfa5597f5081d602ff4ae904af9aef33265bb1d"
integrity sha512-eVdrZJ2U5ISdObkgsi0od5vIJdLwq1P1Xa/Vj/mgxkMZf14DlgobfB6nrlFi3kW4kkvKLsKk4NDqZj1MU1DCpw==
chownr@^1.1.1:
version "1.1.4"
resolved "https://registry.yarnpkg.com/chownr/-/chownr-1.1.4.tgz#6fc9d7b42d32a583596337666e7d08084da2cc6b"

Loading…
Cancel
Save