Skip to content

Commit

Permalink
Course reserves are now driven from the Folio data
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Feb 21, 2024
1 parent dc6e25b commit 1c9a681
Show file tree
Hide file tree
Showing 28 changed files with 134 additions and 228 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</dd>
<dt>Instructor(s)</dt>
<dd>
<%= course.instructor %>
<%= safe_join course.instructor, ', ' %>
</dd>
<% end %>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ def initialize(document:, **html_attrs)
end

def courses
@document.course_reserves&.courses || []
@document.course_reserves
end

def render?
courses.any?
end

def link_to_course_reserve_course(course)
link_to("#{course.id} -- #{course.name}", search_catalog_path({ f: { course: [course.id], instructor: [course.instructor] } }))
link_to("#{course.course_number} -- #{course.name}", search_catalog_path({ f: { courses_folio_id_ssim: [course.id] } }))
end
end
end
7 changes: 6 additions & 1 deletion app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,15 @@ class CatalogController < ApplicationController
}
config.add_facet_field "topic_facet", label: "Topic", limit: 20, component: Blacklight::FacetFieldListComponent
config.add_facet_field "genre_ssim", label: "Genre", limit: 20, component: Blacklight::FacetFieldListComponent
# TODO: remove "course" and "instructor" after a time. These have been replaced by courses_folio_id_ssim.
# We just don't want to break any bookmarks that people may have. Perhaps wait for a semester or so.
config.add_facet_field "course", label: "Course", show: false, component: Blacklight::FacetFieldListComponent
config.add_facet_field "instructor", label: "Instructor", show: false, component: Blacklight::FacetFieldListComponent
config.add_facet_field "courses_folio_id_ssim", label: "Course", show: false,
component: Blacklight::FacetFieldListComponent,
item_presenter: FolioCourseFacetItemPresenter

# Should be shown under the "more..." section see https://github.com/sul-dlss/SearchWorks/issues/257
# Should be shown under the "more..." section see https://github.com/sul-dlss/SearchWorks/issues/257
config.add_facet_field "geographic_facet", label: "Region", limit: 20, component: Blacklight::FacetFieldListComponent
config.add_facet_field "era_facet", label: "Era", limit: 20, component: Blacklight::FacetFieldListComponent
config.add_facet_field "author_other_facet", label: "Organization (as author)", limit: 20, component: Blacklight::FacetFieldListComponent
Expand Down
16 changes: 1 addition & 15 deletions app/controllers/course_reserves_controller.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
class CourseReservesController < ApplicationController
include Blacklight::SearchContext
include Blacklight::Configurable
copy_blacklight_config_from(CatalogController)

def index
facet = "crez_course_info"
p = {}
p[:"facet.field"] = facet
p[:"f.#{facet}.facet.limit"] = "-1" # this implies lexical sort
p[:rows] = 0
response = blacklight_config.repository.search(p)
course_reserves = []
response.aggregations.values.first.items.each do |item|
course_reserves << CourseReserves.from_crez_info(item.value)
end
@course_reserves = course_reserves
@course_reserves = CourseReserve.all
end
end
18 changes: 0 additions & 18 deletions app/helpers/course_reserve_access_point_helper.rb

This file was deleted.

24 changes: 1 addition & 23 deletions app/models/concerns/course_reserves.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,5 @@
module CourseReserves
def course_reserves
if self.respond_to?(:[])
@course_reserves ||= CourseReserves::Processor.new(self)
end
@course_reserves ||= course_ids.present? ? Array(CourseReserve.find(*course_ids)).sort_by(&:course_number) : []
end

def self.from_crez_info(course)
CourseInfo.new(*course.split('-|-').map { |c| c.strip })
end

private

class Processor
def initialize(document)
@courses = Array(document[:crez_course_info]).map { |course| CourseReserves.from_crez_info(course) }
end

def present?
true ? @courses : false
end

attr_reader :courses
end

CourseInfo = Data.define(:id, :name, :instructor)
end
33 changes: 33 additions & 0 deletions app/models/course_reserve.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# The store of course reserve data from courses.json
class CourseReserve
FolioCourseInfo = Data.define(:id, :course_number, :name, :instructor)

class Repository
include Singleton

def all
@all ||= Folio::Types.courses.map do |id, v|
FolioCourseInfo.new(id:, course_number: v['courseNumber'],
name: v['name'],
instructor: v.dig('courseListingObject', 'instructorObjects').pluck('name'))
end
end

def find(*ids)
if ids.length == 1
id = ids.first
all.find { |course| course.id == id }
else
all.select { |course| ids.include?(course.id) }
end
end
end

def self.all
Repository.instance.all
end

def self.find(*id)
Repository.instance.find(*id)
end
end
1 change: 1 addition & 0 deletions app/models/solr_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def to_semantic_values
# Recommendation: Use field names from Dublin Core
use_extension(Blacklight::Document::DublinCore)

attribute :course_ids, :array, :courses_folio_id_ssim
attribute :document_formats, :array, FORMAT_KEY
attribute :live_lookup_id, :string, 'uuid_ssi'

Expand Down
7 changes: 7 additions & 0 deletions app/presenters/folio_course_facet_item_presenter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# The facet value here is a UUID for a folio course. We overide to show a label that a user
# can read.
class FolioCourseFacetItemPresenter < Blacklight::FacetItemPresenter
def constraint_label
CourseReserve.find(value)&.course_number || value
end
end
8 changes: 2 additions & 6 deletions app/views/catalog/_accordion_section_course_reserves.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@
id = document[:id]
%>
<% if document.course_reserves&.courses.present? %>
<%
count = document.course_reserves.courses.length
snippet = document.course_reserves.courses.map(&:id).join(', ')
%>
<% if document.course_reserves.present? %>
<div class="accordion-section course-reserves">
<div class="snippet-wrapper">
<button class="header" data-accordion-section-target=".<%= id %>-course-reserves" aria-expanded="false">
<span class="section-label">Course reserve</span>
</button>
<span class="snippet <%= id %>-course-reserves-snippet">
<%= snippet %>
<%= document.course_reserves.map(&:course_number).join(', ') %>
</span>
</div>
<div class="details <%= id %>-course-reserves" aria-expanded="false">
Expand Down
15 changes: 9 additions & 6 deletions app/views/catalog/mastheads/_course_reserve.html.erb
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<% create_course %>
<% if @course_info.present? %>
<%
id = params[:f][:courses_folio_id_ssim].first
course_info = CourseReserve.find(id)
%>
<% if course_info.present? %>
<div id="masthead-container">
<div id="masthead" class="course-reserve-masthead">
<h1 class="my-3">Course reserve list: <%= @course_info.id %></h1>
<h1 class="my-3">Course reserve list: <%= course_info.course_number %></h1>
<dl class='dl-horizontal dl-invert'>
<dt>Course</dt>
<dd><%= "#{@course_info.id} -- #{@course_info.name}" %></dd>
<dt>Instructor</dt>
<dd><%= @course_info.instructor %></dd>
<dd><%= "#{course_info.course_number} -- #{course_info.name}" %></dd>
<dt>Instructor(s)</dt>
<dd><%= safe_join course_info.instructor, ', ' %></dd>
</dl>
<p>
<%= link_to "Find reserve list for another course", course_reserves_path %>
Expand Down
8 changes: 4 additions & 4 deletions app/views/course_reserves/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@
Description
</th>
<th>
Instructor
Instructor(s)
</th>
</tr>
</thead>
<tbody>
<% @course_reserves.each do |course| %>
<tr>
<td>
<%= link_to course.id, search_catalog_path({f: {course: [course.id], instructor: [course.instructor]}}) %>
<%= link_to course.course_number, search_catalog_path({f: { courses_folio_id_ssim: [course.id] }}) %>
</td>
<td>
<%= course.name %>
</td>
<td>
<%= course.instructor %>
<%= safe_join course.instructor, ', ' %>
</td>
</tr>
<% end %>
</table>
</table>
3 changes: 1 addition & 2 deletions config/solr_configs/schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,7 @@
<!-- instructor, course facet field names are exposed to end users in SW -->
<field name="instructor" type="string" indexed="true" stored="true" multiValued="true" />
<field name="course" type="string" indexed="true" stored="true" multiValued="true" />
<!-- crez_course_info is a facet and display field at this time (2012-03-21) -->
<field name="crez_course_info" type="string" indexed="true" stored="true" multiValued="true" />

<!-- the next two facets are not used in SW at this time -->
<field name="crez_dept_facet" type="string" indexed="true" stored="true" multiValued="true" />
<field name="crez_desk_facet" type="string" indexed="true" stored="true" multiValued="true" />
Expand Down
2 changes: 1 addition & 1 deletion config/solr_configs/solrconfig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@
collection,
collection_type,
collection_with_title,
crez_course_info,
courses_folio_id_ssim,
db_az_subject,
druid,
file_id,
Expand Down
2 changes: 1 addition & 1 deletion lib/page_location.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def format_includes_databases?
end

def course_reserve_parameters?
filter(:course).any? && filter(:instructor).any?
filter(:courses_folio_id_ssim).any?
end

def collection_parameters?
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/searchworks.rake
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace :searchworks do
end

desc "Index test fixtures"
task :fixtures do
task fixtures: :environment do
FixturesIndexer.run
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

RSpec.describe AccessPanels::CourseReservesComponent do
describe "render?" do
let(:course) { CourseReserve.all.first }

it "should have a course reserve present" do
doc = SolrDocument.new(id: '123', crez_course_info: ["CAT-401-01-01 -|- Emergency Kittenz -|- McDonald, Ronald"])
doc = SolrDocument.new(id: '123', courses_folio_id_ssim: [course.id])
expect(described_class.new(document: doc).render?).to be true
end

Expand Down
3 changes: 1 addition & 2 deletions spec/controllers/course_reserves_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
describe "#index" do
it "should get the course reserves page" do
get :index
course_reserves = assigns(:course_reserves)
expect(course_reserves.length).to eq 4
expect(assigns(:course_reserves).length).to be > 25
expect(response).to render_template("index")
end
end
Expand Down
6 changes: 2 additions & 4 deletions spec/features/access_panels/course_reserve_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,17 @@
expect(page).to have_css('dl')
expect(page).to have_css('dt', count: 3, text: "Course")
expect(page).to have_css('dt', text: "Course")
expect(page).to have_css('dd a', text: "ACCT-212-01-02 -- Managerial Accounting: Base")
expect(page).to have_css('dd a')
expect(page).to have_css('dt', text: "Instructor(s)")
end
end

scenario "should have 1 course reservations" do
visit '/view/2'
within "div.panel-course-reserve" do
expect(page).to have_css('dd', count: 1, text: "CAT-401-01-01 -- Emergency Kittenz")
expect(page).to have_css('dt', text: "Course")
expect(page).to have_css('dd a', text: "CAT-401-01-01 -- Emergency Kittenz")
expect(page).to have_css('dd a', count: 1)
expect(page).to have_css('dt', text: "Instructor(s)")
expect(page).to have_css('dd', text: "McDonald, Ronald")
end
end

Expand Down
10 changes: 6 additions & 4 deletions spec/features/access_points/course_reserve_spec.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
require 'rails_helper'

RSpec.feature "Course Reserve Access Point" do
let(:course) { CourseReserve.all.first }

before do
visit search_catalog_path({ f: { course: ["CAT-401-01-01"], instructor: ["McDonald, Ronald"] } })
visit search_catalog_path({ f: { courses_folio_id_ssim: [course.id] } })
end

scenario "Access point masthead is visible with 1 course reserve document" do
expect(page).to have_title("Course reserves in SearchWorks catalog")
within("#masthead") do
expect(page).to have_css("h1", text: "Course reserve list: CAT-401-01-01")
expect(page).to have_css("h1", text: "Course reserve list: #{course.course_number}")
expect(page).to have_css("dt", text: "Instructor")
expect(page).to have_css("dd", text: "McDonald, Ronald")
expect(page).to have_css("dd", text: course.instructor.join(', '))
expect(page).to have_css("dt", text: "Course")
expect(page).to have_css("dd", text: "CAT-401-01-01 -- Emergency Kittenz")
expect(page).to have_css("dd", text: "#{course.course_number} -- #{course.name.gsub(/\s+/, ' ')}")
end
within("#content") do
expect(page).to have_css(".document", count: 1)
Expand Down
8 changes: 4 additions & 4 deletions spec/fixtures/solr_documents/1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ imprint_display: 1990
access_facet: Online
building_facet: Green
callnum_facet_hsim: Dewey Classification|000s - Computer Science, Knowledge & Systems|070s - News Media, Journalism, Publishing
crez_course_info:
- "ACCT-212-01-02 -|- Managerial Accounting: Base -|- Rajan, Madhav V."
- "ACCT-212-01-02 -|- Managerial Accounting: Base -|- Reichelstein, Stefan J"
- "ACCT-215-01-02 -|- Managerial Accounting: Accelerated -|- Marinovic Vial, Ivan"
courses_folio_id_ssim:
- <%= CourseReserve.all[1].id %>
- <%= CourseReserve.all[2].id %>
- <%= CourseReserve.all[3].id %>
item_display_struct:
- barcode: '36105217238315'
library: EARTH-SCI
Expand Down
4 changes: 2 additions & 2 deletions spec/fixtures/solr_documents/2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ access_facet: Online
building_facet: SAL3 (off-campus storage)
course: "CAT-401-01-01"
instructor: "McDonald, Ronald"
crez_course_info:
- "CAT-401-01-01 -|- Emergency Kittenz -|- McDonald, Ronald"
courses_folio_id_ssim:
- <%= CourseReserve.all.first.id %>
Loading

0 comments on commit 1c9a681

Please sign in to comment.