Browse Source

Temporary fix for `sorting` of `doctrines`

pull/112/head
alexdbondoc17 4 years ago
parent
commit
0e8da90449
  1. 3
      app/controllers/documents_controller.rb
  2. 4
      app/models/doctrine.rb
  3. 2
      app/views/doctrines/search.html.erb
  4. 4
      app/views/documents/show.html.erb

3
app/controllers/documents_controller.rb

@ -1,5 +1,6 @@
class DocumentsController < ApplicationController class DocumentsController < ApplicationController
include JurisprudenceSearch include JurisprudenceSearch
include DoctrineSearch
load_and_authorize_resource :document, class: "Cdao::Jurisprudence" load_and_authorize_resource :document, class: "Cdao::Jurisprudence"
@ -16,7 +17,7 @@ class DocumentsController < ApplicationController
def show def show
@subjects = Cdao::Subject.all @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" } where = { enabled: true, state: "published" }
@cited_in_documents = @document.class.citing_docs_of(@document, where) @cited_in_documents = @document.class.citing_docs_of(@document, where)

4
app/models/doctrine.rb

@ -19,6 +19,10 @@ class Doctrine < ApplicationRecord
DoctrineSubject.where(doctrine_id: self.id) DoctrineSubject.where(doctrine_id: self.id)
end end
def jurisprudences
Cdao::Jurisprudence.where(id: doctrine_jurisprudences.map(&:jurisprudence_id)).order(year: :desc, docdate: :desc)
end
def subjects def subjects
Cdao::Subject.where(id: doctrine_subjects.map(&:subject_id)) Cdao::Subject.where(id: doctrine_subjects.map(&:subject_id))
end end

2
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) })) %> <%= render(DoctrineIndexTableComponent.new(current_user: current_user, search_results: @doctrines, opts: { is_index_table: true, subject_ids: params[:subject_ids].map(&:to_i) })) %>
</div> </div>
<% else %> <% 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 %> <% end %>
</div> </div>

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

@ -72,8 +72,8 @@
</div> </div>
</div> </div>
<div class="container-sm row-flex col-sm-12 p-0 doct-body-index"> <div class="container-sm row-flex col-sm-12 p-0 doct-body-index" id="doctrinesIndexView">
<%= 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 })) %>
</div> </div>
</div> </div>

Loading…
Cancel
Save