Commit 35483d61 authored by Zac Wood's avatar Zac Wood

Added Closure model

parent 7ef43b49
......@@ -17,23 +17,6 @@ class CalendarGeneratorController < ApplicationController
private
NO_CLASSES = [
"20180903",
"20181008",
(21..25).map { |n| "201811#{n}" },
(10..19).map { |n| "201812#{n}" }
].flatten.freeze
DAYS = {
"M" => "MO",
"T" => "TU",
"W" => "WE",
"R" => "TH",
"F" => "FR",
"S" => "SA",
"U" => "SU"
}.freeze
def generate_event_from_section(section)
event = Icalendar::Event.new
......@@ -42,9 +25,7 @@ class CalendarGeneratorController < ApplicationController
event.dtstart = Icalendar::Values::DateTime.new(formatted_datetime_str(section.start_date, section.start_time))
event.dtend = Icalendar::Values::DateTime.new(formatted_datetime_str(section.start_date, section.end_time))
event.rrule = Icalendar::Values::Recur.new(recurrence_rule_str(section))
event.exdate = no_classes.map { |date| generate_exdate(date, section.start_time) }
event.exdate = exdates_for_section(section)
event
end
......@@ -56,7 +37,16 @@ class CalendarGeneratorController < ApplicationController
"#{formatted_date}T#{formatted_time}"
end
DAYS = {
"M" => "MO",
"T" => "TU",
"W" => "WE",
"R" => "TH",
"F" => "FR",
"S" => "SA",
"U" => "SU"
}.freeze
def recurrence_rule_str(section)
days = section.days.split("").map do |day|
DAYS[day]
......@@ -65,6 +55,12 @@ class CalendarGeneratorController < ApplicationController
"FREQ=WEEKLY;UNTIL=#{formatted_datetime_str(section.end_date, section.end_time)};BYDAY=#{days.join(',')}"
end
def exdates_for_section(section)
Closure.where(semester: section.course.semester).map { |closure|
generate_exdate(closure.date.to_formatted_s(:number), section.start_time)
}
end
def generate_exdate(date, time)
formatted_time = Time.parse(time).strftime("%H%M%S")
Icalendar::Values::DateTime.new("#{date}T#{formatted_time}")
......
class Closure < ApplicationRecord
belongs_to :semester
validates :date, presence: true
end
class CreateClosures < ActiveRecord::Migration[5.1]
def change
create_table :closures do |t|
t.date :date
t.references :semester, foreign_key: true
t.timestamps
end
end
end
......@@ -10,7 +10,15 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20180407190750) do
ActiveRecord::Schema.define(version: 20180505195736) do
create_table "closures", force: :cascade do |t|
t.date "date"
t.integer "semester_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["semester_id"], name: "index_closures_on_semester_id"
end
create_table "courses", force: :cascade do |t|
t.string "subject"
......
......@@ -8,10 +8,24 @@
require 'rubyXL'
require_relative 'excel_loader'
Semester.delete_all
Course.delete_all
Section.delete_all
Closure.delete_all
loader = if Rails.env.test?
ExcelLoader.new 'db/data/testdata.xlsx'
else
ExcelLoader.new 'db/data/allsections.xlsx'
end
semester = Semester.where(season: "Fall", year: "2018").first
Closure.create! date: Date.new(2018, 9, 3), semester: semester
Closure.create! date: Date.new(2018, 10, 8), semester: semester
(21..25).each { |n| Closure.create! date: Date.new(2018, 11, n), semester: semester }
(10..19).each { |n| Closure.create! date: Date.new(2018, 12, n), semester: semester }
loader.load_data
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
date: 2018-05-05
semester: one
two:
date: 2018-05-05
semester: two
require 'test_helper'
class ClosureTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
......@@ -21,6 +21,7 @@
"dependencies": {
"@types/react": "^16.3.12",
"@types/react-dom": "^16.0.5",
"file-saver": "^1.3.8",
"react": "^16.3.2",
"react-dom": "^16.3.2"
}
......
......@@ -1955,6 +1955,10 @@ figures@^2.0.0:
dependencies:
escape-string-regexp "^1.0.5"
file-saver@^1.3.8:
version "1.3.8"
resolved "https://registry.yarnpkg.com/file-saver/-/file-saver-1.3.8.tgz#e68a30c7cb044e2fb362b428469feb291c2e09d8"
filename-regex@^2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/filename-regex/-/filename-regex-2.0.1.tgz#c1c4b9bee3e09725ddb106b75c1e301fe2f18b26"
......
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