diff options
| author | mo khan <mo@mokhan.ca> | 2017-02-18 11:49:10 -0700 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2017-02-18 11:49:10 -0700 |
| commit | 2fae577b43f930a456bc0ce93e36f3f18eece601 (patch) | |
| tree | c0a78293abed4558c9c6d784795f9eed0fdcecbf /app | |
| parent | 3ea15efd43893620c8c37aafe47d3f134c0182a8 (diff) | |
use chart.js instead of google charts.
Diffstat (limited to 'app')
| -rw-r--r-- | app/assets/javascripts/application.js | 2 | ||||
| -rw-r--r-- | app/controllers/charts_controller.rb | 22 | ||||
| -rw-r--r-- | app/models/workout.rb | 2 | ||||
| -rw-r--r-- | app/views/layouts/application.html.erb | 1 | ||||
| -rw-r--r-- | app/views/workouts/index.html.erb | 14 |
5 files changed, 27 insertions, 14 deletions
diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index e05e5a4..2f9085f 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -18,6 +18,8 @@ //= require ractive //= require backbone //= require ractive-backbone +//= require Chart.bundle +//= require chartkick //= require_self //= require_tree . //= require turbolinks diff --git a/app/controllers/charts_controller.rb b/app/controllers/charts_controller.rb index 9475a0c..cbb7a95 100644 --- a/app/controllers/charts_controller.rb +++ b/app/controllers/charts_controller.rb @@ -3,14 +3,28 @@ class ChartsController < ApplicationController exercise = Exercise.find_by(id: params[:exercise]) respond_to do |format| format.js { @training_history = current_user.history_for(exercise) } - format.json { render json: recent_workouts(exercise).to_line_chart } + #format.json { render json: recent_workouts(exercise).to_line_chart } + format.json { render json: rolled_up_sets(exercise || Exercise.primary).chart_json } end + end private - def recent_workouts(exercise, since = (params[:since] || 7.days).to_i.seconds.ago) - workouts = current_user.workouts.since(since.beginning_of_day).recent - exercise ? workouts.with_exercise(exercise) : workouts + #def recent_workouts(exercise, since = (params[:since] || 7.days).to_i.seconds.ago) + #workouts = current_user.workouts.since(since.beginning_of_day).recent + #exercise ? workouts.with_exercise(exercise) : workouts + #end + + def rolled_up_sets(exercise, since = (params[:since] || 7.days).to_i.seconds.ago) + ExerciseSet + .joins(:exercise) + .where(exercise: exercise) + .where('workouts.occurred_at > ?', since.beginning_of_day) + .where.not(target_weight: nil) + .group('exercises.name') + .joins(:workout) + .group('workouts.occurred_at') + .maximum(:target_weight) end end diff --git a/app/models/workout.rb b/app/models/workout.rb index 2cfa315..6770675 100644 --- a/app/models/workout.rb +++ b/app/models/workout.rb @@ -15,7 +15,7 @@ class Workout < ApplicationRecord joins(:exercises).where(exercises: { id: exercise.id }).distinct end scope :to_line_chart, -> do - joins(:exercise_sets).group(:occurred_at).recent.maximum(:target_weight) + joins(:exercise_sets).group(:occurred_at).recent.maximum('exercise_sets.target_weight') end def train(exercise, target_weight, repetitions:, set: nil) diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 059c519..c5eb5ea 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -8,7 +8,6 @@ <title><%= t('.title') %> <%= content_for?(:title) ? "| #{yield(:title)}" : "" %></title> <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> - <%= javascript_include_tag "https://www.google.com/jsapi", "chartkick" %> <%= javascript_include_tag "https://maps.googleapis.com/maps/api/js?key=#{ENV['GOOGLE_MAPS_API_KEY']}" %> <%= yield(:head) %> </head> diff --git a/app/views/workouts/index.html.erb b/app/views/workouts/index.html.erb index d35f3ed..6b07345 100644 --- a/app/views/workouts/index.html.erb +++ b/app/views/workouts/index.html.erb @@ -30,9 +30,9 @@ <div class="level-right"> <p class="level-item"> <% if @exercise.nil? %> - <strong> <%= link_to 'All', workouts_path(filter_params_hash) %> </strong> + <strong> <%= link_to 'All', workouts_path(filter_params_hash(exercise: nil)) %> </strong> <% else %> - <%= link_to 'All', workouts_path(filter_params_hash) %> + <%= link_to 'All', workouts_path(filter_params_hash(exercise: nil)) %> <% end %> </p> <% @primary_exercises.each do |exercise| %> @@ -49,13 +49,11 @@ </nav> </div> </div> - <% if @exercise %> - <div class="columns"> - <div class="column is-12"> - <%= line_chart charts_path(filter_params_hash) %> - </div> + <div class="columns"> + <div class="column is-12"> + <%= line_chart charts_path(filter_params_hash), download: true %> </div> - <% end %> + </div> <div class="columns"> <div class="column is-12"> |
