-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from sul-dlss/course-reserve
Course reserve
- Loading branch information
Showing
16 changed files
with
222 additions
and
9 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
app/assets/stylesheets/modules/access-panel-course-reserve.css.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
.panel-course-reserve { | ||
ul.links { | ||
padding-left: 0; | ||
list-style-type: none; | ||
li { | ||
padding-right: 20px; | ||
padding-bottom: 15px; | ||
} | ||
li:last-child { | ||
padding-bottom: 0px; | ||
} | ||
} | ||
} | ||
|
||
.course-reserve-title { | ||
text-transform: capitalize !important; | ||
font-size: $font-size-small; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module AccessPanelHelper | ||
|
||
def link_to_course_reserve_course(course) | ||
link_to("#{course.id} -- #{course.name}", catalog_index_path({f: {course: [course.id], instructor: [course.instructor]}})) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
module CourseReserves | ||
def course_reserves | ||
if self.respond_to?(:[]) | ||
@course_reserves ||= CourseReserves::Processor.new(self) | ||
end | ||
end | ||
|
||
private | ||
class Processor | ||
def initialize(document) | ||
@courses = document[:crez_course_info].map { |course| CourseInfo.new(course) } unless document[:crez_course_info].nil? | ||
end | ||
|
||
def present? | ||
true ? @courses : false | ||
end | ||
|
||
attr_reader :courses | ||
|
||
end | ||
|
||
class CourseInfo | ||
def initialize(course) | ||
@course = course.split('-|-').map { |c| c.strip } | ||
end | ||
|
||
def id | ||
@course[0] | ||
end | ||
|
||
def name | ||
@course[1] | ||
end | ||
|
||
def instructor | ||
@course[2] | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<% document ||= @document %> | ||
<% if document.access_panels.course_reserve.present? %> | ||
<div class="panel panel-default panel-course-reserve"> | ||
<div class="panel-heading">Course reserve</div> | ||
<div class="panel-body"> | ||
<ul class="links"> | ||
<% document.access_panels.course_reserve.courses.each do |course| %> | ||
<li> | ||
<div class="course-reserve-course"> | ||
<%= t('blacklight.access_panels.course_reserve.course', link: link_to_course_reserve_course(course)).html_safe %> | ||
</div> | ||
<div class="course-reserve-instructor"> | ||
<%= t('blacklight.access_panels.course_reserve.instructor', instructor: course.instructor).html_safe %> | ||
</div> | ||
</li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class CourseReserve < AccessPanel | ||
delegate :present?, to: :courses | ||
def courses | ||
if @document.course_reserves.present? | ||
@document.course_reserves.courses | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
require 'spec_helper' | ||
|
||
feature "Course Reserve Access Panel" do | ||
|
||
scenario "should have 3 course reservations" do | ||
visit '/catalog/1' | ||
within "div.panel-course-reserve" do | ||
expect(page).to have_css('div.course-reserve-course', count: 3, text: "COURSE:") | ||
expect(page).to have_css('span.course-reserve-title', text: "COURSE:") | ||
expect(page).to have_css('a', text: "ACCT-212-01-02 -- Managerial Accounting: Base") | ||
expect(page).to have_css('div.course-reserve-instructor', text: "INSTRUCTOR(S):") | ||
end | ||
end | ||
|
||
scenario "should have 1 course reservations" do | ||
visit '/catalog/2' | ||
within "div.panel-course-reserve" do | ||
expect(page).to have_css('div.course-reserve-course', count: 1, text: "CAT-401-01-01 -- Emergency Kittenz") | ||
expect(page).to have_css('span.course-reserve-title', text: "COURSE:") | ||
expect(page).to have_css('a', text: "CAT-401-01-01 -- Emergency Kittenz") | ||
expect(page).to have_css('div.course-reserve-instructor', text: "INSTRUCTOR(S): McDonald, Ronald") | ||
end | ||
end | ||
|
||
scenario "should have 0 course reservations" do | ||
visit '/catalog/3' | ||
expect(page.has_no_css?('div.panel-course-reserve')).to eql true | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require 'spec_helper' | ||
require 'course_reserve' | ||
|
||
describe CourseReserve do | ||
|
||
describe "present?" do | ||
|
||
it "should have a course reserve present" do | ||
doc = SolrDocument.new(id: '123', crez_course_info: ["CAT-401-01-01 -|- Emergency Kittenz -|- McDonald, Ronald"]) | ||
expect(CourseReserve.new(doc).present?).to eq true | ||
end | ||
|
||
it "should not have a course reserve present" do | ||
doc = SolrDocument.new(id: '123') | ||
expect(CourseReserve.new(doc).present?).to eq false | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
require 'spec_helper' | ||
|
||
class CourseReservesTestClass | ||
include CourseReserves | ||
end | ||
|
||
describe CourseReserves do | ||
it "should return nil for non course reserve docs" do | ||
expect(CourseReservesTestClass.new.course_reserves).to be_nil | ||
end | ||
|
||
describe "present?" do | ||
it "should return false" do | ||
expect(CourseReservesTestClass.new.course_reserves.present?).to be_false | ||
end | ||
|
||
it "should return true" do | ||
doc = SolrDocument.new(id: '123', crez_course_info: ["CAT-401-01-01 -|- Emergency Kittenz -|- McDonald, Ronald"]) | ||
expect(doc.course_reserves.present?).to be_true | ||
end | ||
end | ||
|
||
describe CourseReserves::CourseInfo do | ||
let(:doc) {"CAT-401-01-01 -|- Emergency Kittenz -|- McDonald, Ronald"} | ||
let(:course_info) { CourseReserves::CourseInfo.new(doc) } | ||
it "should initialize a new reservation" do | ||
expect(course_info).to be_an CourseReserves::CourseInfo | ||
end | ||
|
||
it "should have the correct id" do | ||
expect(course_info.id).to eq "CAT-401-01-01" | ||
end | ||
|
||
it "should have the correct name" do | ||
expect(course_info.name).to eq "Emergency Kittenz" | ||
end | ||
|
||
it "should have the correct instructor" do | ||
expect(course_info.instructor).to eq "McDonald, Ronald" | ||
end | ||
end | ||
end |