Browse Source

Add UI for `documents`

pull/6/head
alexdbondoc17 4 years ago committed by Angel Aviel Domaoan
parent
commit
bce717fce1
  1. 17
      app/components/document_index_table_component.rb
  2. 6
      app/components/document_index_table_component/document_index_table_component.html.erb
  3. 2
      app/components/sidenav_component/sidenav_component.html.erb
  4. 35
      app/controllers/documents_controller.rb
  5. 7
      app/javascript/packs/application.js
  6. 16
      app/javascript/src/application.scss
  7. 32
      app/views/documents/index.html.erb
  8. 52
      app/views/documents/show.html.erb
  9. 1
      config/routes.rb

17
app/components/document_index_table_component.rb

@ -0,0 +1,17 @@
class DocumentIndexTableComponent < BaseComponent
with_collection_parameter :search_result
attr_reader :search_result, :opts
def initialize(search_result:, current_user:)
@search_result = search_result
end
delegate :reference_number, to: :search_result
delegate :title, to: :search_result
def date_or_year
return search_result.docdate.strftime("%m/%d/%Y") if search_result.docdate.present?
search_result.year
end
end

6
app/components/document_index_table_component/document_index_table_component.html.erb

@ -0,0 +1,6 @@
<tr href="<%= document_path(search_result) %>" class="clickable-tr">
<td> <%= reference_number %> </td>
<td> <%= title %> </td>
<td> <%= date_or_year %> </td>
<td></td>
</tr>

2
app/components/sidenav_component/sidenav_component.html.erb

@ -1,7 +1,7 @@
<% if @current_user.present? %> <% if @current_user.present? %>
<div class="accordion accordion-flush flex-column align-items-stretch p-3 overflow-auto sidenav" id="sidenav"> <div class="accordion accordion-flush flex-column align-items-stretch p-3 overflow-auto sidenav" id="sidenav">
<div class="accordion-item"> <h5 class="accordion-header"> <%= link_to "Home", root_path, class: "text-dark" %> </h5> </div> <div class="accordion-item"> <h5 class="accordion-header"> <%= link_to "Home", root_path, class: "text-dark" %> </h5> </div>
<div class="accordion-item"> <h5 class="accordion-header"> <%= link_to "Search", "#", class: "text-dark" %> </h5> </div> <div class="accordion-item"> <h5 class="accordion-header"> <%= link_to "Search", documents_path, class: "text-dark" %> </h5> </div>
<div class="accordion-item"> <div class="accordion-item">
<h5 class="accordion-header"> <h5 class="accordion-header">

35
app/controllers/documents_controller.rb

@ -0,0 +1,35 @@
class DocumentsController < ApplicationController
load_and_authorize_resource :document, class: "Cdao::Jurisprudence"
def index
attrs = %i[id reference_number title docdate ponente edited short_title year].freeze
fulltext_fields = %i[reference_number title short_title].freeze
search = Cdao::Jurisprudence.search do
fulltext search_params[:q], fields: fulltext_fields if search_params[:q].present?
fulltext_fields.each do |field|
fulltext search_params[field], fields: [field] if search_params[field].present?
end
order_by :doc_date
order_by :year
paginate page: params[:page] || 1, per_page: params[:per_page] || 20
end
@jurisprudences = search.results
respond_to do |format|
format.html
end
end
def show; end
private
def search_params
params.permit(:reference_number, :title, :short_title, :q, :page, :per_page)
end
end

7
app/javascript/packs/application.js

@ -37,4 +37,11 @@ $(document).ready(function () {
window.location.href = $href; window.location.href = $href;
} }
}); });
$(".clickable-tr").on("click", function () {
let $href = $(this).attr("href");
if ($href !== undefined) {
window.open($href);
}
})
}); });

16
app/javascript/src/application.scss

@ -1,2 +1,18 @@
@import "~bootstrap/scss/bootstrap"; @import "~bootstrap/scss/bootstrap";
@import "./application/sidenav"; @import "./application/sidenav";
.tableFixHead {
overflow: auto;
height: 680px;
width: 240px;
}
.tableFixHead thead th {
position: sticky;
top: 0;
}
.tableFixHead tbody th {
position: sticky;
left: 0;
}

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

@ -0,0 +1,32 @@
<div class="card mt-2 g-3">
<div class="card-header mt-1 col-sm-12">
<%= form_tag(documents_path, method: :get) do %>
<div class="row">
<div class="col-sm-8 p-2">
<div class="form-floating">
<%= text_field_tag :q, params[:q], class: "form-control" %>
</div>
</div>
<div class="col-sm-4 p-2">
<%= submit_tag "Search", class: "btn btn-primary text-dark" %>
<button class="btn btn-info"> Advanced Search </button>
</div>
</div>
<% end %>
</div>
<div class="card-body col-sm-12 tableFixHead p-0 mt-1">
<table class="table table-striped table-hover mb-0">
<thead>
<th class="bg-light"> Reference No. </th>
<th class="bg-light"> Title </th>
<th class="bg-light"> Date </th>
<th class="bg-light"> Subject </th>
</thead>
<tbody>
<%= render(DocumentIndexTableComponent.with_collection(@jurisprudences, current_user: current_user)) %>
</tbody>
</table>
</div>
</div>

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

@ -0,0 +1,52 @@
<div class="card mt-1 g-3">
<div class="card-header mt-1 mb-2 col-sm-12">
<table class="table table-borderless">
<tbody>
<tr>
<td class="text-start" style="width: 160px;"> Reference Number: </td>
<td class="text-start"> <strong> <%= @document.reference_number %> </strong> </td>
<td class="text-end" style="width: 50px;" > Date: </td>
<td class="text-end" style="width: 160px;"> <strong> <%= @document.docdate.present? ? @document.docdate.strftime("%m/%d/%Y") : @document.year %> </strong> </td>
</tr>
<tr>
<td style="width: 160px;" class="text-start"> Title: </td>
<td colspan="3" class="text-start"> <strong> <%= @document.title %> </strong> </td>
</tr>
</tbody>
</table>
</div>
<div class="card-body">
<ul class="nav nav-tabs" id="menuTab" role="tablist">
<li class="nav-item" role="presentation">
<button class="nav-link active" id="analysisMenuTab" data-bs-toggle="tab" data-bs-target="#analysisTabContent" type="button" role="tab" aria-controls="analysisTab" aria-selected="true">Analysis</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="analysisMenuTab" data-bs-toggle="tab" data-bs-target="#documentTabContent" type="button" role="tab" aria-controls="analysisTab" aria-selected="true">Full Text</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="analysisMenuTab" data-bs-toggle="tab" data-bs-target="#ciatatonTabContent" type="button" role="tab" aria-controls="analysisTab" aria-selected="true">Citator</button>
</li>
</ul>
<div class="tab-content" id="menuTabContent">
<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>
</div>
</div>
<div class="tab-pane fade" id="documentTabContent" role="tabpanel">
<span> Full Text </span>
</div>
<div class="tab-pane fade" id="ciatatonTabContent" role="tabpanel">
<span> Citator </span>
</div>
</div>
</div>
</div>

1
config/routes.rb

@ -4,6 +4,7 @@ Rails.application.routes.draw do
root to: "home#index" root to: "home#index"
resources :case_doctrines resources :case_doctrines
resources :documents, only: %i[index show]
resources :decisions resources :decisions
resources :subject_indexes resources :subject_indexes

Loading…
Cancel
Save