Skip to content
This repository has been archived by the owner on Nov 21, 2022. It is now read-only.

Commit

Permalink
Fix Issue 14
Browse files Browse the repository at this point in the history
Issue: #14

Fixed issue by doing the following:
When processing a CRN, add a hash to the url so that when the course page is loaded, the section with the CRN will be jumped to. (app/controllers/search_controller.rb)

Additionally, with CSS, highlight the target course with a green color (#afa) to signify that it is the desired course. (app/assets/stylesheets/application.scss)

Turbolink messes with the behaviour of anchors, so when the page is loaded, a script makes sure that the hash is acted upon. (app/views/courses/show.html)
  • Loading branch information
ThorGuy committed Aug 24, 2020
1 parent c7f8b5e commit 2b4ec13
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions schedules/app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -288,3 +288,7 @@ footer {
top: 3%;
}
}

:target {
background-color:#afa;
}
4 changes: 3 additions & 1 deletion schedules/app/controllers/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ def index
end

/[0-9]{5}/.match(params[:query]) do |m|
redirect_to(course_url(CourseSection.latest_by_crn(m[0]).course))
course = CourseSection.latest_by_crn(m[0])
url = course_url(course.course) + "#section-" + course.id.to_s
redirect_to(url)
end

if @courses&.count == 1 && @instructors&.count&.zero?
Expand Down
10 changes: 10 additions & 0 deletions schedules/app/views/courses/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
<%= render partial: 'shared/navbar' %>

<script>
//turbolinks prevents the site from properly jumping to an element when using https://www.url.com/page#element-id
//additionally, CSS styling is not properly applied to any :target attributes
//this prevented issue 14 from being resolved (https://github.com/srct/schedules/issues/14)
//the following script forces the page to update both the CSS and the window's location *after* turbolinks does its thing.
document.addEventListener("turbolinks:load", function(){
window.location = window.location.hash;
});
</script>

<div class="row">
<div class="col-12 col-lg">
<h1><%= @course.full_name %></h1>
Expand Down

0 comments on commit 2b4ec13

Please sign in to comment.