Complete dailies, and clear dones

This commit is contained in:
Tyler Renelle 2012-02-01 10:28:34 -05:00
parent 74a2e7eea5
commit 9173c072c4
3 changed files with 27 additions and 6 deletions

View file

@ -5,11 +5,23 @@ class Habit < ActiveRecord::Base
belongs_to :user
# TODO set cron for this
def self.clear_done
Habit.where(:habit_type => Habit::DAILY).collect do |h|
h.vote('down') unless h.done
h.done = false
h.save
end
end
def vote(direction)
next_vote = 1 #TODO return log or linear based on current score
next_vote *= -1 if(direction=='down')
self.score += next_vote
self.votedate = Time.now
#TODO if type=daily & votedate=today, set done back to false (have a done column?)
if(self.habit_type==Habit::DAILY)
self.done = true if direction=='up'
self.done = false if direction=='down'
end
end
end

View file

@ -1,8 +1,16 @@
<div id="<%= habit.id %>">
<%= habit.name %>
(<%= habit.score %>)
<%= link_to "√", { :action => "vote", :id => habit.id, :vote => 'up' }, :remote=>true %>
<%= link_to "X", { :action => "vote", :id => habit.id, :vote => 'down' }, :remote=>true %>
<!--<span class="popup"><%= habit.notes %></span>-->
<% if habit.habit_type==Habit::ALWAYS %>
<%= link_to "√", { :action => "vote", :id => habit.id, :vote => 'up' }, :remote=>true %>
<%= link_to "X", { :action => "vote", :id => habit.id, :vote => 'down' }, :remote=>true %>
<%= habit.name %> (<%= habit.score %>)
<% elsif habit.habit_type==Habit::DAILY %>
<% if habit.done %>
<%= link_to("[X]", { :action => "vote", :id => habit.id, :vote => 'down' }, :remote=>true) %>
<strike><%= habit.name %></strike> (<%= habit.score %>)
<% else %>
<%= link_to("[ ]", { :action => "vote", :id => habit.id, :vote => 'up' }, :remote=>true) %>
<%= habit.name %> (<%= habit.score %>)
<% end %>
<% end %>
<%= link_to 'Edit', edit_habit_path(habit) %>
</div>

View file

@ -7,6 +7,7 @@ class CreateHabits < ActiveRecord::Migration
t.integer :score, :default => 0
t.boolean :up, :default => true
t.boolean :down, :default => true
t.boolean :done, :default => false
t.text :notes
t.datetime :votedate