Sha256: 3ecb9edf78c6c4f0a1f6b000f68947a0aa31ecefe47d38253c3cd4cce1348255

Contents?: true

Size: 1.33 KB

Versions: 6

Compression:

Stored size: 1.33 KB

Contents

require 'action_view/helpers/url_helper'

class Sidebar
  include ActionView::Helpers::UrlHelper
  include ERB::Util
  
  def initialize(controller)
    @controller = controller
  end

  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
    
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
backlog-0.35.0 app/models/sidebar.rb
backlog-0.35.1 app/models/sidebar.rb
backlog-0.35.2 app/models/sidebar.rb
backlog-0.35.3 app/models/sidebar.rb
backlog-0.35.4 app/models/sidebar.rb
backlog-0.35.5 app/models/sidebar.rb