summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/postrunner/ActivitiesDB.rb4
-rw-r--r--lib/postrunner/Activity.rb5
-rw-r--r--lib/postrunner/ActivityListView.rb4
-rw-r--r--lib/postrunner/Main.rb2
-rw-r--r--lib/postrunner/PersonalRecords.rb42
-rw-r--r--lib/postrunner/version.rb2
6 files changed, 46 insertions, 13 deletions
diff --git a/lib/postrunner/ActivitiesDB.rb b/lib/postrunner/ActivitiesDB.rb
index 3ba080c..f63e30a 100644
--- a/lib/postrunner/ActivitiesDB.rb
+++ b/lib/postrunner/ActivitiesDB.rb
@@ -277,6 +277,10 @@ module PostRunner
puts @records.to_s
end
+ def activity_records(activity)
+ @records.activity_records(activity)
+ end
+
# Launch a web browser and show an HTML file.
# @param html_file [String] file name of the HTML file to show
def show_in_browser(html_file)
diff --git a/lib/postrunner/Activity.rb b/lib/postrunner/Activity.rb
index 5c73acb..e0e1e06 100644
--- a/lib/postrunner/Activity.rb
+++ b/lib/postrunner/Activity.rb
@@ -305,6 +305,11 @@ module PostRunner
end
end
+ # Return true if this activity generated any personal records.
+ def has_records?
+ !@db.records.activity_records(self).empty?
+ end
+
def generate_html_view
@fit_activity = load_fit_file unless @fit_activity
ActivityView.new(self, @db.cfg[:unit_system], @db.predecessor(self),
diff --git a/lib/postrunner/ActivityListView.rb b/lib/postrunner/ActivityListView.rb
index e3cd627..643754b 100644
--- a/lib/postrunner/ActivityListView.rb
+++ b/lib/postrunner/ActivityListView.rb
@@ -29,6 +29,10 @@ module PostRunner
def to_html(doc)
doc.a(@activity.name, { :class => 'activity_link',
:href => @activity.fit_file[0..-5] + '.html' })
+ if @activity.has_records?
+ doc.img(nil, { :src => 'icons/record-small.png',
+ :style => 'vertical-align:middle' })
+ end
end
def to_s
diff --git a/lib/postrunner/Main.rb b/lib/postrunner/Main.rb
index 884608b..0dffde2 100644
--- a/lib/postrunner/Main.rb
+++ b/lib/postrunner/Main.rb
@@ -354,7 +354,7 @@ EOT
def handle_version_update
if @cfg.get_option(:version) != VERSION
- Log.warn "Version upgrade detected."
+ Log.warn "PostRunner version upgrade detected."
@activities.handle_version_update
@cfg.set_option(:version, VERSION)
Log.info "Version upgrade completed."
diff --git a/lib/postrunner/PersonalRecords.rb b/lib/postrunner/PersonalRecords.rb
index 2b1cf30..aba2f6a 100644
--- a/lib/postrunner/PersonalRecords.rb
+++ b/lib/postrunner/PersonalRecords.rb
@@ -303,6 +303,19 @@ module PostRunner
@sport_records.each_value { |r| r.each(&block) }
end
+ # Return an Array of all the records associated with the given Activity.
+ def activity_records(activity)
+ records = []
+ each do |record|
+ # puts record.activity
+ if record.activity.equal?(activity) && !records.include?(record)
+ records << record
+ end
+ end
+
+ records
+ end
+
private
def load_records
@@ -319,8 +332,23 @@ module PostRunner
unless @sport_records.is_a?(Hash)
Log.fatal "The personal records file '#{@records_file}' is corrupted"
end
+ fit_file_names_to_activity_refs
+ end
+
+ def save_records
+ activity_refs_to_fit_file_names
+ begin
+ BackedUpFile.open(@records_file, 'w') do |f|
+ f.write(@sport_records.to_yaml)
+ end
+ rescue IOError
+ Log.fatal "Cannot write records file '#{@records_file}': #{$!}"
+ end
+ fit_file_names_to_activity_refs
+ end
- # Convert FIT file names into Activity references.
+ # Convert FIT file names in all Record objects into Activity references.
+ def fit_file_names_to_activity_refs
each do |record|
# Record objects can be referenced multiple times.
if record.activity.is_a?(String)
@@ -329,22 +357,14 @@ module PostRunner
end
end
- def save_records
- # Convert Activity references into FIT file names.
+ # Convert Activity references in all Record objects into FIT file names.
+ def activity_refs_to_fit_file_names
each do |record|
# Record objects can be referenced multiple times.
unless record.activity.is_a?(String)
record.activity = record.activity.fit_file
end
end
-
- begin
- BackedUpFile.open(@records_file, 'w') do |f|
- f.write(@sport_records.to_yaml)
- end
- rescue IOError
- Log.fatal "Cannot write records file '#{@records_file}': #{$!}"
- end
end
end
diff --git a/lib/postrunner/version.rb b/lib/postrunner/version.rb
index f757890..d77a0b6 100644
--- a/lib/postrunner/version.rb
+++ b/lib/postrunner/version.rb
@@ -11,5 +11,5 @@
#
module PostRunner
- VERSION = "0.0.6"
+ VERSION = "0.0.7"
end