diff --git a/app/components/doctrine_index_component.rb b/app/components/doctrine_index_component.rb new file mode 100644 index 0000000..60bfc60 --- /dev/null +++ b/app/components/doctrine_index_component.rb @@ -0,0 +1,46 @@ +class DoctrineIndexComponent < BaseComponent + with_collection_parameter :doctrine + attr_reader :doctrine, :opts + + def initialize(doctrine:, current_user:, opts: {}) + @doctrine = doctrine + @opts = opts + end + + delegate :id, to: :doctrine + delegate :subject_ids, to: :doctrine + delegate :content, to: :doctrine + delegate :annotations, to: :doctrine + delegate :subjects, to: :doctrine + delegate :doctrine_jurisprudences, to: :doctrine + + def annotation_form_url + doctrine_annotations_path(doctrine_id: id) + end + + def subject_names + "(No Subjects Provided)" + end + + def jurisprudence + return nil if doctrine_jurisprudences.blank? + + doctrine_jurisprudences.first.jurisprudence + end + + def document_title(annotation) + return annotation.document.short_title if annotation.document.short_title.present? + + annotation.document.title + end + + def date_or_year(annotation) + return annotation.document.docdate.to_date.strftime("%B %d, %Y") if annotation.document.docdate.present? + + annotation.document.year + end + + def render? + doctrine.present? && doctrine.persisted? + end +end diff --git a/app/components/doctrine_index_component/doctrine_index_component.html.erb b/app/components/doctrine_index_component/doctrine_index_component.html.erb new file mode 100644 index 0000000..203832a --- /dev/null +++ b/app/components/doctrine_index_component/doctrine_index_component.html.erb @@ -0,0 +1,45 @@ + diff --git a/app/views/doctrines/search.html.erb b/app/views/doctrines/search.html.erb index 2ca4a61..54f2a62 100644 --- a/app/views/doctrines/search.html.erb +++ b/app/views/doctrines/search.html.erb @@ -3,9 +3,9 @@
<% if params[:is_index_table].to_s.eql?("true") %>
- <%= render(DoctrineIndexTableComponent.new(current_user: current_user, search_results: @doctrines)) %> + <%= render(DoctrineIndexTableComponent.new(current_user: current_user, search_results: @doctrines, opts: { is_index_table: params[:is_index_table].to_s.eql?("true") })) %>
<% else %> - <%= render(DocumentDoctrineIndexComponent.with_collection(@doctrines, current_user: current_user, opts: { is_doctrines_index: true, subject_ids: params[:subject_ids] })) %> + <%= render(DoctrineIndexComponent.with_collection(@doctrines, current_user: current_user, opts: { subject_ids: params[:subject_ids] })) %> <% end %>