diff --git a/app/models/habit.rb b/app/models/habit.rb
index 9b662e364c..3ac5b51896 100644
--- a/app/models/habit.rb
+++ b/app/models/habit.rb
@@ -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
diff --git a/app/views/habits/_habit.html.erb b/app/views/habits/_habit.html.erb
index c06b4f14c2..1afa68c2ee 100644
--- a/app/views/habits/_habit.html.erb
+++ b/app/views/habits/_habit.html.erb
@@ -1,8 +1,16 @@
- <%= 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 %>
-
+ <% 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) %>
+ <%= habit.name %> (<%= 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) %>
diff --git a/db/migrate/20120201040610_create_habits.rb b/db/migrate/20120201040610_create_habits.rb
index e47ad81886..4e9570e620 100644
--- a/db/migrate/20120201040610_create_habits.rb
+++ b/db/migrate/20120201040610_create_habits.rb
@@ -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