summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Schlaeger <chris@linux.com>2014-11-14 17:17:22 +0100
committerChris Schlaeger <chris@linux.com>2014-11-14 17:17:22 +0100
commitb5fbdd898233d5ec855f329941fd0be9b8b46a2c (patch)
treedaaf45e309ed1e551f3695ec0a168f6b2738d301
parenta92f1d3eb8b8a890df2e2f2846d5beedf78b5955 (diff)
downloadpostrunner-b5fbdd898233d5ec855f329941fd0be9b8b46a2c.zip
Fix: Set proper forward/back links for newly added activities.
-rw-r--r--lib/postrunner/ActivitiesDB.rb14
-rw-r--r--lib/postrunner/Activity.rb2
-rw-r--r--spec/PostRunner_spec.rb7
3 files changed, 16 insertions, 7 deletions
diff --git a/lib/postrunner/ActivitiesDB.rb b/lib/postrunner/ActivitiesDB.rb
index 9aef9de..ea51dab 100644
--- a/lib/postrunner/ActivitiesDB.rb
+++ b/lib/postrunner/ActivitiesDB.rb
@@ -99,6 +99,9 @@ module PostRunner
activity.register_records(@records)
+ # Generate HTML file for this activity.
+ activity.generate_html_view
+
# The HTML activity views contain links to their predecessors and
# successors. After inserting a new activity, we need to re-generate
# these views as well.
@@ -116,8 +119,8 @@ module PostRunner
end
def delete(activity)
- pred = predecessor(activities)
- succ = successor(activities)
+ pred = predecessor(activity)
+ succ = successor(activity)
@activities.delete(activity)
@@ -189,11 +192,12 @@ module PostRunner
@activities[idx - 1]
end
- # Return the previous Activity before the provided activity. Note that
- # this has a higher index. If none is found, return nil.
+ # Return the previous Activity before the provided activity.
+ # If none is found, return nil.
def predecessor(activity)
idx = @activities.index(activity)
- return nil if idx.nil? || idx >= @activities.length - 2
+ return nil if idx.nil?
+ # Activities indexes are reversed. The predecessor has a higher index.
@activities[idx + 1]
end
diff --git a/lib/postrunner/Activity.rb b/lib/postrunner/Activity.rb
index 0e8f4fe..d885a06 100644
--- a/lib/postrunner/Activity.rb
+++ b/lib/postrunner/Activity.rb
@@ -40,8 +40,6 @@ module PostRunner
instance_variable_set(v_str, fit_activity.send(v))
self.class.send(:attr_reader, v.to_sym)
end
- # Generate HTML file for this activity.
- generate_html_view
end
# YAML::load() does not call initialize(). We don't have all attributes
diff --git a/spec/PostRunner_spec.rb b/spec/PostRunner_spec.rb
index 20dc4f6..ac67c80 100644
--- a/spec/PostRunner_spec.rb
+++ b/spec/PostRunner_spec.rb
@@ -83,6 +83,13 @@ describe PostRunner::Main do
list.index('FILE2.FIT').should be_a(Fixnum)
rc = YAML::load_file(File.join(@db_dir, 'config.yml'))
rc[:import_dir].should == '.'
+
+ template = "<a href=\"%s.html\"><img src=\"icons/%s.png\" " +
+ "class=\"active_button\">"
+ html1 = File.read(File.join(@db_dir, 'html', 'FILE1.html'))
+ html1.include?(template % ['FILE2', 'forward']).should be_true
+ html2 = File.read(File.join(@db_dir, 'html', 'FILE2.html'))
+ html2.include?(template % ['FILE1', 'back']).should be_true
end
it 'should delete the first file' do