class PostRunner::ActivityListView
Generates a paged list of all Activity
objects in the database. HTML and plain text output are supported.
Public Class Methods
new(ffs)
click to toggle source
# File lib/postrunner/ActivityListView.rb, line 27 def initialize(ffs) @ffs = ffs @unit_system = @ffs.store['config']['unit_system'].to_sym @page_size = 20 @page_no = -1 @last_page = (@ffs.activities.length - 1) / @page_size end
Public Instance Methods
to_s()
click to toggle source
# File lib/postrunner/ActivityListView.rb, line 42 def to_s generate_table.to_s end
update_index_pages()
click to toggle source
# File lib/postrunner/ActivityListView.rb, line 35 def update_index_pages 0.upto(@last_page) do |page_no| @page_no = page_no generate_html_index_page(page_no) end end
Private Instance Methods
body(doc)
click to toggle source
# File lib/postrunner/ActivityListView.rb, line 67 def body(doc) @view.body { doc.div({ :class => 'main' }) { ViewFrame.new('activities', 'Activities', 900, generate_table).to_html(doc) } } end
generate_html_index_page(page_index)
click to toggle source
# File lib/postrunner/ActivityListView.rb, line 48 def generate_html_index_page(page_index) views = @ffs.views views.current_page = 'index.html' pages = PagingButtons.new((0..@last_page).map do |i| "index#{i == 0 ? '' : "-#{i}"}.html" end) pages.current_page = "index#{page_index == 0 ? '' : "-#{page_index}"}.html" @view = View.new("PostRunner Activities", views, pages) @view.doc.head { @view.doc.style(style) } body(@view.doc) output_file = File.join(@ffs.store['config']['html_dir'], pages.current_page) @view.write(output_file) end
generate_table()
click to toggle source
# File lib/postrunner/ActivityListView.rb, line 76 def generate_table i = @page_no < 0 ? 0 : @page_no * @page_size t = FlexiTable.new t.head t.row(%w( Ref. Activity Type Start Distance Duration Speed/Pace ), { :halign => :left }) t.set_column_attributes([ { :halign => :right }, {}, {}, {}, { :halign => :right }, { :halign => :right }, { :halign => :right } ]) t.body activities = @page_no == -1 ? @ffs.activities : @ffs.activities[(@page_no * @page_size).. ((@page_no + 1) * @page_size - 1)] activities.each do |a| t.row([ i += 1, ActivityLink.new(a, true), a.query('type'), a.query('long_date'), local_value(a.total_distance, 'm', '%.2f', { :metric => 'km', :statute => 'mi' }), secsToHMS(a.total_timer_time), a.sport == 'running' ? pace(a.avg_speed) : local_value(a.avg_speed, 'm/s', '%.1f', { :metric => 'km/h', :statute => 'mph' }) ]) end t end
local_value(value, from_unit, format, units)
click to toggle source
# File lib/postrunner/ActivityListView.rb, line 125 def local_value(value, from_unit, format, units) to_unit = units[@unit_system] return '-' unless value value *= conversion_factor(from_unit, to_unit) "#{format % [value, to_unit]}" end
pace(speed)
click to toggle source
# File lib/postrunner/ActivityListView.rb, line 132 def pace(speed) case @unit_system when :metric "#{speedToPace(speed)}" when :statute "#{speedToPace(speed, 1609.34)}" else Log.fatal "Unknown unit system #{@unit_system}" end end
style()
click to toggle source
# File lib/postrunner/ActivityListView.rb, line 110 def style <<EOT body { font-family: verdana,arial,sans-serif; margin: 0px; } .main { text-align: center; } .ft_cell { height: 30px } EOT end