From 0e8da90449414577b104de6c6ac25cf460a712fa Mon Sep 17 00:00:00 2001 From: alexdbondoc17 Date: Tue, 8 Mar 2022 01:49:33 +0000 Subject: [PATCH] Temporary fix for `sorting` of `doctrines` --- app/controllers/documents_controller.rb | 3 ++- app/models/doctrine.rb | 4 ++++ app/views/doctrines/search.html.erb | 2 +- app/views/documents/show.html.erb | 4 ++-- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/controllers/documents_controller.rb b/app/controllers/documents_controller.rb index 52e0926..8a9d514 100644 --- a/app/controllers/documents_controller.rb +++ b/app/controllers/documents_controller.rb @@ -1,5 +1,6 @@ class DocumentsController < ApplicationController include JurisprudenceSearch + include DoctrineSearch load_and_authorize_resource :document, class: "Cdao::Jurisprudence" @@ -16,7 +17,7 @@ class DocumentsController < ApplicationController def show @subjects = Cdao::Subject.all - @doctrines = @document.doctrines + @doctrines = @document.doctrines.sort_by { |doctrine| @doctrines.sort_by { |doctrine| [-doctrine.jurisprudences.first.year, -doctrine.jurisprudences.first.docdate] } where = { enabled: true, state: "published" } @cited_in_documents = @document.class.citing_docs_of(@document, where) diff --git a/app/models/doctrine.rb b/app/models/doctrine.rb index d3baf04..a2470a7 100644 --- a/app/models/doctrine.rb +++ b/app/models/doctrine.rb @@ -19,6 +19,10 @@ class Doctrine < ApplicationRecord DoctrineSubject.where(doctrine_id: self.id) end + def jurisprudences + Cdao::Jurisprudence.where(id: doctrine_jurisprudences.map(&:jurisprudence_id)).order(year: :desc, docdate: :desc) + end + def subjects Cdao::Subject.where(id: doctrine_subjects.map(&:subject_id)) end diff --git a/app/views/doctrines/search.html.erb b/app/views/doctrines/search.html.erb index d3ae91b..1123ba8 100644 --- a/app/views/doctrines/search.html.erb +++ b/app/views/doctrines/search.html.erb @@ -6,6 +6,6 @@ <%= render(DoctrineIndexTableComponent.new(current_user: current_user, search_results: @doctrines, opts: { is_index_table: true, subject_ids: params[:subject_ids].map(&:to_i) })) %> <% else %> - <%= render(DoctrineIndexComponent.with_collection(@doctrines, current_user: current_user, opts: { is_index_table: false, subject_ids: params[:subject_ids].map(&:to_i) })) %> + <%= render(DoctrineIndexComponent.with_collection(@doctrines.sort_by { |doctrine| [-doctrine.jurisprudences.first.year, -doctrine.jurisprudences.first.docdate.strftime("%Y-%m-%d")] }, current_user: current_user, opts: { is_index_table: false, subject_ids: params[:subject_ids].map(&:to_i) })) %> <% end %> diff --git a/app/views/documents/show.html.erb b/app/views/documents/show.html.erb index dab52c2..aa78199 100644 --- a/app/views/documents/show.html.erb +++ b/app/views/documents/show.html.erb @@ -72,8 +72,8 @@ -
- <%= render(DocumentDoctrineIndexComponent.with_collection(@doctrines, current_user: current_user, opts: { document_id: @document.id })) %> +
+ <%= render(DocumentDoctrineIndexComponent.with_collection(@doctrines.sort_by { |doctrine| [-doctrine.doctrine_jurisprudences.first.jurisprudence.doc_date.strftime("%Y-%m-%d")] }, current_user: current_user, opts: { document_id: @document.id })) %>