Permalink
Browse files

Having app to a working state. Entries work. Working on leaderboard a…

…ssociations
  • Loading branch information...
1 parent 86570bd commit 5c6fe6678168235d25951110a90ddf24ee858b15 Rian Rainey committed Mar 20, 2013
View
@@ -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
@@ -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)
@@ -1,11 +1,14 @@
$(document).ready(function(){
wysihtmlfive();
+
+ $("#entry_date_performed").datepicker({
+ dateFormat: 'yy-mm-dd'});
});
// Apply wysihtml5 to appropriate text areas
function wysihtmlfive() {
$('.wysihtml5').each(function(i, elem) {
$(elem).wysihtml5();
});
-}
+}
@@ -2,7 +2,7 @@ class ApplicationController < ActionController::Base
protect_from_forgery
def require_admin
- unless user_signed_in? and current_user.has_role?(["Super Admin", "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
@@ -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
@@ -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
@@ -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
+ 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
@@ -0,0 +1,2 @@
+module EntriesHelper
+end
View
@@ -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
@@ -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
@@ -1,3 +1,6 @@
class Workout < ActiveRecord::Base
attr_accessible :body, :title
+
+ has_many :workouts
+ has_many :users, :through => :workouts
end
@@ -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 %>
@@ -0,0 +1,5 @@
+<h1>Editing entry</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', workout_entries_path %>
@@ -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 %>
+
@@ -0,0 +1,5 @@
+<h1>New entry</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', workout_entries_path(2) %>
@@ -0,0 +1,5 @@
+<p id="notice"><%= notice %></p>
+
+
+<%= link_to 'Edit', edit_entry_path(@entry) %> |
+<%= link_to 'Back' %>
@@ -9,7 +9,7 @@
<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 Workouts", workouts_path %></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>
@@ -22,7 +22,7 @@
</li>
- <% if current_user.has_role? ["Super Admin", "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
@@ -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]-->
@@ -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>
Oops, something went wrong.

0 comments on commit 5c6fe66

Please sign in to comment.