Skip to content

Commit

Permalink
add javascript to limit display of parents to first 3
Browse files Browse the repository at this point in the history
Uses show more and show less buttons to give users access to the full list of parents with the default to show less.
  • Loading branch information
elrayle committed Jan 17, 2018
1 parent e442dec commit 4ff3d6c
Show file tree
Hide file tree
Showing 14 changed files with 346 additions and 77 deletions.
1 change: 1 addition & 0 deletions .rubocop_fixme.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Metrics/ClassLength:
- 'app/controllers/hyrax/file_sets_controller.rb'
- 'app/forms/hyrax/forms/permission_template_form.rb'
- 'app/presenters/hyrax/work_show_presenter.rb'
- 'app/presenters/hyrax/collection_presenter.rb'
- 'app/services/hyrax/user_stat_importer.rb'
- 'lib/generators/hyrax/templates/catalog_controller.rb'
- 'lib/generators/hyrax/install_generator.rb'
Expand Down
12 changes: 12 additions & 0 deletions app/assets/javascripts/hyrax/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,16 @@ Blacklight.onLoad(function () {
$('#collections-to-delete-deny-modal').modal('show');
}
});

$('#show-more-parent-collections').on('click', function () {
$(this).hide();
$("#more-parent-collections").show();
$("#show-less-parent-collections").show();
});

$('#show-less-parent-collections').on('click', function () {
$(this).hide();
$("#more-parent-collections").hide();
$("#show-more-parent-collections").show();
});
});
11 changes: 11 additions & 0 deletions app/assets/stylesheets/hyrax/_collections.scss
Original file line number Diff line number Diff line change
Expand Up @@ -624,3 +624,14 @@ button.branding-banner-remove:hover {
margin-left: 0.5em;

}

.more-parent-collections-block {
display: none;
}

.show-more-parent-collections-btn,
.show-less-parent-collections-btn {
color: #8598b7;
font-size: 0.8em;
margin-left: 10px;
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,13 @@ def member_works
end

def parent_collections
col = @collection
col = Collection.find(collection.id) if col.blank?
@parent_collections = col.member_of_collections
@parent_collections = collection_object.member_of_collections
@parent_collection_count = @parent_collections.size
collection.parent_collections = @parent_collections if action_name == 'show'
end

def collection_object
action_name == 'show' ? Collection.find(collection.id) : collection
end

def member_subcollections
Expand Down
9 changes: 6 additions & 3 deletions app/controllers/hyrax/dashboard/collections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -449,10 +449,13 @@ def member_subcollections
end

def parent_collections
col = @collection
col = Collection.find(collection.id) if col.blank?
@parent_collections = col.member_of_collections
@parent_collections = collection_object.member_of_collections
@parent_collection_count = @parent_collections.size
collection.parent_collections = @parent_collections if action_name == 'show'
end

def collection_object
action_name == 'show' ? Collection.find(collection.id) : collection
end

# You can override this method if you need to provide additional
Expand Down
35 changes: 26 additions & 9 deletions app/presenters/hyrax/collection_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ class CollectionPresenter
include PresentsAttributes
include ActionView::Helpers::NumberHelper
attr_accessor :solr_document, :current_ability, :request
attr_writer :collection_type
attr_writer :collection_type, :parent_collections

NUM_PARENTS_TO_SHOW = 3

class_attribute :create_work_presenter_class
self.create_work_presenter_class = Hyrax::SelectTypeListPresenter
Expand All @@ -29,19 +31,16 @@ def collection_type
end

# Metadata Methods
delegate :title, :description, :creator, :contributor, :subject, :publisher, :keyword, :language,
:embargo_release_date, :lease_expiration_date, :license, :date_created,
:resource_type, :based_near, :related_url, :identifier, :thumbnail_path,
:title_or_label, :collection_type_gid, :create_date, :modified_date, :visibility, :edit_groups,
:edit_people,
delegate :title, :description, :creator, :contributor, :subject, :publisher, :keyword, :language, :embargo_release_date,
:lease_expiration_date, :license, :date_created, :resource_type, :based_near, :related_url, :identifier, :thumbnail_path,
:title_or_label, :collection_type_gid, :create_date, :modified_date, :visibility, :edit_groups, :edit_people,
to: :solr_document

# Terms is the list of fields displayed by
# app/views/collections/_show_descriptions.html.erb
def self.terms
[:total_items, :size, :resource_type, :creator, :contributor, :keyword,
:license, :publisher, :date_created, :subject, :language, :identifier,
:based_near, :related_url]
[:total_items, :size, :resource_type, :creator, :contributor, :keyword, :license, :publisher, :date_created, :subject,
:language, :identifier, :based_near, :related_url]
end

def terms_with_values
Expand Down Expand Up @@ -83,6 +82,24 @@ def collection_type_badge
collection_type.title
end

def parent_collection_count
@parent_collections.blank? ? 0 : @parent_collections.size
end

def more_parent_collections?
parent_collection_count > NUM_PARENTS_TO_SHOW
end

def visible_parent_collections
return @parent_collections[0..NUM_PARENTS_TO_SHOW - 1] if more_parent_collections?
@parent_collections || []
end

def more_parent_collections
return @parent_collections[NUM_PARENTS_TO_SHOW..parent_collection_count - 1] if more_parent_collections?
[]
end

def user_can_nest_collection?
current_ability.can?(:deposit, solr_document)
end
Expand Down
21 changes: 19 additions & 2 deletions app/views/hyrax/collections/_show_parent_collections.html.erb
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
<% if @parent_collections.nil? || @parent_collections.empty? %>
<% if presenter.parent_collection_count <= 0 %>
<div class="alert alert-warning" role="alert"><%= t('hyrax.collections.show.no_visible_parent_collections') %></div>
<% else %>
<div class="media-body">
<h4 class="media-heading">
<% @parent_collections.each do |document| %>
<div class="less-parent-collections-block" id="less-parent-collections">
<% presenter.visible_parent_collections.each do |document| %>
<ul>
<li>
<%= link_to document, [hyrax, document], id: "src_copy_link_#{document.id}" %>
</li>
</ul>
<% end %>
<% if presenter.more_parent_collections? %>
<button id="show-more-parent-collections" class="btn show-more-parent-collections-btn"><%= t("hyrax.collections.show.show_more_parent_collections") %></button>
<% end %>
</div>
<% if presenter.more_parent_collections? %>
<div class="more-parent-collections-block" id="more-parent-collections">
<% presenter.more_parent_collections.each do |document| %>
<ul>
<li>
<%= link_to document, [hyrax, document], id: "src_copy_link_#{document.id}" %>
</li>
</ul>
<button id="show-less-parent-collections" class="btn show-less-parent-collections-btn"><%= t("hyrax.collections.show.show_less_parent_collections") %></button>
<% end %>
</div>
<% end %>
</h4>
</div>
Expand Down
18 changes: 7 additions & 11 deletions app/views/hyrax/collections/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,14 @@
<div class="col-md-8 hyc-description">
<%= render 'collection_description', presenter: @presenter %>

<% if @presenter.collection_type_is_nestable? && @parent_collection_count > 0 %>
<div class="row hyc-blacklight hyc-bl-title">
<div class="col-md-12">
<h2>
<%= t('.parent_collection_header') %> (<%= @parent_collection_count %>)
</h2>
</div>
<% if @presenter.collection_type_is_nestable? && @presenter.parent_collection_count > 0 %>
<div class="hyc-blacklight hyc-bl-title">
<h2>
<%= t('.parent_collection_header') %> (<%= @presenter.parent_collection_count %>)
</h2>
</div>
<div class="row hyc-blacklight hyc-bl-results">
<div class="col-md-12">
<%= render 'show_parent_collections', collection: @parent_collections %>
</div>
<div class="hyc-blacklight hyc-bl-results">
<%= render 'show_parent_collections', presenter: @presenter %>
</div>
<% end %>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
<% if @parent_collections.nil? || @parent_collections.empty? %>
<div class="alert alert-warning" role="alert"><%= t('hyrax.collections.show.no_visible_parent_collections') %></div>
<% if presenter.parent_collection_count <= 0 %>
<div class="alert alert-warning" role="alert"><%= t('hyrax.collections.show.no_visible_parent_collections') %></div>
<% else %>
<div class="media-body">
<h4 class="media-heading">
<% @parent_collections.each do |document| %>
<ul>
<li>
<%= link_to document, [hyrax, :dashboard, document], id: "src_copy_link_#{document.id}" %>
</li>
</ul>
<% end %>
</h4>
</div>
<div class="media-body">
<h4 class="media-heading">
<div class="less-parent-collections-block" id="less-parent-collections">
<% presenter.visible_parent_collections.each do |document| %>
<ul>
<li>
<%= link_to document, [hyrax, :dashboard, document], id: "src_copy_link_#{document.id}" %>
</li>
</ul>
<% end %>
<% if presenter.more_parent_collections? %>
<button id="show-more-parent-collections" class="btn show-more-parent-collections-btn"><%= t("hyrax.collections.show.show_more_parent_collections") %></button>
<% end %>
</div>
<% if presenter.more_parent_collections? %>
<div class="more-parent-collections-block" id="more-parent-collections">
<% presenter.more_parent_collections.each do |document| %>
<ul>
<li>
<%= link_to document, [hyrax, :dashboard, document], id: "src_copy_link_#{document.id}" %>
</li>
</ul>
<button id="show-less-parent-collections" class="btn show-less-parent-collections-btn"><%= t("hyrax.collections.show.show_less_parent_collections") %></button>
<% end %>
</div>
<% end %>
</h4>
</div>
<% end %>
4 changes: 2 additions & 2 deletions app/views/hyrax/dashboard/collections/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
</div>
<div class="col-sm-9 collection-description-wrapper">
<!-- Parent Collection(s) -->
<% if @presenter.collection_type_is_nestable? %>
<h3><%= t('.parent_collection_header') %> (<%= @parent_collection_count %>)</h3>
<% if @presenter.collection_type_is_nestable? && @presenter.parent_collection_count > 0 %>
<h3><%= t('.parent_collection_header') %> (<%= @presenter.parent_collection_count %>)</h3>
<section class="parent-collections-wrapper">
<%= render 'hyrax/dashboard/collections/show_parent_collections', presenter: @presenter %>
</section>
Expand Down
4 changes: 4 additions & 0 deletions config/locales/hyrax.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,8 @@ en:
no_visible_parent_collections: "There are no visible parent collections."
no_visible_subcollections: "There are no visible subcollections."
parent_collection_header: "Parent Collections"
show_less_parent_collections: "...show less"
show_more_parent_collections: "show more..."
subcollection_count: "Subcollections"
works_in_collection: "Works"
collection_type:
Expand Down Expand Up @@ -631,6 +633,8 @@ en:
parent_collection_header: "Parent Collections"
public_view_label: "Public view of Collection"
search_results: "Search Results within this Collection"
show_less_parent_collections: "...show less"
show_more_parent_collections: "show more..."
subcollection_count: "Subcollections"
collection_type_actions:
close: "Close"
Expand Down
Loading

0 comments on commit 4ff3d6c

Please sign in to comment.