Completed
+-
+ <% @one_time.each do |habit| %>
+ <%= render :partial => "habit", :locals => { :habit => habit } %>
+ <% end %>
+
diff --git a/app/assets/javascripts/habits.js.coffee b/app/assets/javascripts/habits.js.coffee index d89ef22be6..94520990bb 100644 --- a/app/assets/javascripts/habits.js.coffee +++ b/app/assets/javascripts/habits.js.coffee @@ -4,6 +4,9 @@ $(document).ready -> + $(".one-time a.vote-link").click -> + $(this).parent().fadeOut() + $(".comment").qtip content: text: (api) -> $(this).next().html() diff --git a/app/controllers/habits_controller.rb b/app/controllers/habits_controller.rb index 16273b51c1..32575479fb 100644 --- a/app/controllers/habits_controller.rb +++ b/app/controllers/habits_controller.rb @@ -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 diff --git a/app/helpers/habits_helper.rb b/app/helpers/habits_helper.rb index 0b05c7eaec..fee9a45ffc 100644 --- a/app/helpers/habits_helper.rb +++ b/app/helpers/habits_helper.rb @@ -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 diff --git a/app/models/habit.rb b/app/models/habit.rb index f552d3c91f..0ccfeebcf8 100644 --- a/app/models/habit.rb +++ b/app/models/habit.rb @@ -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 diff --git a/app/views/habits/_habit.html.erb b/app/views/habits/_habit.html.erb index 7aea32c720..9749167f9e 100644 --- a/app/views/habits/_habit.html.erb +++ b/app/views/habits/_habit.html.erb @@ -1,9 +1,9 @@ -
|
+
+
+
+
+ Completed+
+
+
|
+
+