Commit 8e0b4f45 authored by Zach Perkins's avatar Zach Perkins

Finished toying with front-end to make way for filtering

parent 7822496c
......@@ -28,34 +28,29 @@ body {
box-shadow: 0 0 5px rgba(0,0,0,0.2);
transition: 0.3s;
ul.attr-list {
list-style-type: none;
margin: 0;
padding: 0;
li {
&:nth-child(odd) {
float: left;
clear: left;
}
&:nth-child(even) {
float: right;
clear: right;
}
}
}
.card-header {
display: flex;
flex-direction: column;
}
.card-body {
.attr-list {
display: flex;
flex-direction: row;
justify-content: flex-start;
padding-bottom: 10px;
.attr {
margin-right: 13px;
}
}
}
}
.unpadded {
padding: 0px;
}
/* On mouse-over, add a deeper shadow */
.card:hover {
box-shadow: 0 0 20px rgba(0,0,0,0.4);
......
......@@ -4,18 +4,18 @@ module CourseListingsHelper
@course = course
@sections = course.course_sections
end
def self.name
:course
end
def self.wrap(course_list)
course_listings = []
course_list.each do |course|
course_listings.push(CourseListing.new(course))
end
course_listings
end
end
end
\ No newline at end of file
end
......@@ -3,23 +3,23 @@ module SearchHelper
attr_reader :semester
attr_reader :sort_mode
attr_reader :search_string
def initialize(search_string, sort_mode, semester)
@semester = semester
@sort_mode = sort_mode
@search_string = search_string
end
end
class GenericItem
attr_reader :data
attr_reader :type
def initialize(type, data)
@type = type
@data = data
end
def self.fetchall(search_string, sort_mode: :auto, semester: :fall2018)
query_data = GenericQueryData.new(search_string, sort_mode, semester)
models = []
......@@ -27,13 +27,13 @@ module SearchHelper
models += fetch_courses query_data
build_list(models)
end
def self.fetch_instructors(query_data)
Instructor.from_name(Instructor.select("instructors.*, COUNT(course_sections.id) AS section_count"), query_data.search_string)
.left_outer_joins(:course_sections)
.group("instructors.id")
end
def self.fetch_courses(query_data)
query_string = query_data.search_string
query_string.upcase!
......@@ -43,54 +43,52 @@ module SearchHelper
.having("section_count > 0")
.where("courses.semester_id = ?", query_data.semester)
.group("courses.id")
subj = nil
query_string.scan(/(?<= |^)([a-zA-Z]{2,4})(?=$| )/).each do |a|
s = a[0]
if get_count(Course.from_subject(base_query, s)).positive?
subj = s
base_query = Course.from_subject(base_query, subj)
query_string.remove!(s)
end
next unless get_count(Course.from_subject(base_query, s)).positive?
subj = s
base_query = Course.from_subject(base_query, subj)
query_string.remove!(s)
end
query_string.scan(/(?<= |^)(\d{3})(?=$| )/).each do |a|
s = a[0]
next unless !subj.nil? && get_count(Course.from_course_number(base_query, s)).positive?
base_query = Course.from_course_number(base_query, s)
return base_query.all
end
stripped_query_string = query_string.gsub(/ +/, " ").strip
# There's more to parse
if stripped_query_string.length.positive?
base_query = Course.from_title(base_query, stripped_query_string)
base_query = if stripped_query_string.length.positive?
Course.from_title(base_query, stripped_query_string)
.order("section_count DESC")
else
base_query = base_query.order("courses.course_number ASC")
end
else
base_query.order("courses.course_number ASC")
end
base_query.all
end
# Given a set of models, create a list of GenericItems for each model's data
def self.build_list(models)
list = []
models.each do |model|
list.push(GenericItem.new(model.class.name.underscore.to_sym, model))
end
list
end
def self.get_count(base_query)
# I think I finally hit a limit of active record
ActiveRecord::Base.connection.execute("SELECT COUNT(*) AS count FROM (#{base_query.to_sql})")[0]["count"]
end
def to_s()
def to_s
@type
end
end
......
......@@ -2,16 +2,15 @@
<div class="card" id="course-<%= course.id %>" onclick="toggleSections(this)">
<div class="card-header">
<h3><%= "#{course.subject} #{course.course_number}" %></h3>
<h4><%= "#{course.subject} #{course.course_number}" %></h4>
<h5><em><%= course.title %></em>. <%= course.credits %> credits.</h5>
</div>
<div class="card-body">
<div>
<ul class="attr-list">
<li><i class="fa fa-book"></i></li>
</ul>
<div class="attr-list">
<div class="attr"><i class="fa fa-book"></i> 3 credits</div>
<div class="attr"><i class="fa fa-bars"></i> 3 sections</div>
</div>
<p class="description"><%= course.description %>...</p>
<p class="description"><%= course.description %></p>
<% unless course.prereqs.nil? || course.prereqs.empty? %>
<% first, rest = course.prereqs.split(':') %>
......
<div class="card">
<div class="card-header">
<h4><%= "#{instructor.name}" %></h4>
</div>
<div class="card-body">
<h3><%= "#{instructor.name}" %></h3>
<ul class="attr-list">
<li><i class="fa fa-user"></i> Instructor</li>
<li><i class="fa fa-bars"></i> <%= "#{instructor.section_count}" %> sections</li>
</ul>
<div class="attr-list">
<div class="attr"><i class="fa fa-user"></i> Instructor</div>
<div class="attr"><i class="fa fa-bars"></i> <%= "#{instructor.section_count}" %> sections</div>
</div>
</div>
</div>
\ No newline at end of file
......@@ -17,12 +17,24 @@
class="list-group-item section-item <%= "selected" if @cart.include? section %>"
data-crn="<%= section.crn %>"
onclick="addOrRemoveFromSchedule(event, this)">
<ul class="attr-list">
<li><b class="subj"><%= "#{section.name}" %></b>: <%= section.title %></li>
<li><i class="fas fa-map-marker-alt"></i> <%= section.location %></li>
<li><i class="fas fa-chalkboard-teacher"></i> <%= link_to section.instructor.name, instructor_path(section.instructor) %> </li>
<li><i class="fas fa-clock"></i> <%= "#{section.days}, #{section.start_time}-#{section.end_time}" %></li>
</ul>
<div class="unpadded container">
<div class="row">
<div class="col">
<b class="subj"><%= "#{section.name}" %></b>: <%= section.title %>
</div>
<div class="col text-right">
<i class="fas fa-map-marker-alt"></i> <%= section.location %>
</div>
</div>
<div class="row">
<div class="col">
<i class="fas fa-chalkboard-teacher"></i> <%= link_to section.instructor.name, instructor_path(section.instructor) %>
</div>
<div class="col text-right">
<i class="fas fa-clock"></i> <%= "#{section.days}, #{section.start_time}-#{section.end_time}" %>
</div>
</div>
</div>
</div>
<% end %>
......
......@@ -2,7 +2,7 @@
Rails.application.routes.draw do
get 'search', to: 'search#index'
get 'sessions/update', as: 'update_session'
resources :instructors, only: [:index, :show]
scope :api do # Register /api routes
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment