Browse Source

Fix UI for `documents#show`

pull/76/head
alexdbondoc17 4 years ago
parent
commit
a0ee3f5c0b
  1. 23
      app/components/citation_index_table_component.rb
  2. 5
      app/components/citation_index_table_component/citation_index_table_component.html.erb
  3. 6
      app/components/document_index_table_component.rb
  4. 2
      app/components/document_index_table_component/document_index_table_component.html.erb
  5. 8
      app/views/documents/show.html.erb

23
app/components/citation_index_table_component.rb

@ -0,0 +1,23 @@
class CitationIndexTableComponent < BaseComponent
with_collection_parameter :search_result
attr_reader :search_result, :opts
def initialize(search_result:, current_user:, opts: {})
@search_result = search_result
@opts = opts
end
delegate :clean_reference_number, to: :search_result
delegate :title, to: :search_result
delegate :short_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
def doctrine_annotations_path(doctrine_id)
doctrine_annotations_path(doctrine_id: doctrine_id)
end
end

5
app/components/citation_index_table_component/citation_index_table_component.html.erb

@ -0,0 +1,5 @@
<tr href="<%= document_path(search_result.id, is_citator_tab: true) %>" class="clickable-tr" target="_blank">
<td> <%= clean_reference_number %> </td>
<td> <%= short_title || title %> </td>
<td> <%= date_or_year %> </td>
</tr>

6
app/components/document_index_table_component.rb

@ -7,6 +7,7 @@ class DocumentIndexTableComponent < BaseComponent
@opts = opts
end
delegate :id, to: :search_result
delegate :clean_reference_number, to: :search_result
delegate :title, to: :search_result
delegate :short_title, to: :search_result
@ -20,9 +21,4 @@ class DocumentIndexTableComponent < BaseComponent
def doctrine_annotations_path(doctrine_id)
doctrine_annotations_path(doctrine_id: doctrine_id)
end
def show_url
return document_path(search_result.id, is_citator_tab: true) if opts[:is_citator_tab].present?
document_path(search_result.id, opts[:search_params])
end
end

2
app/components/document_index_table_component/document_index_table_component.html.erb

@ -1,4 +1,4 @@
<tr href="<%= show_url %>" class="<%= opts[:is_citator_tab].present? ? 'clickable-tr' : 'clickable-link' %>" target="_blank">
<tr href="<%= document_path(id) %>" class="clickable-link" target="_blank">
<td> <%= clean_reference_number %> </td>
<td> <%= short_title || title %> </td>
<td> <%= date_or_year %> </td>

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

@ -11,9 +11,7 @@
<div class="col-lg-12">
<div class="row">
<div class="col-lg-6">
<% if params[:is_document_view].blank? && params[:is_citator_tab].blank? %>
<a class="btn btn-danger" href="<%= documents_path(params.reject { |k, v| %i[action controller id].include?(k.to_sym) }.to_unsafe_h) %>"> Back </a>
<% end %>
<a class="btn btn-danger" href="<%= documents_path %>"> Back </a>
</div>
<div class="col-lg-3 text-end">
<b>Date : </b>
@ -40,7 +38,7 @@
Title :
</div>
<div class="col-lg-9">
<strong> <%= @document.short_title %> </strong>
<strong> <%= @document.short_title || @document.title %> </strong>
</div>
</div>
</div>
@ -94,7 +92,7 @@
</thead>
<tbody>
<%= render(DocumentIndexTableComponent.with_collection(@cited_in_documents, current_user: current_user, opts: { search_params: params.reject { |k, v| %i[action controller id].include?(k.to_sym) }, is_document_view: false, is_citator_tab: true })) %>
<%= render(CitationIndexTableComponent.with_collection(@cited_in_documents, current_user: current_user)) %>
</tbody>
</table>
</div>

Loading…
Cancel
Save