13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/report.rb', line 13
def week
@report[:tasks] = @db.fetch("SELECT * FROM tasks
WHERE (created_at BETWEEN #{last_mon} AND #{now})
OR id IN (SELECT task_id FROM subtasks WHERE (created_at BETWEEN #{last_mon} AND #{now})
OR (finished_at BETWEEN #{last_mon} AND #{now}))
OR id IN (SELECT task_id FROM notes WHERE (created_at BETWEEN #{last_mon} AND #{now}))
ORDER BY id DESC").to_a
order = Array.new
@report[:tasks].each{ |task| order << task[:id] }
@report[:tasks].select{ |task| task[:created_at].between?(last_mon, now) }.each{ |task| to_event(task) }
@db[:notes].where("created_at BETWEEN #{last_mon} AND #{now}").all.each{ |note| to_event(note) }
@db[:subtasks].where("created_at BETWEEN #{last_mon} AND #{now}").all.each{ |subtask| to_event(subtask) }
@db[:subtasks].where("finished_at BETWEEN #{last_mon} AND #{now}").all.each{ |subtask| to_event(subtask, :finished) }
@report[:events].sort_by!{ |event| [order.index(event[:task_id]), event[:timestamp]] }
return @report
end
|