summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChris Schlaeger <chris@linux.com>2016-02-28 21:29:00 +0100
committerChris Schlaeger <chris@linux.com>2016-02-28 21:29:00 +0100
commitfa8d419e0f5b87501061600508c6c52be84ceb30 (patch)
tree34d9c09223cb04fa530754c655188eab038ba97a /lib
parent6c2e9624364af2713a54b2e8655e954206271ec9 (diff)
downloadpostrunner-fa8d419e0f5b87501061600508c6c52be84ceb30.zip
NEW: Add checkbox to frames in activity page to hide the frame.
Diffstat (limited to 'lib')
-rw-r--r--lib/postrunner/Activity.rb12
-rw-r--r--lib/postrunner/ActivityListView.rb3
-rw-r--r--lib/postrunner/ActivitySummary.rb8
-rw-r--r--lib/postrunner/ActivityView.rb13
-rw-r--r--lib/postrunner/ChartView.rb8
-rw-r--r--lib/postrunner/DataSources.rb3
-rw-r--r--lib/postrunner/DeviceList.rb2
-rw-r--r--lib/postrunner/EventList.rb2
-rw-r--r--lib/postrunner/HTMLBuilder.rb12
-rw-r--r--lib/postrunner/RecordListPageView.rb5
-rw-r--r--lib/postrunner/TrackView.rb7
-rw-r--r--lib/postrunner/UserProfileView.rb3
-rw-r--r--lib/postrunner/ViewFrame.rb44
13 files changed, 89 insertions, 33 deletions
diff --git a/lib/postrunner/Activity.rb b/lib/postrunner/Activity.rb
index 07dd999..e92a105 100644
--- a/lib/postrunner/Activity.rb
+++ b/lib/postrunner/Activity.rb
@@ -280,14 +280,16 @@ module PostRunner
last_distance = nil
@fit_activity.records.each do |record|
+ if record.timestamp.nil?
+ # All records must have a valid timestamp
+ Log.warn "Found a record without a valid timestamp"
+ return
+ end
if record.distance.nil?
# All records must have a valid distance mark or the activity does
# not qualify for a personal record.
- Log.warn "Found a record without a valid distance"
- return
- end
- if record.timestamp.nil?
- Log.warn "Found a record without a valid timestamp"
+ Log.warn "Found a record at #{record.timestamp} without a " +
+ "valid distance"
return
end
diff --git a/lib/postrunner/ActivityListView.rb b/lib/postrunner/ActivityListView.rb
index 11ae0b9..b9c7d39 100644
--- a/lib/postrunner/ActivityListView.rb
+++ b/lib/postrunner/ActivityListView.rb
@@ -67,7 +67,8 @@ module PostRunner
def body(doc)
@view.body {
doc.div({ :class => 'main' }) {
- ViewFrame.new('Activities', 900, generate_table).to_html(doc)
+ ViewFrame.new('activities', 'Activities', 900,
+ generate_table).to_html(doc)
}
}
end
diff --git a/lib/postrunner/ActivitySummary.rb b/lib/postrunner/ActivitySummary.rb
index 9caa9dd..35e4ecc 100644
--- a/lib/postrunner/ActivitySummary.rb
+++ b/lib/postrunner/ActivitySummary.rb
@@ -40,9 +40,11 @@ module PostRunner
def to_html(doc)
width = 600
- ViewFrame.new("Activity: #{@name}", width, summary).to_html(doc)
- ViewFrame.new('Note', width, note).to_html(doc) if @activity.note
- ViewFrame.new('Laps', width, laps).to_html(doc)
+ ViewFrame.new('activity', "Activity: #{@name}",
+ width, summary).to_html(doc)
+ ViewFrame.new('note', 'Note', width, note,
+ true).to_html(doc) if @activity.note
+ ViewFrame.new('laps', 'Laps', width, laps, true).to_html(doc)
end
private
diff --git a/lib/postrunner/ActivityView.rb b/lib/postrunner/ActivityView.rb
index 4f2477e..2e704cb 100644
--- a/lib/postrunner/ActivityView.rb
+++ b/lib/postrunner/ActivityView.rb
@@ -51,14 +51,23 @@ module PostRunner
private
def generate_html(doc)
- doc.head { doc.style(style) }
+ doc.unique(:activityview_style) {
+ doc.head {
+ [ 'jquery/jquery-2.1.1.min.js', 'flot/jquery.flot.js',
+ 'flot/jquery.flot.time.js' ].each do |js|
+ doc.script({ 'language' => 'javascript',
+ 'type' => 'text/javascript', 'src' => js })
+ end
+ doc.style(style)
+ }
+ }
#doc.meta({ 'name' => 'viewport',
# 'content' => 'width=device-width, ' +
# 'initial-scale=1.0, maximum-scale=1.0, ' +
# 'user-scalable=0' })
body {
- doc.body({ :onload => 'init()' }) {
+ doc.body {
# The main area with the 2 column layout.
doc.div({ :class => 'main' }) {
doc.div({ :class => 'left_col' }) {
diff --git a/lib/postrunner/ChartView.rb b/lib/postrunner/ChartView.rb
index df52554..c82b41e 100644
--- a/lib/postrunner/ChartView.rb
+++ b/lib/postrunner/ChartView.rb
@@ -157,15 +157,9 @@ module PostRunner
def to_html(doc)
doc.unique(:chartview_style) {
doc.head {
- [ 'jquery/jquery-2.1.1.min.js', 'flot/jquery.flot.js',
- 'flot/jquery.flot.time.js' ].each do |js|
- doc.script({ 'language' => 'javascript',
- 'type' => 'text/javascript', 'src' => js })
- end
doc.style(style)
}
}
-
doc.script(java_script)
@charts.each do |chart|
label = chart[:label] + (chart[:unit] ? " (#{chart[:unit]})" : '')
@@ -411,7 +405,7 @@ EOT
# Don't plot frame for graph without data.
return if @empty_charts[field]
- ViewFrame.new(title) {
+ ViewFrame.new("#{field}_chart", title, 600, nil, true) {
doc.div({ 'id' => "#{field}_chart", 'class' => 'chart-placeholder'})
}.to_html(doc)
end
diff --git a/lib/postrunner/DataSources.rb b/lib/postrunner/DataSources.rb
index c90a405..1aca80c 100644
--- a/lib/postrunner/DataSources.rb
+++ b/lib/postrunner/DataSources.rb
@@ -39,7 +39,8 @@ module PostRunner
end
def to_html(doc)
- ViewFrame.new("Data Sources", 1210, data_sources).to_html(doc)
+ ViewFrame.new('data_sources', "Data Sources", 1210, data_sources,
+ true).to_html(doc)
end
private
diff --git a/lib/postrunner/DeviceList.rb b/lib/postrunner/DeviceList.rb
index 184a5cf..ced0eab 100644
--- a/lib/postrunner/DeviceList.rb
+++ b/lib/postrunner/DeviceList.rb
@@ -44,7 +44,7 @@ module PostRunner
end
def to_html(doc)
- ViewFrame.new('Devices', 600, devices).to_html(doc)
+ ViewFrame.new('devices', 'Devices', 600, devices, true).to_html(doc)
end
def to_s
diff --git a/lib/postrunner/EventList.rb b/lib/postrunner/EventList.rb
index 3ebb757..7679b6f 100644
--- a/lib/postrunner/EventList.rb
+++ b/lib/postrunner/EventList.rb
@@ -42,7 +42,7 @@ module PostRunner
# Add the list as HTML table to the specified doc.
# @param doc [HTMLBuilder] HTML document
def to_html(doc)
- ViewFrame.new("Events", 600, list).to_html(doc)
+ ViewFrame.new('events', 'Events', 600, list, true).to_html(doc)
end
private
diff --git a/lib/postrunner/HTMLBuilder.rb b/lib/postrunner/HTMLBuilder.rb
index 8c53f2f..75c4979 100644
--- a/lib/postrunner/HTMLBuilder.rb
+++ b/lib/postrunner/HTMLBuilder.rb
@@ -32,8 +32,14 @@ module PostRunner
create_node('meta', { 'http-equiv' => 'Content-Type',
'content' => 'text/html; charset=utf-8' })
create_node('title', title)
+ @init_script = create_node('script', <<EOT
+function postrunner_init() {
+};
+EOT
+ )
}
@body = create_node('body')
+ @body['onload'] = 'postrunner_init()'
}
@node_stack << @html
@node_stack << @body
@@ -62,6 +68,12 @@ module PostRunner
end
end
+ def body_init_script(script)
+ # We have to insert the new script snippet after the last snippet and
+ # before the tailing "};\n".
+ @init_script.content = @init_script.text[0..-4] + script + "\n};\n"
+ end
+
# Only execute the passed block if the provided tag has not been added
# yet.
def unique(tag)
diff --git a/lib/postrunner/RecordListPageView.rb b/lib/postrunner/RecordListPageView.rb
index 7161cb5..8cd2497 100644
--- a/lib/postrunner/RecordListPageView.rb
+++ b/lib/postrunner/RecordListPageView.rb
@@ -52,13 +52,14 @@ module PostRunner
frame_width = 800
@doc.div({ :class => 'main' }) {
- ViewFrame.new("All-time #{@sport_name} Records",
+ ViewFrame.new('all_time_records', "All-time #{@sport_name} Records",
frame_width, @records.all_time).to_html(@doc)
@records.yearly.sort{ |y1, y2| y2[0].to_i <=> y1[0].to_i }.
each do |year, record|
next if record.empty?
- ViewFrame.new("#{year} #{@sport_name} Records",
+ ViewFrame.new("year_#{year}_records",
+ "#{year} #{@sport_name} Records",
frame_width, record).to_html(@doc)
end
}
diff --git a/lib/postrunner/TrackView.rb b/lib/postrunner/TrackView.rb
index 79018b5..ff1f0be 100644
--- a/lib/postrunner/TrackView.rb
+++ b/lib/postrunner/TrackView.rb
@@ -43,9 +43,10 @@ module PostRunner
doc.script({ 'src' => 'postrunner/trackview.js' })
}
doc.script(java_script)
+ doc.body_init_script('pr_trackview_init_xy()')
}
- ViewFrame.new('Map', 600) {
+ ViewFrame.new('map', 'Map', 600, nil, true) {
doc.div({ 'id' => 'map', 'class' => 'trackmap' })
}.to_html(doc)
end
@@ -75,9 +76,9 @@ EOT
<<"EOT"
#{track_points}
#{lap_markers}
-function init() {
+function pr_trackview_init_xy() {
pr_trackview_init(#{center_long}, #{center_lat});
-}
+};
EOT
end
diff --git a/lib/postrunner/UserProfileView.rb b/lib/postrunner/UserProfileView.rb
index 6f009d0..86d4783 100644
--- a/lib/postrunner/UserProfileView.rb
+++ b/lib/postrunner/UserProfileView.rb
@@ -26,7 +26,8 @@ module PostRunner
def to_html(doc)
return nil if @fit_activity.user_profiles.empty?
- ViewFrame.new('User Profile', 600, profile).to_html(doc)
+ ViewFrame.new('user_profile', 'User Profile', 600, profile,
+ true).to_html(doc)
end
def to_s
diff --git a/lib/postrunner/ViewFrame.rb b/lib/postrunner/ViewFrame.rb
index 863ad2a..aa416d0 100644
--- a/lib/postrunner/ViewFrame.rb
+++ b/lib/postrunner/ViewFrame.rb
@@ -16,16 +16,21 @@ module PostRunner
class ViewFrame
# Create a ViewFrame object.
+ # @param id [String] ID that is unique with regards to the rendered HTML
+ # page.
# @param title [String] Title/heading of the framed box
# @param width [Fixnum or nil] Width of the frame. Use nil to set no
# width.
# @param content [Any object that respons to to_html] Object to frame
# @param &block [HTMLBuilder actions]
- def initialize(title, width = 600, content = nil, &block)
+ def initialize(id, title, width = 600, content = nil, hide_button = false,
+ &block)
+ @id = id
@title = title
@content = content
@block = block
@width = width
+ @hide_button = hide_button
end
# Generate the HTML code for the frame and the enclosing content.
@@ -33,16 +38,41 @@ module PostRunner
def to_html(doc)
doc.unique(:viewframe_style) {
# Add the necessary style sheet snippets to the document head.
- doc.head { doc.style(style) }
+ doc.head {
+ doc.style(style)
+ doc.script({ 'src' => 'postrunner/postrunner.js' })
+ }
+ }
+ doc.head {
+ doc.script(<<"EOT"
+function init_viewframe_#{@id}() {
+ if (readCookie('postrunner_checkbox_#view_#{@id}') == 'false') {
+ $('#checkbox-#{@id}').attr('checked', false);
+ $('#view_#{@id}').hide();
+ } else {
+ $('#checkbox-#{@id}').attr('checked', true);
+ $('#view_#{@id}').show();
+ };
+};
+EOT
+ )
+ doc.body_init_script("init_viewframe_#{@id}();")
}
attr = { 'class' => 'widget_frame' }
attr['style'] = "width: #{@width}px" if @width
doc.div(attr) {
doc.div({ 'class' => 'widget_frame_title' }) {
- doc.b(@title)
+ doc.div('style' => 'float:left') { doc.b(@title) }
+ if @hide_button
+ doc.div('style' => 'float:right') {
+ doc.input('id' => "checkbox-#{@id}", 'type' => "checkbox",
+ 'onclick' =>
+ "pr_view_frame_toggle(this, \"#view_#{@id}\");")
+ }
+ end
}
- doc.div {
+ doc.div('class' => 'view_frame', 'id' => "view_#{@id}") {
# The @content holds an object that must respond to to_html to
# generate the HTML code.
if @content
@@ -81,8 +111,10 @@ module PostRunner
}
.widget_frame_title {
font-size:13pt;
- padding-bottom: 5px;
- text-align: left;
+ height: 23px;
+}
+.view_frame {
+ padding-top: 5px;
}
EOT
end