Skip to content

Commit

Permalink
modified tasks and added profile page
Browse files Browse the repository at this point in the history
  • Loading branch information
jodyalbritton committed Oct 30, 2012
1 parent a04123e commit 8212b76
Show file tree
Hide file tree
Showing 13 changed files with 82 additions and 12 deletions.
4 changes: 2 additions & 2 deletions app/controllers/contents_controller.rb
Expand Up @@ -62,11 +62,11 @@ def create
# PUT /contents/1.json
def update
@topic = Topic.find(params[:topic_id])
@content = @topic.contents.build(params[:content])
@content = Content.find(params[:id])

respond_to do |format|
if @content.update_attributes(params[:content])
format.html { redirect_to @content, notice: 'Content was successfully updated.' }
format.html { redirect_to @topic, notice: 'Content was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
Expand Down
15 changes: 15 additions & 0 deletions app/controllers/users_controller.rb
@@ -0,0 +1,15 @@
class UsersController < ApplicationController




def show
@user = User.find(params[:id])
@tasks_by_name = @user.task_completions.group_by { |t| t.task.name }
end





end
10 changes: 9 additions & 1 deletion app/models/user.rb
Expand Up @@ -2,18 +2,26 @@ class User < ActiveRecord::Base
rolify
acts_as_followable
acts_as_follower
extend FriendlyId
friendly_id :username, use: :slugged
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable

# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
attr_accessible :email, :password, :password_confirmation, :remember_me, :username, :first_name, :last_name, :privacy
# attr_accessible :title, :body

has_many :task_completions
has_many :tasks, :through => :task_completions
has_many :task_ownerships, :class_name => "Task", :foreign_key => "user_id"



def total_task_minutes
self.task_completions.sum(:active_minutes)
end

end
6 changes: 3 additions & 3 deletions app/views/dashboard/_complete.html.erb
@@ -1,11 +1,11 @@
<% @complete.each do |task| %>
<% if task.last_completed.strftime("%Y-%B-%d") == Date.today.strftime("%Y-%B-%d") %>
<% if task.task.last_completed.strftime("%Y-%B-%d") == Date.today.strftime("%Y-%B-%d") %>
<div class="row-fluid">
<div class="span2">
<%= task.name %>
<%= task.task.name %>
</div>
<div class="span2">
<%= task.last_completed.strftime("%d - %B - %Y") %> <%= link_to "Edit", edit_task_path(task) %>
<%= task.task.last_completed.strftime("%d - %B - %Y") %> <%= link_to "Edit", edit_task_path(task) %>
</div>
</div>
<% end %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/dashboard/_one-time.html.erb
@@ -1,6 +1,6 @@
<% @task_list.each do |task| %>
<% unless task.last_completed.present? %>
<% if task.last_completed == nil %>
<h4><%= task.name %></h4>
<%= render "task_completions/new", :task => task %>
<% end %>
<% end %>
<% end %>
5 changes: 2 additions & 3 deletions app/views/dashboard/index.html.erb
@@ -1,7 +1,6 @@
<div>
<%= link_to new_task_path, :class=> "btn btn-primary" do %>
<i class="icon-plus"></i> New Task
<% end %>


<h3>
Reccuring Tasks
</h3>
Expand Down
1 change: 1 addition & 0 deletions app/views/devise/registrations/edit.html.erb
Expand Up @@ -5,6 +5,7 @@

<div class="form-inputs">
<%= f.input :email, :required => true, :autofocus => true %>
<%= f.input :username, :required => true%>
<%= f.input :password, :autocomplete => "off", :hint => "leave it blank if you don't want to change it", :required => false %>
<%= f.input :password_confirmation, :required => false %>
<%= f.input :current_password, :hint => "we need your current password to confirm your changes", :required => true %>
Expand Down
1 change: 1 addition & 0 deletions app/views/task_completions/_new.html.erb
Expand Up @@ -2,6 +2,7 @@
<%= f.input_field :complete %>
<%= f.button :submit, "Update" %>
<%= f.input :task_id, :as => "hidden", :input_html => {:value => task.id}%>
<%= f.input :user_id, :as => "hidden", :input_html => {:value => current_user.id}%>
<label>Minutes
<%= f.input_field :active_minutes, :class => "input-mini"%>
</label>
Expand Down
24 changes: 24 additions & 0 deletions app/views/users/show.html.erb
@@ -0,0 +1,24 @@
<% @tasks_by_name.sort.each do |name, tasks| %>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th class="span8"><%= name %></th>
<th></th>
</tr>
</thead>
<tbody>
<% for task in tasks %>
<tr>
<td><%= task.completed_at.strftime("%d %B, %Y")%> </td>
<td><%= task.active_minutes %></td>
</tr>
<% end %>
<tr>
<td class="span8">Total Minutes</td>
<td class="span4"><%= tasks.map { |t| t.active_minutes}.sum %></td>
</tr>
</tbody>
</table>
<% end %>

1 change: 1 addition & 0 deletions config/routes.rb
Expand Up @@ -90,4 +90,5 @@
# Note: This route will make all actions in every controller accessible via GET requests.
# match ':controller(/:action(/:id))(.:format)'
root :to => 'welcome#index'
resources :users, :only => [:show], :path => '/'
end
7 changes: 7 additions & 0 deletions db/migrate/20121030091621_add_slug_to_users.rb
@@ -0,0 +1,7 @@
class AddSlugToUsers < ActiveRecord::Migration
def change
add_column :users, :slug, :string
add_index(:users, :slug)
end

end
8 changes: 8 additions & 0 deletions db/migrate/20121030092039_add_user_name_to_users.rb
@@ -0,0 +1,8 @@
class AddUserNameToUsers < ActiveRecord::Migration
def change
add_column :users, :username, :string
add_column :users, :first_name, :string
add_column :users, :last_name, :string
add_column :users, :privacy, :boolean
end
end
8 changes: 7 additions & 1 deletion db/schema.rb
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20121030044317) do
ActiveRecord::Schema.define(:version => 20121030092039) do

create_table "contents", :force => true do |t|
t.string "name"
Expand Down Expand Up @@ -132,10 +132,16 @@
t.string "last_sign_in_ip"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "slug"
t.string "username"
t.string "first_name"
t.string "last_name"
t.boolean "privacy"
end

add_index "users", ["email"], :name => "index_users_on_email", :unique => true
add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true
add_index "users", ["slug"], :name => "index_users_on_slug"

create_table "users_roles", :id => false, :force => true do |t|
t.integer "user_id"
Expand Down

0 comments on commit 8212b76

Please sign in to comment.