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

Test with Blacklight 8 #233

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
matrix:
ruby: [2.7, '3.0']
rails_version: ['6.1.7.1', '7.0.4.1']
blacklight_version: ['']
additional_engine_cart_rails_options: ['']
include:
- ruby: '3.2'
Expand All @@ -29,9 +30,14 @@ jobs:
rails_version: '7.0.4.1'
- ruby: '3.0'
rails_version: '7.0.4.1'
- ruby: '3.2'
rails_version: '7.0.4.1'
name: 'Blacklight 8 beta'
blacklight_version: '~> 8.0'

env:
BLACKLIGHT_VERSION: "~> 7.0" # only test on BL 7 for now
RAILS_VERSION: ${{ matrix.rails_version }}
BLACKLIGHT_VERSION: ${{ matrix.blacklight_version }}
ENGINE_CART_RAILS_OPTIONS: "--skip-git --skip-listen --skip-spring --skip-keeps --skip-action-cable --skip-coffee --skip-test ${{ matrix.engine_cart_rails_options }}"
steps:
- uses: actions/checkout@v3
Expand Down
8 changes: 0 additions & 8 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@ group :test do
gem 'activerecord-jdbcsqlite3-adapter', platform: :jruby
end

# While gemspec allows BL8 and some people are using BL8... the build
# has never actually passed on BL8 yet. We may choose to run tests on
# a blacklight version other than the latest allowed by gemspec, to get
# tests to pass, or to test on older BL still supported here.
if ENV['BLACKLIGHT_VERSION']
gem "blacklight", ENV['BLACKLIGHT_VERSION']
end

# BEGIN ENGINE_CART BLOCK
# engine_cart: 2.5.0
# engine_cart stanza: 2.5.0
Expand Down
1 change: 1 addition & 0 deletions app/assets/config/blacklight_range_limit/manifest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//= link_tree ../../javascripts .js
17 changes: 17 additions & 0 deletions app/assets/javascripts/blacklight_range_limit.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,20 @@
//= require 'blacklight_range_limit/range_limit_plotting'
//= require 'blacklight_range_limit/range_limit_slider'
//= require 'blacklight_range_limit/range_limit_distro_facets'

BlacklightRangeLimit.initialize = function() {
// Support for Blacklight 7 and 8:
const modalSelector = Blacklight.modal?.modalSelector || Blacklight.Modal.modalSelector

RangeLimitDistroFacet.initialize(modalSelector)
RangeLimitSlider.initialize(modalSelector)
}

// Blacklight will only be defined if you aren't using this in a module context
if (Blacklight)
Blacklight.onLoad(() => BlacklightRangeLimit.initialize())

// In a module context you can do:
// import BlacklightRangeLimit from 'blacklight_range_limit'
// Blacklight.onLoad(() => BlacklightRangeLimit.initialize())
export default BlacklightRangeLimit
Original file line number Diff line number Diff line change
Expand Up @@ -6,72 +6,73 @@
* events.
*/

Blacklight.onLoad(function() {
const RangeLimitDistroFacet = {
initialize: function(modalSelector) {
// Facets already on the page? Turn em into a chart.
$(".range_limit .profile .distribution.chart_js ul").each(function() {
BlacklightRangeLimit.turnIntoPlot($(this).parent());
});

// Facets already on the page? Turn em into a chart.
$(".range_limit .profile .distribution.chart_js ul").each(function() {
BlacklightRangeLimit.turnIntoPlot($(this).parent());
});
BlacklightRangeLimit.checkForNeededFacetsToFetch();

BlacklightRangeLimit.checkForNeededFacetsToFetch();
// Listen for twitter bootstrap collapsible open events, to render flot
// in previously hidden divs on open, if needed.
$("body").on("show.bs.collapse", function(event) {
// Was the target a .facet-content including a .chart-js?
var container = $(event.target).filter(".facet-content").find(".chart_js");

// Listen for twitter bootstrap collapsible open events, to render flot
// in previously hidden divs on open, if needed.
$("body").on("show.bs.collapse", function(event) {
// Was the target a .facet-content including a .chart-js?
var container = $(event.target).filter(".facet-content").find(".chart_js");
// only if it doesn't already have a canvas, it isn't already drawn
if (container && container.find("canvas").length == 0) {
// be willing to wait up to 1100ms for container to
// have width -- right away on show.bs is too soon, but
// shown.bs is later than we want, we want to start rendering
// while animation is still in progress.
BlacklightRangeLimit.turnIntoPlot(container, 1100);
}
});

// only if it doesn't already have a canvas, it isn't already drawn
if (container && container.find("canvas").length == 0) {
// be willing to wait up to 1100ms for container to
// have width -- right away on show.bs is too soon, but
// shown.bs is later than we want, we want to start rendering
// while animation is still in progress.
BlacklightRangeLimit.turnIntoPlot(container, 1100);
}
});
// For Blacklight version < 8, when loaded in a modal
$(modalSelector).on('shown.bs.modal', function() {
$(this).find(".range_limit .profile .distribution.chart_js ul").each(function() {
BlacklightRangeLimit.turnIntoPlot($(this).parent());
});

// For Blacklight version < 8, when loaded in a modal
$(BlacklightRangeLimit.modalSelector).on('shown.bs.modal', function() {
$(this).find(".range_limit .profile .distribution.chart_js ul").each(function() {
BlacklightRangeLimit.turnIntoPlot($(this).parent());
// Case when there is no currently selected range
BlacklightRangeLimit.checkForNeededFacetsToFetch();
});

// Case when there is no currently selected range
BlacklightRangeLimit.checkForNeededFacetsToFetch();
});
// Use a mutation observer to detect when the HTML dialog is open
BlacklightRangeLimit.initPlotModalObserver();

// Use a mutation observer to detect when the HTML dialog is open
BlacklightRangeLimit.initPlotModalObserver();

$("body").on("shown.bs.collapse", function(event) {
var container = $(event.target).filter(".facet-content").find(".chart_js");
BlacklightRangeLimit.redrawPlot(container);
});
$("body").on("shown.bs.collapse", function(event) {
var container = $(event.target).filter(".facet-content").find(".chart_js");
BlacklightRangeLimit.redrawPlot(container);
});

// debouce borrowed from underscore
// Returns a function, that, as long as it continues to be invoked, will not
// be triggered. The function will be called after it stops being called for
// N milliseconds. If `immediate` is passed, trigger the function on the
// leading edge, instead of the trailing.
const debounce = function(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
// debouce borrowed from underscore
// Returns a function, that, as long as it continues to be invoked, will not
// be triggered. The function will be called after it stops being called for
// N milliseconds. If `immediate` is passed, trigger the function on the
// leading edge, instead of the trailing.
const debounce = function(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args);
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args);
};
};

$(window).on("resize", debounce(function() {
$(".chart_js").each(function(i, container) {
BlacklightRangeLimit.redrawPlot($(container));
});
}, 350));
});
$(window).on("resize", debounce(function() {
$(".chart_js").each(function(i, container) {
BlacklightRangeLimit.redrawPlot($(container));
});
}, 350));
}
}
43 changes: 20 additions & 23 deletions app/assets/javascripts/blacklight_range_limit/range_limit_slider.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
// for Blacklight.onLoad:

Blacklight.onLoad(function() {

$(".range_limit .profile .range.slider_js").each(function() {
BlacklightRangeLimit.buildSlider(this);
});

// For Blacklight < 8, when loaded in a modal
$(BlacklightRangeLimit.modalSelector).on('shown.bs.modal', function() {
$(this).find(".range_limit .profile .range.slider_js").each(function() {
const RangeLimitSlider = {
initialize: function(modalSelector) {
$(".range_limit .profile .range.slider_js").each(function() {
BlacklightRangeLimit.buildSlider(this);
});
});

// For Blacklight 8, use a mutation observer to detect when the HTML dialog is open
BlacklightRangeLimit.initSliderModalObserver();
$(modalSelector).on('shown.bs.modal', function() {
$(this).find(".range_limit .profile .range.slider_js").each(function() {
BlacklightRangeLimit.buildSlider(this);
});
});

// catch event for redrawing chart, to redraw slider to match width
$("body").on("plotDrawn.blacklight.rangeLimit", function(event) {
var area = $(event.target).closest(".limit_content.range_limit");
var plot = area.find(".chart_js").data("plot");
var slider_el = area.find(".slider");
// catch event for redrawing chart, to redraw slider to match width
$("body").on("plotDrawn.blacklight.rangeLimit", function(event) {
var area = $(event.target).closest(".limit_content.range_limit");
var plot = area.find(".chart_js").data("plot");
var slider_el = area.find(".slider");

if (plot && slider_el) {
slider_el.width(plot.width());
slider_el.css("display", "block")
}
});
});
if (plot && slider_el) {
slider_el.width(plot.width());
slider_el.css("display", "block")
}
});
}
}

// returns two element array min/max as numbers. If there is a limit applied,
// it's boundaries are are limits. Otherwise, min/max in current result
Expand Down
3 changes: 3 additions & 0 deletions config/importmap.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# frozen_string_literal: true

pin_all_from File.expand_path("../app/assets/javascripts/", __dir__)
4 changes: 4 additions & 0 deletions lib/blacklight_range_limit/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@ class Engine < Rails::Engine
config.before_configuration do
Blacklight::Configuration::FacetField.prepend BlacklightRangeLimit::FacetFieldConfigOverride
end

initializer 'blacklight_range_limit.importmap', before: "importmap" do |app|
app.config.importmap.paths << Engine.root.join("config/importmap.rb") if app.config.respond_to?(:importmap)
end
end
end
31 changes: 20 additions & 11 deletions lib/generators/blacklight_range_limit/assets_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class AssetsGenerator < Rails::Generators::Base
source_root File.join(BlacklightRangeLimit::Engine.root, 'app', 'assets')

def assets
append_to_file 'app/assets/config/manifest.js', "\n//= link blacklight_range_limit/manifest.js"
application_css = Dir["app/assets/stylesheets/application{.css,.scss,.css.scss}"].first

if application_css
Expand All @@ -32,18 +33,26 @@ def assets
say_status "warning", "Can not find application.css, did not insert our require", :red
end

append_to_file "app/assets/javascripts/application.js" do
%q{

// For blacklight_range_limit built-in JS, if you don't want it you don't need
// this:
//= require 'blacklight_range_limit'

}
if defined?(Importmap)
run 'bin/importmap pin jquery'
append_to_file "app/javascript/application.js" do
<<~CONTENT
import jQuery from "jquery"
window.jQuery = jQuery
window.$ = jQuery
import BlacklightRangeLimit from "blacklight_range_limit"
Blacklight.onLoad(() => BlacklightRangeLimit.initialize())
CONTENT
end
else
append_to_file "app/assets/javascripts/application.js" do
<<~CONTENT
// For blacklight_range_limit built-in JS, if you don't want it you don't need
// this:
//= require 'blacklight_range_limit'
CONTENT
end
end
end



end
end
4 changes: 2 additions & 2 deletions spec/components/range_facet_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
modal_path: nil,
facet_field: facet_config,
**facet_field_params,
**extra_facet_field_params
**version_dependent_params
)
end

Expand All @@ -39,7 +39,7 @@
end

let(:facet_field_params) { {} }
let(:extra_facet_field_params) { Blacklight::VERSION > '8' ? {} : { html_id: 'id' } }
let(:version_dependent_params) { Blacklight::VERSION > '8' ? {} : { html_id: 'id' } }

before do
allow(component).to receive(:search_facet_path).and_return('/range/key')
Expand Down
3 changes: 2 additions & 1 deletion spec/features/a_javascript_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

require 'spec_helper'

describe 'JavaScript', js: true do
RSpec.describe 'JavaScript', js: true do
it 'initializes canvas chart' do
visit search_catalog_path

click_button 'Publication Date Sort'
debugger
expect(page).to have_css '.flot-base'
end
it 'has a View larger modal' do
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
require 'capybara/rspec'
require 'selenium-webdriver'

Capybara.javascript_driver = :headless_chrome
Capybara.javascript_driver = :selenium#:headless_chrome

Capybara.register_driver :headless_chrome do |app|
Capybara::Selenium::Driver.load_selenium
Expand Down
7 changes: 6 additions & 1 deletion spec/test_app_templates/Gemfile.extra
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
gem 'rails-controller-testing'
gem 'blacklight', ENV['BLACKLIGHT_VERSION'] if ENV['BLACKLIGHT_VERSION']

if ENV['BLACKLIGHT_VERSION'] == 'github'
gem 'blacklight', github: 'projectblacklight/blacklight'
elsif ENV['BLACKLIGHT_VERSION'] && !ENV['BLACKLIGHT_VERSION'].empty?
gem 'blacklight', ENV['BLACKLIGHT_VERSION']
end
Loading