summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/workouts_controller.rb5
-rw-r--r--app/models/workout.rb4
-rw-r--r--app/views/workouts/index.html.erb4
3 files changed, 9 insertions, 4 deletions
diff --git a/app/controllers/workouts_controller.rb b/app/controllers/workouts_controller.rb
index 76842d4..74bf26b 100644
--- a/app/controllers/workouts_controller.rb
+++ b/app/controllers/workouts_controller.rb
@@ -3,7 +3,7 @@ class WorkoutsController < ApplicationController
def index
@ranges = [5.years, 1.year, 6.months, 3.months, 1.month, 2.weeks, 1.week].reverse
- @exercise = Exercise.find_by(name: params[:exercise])
+ @exercise = Exercise.find_by(id: params[:exercise])
@primary_exercises = Exercise.primary.order_by_name.to_a
@workouts = recent_workouts(@exercise)
end
@@ -41,7 +41,8 @@ class WorkoutsController < ApplicationController
)
end
- def recent_workouts(exercise, since = (params[:since] || 30.days.to_i).to_i.seconds.ago)
+ def recent_workouts(exercise, since = (params[:since] || 7.days.to_i).to_i.seconds.ago)
+ @since = since.beginning_of_day
workouts = current_user.workouts.since(since).recent.includes(:routine)
exercise ? workouts.with_exercise(exercise) : workouts
end
diff --git a/app/models/workout.rb b/app/models/workout.rb
index 69b6b4d..e2c96b1 100644
--- a/app/models/workout.rb
+++ b/app/models/workout.rb
@@ -48,4 +48,8 @@ class Workout < ApplicationRecord
yield exercise
end
end
+
+ def display_status_for(exercise)
+ progress_for(exercise).status
+ end
end
diff --git a/app/views/workouts/index.html.erb b/app/views/workouts/index.html.erb
index 78c7941..f6ad950 100644
--- a/app/views/workouts/index.html.erb
+++ b/app/views/workouts/index.html.erb
@@ -16,7 +16,7 @@
<%= form_tag @search_path, method: :get do %>
<p class="control">
<span class="select">
- <%= select_tag :since, options_for_select(@ranges.map { |x| [time_ago_in_words(x.ago), x.to_i] }) %>
+ <%= select_tag :since, options_for_select(@ranges.map { |x| [time_ago_in_words(x.ago), x.to_i] }, params[:since]) %>
</span>
</p>
<% end %>
@@ -75,7 +75,7 @@
<td> <%= I18n.l workout.occurred_at, format: :short %> </td>
<td> <%= workout.body_weight.to(:lbs) %> lbs </td>
<% @primary_exercises.each do |exercise| %>
- <td> <%= workout.progress_for(exercise).status %> </td>
+ <td> <%= workout.display_status_for(exercise) %> </td>
<% end %>
</tr>
<% end %>