From bce717fce1de49928ae843071d5880af9205db50 Mon Sep 17 00:00:00 2001 From: alexdbondoc17 Date: Wed, 26 Jan 2022 00:49:27 +0000 Subject: [PATCH] Add UI for `documents` --- .../document_index_table_component.rb | 17 ++++++ .../document_index_table_component.html.erb | 6 +++ .../sidenav_component.html.erb | 2 +- app/controllers/documents_controller.rb | 35 +++++++++++++ app/javascript/packs/application.js | 7 +++ app/javascript/src/application.scss | 16 ++++++ app/views/documents/index.html.erb | 32 ++++++++++++ app/views/documents/show.html.erb | 52 +++++++++++++++++++ config/routes.rb | 1 + 9 files changed, 167 insertions(+), 1 deletion(-) create mode 100644 app/components/document_index_table_component.rb create mode 100644 app/components/document_index_table_component/document_index_table_component.html.erb create mode 100644 app/controllers/documents_controller.rb create mode 100644 app/views/documents/index.html.erb create mode 100644 app/views/documents/show.html.erb diff --git a/app/components/document_index_table_component.rb b/app/components/document_index_table_component.rb new file mode 100644 index 0000000..0e7dd2c --- /dev/null +++ b/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 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 new file mode 100644 index 0000000..8dd4d3e --- /dev/null +++ b/app/components/document_index_table_component/document_index_table_component.html.erb @@ -0,0 +1,6 @@ + + <%= reference_number %> + <%= title %> + <%= date_or_year %> + + diff --git a/app/components/sidenav_component/sidenav_component.html.erb b/app/components/sidenav_component/sidenav_component.html.erb index caaed68..a4e0444 100644 --- a/app/components/sidenav_component/sidenav_component.html.erb +++ b/app/components/sidenav_component/sidenav_component.html.erb @@ -1,7 +1,7 @@ <% if @current_user.present? %>
<%= link_to "Home", root_path, class: "text-dark" %>
-
<%= link_to "Search", "#", class: "text-dark" %>
+
<%= link_to "Search", documents_path, class: "text-dark" %>
diff --git a/app/controllers/documents_controller.rb b/app/controllers/documents_controller.rb new file mode 100644 index 0000000..0b13bc8 --- /dev/null +++ b/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 diff --git a/app/javascript/packs/application.js b/app/javascript/packs/application.js index 7d088c5..e690518 100644 --- a/app/javascript/packs/application.js +++ b/app/javascript/packs/application.js @@ -37,4 +37,11 @@ $(document).ready(function () { window.location.href = $href; } }); + + $(".clickable-tr").on("click", function () { + let $href = $(this).attr("href"); + if ($href !== undefined) { + window.open($href); + } + }) }); diff --git a/app/javascript/src/application.scss b/app/javascript/src/application.scss index 278b453..9e8e59d 100644 --- a/app/javascript/src/application.scss +++ b/app/javascript/src/application.scss @@ -1,2 +1,18 @@ @import "~bootstrap/scss/bootstrap"; @import "./application/sidenav"; + +.tableFixHead { + overflow: auto; + height: 680px; + width: 240px; +} + +.tableFixHead thead th { + position: sticky; + top: 0; +} + +.tableFixHead tbody th { + position: sticky; + left: 0; +} diff --git a/app/views/documents/index.html.erb b/app/views/documents/index.html.erb new file mode 100644 index 0000000..481ce4f --- /dev/null +++ b/app/views/documents/index.html.erb @@ -0,0 +1,32 @@ +
+
+ <%= form_tag(documents_path, method: :get) do %> +
+
+
+ <%= text_field_tag :q, params[:q], class: "form-control" %> +
+
+ +
+ <%= submit_tag "Search", class: "btn btn-primary text-dark" %> + +
+
+ <% end %> +
+ +
+ + + + + + + + + <%= render(DocumentIndexTableComponent.with_collection(@jurisprudences, current_user: current_user)) %> + +
Reference No. Title Date Subject
+
+
diff --git a/app/views/documents/show.html.erb b/app/views/documents/show.html.erb new file mode 100644 index 0000000..aeff621 --- /dev/null +++ b/app/views/documents/show.html.erb @@ -0,0 +1,52 @@ +
+
+ + + + + + + + + + + + + + +
Reference Number: <%= @document.reference_number %> Date: <%= @document.docdate.present? ? @document.docdate.strftime("%m/%d/%Y") : @document.year %>
Title: <%= @document.title %>
+
+ + +
+ + + +
+
diff --git a/config/routes.rb b/config/routes.rb index 9592ae3..499649c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,6 +4,7 @@ Rails.application.routes.draw do root to: "home#index" resources :case_doctrines + resources :documents, only: %i[index show] resources :decisions resources :subject_indexes