Skip to content
This repository was archived by the owner on Oct 5, 2022. It is now read-only.

Integrate bento search into the "data" page #1

Closed
wants to merge 8 commits into from
Closed
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
66 changes: 65 additions & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,71 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2022-01-07 23:53:49 UTC using RuboCop version 1.23.0.
# on 2022-01-08 21:44:41 UTC using RuboCop version 1.23.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
# Configuration parameters: AllowComments.
Lint/EmptyClass:
Exclude:
- 'app/services/abstract_search_service.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods, IgnoreNotImplementedMethods.
Lint/UnusedMethodArgument:
Exclude:
- 'app/services/search_service.rb'

# Offense count: 4
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 34

# Offense count: 4
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
Metrics/MethodLength:
Max: 24

# Offense count: 1
# Configuration parameters: EnforcedStyleForLeadingUnderscores.
# SupportedStylesForLeadingUnderscores: disallowed, required, optional
Naming/MemoizedInstanceVariableName:
Exclude:
- 'app/searchers/quick_search/article_searcher.rb'

# Offense count: 2
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
# AllowedNames: at, by, db, id, in, io, ip, of, on, os, pp, to
Naming/MethodParameterName:
Exclude:
- 'app/searchers/quick_search/application_searcher.rb'
- 'app/services/catalog_search_service.rb'

# Offense count: 2
# Configuration parameters: Include.
# Include: app/helpers/**/*.rb
Rails/HelperInstanceVariable:
Exclude:
- 'app/helpers/search_helper.rb'

# Offense count: 1
Rails/OutputSafety:
Exclude:
- 'app/services/article_search_service.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: format, sprintf, percent
Style/FormatString:
Exclude:
- 'app/services/search_service.rb'

# Offense count: 2
# Configuration parameters: MaxUnannotatedPlaceholdersAllowed, IgnoredMethods.
# SupportedStyles: annotated, template, unannotated
Style/FormatStringToken:
EnforcedStyle: unannotated
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ gem 'jbuilder', '~> 2.7'
# Use Active Storage variant
# gem 'image_processing', '~> 1.2'

gem 'jquery-rails'
gem 'config'
gem 'http'

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.4', require: false

Expand Down
62 changes: 62 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -108,25 +108,81 @@ GEM
xpath (~> 3.2)
childprocess (4.1.0)
concurrent-ruby (1.1.9)
config (3.1.0)
deep_merge (~> 1.2, >= 1.2.1)
dry-validation (~> 1.0, >= 1.0.0)
crass (1.0.6)
deep_merge (1.2.2)
diff-lcs (1.5.0)
dlss-capistrano (3.11.1)
capistrano (~> 3.0)
capistrano-bundle_audit (>= 0.3.0)
capistrano-one_time_key
capistrano-shared_configs
domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0)
dry-configurable (0.13.0)
concurrent-ruby (~> 1.0)
dry-core (~> 0.6)
dry-container (0.9.0)
concurrent-ruby (~> 1.0)
dry-configurable (~> 0.13, >= 0.13.0)
dry-core (0.7.1)
concurrent-ruby (~> 1.0)
dry-inflector (0.2.1)
dry-initializer (3.0.4)
dry-logic (1.2.0)
concurrent-ruby (~> 1.0)
dry-core (~> 0.5, >= 0.5)
dry-schema (1.8.0)
concurrent-ruby (~> 1.0)
dry-configurable (~> 0.13, >= 0.13.0)
dry-core (~> 0.5, >= 0.5)
dry-initializer (~> 3.0)
dry-logic (~> 1.0)
dry-types (~> 1.5)
dry-types (1.5.1)
concurrent-ruby (~> 1.0)
dry-container (~> 0.3)
dry-core (~> 0.5, >= 0.5)
dry-inflector (~> 0.1, >= 0.1.2)
dry-logic (~> 1.0, >= 1.0.2)
dry-validation (1.7.0)
concurrent-ruby (~> 1.0)
dry-container (~> 0.7, >= 0.7.1)
dry-core (~> 0.5, >= 0.5)
dry-initializer (~> 3.0)
dry-schema (~> 1.8, >= 1.8.0)
erubi (1.10.0)
ffi (1.15.4)
ffi-compiler (1.0.1)
ffi (>= 1.0.0)
rake
globalid (1.0.0)
activesupport (>= 5.0)
http (5.0.4)
addressable (~> 2.8)
http-cookie (~> 1.0)
http-form_data (~> 2.2)
llhttp-ffi (~> 0.4.0)
http-cookie (1.0.4)
domain_name (~> 0.5)
http-form_data (2.3.0)
i18n (1.8.11)
concurrent-ruby (~> 1.0)
jbuilder (2.11.5)
actionview (>= 5.0.0)
activesupport (>= 5.0.0)
jquery-rails (4.4.0)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
listen (3.7.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
llhttp-ffi (0.4.0)
ffi-compiler (~> 1.0)
rake (~> 13.0)
loofah (2.13.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
Expand Down Expand Up @@ -273,6 +329,9 @@ GEM
turbolinks-source (5.2.0)
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
unf (0.1.4)
unf_ext
unf_ext (0.0.8)
unicode-display_width (2.1.0)
web-console (4.2.0)
actionview (>= 6.0.0)
Expand Down Expand Up @@ -309,8 +368,11 @@ DEPENDENCIES
capistrano-rails
capistrano-rvm
capybara (>= 3.26)
config
dlss-capistrano (~> 3.11)
http
jbuilder (~> 2.7)
jquery-rails
listen (~> 3.3)
puma (~> 5.0)
rack-mini-profiler (~> 2.0)
Expand Down
1 change: 1 addition & 0 deletions app/assets/config/manifest.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
//= link_tree ../images
//= link_directory ../stylesheets .css
//= link application.js
16 changes: 16 additions & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's
// vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file. JavaScript code in this file should be added after the last require_* statement.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require rails-ujs
//= require jquery3
//= require custom_quick_search
//= require toggleableResults
79 changes: 79 additions & 0 deletions app/assets/javascripts/custom_quick_search.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
function remove_timedout_spinners(){
$('.fa-refresh').not('.icon-5x').remove();
$('#no-results-trying-again').remove();
}

var xhr_searches = function(){
// We want to remove the spinners once all of the ajax requests are done. To do this we create an array of all of the ajax
// requests, which are promises. We can then apply this array so that all the promises are wrapped up together. When
// they're all done then the 'then' function runs removing the spinners.
$.when.apply(this,
$('.search-error').map(function(index){
var that = $(this);
var parent = that.parent('.module-contents');
var url = that.data('quicksearch-xhr-url');

parent.append('<div class="trying_again"><i class="fa fa-refresh fa-spin"></i> Just a few more seconds </div>');

return $.ajax({
url: url,
timeout: 15000,
success: function(response){
var response_object = jQuery.parseJSON(response);
var endpoint = Object.keys(response_object)[0];

if (response_object.spelling_suggestion != ' ') {
$('#spelling-suggestion').append(response_object.spelling_suggestion).removeClass('hidden');
}
if (response_object.related_topics != ' ') {
$('#related-topics').append(response_object.related_topics).removeClass('hidden');
}

parent.replaceWith(response_object[endpoint]);
},
error: function(){
parent.find('.trying_again').remove();
parent.find('.search-error-rescue').show();
}
});
})
).then(
// No matter what the result (success, failure) the spinners ought to be removed.
remove_timedout_spinners,
remove_timedout_spinners
);
}

$(document).ready(function() {
xhr_searches();
});

// add a >> to the focused element
$(document).ready(function() {

// Fade out best bet highlight after 3 seconds
if (window.innerWidth > 640) {
$('.highlight').delay( 6000 ).fadeOut( 500 );
} else {
$('.highlight').remove();
}
});

// This handles the highlighting of modules when a result types quide link is clicked
$(document).on('click', '.result-types a', function () {

// Grab the hash value
var hash = this.hash.substr(1);

// Remove any active highlight
$('.result-types-highlight').remove();

// Add the highlight
$('#' + hash + ' h2').prepend('<span class="result-types-highlight"><i class="fa fa-angle-double-right highlight"></i>&nbsp;</span>');

// Fade it away and then remove it.
$('#' + hash + ' .highlight').delay( 3000 ).animate({backgroundColor: 'transparent'}, 500 );
setTimeout(function() {
$('#' + hash + ' .result-types-highlight').remove();
}, 3550);
});
25 changes: 25 additions & 0 deletions app/assets/javascripts/toggleableResults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
function toggleableResults(searcher) {
var toggleableResults = $('#' + searcher + ' [data-behavior="toggleable-results"]');
var threshold = toggleableResults.data('toggleThreshold');
var toggleButton = $('#' + searcher + '-results-toggle-button');
var listItemsBeyondThreshold = toggleableResults.find('li:nth-child(n+' + (threshold + 1) + ')');

listItemsBeyondThreshold.toggle();

toggleButton.data('opened', false);
toggleButton.on('click', function() {
toggleButton.data('opened', !toggleButton.data('opened'));

listItemsBeyondThreshold.slideToggle();

if (toggleButton.data('opened')) {
toggleButton.text(' Show fewer');
toggleButton.prepend('<i class="fa fa-chevron-up"></i>')
toggleButton.attr('aria-expanded', true);
} else {
toggleButton.text(' ' + toggleButton.data('originalText'));
toggleButton.prepend('<i class="fa fa-chevron-down"></i>')
toggleButton.attr('aria-expanded', false);
}
});
}
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
@import 'bootstrap/scss/bootstrap';
@import 'main';
@import 'quick_search_overrides';
38 changes: 38 additions & 0 deletions app/assets/stylesheets/quick_search_overrides.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
$su-cloud: #dad7cb;
$white: #ffffff;
$red: #8c1515 !default;

#content {
h3.result-title {
font-family: 'dejavu_sansextralight';
letter-spacing: -.03em;
}
}

.module-contents {
background-color: $white;
border: 1px solid $su-cloud;
border-top: 5px solid $red;
padding: 10px 15px;
margin-bottom: 15px;
}

.search-container {
.form-group {
h1 {
margin: 0 15px 0 0;
padding: 0;
}

width: 100%;
justify-content: center;
margin-bottom: 0;
}

label {
color: $red;
font-weight: inherit;
line-height: inherit;
padding: 0;
}
}
Loading