diff options
| author | mo khan <mo@mokhan.ca> | 2017-02-26 20:25:36 -0700 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2017-02-26 20:25:36 -0700 |
| commit | 60bc351ebe38330baedccaf828fd7fc10dea2350 (patch) | |
| tree | fcef033432e6d36f703c175af38058d2b5e5a712 /app | |
| parent | fb764372499298256b30730d17a8e47cb49d0d29 (diff) | |
load data for each month as json.
Diffstat (limited to 'app')
| -rw-r--r-- | app/controllers/workouts_controller.rb | 14 | ||||
| -rw-r--r-- | app/models/workout.rb | 4 | ||||
| -rw-r--r-- | app/views/workouts/calendar.html.erb | 2 |
3 files changed, 17 insertions, 3 deletions
diff --git a/app/controllers/workouts_controller.rb b/app/controllers/workouts_controller.rb index f17f098..793f56d 100644 --- a/app/controllers/workouts_controller.rb +++ b/app/controllers/workouts_controller.rb @@ -9,7 +9,19 @@ class WorkoutsController < ApplicationController end def calendar - @workouts = current_user.workouts.recent.includes(:routine) + respond_to do |format| + format.html + format.json do + workouts = current_user.workouts.recent.before(params[:end]).after(params[:start]).includes(:routine) + results = workouts.map do |workout| + { + title: workout.routine.name, + start: workout.occurred_at.strftime("%Y-%m-%d") + } + end + render json: results.to_json + end + end end def new diff --git a/app/models/workout.rb b/app/models/workout.rb index 6770675..e8f6549 100644 --- a/app/models/workout.rb +++ b/app/models/workout.rb @@ -9,7 +9,9 @@ class Workout < ApplicationRecord delegate :name, to: :routine alias_method :sets, :exercise_sets - scope :since, ->(date) { where('occurred_at > ?', date) } + scope :since, ->(date) { after(date) } + scope :before, ->(date) { where('occurred_at < ?', date) } + scope :after, ->(date) { where('occurred_at > ?', date) } scope :recent, -> { order(occurred_at: :desc) } scope :with_exercise, ->(exercise) do joins(:exercises).where(exercises: { id: exercise.id }).distinct diff --git a/app/views/workouts/calendar.html.erb b/app/views/workouts/calendar.html.erb index f9c83a7..b06a104 100644 --- a/app/views/workouts/calendar.html.erb +++ b/app/views/workouts/calendar.html.erb @@ -9,7 +9,7 @@ <% content_for :javascript do %> $(function(){ $('#calendar').fullCalendar({ - events: <%= raw @workouts.map { |x| { title: x.routine.name, start: x.occurred_at.strftime("%Y-%m-%d") } }.to_json %> + events: '<%= calendar_workouts_path(format: :json) %>' }); }); <% end %> |
