Browse Source

Merge pull request #18 from lexintegritastech/improve-main-ui

Implement Fixes
pull/19/head
Angel Aviel Domaoan 4 years ago committed by GitHub
parent
commit
85454b33f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      app/components/annotation_marks_modal_form_component.rb
  2. 14
      app/components/annotation_marks_modal_form_component/annotation_marks_modal_form_component.html.erb
  3. 2
      app/components/doctrine_modal_form_component/doctrine_modal_form_component.html.erb
  4. 12
      app/components/document_doctrine_index_component.rb
  5. 2
      app/components/document_doctrine_index_component/document_doctrine_index_component.html.erb
  6. 12
      app/components/document_doctrine_show_component.rb
  7. 21
      app/components/document_doctrine_show_component/document_doctrine_show_component.html.erb
  8. 22
      app/components/subject_accordion_component/subject_accordion_component.html.erb
  9. 2
      app/controllers/concerns/jurisprudence_search.rb
  10. 20
      app/controllers/doctrine/annotations_controller.rb
  11. 2
      app/controllers/doctrines_controller.rb
  12. 2
      app/controllers/documents_controller.rb
  13. 29
      app/javascript/controllers/document_controller.js
  14. 13
      app/javascript/packs/application.js
  15. 12
      app/javascript/src/application.scss
  16. 9
      app/models/annotation.rb
  17. 2
      app/models/cdao/jurisprudence.rb
  18. 2
      app/models/doctrine.rb
  19. 8
      app/views/documents/index.html.erb
  20. 2
      app/views/layouts/application.html.erb
  21. 6
      app/views/subject_indexes/index.html.erb
  22. 2
      app/views/subject_indexes/show.html.erb

12
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

14
app/components/annotation_marks_modal_form_component/annotation_marks_modal_form_component.html.erb

@ -11,6 +11,7 @@
<div class="col-sm-12 p-2">
<strong> <%= label_tag :annotation_marks %> </strong>
<%= 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" %>
</div>
</div>
@ -18,14 +19,7 @@
<div class="row">
<div class="col-sm-12 p-2">
<strong> <%= label_tag :document_title %> </strong>
<%= text_area_tag :document_title, document_title, class: "form-control selected-citing-docs" %>
</div>
</div>
<div class="row">
<div class="col-sm-12 p-2">
<strong> Selected Citing Documents </strong>
<%= 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" %>
</div>
</div>
@ -54,8 +48,8 @@
</div>
<div class="row">
<div class="col-sm-12 p-2">
<strong> <%= label_tag :phil_rep %> </strong>
<div class="form-floating col-sm-12 p-2">
<%= label_tag :phil_rep %>
<%= text_field_tag :phil_rep, annotation.phil_rep, class: "form-control" %>
</div>
</div>

2
app/components/doctrine_modal_form_component/doctrine_modal_form_component.html.erb

@ -18,7 +18,7 @@
<div class="row">
<div class="col-sm-12 p-2">
<strong> <%= label_tag :content %> </strong>
<%= 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" } %>
</div>
</div>
</div>

12
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

2
app/components/document_doctrine_index_component/document_doctrine_index_component.html.erb

@ -18,7 +18,7 @@
<% annotations.each do |annotation| %>
<p class="mb-0">
<strong> <%= "#{annotation.annomarks.map { |annomark| "(#{annomark.code})" }.join(" ")}" %> </strong>
<%= 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(', ') %>
</p>
<% if annotation.editor_notes.present? %>

12
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

21
app/components/document_doctrine_show_component/document_doctrine_show_component.html.erb

@ -18,14 +18,22 @@
<div class="card-body">
<div class="row">
<strong> <%= label_tag :subjects %> </strong>
<%= 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 %>
<div class="col-sm-2" style="width: 100px;">
<strong> Subjects: </strong>
</div>
<div class="col-sm-10">
<%= subjects.map(&:lineage_name).join(" & ") %>
</div>
</div>
<div class="row">
<div class="col-sm-12 p-2">
<strong> <%= label_tag :content %> </strong>
<%= rich_text_area_tag :content, content, placeholder: "Doctrine Content", readonly: true %>
<div class="col-sm-2" style="width: 100px;">
<strong> Content: </strong>
</div>
<div class="col-sm-10">
<%= raw content %>
</div>
</div>
@ -72,6 +80,7 @@
<div class="col-sm-12 p-2">
<strong> <%= label_tag :annotation_marks %> </strong>
<%= 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" %>
</div>
</div>
@ -117,7 +126,7 @@
<div class="row">
<div class="col-sm-12 p-2">
<strong> <%= label_tag :editor_notes %> </strong>
<trix-editor id="editor_notes" placeholder="Doctrine Content"> </trix-editor>
<trix-editor id="editor_notes" placeholder="Editor Notes"> </trix-editor>
</div>
</div>
</div>

22
app/components/subject_accordion_component/subject_accordion_component.html.erb

@ -1,15 +1,15 @@
<% parent.children.each do |sub1| %>
<div class="accordion accordion-flush ps-20" id="#secondLevelPanel<%= sub1.id %>">
<div class="accordion-item">
<div class="accordion-header">
<div class="accordion-header d-flex justify-content-between">
<% if sub1.children.present? %>
<div class="accordion-button collapsed" data-bs-toggle="collapse" data-bs-target="#<%= ["secondLevel", sub1.id].join %>">
<%= 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-4" %>
<%= 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-5" %>
</div>
<% 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 %>
</div>
@ -18,15 +18,15 @@
<% sub1.children.each do |sub2| %>
<div class="accordion accordion-flush ps-20" id="thirdLevelPanel<%= sub2.id %>">
<div class="accordion-item">
<div class="accordion-header">
<div class="accordion-header d-flex justify-content-between">
<% if sub1.children.present? %>
<div class="accordion-button collapsed" data-bs-toggle="collapse" data-bs-target="#<%= ["thirdLevel", sub2.id].join %>">
<%= 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-4" %>
<%= 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-5" %>
</div>
<% 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 %>
</div>
@ -35,15 +35,15 @@
<% sub2.children.each do |sub3| %>
<div class="accordion accordion-flush ps-20" id="fourthLevelPanel<%= sub3.id %>">
<div class="accordion-item">
<div class="accordion_header">
<div class="accordion-header d-flex justify-content-between">
<% if sub3.children.present? %>
<div class="<%= sub3.children.present? ? 'accordion-button' : '' %> collapsed" data-bs-toggle="collapse" data-bs-target="#<%= ["fourthLevel", sub3.id].join %>">
<%= 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-4" %>
<%= 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-5" %>
</div>
<% 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 %>
</div>
@ -51,10 +51,10 @@
<div class="accordion-body pt-1">
<% sub3.children.each do |sub4| %>
<div class="accordion accordion-flush ps-20">
<div class="accordion-item">
<div class="accordion-item d-flex justify-content-between">
<div>
<%= 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" %>
</div>
</div>
</div>

2
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

20
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

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

2
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

29
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])
}
});
}
}

13
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"

12
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;
}

9
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

2
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

2
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

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

@ -22,18 +22,18 @@
<div class="modal-body">
<div class="row">
<div class="col-sm-6 p-2">
<strong> <%= label_tag :subjects %> </strong>
<strong> <%= label_tag :phil_rep %> </strong>
<%= text_field_tag "Phil Rep", params[:phil_rep], class: "form-control" %>
</div>
<div class="col-sm-6 p-2">
<strong> <%= label_tag :subjects %> </strong>
<strong> <%= label_tag "SCRA" %> </strong>
<%= text_field_tag "SCRA", params[:scra], class: "form-control" %>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary">Save</button>
<button type="submit" class="btn btn-primary">Search</button>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
</div>
</div>
@ -46,7 +46,7 @@
</div>
<div class="card-body col-sm-12 tableFixHead p-0 mt-1">
<% if @search_params.reject { |k, v| v.blank? }.present? %>
<% if @search_params.present? %>
<div class="container m-2"> <%= render PaginationComponent.new(data: @jurisprudences) %> </div>
<table class="table table-striped table-hover mb-0">
<thead>

2
app/views/layouts/application.html.erb

@ -11,7 +11,7 @@
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
</head>
<body class="container-fluid h-100 w-100 p-0" data-controller="selectize">
<body class="container-fluid h-100 w-100 p-0">
<div class="<%= current_user.present? ? 'row flex-nowrap h-100 w-100 p-0 ms-0' : 'row h-100 justify-content-center align-items-center' %>">
<% if current_user.present? %>

6
app/views/subject_indexes/index.html.erb

@ -7,15 +7,15 @@
<% Cdao::Subject.roots.all.each do |root| %>
<div class="accordion accordion-flash" id="mainPanel<%= root.id %>">
<div class="accordion-item">
<div class="accordion-header">
<div class="accordion-header d-flex justify-content-between">
<% if root.children.present? %>
<div class="accordion-button collapsed m-0 p-0" data-bs-toggle="collapse" data-bs-target="#<%= ["rootLevel", root.id].join %>">
<%= 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-4" %>
<%= 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-5" %>
</div>
<% 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 %>
</div>

2
app/views/subject_indexes/show.html.erb

@ -16,7 +16,7 @@
<td class="text-start"> Name: </td>
<td class="text-start"> <strong> <%= @subject_index.name %> </strong> </td>
<td class="text-start"> Parent Subject: </td>
<td class="text-start"> <strong> <%= @subject_index.parent.lineage_name %> </strong> </td>
<td class="text-start"> <strong> <%= @subject_index.is_root? ? "N/A" : @subject_index.parent.lineage_name %> </strong> </td>
</tr>
</tbody>
</table>

Loading…
Cancel
Save