Skip to content

Commit

Permalink
before changing time scheduling logic
Browse files Browse the repository at this point in the history
  • Loading branch information
pitosalas committed Jan 3, 2017
1 parent ecedfa8 commit ee58273
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 90 deletions.
2 changes: 2 additions & 0 deletions lib/coursegen/course/data/citem.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'byebug'
require 'active_support/inflector'

#
Expand Down Expand Up @@ -52,6 +53,7 @@ def lecture_date_s

def schedule_start_date_time
return if @lecture_date.nil?
byebug
schedule = Toc.instance.section(@section).schedule
lecture_date + schedule.start_time
end
Expand Down
145 changes: 73 additions & 72 deletions lib/coursegen/course/data/lectures.rb
Original file line number Diff line number Diff line change
@@ -1,91 +1,92 @@
require 'tree'

class Lectures < Section
def initialize(sect, citems, schedule=nil, collapsed=false)
super sect, citems, collapsed
@schedule = schedule || ::Scheduler.new
@citems = sort_items
build_tree
end
def initialize(sect, citems, schedule=nil, collapsed=false)
super sect, citems, collapsed
@schedule = schedule || ::Scheduler.new
@citems = sort_items
build_tree
end

def has_subsections?
true
end
def has_subsections?
true
end

def has_lecture_numbers?
true
end
def has_lecture_numbers?
true
end

def schedule
@schedule
end
def schedule
@schedule
end

def build_tree
lecture_num = 1
@root = Tree::TreeNode.new("root", "root")
@citems.each do |i|
i.lecture_number = lecture_num
i.lecture_date = @schedule.event_date_by_index(lecture_num - 1) # Lecture numbers are base 1
if i.type == "subsection"
@root.add(Tree::TreeNode.new(i.subsection, i))
elsif i.type == "page"
parent_tree_node = parent_node_of(i)
parent_tree_node.add(Tree::TreeNode.new(i.identifier, i))
lecture_num += 1
else
raise ArgumentError, "invalid lecture page type of #{i.type}for #{i.title}"
end
end
end
def build_tree
lecture_num = 1
@root = Tree::TreeNode.new("root", "root")
@citems.each do |i|
i.lecture_number = lecture_num
i.lecture_date = @schedule.event_date_by_index(lecture_num - 1) # Lecture numbers are base 1
if i.type == "subsection"
@root.add(Tree::TreeNode.new(i.subsection, i))
elsif i.type == "page"
parent_tree_node = parent_node_of(i)
parent_tree_node.add(Tree::TreeNode.new(i.identifier, i))
lecture_num += 1
else
raise ArgumentError, "invalid lecture page type of #{i.type}for #{i.title}"
end
end
end

def parent_node_of citem
parent_node = @root[citem.subsection]
raise RuntimeError, "Cant find section for item: #{citem.identifier}" if parent_node.nil?
parent_node
end
def parent_node_of citem
parent_node = @root[citem.subsection]
raise RuntimeError, "Cant find section for item: #{citem.identifier}" if parent_node.nil?
parent_node
end

def treenode_of citem
@root.find do
|tree_node|
if citem.type == "subsection"
citem.subsection == tree_node.name
else
citem.identifier == tree_node.name
end
end
end
def treenode_of citem
@root.find do |tree_node|
if citem.type == "subsection"
citem.subsection == tree_node.name
else
citem.identifier == tree_node.name
end
end
end

def subsections
@root.children
end
def subsections
@root.children
end

def next_for(citem)
next_node = treenode_of(citem).next_sibling
if !next_node.nil?
next_node.content
else
citem
end
end
def next_for(citem)
next_node = treenode_of(citem).next_sibling
if !next_node.nil?
next_node.content
else
citem
end
end

def previous_for(citem)
prev_node = treenode_of(citem).previous_sibling
if !prev_node.nil?
prev_node.content
else
citem
end
end
def previous_for(citem)
prev_node = treenode_of(citem).previous_sibling
if !prev_node.nil?
prev_node.content
else
citem
end
end

protected
protected

#
# Sort all the items in this section: First by the ordering of the subseciton
# that the item belongs to, and second by the item's own indicated order.
#
def sort_items
new_citems = @citems.sort_by { |i| [ lookup_citem_by_identifier(i.subsection+"index.html").order, ((i.type == "page" ? 100 : 1 ) * i.order) ] }
@items = new_citems
end

def sort_items
new_citems = @citems.sort_by do |i|
[lookup_citem_by_identifier(i.subsection + "index.html").order,
((i.type == "page" ? 100 : 1) * i.order)]
end
@items = new_citems
end
end
12 changes: 6 additions & 6 deletions lib/coursegen/course/data/section_def.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Sidebar configuration

class SectionDef
attr_accessor :title, :selector, :options
def initialize(title, selector, options = {})
@title = title
@selector = selector
@options = options
end
attr_accessor :title, :selector, :options
def initialize(title, selector, options = {})
@title = title
@selector = selector
@options = options
end
end
2 changes: 1 addition & 1 deletion lib/coursegen/course/helpers/ical_feed_helpers.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module ICalFeedHelpers
def generate_ical source
data_adaptor = DataAdaptor.new(source)
ical_adaptor = ICalAdaptor.new()
ical_adaptor = ICalAdaptor.new
schedule_feed = ScheduleFeed.new(ical_adaptor, data_adaptor)
schedule_feed.render
end
Expand Down
16 changes: 7 additions & 9 deletions lib/coursegen/course/helpers/list_of.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class ListOf

# source: name of a section as a string
# rows: array with one or more of:
# "pages"
Expand Down Expand Up @@ -56,13 +55,13 @@ def generate_rows
end

def generate_detail_row(row_id)
@mark.row_begin
@cols.each do |col_selector|
@mark.cell_begin
@mark.cell_content(cell_content_string(row_id, col_selector, detail: true))
@mark.cell_end
end
@mark.row_end
@mark.row_begin
@cols.each do |col_selector|
@mark.cell_begin
@mark.cell_content(cell_content_string(row_id, col_selector, detail: true))
@mark.cell_end
end
@mark.row_end
end

def generate_summary_row(row_id)
Expand Down Expand Up @@ -99,5 +98,4 @@ def include_by_subsection_path?(row_id)
def subsection_hdr?(row_id)
row_id.type == "subsection"
end

end
4 changes: 3 additions & 1 deletion lib/coursegen/course/schedule/schedule_feed.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Used in generating iCal feed. Given a data_adapter (who knows how to get data out and iterate across things) and a feed_builder (who knows how to turn that data into some kind of feed), produce the feed. This same class could also generate, for example, an RSs feed.
# Used in generating iCal feed. Given a data_adapter (who knows how to get data out and iterate across things) and a
# feed_builder (who knows how to turn that data into some kind of feed), produce the feed. This same class could also
# generate, for example, an RSs feed.

class ScheduleFeed
def initialize feed_builder, data_adapter
Expand Down
2 changes: 1 addition & 1 deletion lib/coursegen/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Coursegen
VERSION = "0.3.2"
VERSION = "0.4.0"
end

0 comments on commit ee58273

Please sign in to comment.