Browse Source

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

Enhancement of `documents`, `doctrines`, and `annotations`
pull/20/head
Angel Aviel Domaoan 4 years ago committed by GitHub
parent
commit
dfa8802b55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 24
      app/components/doctrine_index_table_component.rb
  2. 19
      app/components/doctrine_index_table_component/doctrine_index_table_component.html.erb
  3. 9
      app/components/doctrine_modal_form_component/doctrine_modal_form_component.html.erb
  4. 4
      app/components/document_doctrine_show_component.rb
  5. 2
      app/components/document_doctrine_show_component/document_doctrine_show_component.html.erb
  6. 4
      app/components/subjects_sidenav_sub_menu_component.rb
  7. 4
      app/controllers/concerns/jurisprudence_search.rb
  8. 2
      app/controllers/documents_controller.rb
  9. 14
      app/javascript/controllers/document_controller.js
  10. 17
      app/javascript/controllers/selectize_controller.js
  11. 14
      app/javascript/packs/application.js
  12. 2
      app/models/cdao/jurisprudence.rb
  13. 9
      app/views/doctrines/search.html.erb
  14. 6
      app/views/documents/index.html.erb
  15. 2
      app/views/layouts/application.html.erb

24
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

19
app/components/doctrine_index_table_component/doctrine_index_table_component.html.erb

@ -0,0 +1,19 @@
<table class="table table-striped table-hover mb-0">
<thead>
<th class="bg-light"> Reference Number </th>
<th class="bg-light"> Title </th>
<th class="bg-light"> Date </th>
<th class="bg-light"> PhilRep </th>
</thead>
<tbody>
<% search_results.each do |search_result| %>
<tr href="<%= document_path(search_result.document_id) %>" class="clickable-tr">
<td> <%= document_reference_number(search_result.document) %> </td>
<td> <%= document_title(search_result.document) %> </td>
<td> <%= date_or_year(search_result.document) %> </td>
<td> <%= search_result.annotations.map(&:phil_rep).join(", ") %> </td>
</tr>
<% end %>
</tbody>
</table>

9
app/components/doctrine_modal_form_component/doctrine_modal_form_component.html.erb

@ -15,10 +15,17 @@
</div>
</div>
<div class="row">
<div class="col-sm-12 p-2">
<strong> <%= label_tag :doctine_content_suggestions %> </strong>
<%= select_tag :doctine_content_suggestions, options_from_collection_for_select(Doctrine.all, :content, :content), class: "form-select", prompt: "Please select" %>
</div>
</div>
<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", data: { controller: "document", target: "document.input", action: "keyup->document#suggestDoctrine" } %>
<%= rich_text_area_tag :content, doctrine.content, placeholder: "Doctrine Content" %>
</div>
</div>
</div>

4
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?

2
app/components/document_doctrine_show_component/document_doctrine_show_component.html.erb

@ -12,7 +12,7 @@
</div>
<div class="container-sm row-flex col-sm-12 mt-2">
<%= 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" })) %>
</div>
</div>

4
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

4
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?

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, :phil_rep, :year)
:subject_ids, :phil_rep, :scra, :year)
end
end

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

17
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))
}
}

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

2
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

9
app/views/doctrines/search.html.erb

@ -1,4 +1,11 @@
<div class="card container-sm mt-1 p-0">
<div class="container m-2"> <%= render PaginationComponent.new(data: @doctrines) %> </div>
<%= 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") %>
<div class="card-body col-sm-12 tableFixHead p-0 mt-1">
<%= render(DoctrineIndexTableComponent.new(current_user: current_user, search_results: @doctrines)) %>
</div>
<% else %>
<%= render(DocumentDoctrineIndexComponent.with_collection(@doctrines, current_user: current_user, opts: { is_doctrines_index: true, subject_ids: params[:subject_ids] })) %>
<% end %>
</div>

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

@ -22,13 +22,13 @@
<div class="modal-body">
<div class="row">
<div class="col-sm-6 p-2">
<strong> <%= label_tag :phil_rep %> </strong>
<%= text_field_tag "Phil Rep", params[:phil_rep], class: "form-control" %>
<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 "SCRA" %> </strong>
<%= text_field_tag "SCRA", params[:scra], class: "form-control" %>
<%= text_field_tag :scra, params[:scra], class: "form-control" %>
</div>
</div>

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">
<body class="container-fluid h-100 w-100 p-0" data-controller="selectize">
<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? %>

Loading…
Cancel
Save