Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ANW-730: Add PUI expand/collapse all config option #2538

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions common/config/config-defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,9 @@
#The number of characters to truncate before showing the 'Read More' link on notes
AppConfig[:pui_readmore_max_characters] = 450

# Whether to expand all additional information blocks at the bottom of record pages by default. `true` expands all blocks, `false` collapses all blocks.
AppConfig[:pui_expand_all] = true

# Enable / disable PUI resource/archival object page actions
AppConfig[:pui_page_actions_cite] = true
AppConfig[:pui_page_actions_request] = true
Expand Down
27 changes: 23 additions & 4 deletions public/app/assets/javascripts/handle_accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
var expand_text = '';
var collapse_text = '';
/* we don't provide a button if there's only one panel; neither do we collapse that one panel */
function initialize_accordion(what, ex_text, col_text) {

/**
* @param {string} what accordion panels selector
* @param {string} ex_text 'expand text' i18n
* @param {string} col_text 'collapse text' i18n
* @param {boolean} expand_all
*/
function initialize_accordion(what, ex_text, col_text, expand_all) {
expand_text = ex_text;
collapse_text = col_text;
if ($(what).size() > 1 && $(what).parents('.acc_holder').size() === 1) {
Expand All @@ -14,21 +21,33 @@ function initialize_accordion(what, ex_text, col_text) {
"<a class='btn btn-primary btn-sm acc_button' role='button' ></a>"
);
}
collapse_all(what, true);
expandAllByDefault(what, expand_all);
}
}
function collapse_all(what, expand) {

/**
* @param {string} what accordion panels selector
* @param {boolean} expand to expand or not
*/
function expandAllByDefault(what, expand) {
$(what).each(function () {
$(this).collapse(expand ? 'show' : 'hide');
});
set_button(what, !expand);
}

/**
* @param {string} what accordion panels selector
* @param {boolean} expand to expand or not
*/
function set_button(what, expand) {
$holder = $(what).parents('.acc_holder');
$btn = $holder.children('.acc_button');
if ($btn.size() === 1) {
$btn.text(expand ? expand_text : collapse_text);
$btn.attr('href', "javascript:collapse_all('" + what + "'," + expand + ')');
$btn.attr(
'href',
"javascript:expandAllByDefault('" + what + "'," + expand + ')'
);
}
}
2 changes: 1 addition & 1 deletion public/app/views/agents/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
</div>
</div>
<script type="text/javascript" >
initialize_accordion("#agent_accordion .note_panel", "<%= t('accordion.expand') %>" , "<%= t('accordion.collapse') %>");
initialize_accordion("#agent_accordion .note_panel", "<%= t('accordion.expand') %>" , "<%= t('accordion.collapse') %>", <%= AppConfig[:pui_expand_all] %>);
</script>
<% end %>

Expand Down
2 changes: 1 addition & 1 deletion public/app/views/shared/_record_innards.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,5 @@
<%= render :file => template if File.exists?(template) %>
<% end %>
</div>
<script type="text/javascript" >initialize_accordion(".note_panel", "<%= t('accordion.expand') %>" , "<%= t('accordion.collapse') %>");
<script type="text/javascript" >initialize_accordion(".note_panel", "<%= t('accordion.expand') %>" , "<%= t('accordion.collapse') %>", <%= AppConfig[:pui_expand_all] %>);
</script>
2 changes: 1 addition & 1 deletion public/app/views/subjects/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</div>
</div>
<script type="text/javascript" >
initialize_accordion(".note_panel", "<%= t('accordion.expand') %>" , "<%= t('accordion.collapse') %>");
initialize_accordion(".note_panel", "<%= t('accordion.expand') %>" , "<%= t('accordion.collapse') %>", <%= AppConfig[:pui_expand_all] %>);
</script>
<% unless @results.blank? || @results['total_hits'] == 0 %>
<%= render partial: 'shared/facets' %>
Expand Down
42 changes: 42 additions & 0 deletions public/spec/features/record_accordion_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
require 'spec_helper'
require 'rails_helper'

describe 'Accordion of additional record information blocks', js: true do
before(:each) do
visit('/')
click_link 'Collections'
expect(current_path).to eq ('/repositories/resources')
resource = first("a.record-title")
visit(resource['href'])

$panels = page.all('.upper-record-details + .acc_holder div.panel.panel-default')
end

it 'should be found after the upper record details of a resource page' do
expect(page).to have_css('div.upper-record-details + div.acc_holder')
end

it 'should have all panels expanded by default' do
$panels.each do |panel|
expect(panel).to have_css('.note_panel[aria-expanded="true"]', visible: true)
end

end

it 'should collapse then expand all panels on button clicks' do
accordion_toggle_btn = page.find('.upper-record-details + .acc_holder > a.acc_button')
accordion_toggle_btn.click

$panels.each do |panel|
expect(panel).to have_css('.note_panel[aria-expanded="false"]', visible: :hidden)
end

accordion_toggle_btn.click

$panels.each do |panel|
expect(panel).to have_css('.note_panel[aria-expanded="true"]', visible: true)
end

end

end