Class: Sidebar
- Inherits:
-
Object
- Object
- Sidebar
- Includes:
- ActionView::Helpers::TagHelper, ActionView::Helpers::UrlHelper, ERB::Util
- Defined in:
- app/models/sidebar.rb
Instance Method Summary collapse
- #blocks(period) ⇒ Object
-
#initialize(controller) ⇒ Sidebar
constructor
A new instance of Sidebar.
Constructor Details
#initialize(controller) ⇒ Sidebar
Returns a new instance of Sidebar.
8 9 10 |
# File 'app/models/sidebar.rb', line 8 def initialize(controller) @controller = controller end |
Instance Method Details
#blocks(period) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/models/sidebar.rb', line 12 def blocks(period) @period = period # TODO (uwe): This does not scale! #periods = Period.find(:all).select {|period| period.active_or_future?(true) && period.party.includes?(user)} periods = Period.find_active_or_future(true) blocks = periods.sort_by {|p| p.required_speed}.reverse.map do |period| content = @controller.render_to_string :partial => '/periods/sidebar_block', :locals => {:period => period} { :id => period.id, :title => "#{period.party.name}##{period.position} (#{'%0.1f' % period.required_speed})", :options => {:controller => 'periods', :action => :show, :id => period}, :content => content } end started_tasks = Task.find_started if not started_tasks.empty? links = started_tasks.map do |task| "<li><a href=\"#{url_for :controller => 'tasks', :action => :list_started, :id => task.id}\">#{task.description}</a></li>" end blocks.unshift({ :title => @controller.l(:started_tasks), :options => {:controller => 'tasks', :action => :list_started}, :content => "<ul>#{links}" }) end blocks end |