Commit 6c8d6b74 authored by Zac Wood's avatar Zac Wood

basic calendar setup

parent 4fc4f044
......@@ -16,18 +16,32 @@ class SchedulesController < ApplicationController
render plain: @schedule.to_ical # render a plaintext iCal file
end
DAYS = {
"M": Date.new(2019, 1, 14),
"T": Date.new(2019, 1, 15),
"W": Date.new(2019, 1, 16),
"R": Date.new(2019, 1, 17),
"F": Date.new(2019, 1, 18),
"S": Date.new(2019, 1, 19),
"U": Date.new(2019, 1, 20)
}.freeze
def show
@events = @cart.map do |_cid, sections|
s = sections.first
formatted_date = Date.today.to_s.tr('-', '')
formatted_time = Time.parse(s.start_time).strftime("%H%M%S")
formatted_endtime = Time.parse(s.end_time).strftime("%H%M%S")
s.days.split('').map do |day|
formatted_date = DAYS[day.to_sym].to_s.tr('-', '')
time = Time.parse(s.start_time).strftime("%H%M%S")
endtime = Time.parse(s.end_time).strftime("%H%M%S")
{
title: s.name,
start: "#{formatted_date}T#{formatted_time}",
end: "#{formatted_date} #{formatted_endtime}"
}
end
{
title: s.name,
start: "#{formatted_date}T#{time}",
end: "#{formatted_date}T#{endtime}"
}
end
end.flatten
end
end
......@@ -2,8 +2,6 @@
#
# TODO: Add more docs
require("course_replacement_helper.rb")
class Course < ApplicationRecord
# Each course belongs to a +Semester+
belongs_to :semester
......@@ -14,12 +12,6 @@ class Course < ApplicationRecord
validates :subject, presence: true
validates :semester_id, presence: true
# Returns all +CourseSection+ objects that belong to this course.
# @return [Array]
def course_sections
CourseSection.where course_id: id
end
def self.from_subject(base_query, subject)
base_query.where("courses.subject = ?", subject.upcase)
end
......
......@@ -10,6 +10,15 @@ class CourseSection < ApplicationRecord
validates :title, presence: true
validates :course_id, presence: true
def labs
return nil unless section_type == "Lecture"
lecture_number = name.split[name.split.length-1]
course.course_sections.select do |s|
s.title.split[s.title.split.length-1] == lecture_number
end
end
# Select all course sections that have an instructor that matches the given name
def self.with_instructor(name: "")
joins(:instructor).where("instructors.name LIKE ?", "%#{name}%").select('course_sections.*, instructors.name as instructor_name')
......
......@@ -12,6 +12,7 @@
const events = JSON.parse(eventsJSON);
console.log(events);
$('#calendar').fullCalendar({
defaultDate: new Date(2019, 0, 14),
defaultView: 'agendaWeek',
header: { right: 'next'},
events: events
......
<% expanded = false unless defined? expanded %>
<div class="card" id="course-<%= course.id %>" onclick="toggleSections(this)">
<div class="card-header">
<h4 class="title"><%= "#{course.subject} #{course.course_number}" %></h4>
<h5><em><%= course.title %></em>. <%= course.credits %> credits.</h5>
<h4 id="add-course-btn" onclick="addCourse(event, '<%= course.id %>');">
<i class="fas fa-plus" style="color: green"></i>
</h4>
</div>
<div class="card-body">
<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 class="card-header">
<h4 class="title"><%= "#{course.subject} #{course.course_number}" %></h4>
<h5><em><%= course.title %></em>. <%= course.credits %> credits.</h5>
<h4 id="add-course-btn" onclick="addCourse(event, '<%= course.id %>');">
<i class="fas fa-plus" style="color: green"></i>
</h4>
</div>
<p class="description"><%= course.description %></p>
<div class="card-body">
<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>
<% unless course.prereqs.nil? || course.prereqs.empty? %>
<% first, rest = course.prereqs.split(':') %>
<% prereqs, note = rest.split('.') %>
<p><strong><%= first %>:</strong> <%= prereqs %> <sub><%= note %></sub></p>
<% end %>
<div class="d-block" style="text-align: center">
<p style="margin-bottom:-4px; font-size: 10px;">Expand</p>
<i class="fas fa-chevron-down"></i>
</div>
<!-- List of Course Sections -->
<div class="list-group list-group-flush sections" style="display: <%= expanded ? "flex" : "none" %>">
<% unless course.prereqs.nil? || course.prereqs.empty? %>
<% first, rest = course.prereqs.split(':') %>
<% prereqs, note = rest.split('.') %>
<p><strong><%= first %>:</strong> <%= prereqs %> <sub><%= note %></sub></p>
<% end %>
<div class="d-block" style="text-align: center">
<p style="margin-bottom:-4px; font-size: 10px;">Expand</p>
<i class="fas fa-chevron-down"></i>
</div>
<!-- List of Course Sections -->
<div class="list-group list-group-flush sections" style="display: <%= expanded ? "flex" : "none" %>">
<% if defined?(@instructor) %>
<%= render partial: 'shared/section', collection: course.course_sections.where(instructor: @instructor), locals: { course: course } %>
<%= render partial: 'shared/section', collection: course.course_sections.where(instructor: @instructor), locals: { course: course } %>
<% else %>
<%= render partial: 'shared/section', collection: course.course_sections, locals: { course: course } %>
<%= render partial: 'shared/section', collection: course.course_sections, locals: { course: course } %>
<% end %>
</div>
</div>
</div>
</div>
\ No newline at end of file
</div>
......@@ -33,14 +33,14 @@
<div class="col order-1 order-sm-0">
<form action="/search" class="form">
<div class="form-group">
<div class="input-group" style="width:100%;">
<input name="query" type="text" class="form-control" placeholder="Search by CRN, course, professor..." aria-describedby="basic-addon2">
<div class="input-group-append">
<button class="btn btn-secondary" type="button">
<i class="fas fa-search"></i>
</button>
</div>
</div>
<div class="input-group" style="width:100%;">
<input name="query" type="text" class="form-control" placeholder="Search by CRN, course, professor..." aria-describedby="basic-addon2">
<div class="input-group-append">
<button class="btn btn-secondary" type="button">
<i class="fas fa-search"></i>
</button>
</div>
</div>
</div>
</form>
</div>
......
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