Commit a953f1a

mo khan <mo@mokhan.ca>
2017-02-26 03:30:13
add profiles#index.
1 parent abf17d4
app/controllers/charts_controller.rb
@@ -2,7 +2,7 @@ class ChartsController < ApplicationController
   def index
     exercise = Exercise.find_by(id: params[:exercise])
     respond_to do |format|
-      format.js { @training_history = current_user.history_for(exercise) }
+      format.js { @training_history = user.history_for(exercise) }
       format.json { render json: rolled_up_sets(exercise || Exercise.primary).chart_json }
     end
 
@@ -11,7 +11,7 @@ class ChartsController < ApplicationController
   private
 
   def rolled_up_sets(exercise, since = (params[:since] || 1.month).to_i.seconds.ago)
-    ExerciseSet
+    user.exercise_sets
       .joins(:exercise)
       .where(exercise: exercise)
       .where('workouts.occurred_at > ?', since.beginning_of_day)
@@ -21,4 +21,8 @@ class ChartsController < ApplicationController
       .group('workouts.occurred_at')
       .maximum(:target_weight)
   end
+
+  def user
+    User.find_by(id: params[:user_id]) || current_user
+  end
 end
app/controllers/profiles_controller.rb
@@ -1,4 +1,8 @@
 class ProfilesController < ApplicationController
+  def index
+    @users = paginate(User.all)
+  end
+
   def show
     @user = User.find_by(username: params[:id])
     @profile = @user.profile
app/models/profile.rb
@@ -3,6 +3,7 @@ class Profile < ApplicationRecord
   belongs_to :gym, optional: true
   enum social_tolerance: { low: 0, medium: 1, high: 2 }
   enum gender: { female: 1, male: 2, transgender: 3, other: 0 }
+  delegate :username, to: :user
 
   def to_param
     user.username
app/views/application/_navigation.html.erb
@@ -3,6 +3,9 @@
     <div class="nav-left">
       <%= link_to t("app"), root_path, class: 'nav-item is-brand' %>
       <%= link_to t(".workouts"), workouts_path, class: 'nav-item' %>
+      <% if feature_enabled? :athletes %>
+      <%= link_to t(".athletes"), profiles_path, class: 'nav-item' %>
+      <% end %>
       <%= link_to t(".gyms"), gyms_path, class: 'nav-item' %>
       <%= link_to t(".blog"), "http://slog.stronglifters.com", class: 'nav-item' %>
       <%= link_to t(".about"), "http://slog.stronglifters.com/about", class: 'nav-item' %>
app/views/profiles/index.html.erb
@@ -0,0 +1,31 @@
+<div class="container">
+  <div class="columns">
+    <div class="column is-3">
+      <% @users.each do |user| %>
+        <div class="card">
+          <div class="card-content">
+            <div class="media">
+              <div class="media-left">
+                <figure class="image" style="height: 40px; width: 40px;">
+                  <%= link_to profile_path(user) do %>
+                    <%= gravatar_for(user, size: 96) %>
+                  <% end %>
+                </figure>
+              </div>
+              <div class="media-content">
+                <p class="title is-4"><%= link_to user.username, profile_path(user) %></p>
+                <p class="subtitle is-6"><%= user.profile.gender %></p>
+              </div>
+            </div>
+
+            <div class="content">
+              <small><%= user.created_at.strftime("%D at %I:%M%p") %></small>
+            </div>
+          </div>
+        </div>
+      <% end %>
+
+      <%= paginate @users, remote: false %>
+    </div>
+  </div>
+</div>
app/views/profiles/show.html.erb
@@ -26,7 +26,7 @@
           <% personal_record = history.personal_record %>
           <div class="level-item has-text-centered">
             <div>
-              <p class="heading"><%= link_to history.exercise.name, charts_path(exercise: history.exercise), remote: true %></p>
+              <p class="heading"><%= link_to history.exercise.name, charts_path(exercise: history.exercise, user_id: @user), remote: true %></p>
               <p class="title"><%= personal_record ? "#{personal_record} lbs" : t('.not_available') %></p>
             </div>
           </div>
config/locales/en.yml
@@ -47,9 +47,10 @@ en:
   app: Strong Lifters
   application:
     navigation:
+      about: About
+      athletes: Athletes
       blog: Blog
       gyms: Gyms
-      home: Home
       log_out: Log out
       profile: Profile
       workouts: Workouts
config/routes.rb
@@ -9,7 +9,7 @@ Rails.application.routes.draw do
       get :texas_method
     end
   end
-  resources :profiles, only: [:new, :create, :show, :edit, :update], constraints: { id: /[^\/]+/ }
+  resources :profiles, only: [:index, :new, :create, :show, :edit, :update], constraints: { id: /[^\/]+/ }
   resources :gyms, only: [:index, :show, :new, :create]
   resources :charts, only: [:index]
   resource :dashboards, only: [:show]