Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #1 from rianrainey/entries

App to working condition
  • Loading branch information...
commit b05e4e7fc08a5d67191caf4814e7cfe4284379d3 2 parents beddb4f + 5c6fe66
rianrainey authored
Showing with 2,494 additions and 31 deletions.
  1. +4 −0 Gemfile
  2. +10 −0 Gemfile.lock
  3. +4 −1 app/assets/javascripts/script.js
  4. 0  app/assets/stylesheets/{application.css → application.css.scss}
  5. +6 −0 app/assets/stylesheets/custom.css.scss
  6. +1 −1  app/controllers/application_controller.rb
  7. +90 −0 app/controllers/entries_controller.rb
  8. +4 −1 app/controllers/users_controller.rb
  9. +25 −6 app/controllers/workouts_controller.rb
  10. +2 −0  app/helpers/entries_helper.rb
  11. +8 −0 app/models/entry.rb
  12. +7 −0 app/models/user.rb
  13. +3 −0  app/models/workout.rb
  14. +27 −0 app/views/entries/_form.html.erb
  15. +5 −0 app/views/entries/edit.html.erb
  16. +37 −0 app/views/entries/index.html.erb
  17. +5 −0 app/views/entries/new.html.erb
  18. +5 −0 app/views/entries/show.html.erb
  19. +7 −7 app/views/layouts/_header.html.erb
  20. +1 −0  app/views/layouts/admin.html.erb
  21. +2 −0  app/views/layouts/application.html.erb
  22. +1 −1  app/views/users/edit.html.erb
  23. +2 −2 app/views/users/show.html.erb
  24. +11 −10 app/views/workouts/index.html.erb
  25. +29 −0 app/views/workouts/individual_workouts.html.erb
  26. +24 −0 app/views/workouts/leaderboard.html.erb
  27. +16 −1 config/routes.rb
  28. +8 −0 db/migrate/20130112213530_create_entries.rb
  29. +11 −0 db/migrate/20130125204354_add_fields_to_entries.rb
  30. +13 −0 db/migrate/20130130020524_add_roles_to_table.rb
  31. +13 −1 db/schema.rb
  32. +2,113 −0 logfile
View
4 Gemfile
@@ -10,12 +10,16 @@ gem 'bootstrap-wysihtml5-rails'
gem 'devise'
group :development, :test do
+ gem 'pry'
+ gem 'pry-rails'
gem 'rspec-rails'
gem 'annotate' # Automatic model documentation
gem 'guard-rspec' # Automate testing
gem 'factory_girl_rails' # Uses test data for tests
gem 'capybara' # Helps imitate a browser
gem 'faker' # Generates fake test data
+ gem 'awesome_print'
+ gem 'better_errors'
end
group :test do
View
10 Gemfile.lock
@@ -32,7 +32,11 @@ GEM
annotate (2.5.0)
rake
arel (3.0.2)
+ awesome_print (1.1.0)
bcrypt-ruby (3.0.1)
+ better_errors (0.7.2)
+ coderay (>= 1.0.0)
+ erubis (>= 2.6.6)
bootstrap-sass (2.0.4.0)
bootstrap-wysihtml5-rails (0.3.1.10)
railties (>= 3.0)
@@ -104,6 +108,8 @@ GEM
coderay (~> 1.0.5)
method_source (~> 0.8)
slop (~> 3.3.1)
+ pry-rails (0.2.2)
+ pry (>= 0.9.10)
rack (1.4.1)
rack-cache (1.2)
rack (>= 0.4)
@@ -177,6 +183,8 @@ PLATFORMS
DEPENDENCIES
annotate
+ awesome_print
+ better_errors
bootstrap-sass (= 2.0.4)
bootstrap-wysihtml5-rails
capybara
@@ -187,6 +195,8 @@ DEPENDENCIES
guard-rspec
jquery-rails
pg
+ pry
+ pry-rails
rails (= 3.2.8)
rspec-rails
sass-rails (~> 3.2.3)
View
5 app/assets/javascripts/script.js
@@ -1,6 +1,9 @@
$(document).ready(function(){
wysihtmlfive();
+
+ $("#entry_date_performed").datepicker({
+ dateFormat: 'yy-mm-dd'});
});
// Apply wysihtml5 to appropriate text areas
@@ -8,4 +11,4 @@ function wysihtmlfive() {
$('.wysihtml5').each(function(i, elem) {
$(elem).wysihtml5();
});
-}
+}
View
0  app/assets/stylesheets/application.css → app/assets/stylesheets/application.css.scss
File renamed without changes
View
6 app/assets/stylesheets/custom.css.scss
@@ -70,6 +70,12 @@ a {
color: $btn-primary-color;
}
+ul.inline {
+ li {
+ display:inline;
+ }
+}
+
/* header */
#logo {
float: left;
View
2  app/controllers/application_controller.rb
@@ -2,7 +2,7 @@ class ApplicationController < ActionController::Base
protect_from_forgery
def require_admin
- unless user_signed_in? and current_user.has_role? "Admin"
+ unless user_signed_in? and current_user.is_admin?
flash[:error] = "You must be an admin to access this section."
redirect_to root_path # halts request cycle
end
View
90 app/controllers/entries_controller.rb
@@ -0,0 +1,90 @@
+class EntriesController < ApplicationController
+ # GET /entries
+ # GET /entries.json
+ def index
+ @entries = Entry.find_all_by_workout_id(params[:workout_id])
+ @workout = Workout.find(params[:workout_id])
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @entries }
+ end
+ end
+
+ # GET /entries/1
+ # GET /entries/1.json
+ def show
+ @entry = Entry.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @entry }
+ end
+ end
+
+ # GET /entries/new
+ # GET /entries/new.json
+ def new
+ @entry = Entry.new
+ @workout = Workout.find(params[:workout_id])
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render json: @entry }
+ end
+ end
+
+ # GET /entries/1/edit
+ def edit
+ #binding.pry
+ @entry = Entry.find(params[:id])
+ @workout = Workout.find(params[:workout_id])
+ end
+
+ # POST /entries
+ # POST /entries.json
+ def create
+ @entry = Entry.new(params[:entry])
+ @entry.workout_id = params[:workout_id]
+ @entry.user_id = current_user.id
+ #@entry.date_performed(params[:entry][:date_performed])
+
+ respond_to do |format|
+ if @entry.save
+ format.html { redirect_to workout_entries_path(params[:workout_id]), notice: 'Entry was successfully created.' }
+ format.json { render json: @entry, status: :created, location: @entry }
+ else
+ format.html { render action: "new" }
+ format.json { render json: @entry.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /entries/1
+ # PUT /entries/1.json
+ def update
+ @entry = Entry.find(params[:id])
+
+ respond_to do |format|
+ if @entry.update_attributes(params[:entry])
+ format.html { redirect_to workout_entries_path, notice: 'Entry was successfully updated.' }
+ format.json { head :no_content }
+ else
+ format.html { render action: "edit" }
+ format.json { render json: @entry.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /entries/1
+ # DELETE /entries/1.json
+ def destroy
+ @entry = Entry.find(params[:id])
+ @entry.destroy
+
+ respond_to do |format|
+ format.html { redirect_to workout_entries_path, :notice => "Entry successfully deleted." }
+ format.json { head :no_content }
+ end
+ end
+end
View
5 app/controllers/users_controller.rb
@@ -3,7 +3,10 @@ class UsersController < ApplicationController
# GET /users/1
# GET /users/1.json
def show
- @user = User.find(params[:id])
+ #@user = User.find(params[:id])
+ puts current_user.id
+ puts params[:id]
+ @user = User.find(1) #current_user
respond_to do |format|
format.html # show.html.erb
View
31 app/controllers/workouts_controller.rb
@@ -1,10 +1,29 @@
class WorkoutsController < ApplicationController
def index
- @workouts = Workout.all
+ @workouts = Workout.all
- respond_to do |format|
- format.html # index.html.erb
- format.json { render json: @workouts }
- end
- end
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @workouts }
+ end
+ end
+
+ def individual_workouts
+ @entries = Entry.find_all_by_user_id(params[:user_id])
+ @workout = Workout.find_by_id(@entries.first.workout_id)
+
+ respond_to do |format|
+ format.html
+ format.json { render json: @workouts }
+ end
+ end
+
+ def leaderboard
+ @entries = Entry.find_all_by_workout_id(params[:workout_id]).first(20)
+ @workout = Workout.find_by_id(params[:workout_id])
+
+ respond_to do |format|
+ format.html
+ end
+ end
end
View
2  app/helpers/entries_helper.rb
@@ -0,0 +1,2 @@
+module EntriesHelper
+end
View
8 app/models/entry.rb
@@ -0,0 +1,8 @@
+class Entry < ActiveRecord::Base
+ attr_accessible :id, :body, :user_id, :workout_id, :time, :rounds, :repetitions, :date_performed
+
+ #accepts_nested_attributes_for :workout, :user
+
+ belongs_to :workout
+ belongs_to :user
+end
View
7 app/models/user.rb
@@ -23,11 +23,18 @@ class User < ActiveRecord::Base
has_and_belongs_to_many :roles
accepts_nested_attributes_for :roles
+ has_many :entries
+ has_many :workouts, :through => :entries
+
# Check if user has a given role
def has_role?(*role_names)
self.roles.where(:name => role_names).present?
end
+ def is_admin?
+ admin_roles = ["Super Admin", "Admin"]
+ self.roles.where(:name => admin_roles).present?
+ end
# Join first and last names of user
def name
[firstName, lastName].join(" ")
View
3  app/models/workout.rb
@@ -1,3 +1,6 @@
class Workout < ActiveRecord::Base
attr_accessible :body, :title
+
+ has_many :workouts
+ has_many :users, :through => :workouts
end
View
27 app/views/entries/_form.html.erb
@@ -0,0 +1,27 @@
+<%= form_for([@workout, @entry]) do |f| %>
+ <h2 style="text-align: left">Workout Entry for <%= @workout.title %></h2>
+
+ <div class="field">
+ <%= f.label :Rounds %>
+ <%= f.text_field :rounds, :class => "input-medium" %>
+ </div>
+
+ <div class="field">
+ <%= f.label :Repetitions %>
+ <%= f.text_field :repetitions, :class => "input-medium" %>
+ </div>
+
+ <div class="field">
+ <%= f.text_area :body, :placeholder => "Enter workout entry description here...", :class => "wysihtml5", :style => "width: 50%;", :rows => 5 %>
+ </div>
+
+ <div class="field">
+ <%= f.label :date_performed, "Date Performed" %>
+ <%= f.text_field :date_performed, :class => "input-medium" %>
+ </div>
+
+
+ <div class="actions">
+ <%= f.submit :class => "btn btn-primary" %>
+ </div>
+<% end %>
View
5 app/views/entries/edit.html.erb
@@ -0,0 +1,5 @@
+<h1>Editing entry</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', workout_entries_path %>
View
37 app/views/entries/index.html.erb
@@ -0,0 +1,37 @@
+<h1>Listing Workout Entries For <%= @workout.title %></h1>
+
+<table class="table table-striped">
+ <tr>
+ <th>Date</th>
+ <th>Description</th>
+ <th>Rounds</th>
+ <th>Repetitions</th>
+ <th>Time</th>
+ <th>Actions</th>
+ </tr>
+
+<% @entries.each do |entry| %>
+ <tr>
+ <td><%= entry.date_performed.strftime("%m/%d/%y") %></td>
+ <td><%= entry.body %></td>
+ <td><%= entry.rounds %></td>
+ <td><%= entry.repetitions %></td>
+ <td><%= entry.time %></td>
+ <td>
+ <div class="btn-group">
+ <a href="#" class="btn dropdown-toggle" data-toggle="dropdown">Action<span class="caret"></span></a>
+ <ul class="dropdown-menu">
+ <li><%= link_to 'Edit', edit_workout_entry_path(@workout, entry) %></li>
+ <li><%= link_to 'Delete', workout_entry_path(@workout, entry),
+ :confirm => "Are you sure?", :method => :delete %></li>
+ </ul>
+ </div>
+ </td>
+ </tr>
+<% end %>
+</table>
+
+<br />
+<%= link_to 'Add Entry', new_workout_entry_path %> |
+<%= link_to 'Back', workouts_path %>
+
View
5 app/views/entries/new.html.erb
@@ -0,0 +1,5 @@
+<h1>New entry</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', workout_entries_path(2) %>
View
5 app/views/entries/show.html.erb
@@ -0,0 +1,5 @@
+<p id="notice"><%= notice %></p>
+
+
+<%= link_to 'Edit', edit_entry_path(@entry) %> |
+<%= link_to 'Back' %>
View
14 app/views/layouts/_header.html.erb
@@ -4,15 +4,13 @@
<%= link_to "CrossFit West Nashville", root_path, id: "logo" %>
<div class="navbar">
<ul class="nav pull-right">
-
- <li><%= link_to "Home", root_path %></li>
-
+ <li><%= link_to "Workouts", workouts_path %></li>
<% if user_signed_in? # Devise function %>
- <li><%= link_to "Workouts", workouts_index_path %></li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Me<b class="caret"></b></a>
<ul class="dropdown-menu">
- <li><%= link_to "My Profile", user_path(current_user) %></li>
+ <li><%= link_to "My Workouts", my_workout_path(current_user.id) %></li>
+ <li><%= link_to "My Profile", user_path(current_user.id) %></li>
<li class="divider"></li>
<li>
<%= link_to "Log Out", destroy_user_session_path,
@@ -24,7 +22,7 @@
</li>
- <% if current_user.has_role? "Admin" %>
+ <% if user_signed_in? and current_user.is_admin? %>
<div class="btn-group" style="float:left; display:inline;">
<a class="btn btn-success dropdown-toggle" data-toggle="dropdown" href="#">
Admin
@@ -32,6 +30,8 @@
</a>
<ul class="dropdown-menu">
<li><%= link_to "Users", admin_users_path %></li>
+ <li><%= link_to "Roles", admin_roles_path %></li>
+ <li><%= link_to "Workouts", admin_workouts_path %></li>
</ul>
</div>
<% end %>
@@ -46,4 +46,4 @@
</div>
</div>
</div>
-</header>
+</header>
View
1  app/views/layouts/admin.html.erb
@@ -3,6 +3,7 @@
<head>
<title>CrossFit West Nashville</title>
<%= stylesheet_link_tag "application", :media => "all" %>
+ <%= javascript_include_tag 'jquery_ujs' %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
<!--[ if lt IE 9]><script src ="http://html5shim.googlecode.com/svn/trunk/html5.js"></script><![ endif]-->
View
2  app/views/layouts/application.html.erb
@@ -4,6 +4,8 @@
<title>CrossFit West Nashville</title>
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
+ <%= stylesheet_link_tag "http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/south-street/jquery-ui.css", "application" %>
+ <%= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js" %>
<%= csrf_meta_tags %>
<!--[ if lt IE 9]><script src ="http://html5shim.googlecode.com/svn/trunk/html5.js"></script><![ endif]-->
</head>
View
2  app/views/users/edit.html.erb
@@ -2,5 +2,5 @@
<%= render 'form' %>
-<%= link_to 'Show', edit_admin_user_path %> |
+<%= link_to 'Show', edit_user_path %> |
<%= link_to 'Back', user_path %>
View
4 app/views/users/show.html.erb
@@ -15,5 +15,5 @@
</p>
-<%= link_to 'Edit', edit_admin_user_path(@user) %> |
-<%= link_to 'Back', admin_users_path %>
+<%= link_to 'Edit', edit_user_path(@user) %> |
+<%= link_to 'Back', user_path %>
View
21 app/views/workouts/index.html.erb
@@ -1,4 +1,4 @@
-<h1>Listing workouts</h1>
+<h1>All Workouts</h1>
<table class="table table-striped">
<tr>
@@ -10,16 +10,15 @@
<% @workouts.each do |workout| %>
<tr>
<td><%= workout.title %></td>
- <td><%= workout.body %></td>
+ <td><%= workout.body.html_safe %></td>
<td>
- <div class="btn-group">
- <a href="#" class="btn dropdown-toggle" data-toggle="dropdown">Action<span class="caret"></span></a>
- <ul class="dropdown-menu">
- <li><%= link_to 'Show', admin_workout_path(workout) %></li>
- <li><%= link_to 'Edit', edit_admin_workout_path(workout) %></li>
- <li><%= link_to 'Destroy', admin_workout_path(workout), method: :delete, data: { confirm: 'Are you sure?' } %></li>
+ <% if user_signed_in? %>
+ <ul class="inline">
+ <li><%= link_to 'Add', new_workout_entry_path(workout) %></li> |
+ <li><%= link_to 'View', workout_entries_path(workout) %></li> |
+ <li><%= link_to 'Leaderboard', leaderboard_path(workout) %></li>
</ul>
- </div>
+ <% end %>
</td>
</tr>
@@ -28,4 +27,6 @@
<br />
-<%= link_to 'New Workout', new_admin_workout_path %>
+<% if user_signed_in? and current_user.is_admin? %>
+ <%= link_to 'New Workout', new_admin_workout_path %>
+<% end %>
View
29 app/views/workouts/individual_workouts.html.erb
@@ -0,0 +1,29 @@
+<h1>My Workouts</h1>
+
+<table class="table table-striped">
+ <tr>
+ <th>Title</th>
+ <th>Body</th>
+ <th></th>
+ </tr>
+
+ <tr>
+ <td><%= @workout.title %></td>
+ <td><%= @workout.body %></td>
+ <td>
+ <% if user_signed_in? %>
+ <ul class="inline">
+ <li><%= link_to 'Add', new_workout_entry_path(@workout) %></li> |
+ <li><%= link_to 'View', workout_entries_path(@workout) %></li>
+ </ul>
+ <% end %>
+ </td>
+
+ </tr>
+</table>
+
+<br />
+
+<% if user_signed_in? and current_user.is_admin? %>
+ <%= link_to 'New Workout', new_admin_workout_path %>
+<% end %>
View
24 app/views/workouts/leaderboard.html.erb
@@ -0,0 +1,24 @@
+<h1><%= @workout.title %> Leaderboard</h1>
+
+<table class="table table-striped">
+ <tr>
+ <th>#</th>
+ <th>Date</th>
+ <th>Name</th>
+ <th>Rounds</th>
+ <th>Repetitions</th>
+ <th>Time</th>
+ </tr>
+
+ <% @entries.to_enum.with_index(1).each do |entry, rank| %>
+ <tr>
+ <td><%= rank %></td>
+ <td><%= entry.date_performed.strftime("%m/%d/%y") %></td>
+ <td><%= entry.user_id %></td>
+ <td><%= entry.rounds %></td>
+ <td><%= entry.repetitions %></td>
+ <td><%= entry.time %></td>
+ </tr>
+ <% end %>
+</table>
+
View
17 config/routes.rb
@@ -2,12 +2,27 @@
devise_for :users
- get "workouts/index"
+# get "workouts/index"
#resources :workouts
+ match '/workouts/individual/:user_id/',
+ :as => 'my_workout',
+ :controller => 'workouts',
+ :action => 'individual_workouts',
+ :via => [:get]
+
+ match '/workouts/:workout_id/leaderboard',
+ :as => 'leaderboard',
+ :controller => 'workouts',
+ :action => 'leaderboard',
+ :via => [:get]
resources :users, :only => [:show, :edit, :update]
+ resources :workouts, :only => [:index] do
+ resources :entries
+ end
+
# Static Pages
root to: 'static_pages#home'
match '/about', to: 'static_pages#about'
View
8 db/migrate/20130112213530_create_entries.rb
@@ -0,0 +1,8 @@
+class CreateEntries < ActiveRecord::Migration
+ def change
+ create_table :entries do |t|
+
+ t.timestamps
+ end
+ end
+end
View
11 db/migrate/20130125204354_add_fields_to_entries.rb
@@ -0,0 +1,11 @@
+class AddFieldsToEntries < ActiveRecord::Migration
+ def change
+ add_column :entries, :user_id, :integer
+ add_column :entries, :workout_id, :integer
+ add_column :entries, :body, :text
+ add_column :entries, :time, :integer
+ add_column :entries, :rounds, :integer
+ add_column :entries, :repetitions, :integer
+ add_column :entries, :date_performed, :timestamp
+ end
+end
View
13 db/migrate/20130130020524_add_roles_to_table.rb
@@ -0,0 +1,13 @@
+class AddRolesToTable < ActiveRecord::Migration
+ def self.up
+ Role.create :name => "Super Admin"
+ Role.create :name => "Admin"
+ Role.create :name => "Staff"
+ Role.create :name => "Member"
+ end
+
+ def self.down
+ Role.destroy_all
+ end
+end
+
View
14 db/schema.rb
@@ -11,7 +11,19 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20121123025145) do
+ActiveRecord::Schema.define(:version => 20130130020524) do
+
+ create_table "entries", :force => true do |t|
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ t.integer "user_id"
+ t.integer "workout_id"
+ t.text "body"
+ t.integer "time"
+ t.integer "rounds"
+ t.integer "repetitions"
+ t.datetime "date_performed"
+ end
create_table "roles", :force => true do |t|
t.datetime "created_at", :null => false
View
2,113 logfile
2,113 additions, 0 deletions not shown
Please sign in to comment.
Something went wrong with that request. Please try again.