Adding TODOs & completed page

This commit is contained in:
Tyler Renelle 2012-02-04 16:32:12 -05:00
parent deb403cd54
commit 88e105a442
9 changed files with 74 additions and 6 deletions

View file

@ -4,6 +4,9 @@
$(document).ready ->
$(".one-time a.vote-link").click ->
$(this).parent().fadeOut()
$(".comment").qtip content:
text: (api) ->
$(this).next().html()

View file

@ -7,6 +7,7 @@ class HabitsController < ApplicationController
def index
@habits = current_user.habits.where(:habit_type => Habit::ALWAYS)
@daily = current_user.habits.where(:habit_type => Habit::DAILY)
@one_time = current_user.habits.where(:habit_type => Habit::ONE_TIME).where(:done=>false)
@score = current_user.habits.sum('score').to_i
respond_to do |format|
@ -14,6 +15,17 @@ class HabitsController < ApplicationController
format.json { render json: @habits }
end
end
# GET /habits/completed
# GET /habits/completed.json
def completed
@one_time = current_user.habits.where(:habit_type => Habit::ONE_TIME).where(:done=>true)
respond_to do |format|
format.html # completed.html.erb
format.json { render json: @one_time }
end
end
# GET /habits/new

View file

@ -1,5 +1,13 @@
module HabitsHelper
def habit_type(habit)
case habit.habit_type
when 1 then return "habit"
when 2 then return "daily"
when 3 then return "one-time"
end
end
def score_color(habit)
s = habit.score
case
@ -23,7 +31,7 @@ module HabitsHelper
else
text,dir,style = "[ ]","up","check"
end
return link_to(text, { :action => "vote", :id => habit.id, :vote => dir }, :class=>style, :remote=>true)
return link_to(text, { :action => "vote", :id => habit.id, :vote => dir }, :class=>style+" vote-link", :remote=>true)
end
def user_gold

View file

@ -37,7 +37,7 @@ class Habit < ActiveRecord::Base
end
# up/down -voting as checkbox & assigning as done, 2 birds one stone
if(self.habit_type==Habit::DAILY)
if(self.habit_type==Habit::DAILY || self.habit_type==Habit::ONE_TIME)
self.done = true if direction=='up'
self.done = false if direction=='down'
end

View file

@ -1,9 +1,9 @@
<li id="habit_<%= habit.id %>" class="habit <%= score_color(habit) %>">
<li id="habit_<%= habit.id %>" class="habit <%= habit_type(habit) %> <%= score_color(habit) %>">
<% if habit.habit_type==Habit::ALWAYS %>
<%= vote_link(habit, 'up') %>
<%= vote_link(habit, 'down') %>
<%= habit.name %>
<% elsif habit.habit_type==Habit::DAILY %>
<% else %>
<% if habit.done %>
<%= vote_link(habit, 'checked') %>
<strike><%= habit.name %></strike>

View file

@ -0,0 +1,27 @@
<% content_for :score do %>
<%= render :partial => "progressbar", :locals => { :score => @score } %>
<% end %>
<%= link_to 'New Habit', new_habit_path %>
<table id="layout">
<tr>
<td class="panel">
<div class="block">
<div class='content'>
<h2 class='title'>Completed</h2>
<div class='inner'>
<ul id="daily">
<% @one_time.each do |habit| %>
<%= render :partial => "habit", :locals => { :habit => habit } %>
<% end %>
</ul>
</div>
</div>
</div>
</td>
</tr>
</table>

View file

@ -36,11 +36,26 @@
</div>
</div>
</td>
<td class="panel">
<div class="block">
<div class='content'>
<h2 class='title'>One-offs</h2>
<div class='inner'>
<ul id="daily">
<% @one_time.each do |habit| %>
<%= render :partial => "habit", :locals => { :habit => habit } %>
<% end %>
</ul>
</div>
</div>
</div>
</td>
<td class="panel">
<div class="block">
<div class='content'>
<h2 class='title'>Store
<h2 class='title'>Rewards
<%= render 'money'%>
</h2>
<div class='inner'>

View file

@ -1,3 +1,5 @@
$('#habit_<%= @habit.id %>').replaceWith("<%= escape_javascript(render :partial => "habit", :locals => { :habit => @habit }) %>");
<% unless @habit.habit_type==Habit::ONE_TIME %>
$('#habit_<%= @habit.id %>').replaceWith("<%= escape_javascript(render :partial => "habit", :locals => { :habit => @habit }) %>");
<% end %>
$('#progressbar').replaceWith("<%= escape_javascript(render :partial => "progressbar", :locals => { :score => @score }) %>");
$('#money').replaceWith("<%= escape_javascript(render 'money') %>");

View file

@ -1,6 +1,7 @@
HabitTracker::Application.routes.draw do
resources :habits do
post :sort, on: :collection
get :completed, on: :collection
end
match 'habits/:id/vote' => 'habits#vote'