diff options
author | Chris Schlaeger <chris@linux.com> | 2014-08-23 20:20:04 +0200 |
---|---|---|
committer | Chris Schlaeger <chris@linux.com> | 2014-08-23 20:20:04 +0200 |
commit | c5001f84e7a5f6714909387389992b971c9d5766 (patch) | |
tree | cd83c1a2152dafd9fc4ba9c32ec5767a6e0d53f2 /lib | |
parent | c879fd4a6e1da1996c7f05daf3979080e3d51f29 (diff) | |
download | postrunner-c5001f84e7a5f6714909387389992b971c9d5766.zip |
Paging support for browser list view.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/postrunner/ActivitiesDB.rb | 2 | ||||
-rw-r--r-- | lib/postrunner/ActivityListView.rb | 51 | ||||
-rw-r--r-- | lib/postrunner/Main.rb | 8 | ||||
-rw-r--r-- | lib/postrunner/ViewWidgets.rb | 32 |
4 files changed, 77 insertions, 16 deletions
diff --git a/lib/postrunner/ActivitiesDB.rb b/lib/postrunner/ActivitiesDB.rb index fd26e13..6dd3593 100644 --- a/lib/postrunner/ActivitiesDB.rb +++ b/lib/postrunner/ActivitiesDB.rb @@ -189,6 +189,7 @@ module PostRunner # Show the activity list in a web browser. def show_list_in_browser + #ActivityListView.new(self).update_html_index show_in_browser(File.join(@html_dir, 'index.html')) end @@ -229,6 +230,7 @@ module PostRunner create_directory(@fit_dir, 'fit') create_directory(@html_dir, 'html') + create_symlink('icons') create_symlink('jquery') create_symlink('flot') create_symlink('openlayers') diff --git a/lib/postrunner/ActivityListView.rb b/lib/postrunner/ActivityListView.rb index 40728b1..5a37c26 100644 --- a/lib/postrunner/ActivityListView.rb +++ b/lib/postrunner/ActivityListView.rb @@ -42,17 +42,16 @@ module PostRunner def initialize(db) @db = db + @page_size = 20 + @page_no = -1 + @last_page = (@db.activities.length - 1) / @page_size end def update_html_index - doc = HTMLBuilder.new - - doc.html { - head(doc) - body(doc) - } - - write_file(doc) + 0.upto(@last_page) do |page_no| + @page_no = page_no + generate_html_index_page + end end def to_html(doc) @@ -65,6 +64,17 @@ module PostRunner private + def generate_html_index_page + doc = HTMLBuilder.new + + doc.html { + head(doc) + body(doc) + } + + write_file(doc) + end + def head(doc) doc.head { doc.meta({ 'http-equiv' => 'Content-Type', @@ -90,13 +100,26 @@ body { .activity_link { padding: 0px 3px 0px 3px; } +.ft_cell { + height: 30px +} EOT ) end def body(doc) doc.body { - titlebar(doc) + first_page = @page_no == 0 ? nil: 'index.html' + prev_page = @page_no == 0 ? nil : + @page_no == 1 ? 'index.html' : + "index#{@page_no - 1}.html" + prev_page = @page_no == 0 ? nil : + @page_no == 1 ? 'index.html' : + "index#{@page_no - 1}.html" + next_page = @page_no < @last_page ? "index#{@page_no + 1}.html" : nil + last_page = @page_no == @last_page ? nil : "index#{@last_page}.html" + titlebar(doc, first_page, prev_page, nil, next_page, last_page) + doc.div({ :class => 'main' }) { frame(doc, 'Activities') { generate_table.to_html(doc) @@ -107,7 +130,7 @@ EOT end def generate_table - i = 0 + i = @page_no * @page_size t = FlexiTable.new t.head t.row(%w( Ref. Activity Start Distance Duration Pace ), @@ -120,7 +143,10 @@ EOT { :halign => :right } ]) t.body - @db.activities.each do |a| + activities = @page_no == -1 ? @db.activities : + @db.activities[(@page_no * @page_size).. + ((@page_no + 1) * @page_size - 1)] + activities.each do |a| t.row([ i += 1, ActivityLink.new(a), @@ -134,7 +160,8 @@ EOT end def write_file(doc) - output_file = File.join(@db.html_dir, 'index.html') + output_file = File.join(@db.html_dir, + "index#{@page_no == 0 ? '' : @page_no}.html") begin File.write(output_file, doc.to_html) rescue IOError diff --git a/lib/postrunner/Main.rb b/lib/postrunner/Main.rb index bd21a17..a2e6d11 100644 --- a/lib/postrunner/Main.rb +++ b/lib/postrunner/Main.rb @@ -180,6 +180,11 @@ EOT process_files([ @cfg.get_option(:import_dir) ], :import) else process_files(args, :import) + if args.length == 1 && Dir.exists?(args[0]) + # If only one directory was specified as argument we store the + # directory for future use. + @cfg.set_option(:import_dir, args[0]) + end end when 'list' @activities.list @@ -247,9 +252,6 @@ EOT process_file(fod, command) end end - if command == :import - @cfg.set_option(:import_dir, File.dirname(files_or_dirs[-1])) - end end def process_file(file, command) diff --git a/lib/postrunner/ViewWidgets.rb b/lib/postrunner/ViewWidgets.rb index 05e5455..6533418 100644 --- a/lib/postrunner/ViewWidgets.rb +++ b/lib/postrunner/ViewWidgets.rb @@ -23,12 +23,24 @@ module PostRunner background: linear-gradient(#7FA1FF 0, #002EAC 50px); } .title { + float: left; font-size: 24pt; font-style: italic; font-weight: bold; color: #F8F8F8; padding: 3px 30px; } +.navigator { + float: right; + padding: 3px 30px; +} +.active_button { + padding: 5px; +} +.inactive_button { + padding: 5px; + opacity: 0.4; +} .widget_frame { box-sizing: border-box; width: 600px; @@ -94,13 +106,31 @@ EOT } end - def titlebar(doc) + def titlebar(doc, first_page = nil, prev_page = nil, home_page = nil, + next_page = nil, last_page = nil) # The top title bar. doc.div({ :class => 'titlebar' }) { doc.div('PostRunner', { :class => 'title' }) + doc.div({ :class => 'navigator' }) { + button(doc, first_page, 'first.png') + button(doc, prev_page, 'back.png') + button(doc, home_page, 'home.png') + button(doc, next_page, 'forward.png') + button(doc, last_page, 'last.png') + } } end + def button(doc, link, icon) + if link + doc.a({ :href => link }) { + doc.img({ :src => "icons/#{icon}", :class => 'active_button' }) + } + else + doc.img({ :src => "icons/#{icon}", :class => 'inactive_button' }) + end + end + def footer(doc) doc.div({ :class => 'footer' }){ doc.hr |