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 @@ -
  • +
  • <% 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') %> <%= habit.name %> diff --git a/app/views/habits/completed.erb b/app/views/habits/completed.erb new file mode 100644 index 0000000000..a526ce6c23 --- /dev/null +++ b/app/views/habits/completed.erb @@ -0,0 +1,27 @@ +<% content_for :score do %> + <%= render :partial => "progressbar", :locals => { :score => @score } %> +<% end %> + + +<%= link_to 'New Habit', new_habit_path %> + + + + + + + +
    +
    +
    +

    Completed

    +
    +
      + <% @one_time.each do |habit| %> + <%= render :partial => "habit", :locals => { :habit => habit } %> + <% end %> +
    +
    +
    +
    +
    diff --git a/app/views/habits/index.html.erb b/app/views/habits/index.html.erb index 72d71ad334..728b2a4e60 100644 --- a/app/views/habits/index.html.erb +++ b/app/views/habits/index.html.erb @@ -36,11 +36,26 @@ + + +
    +
    +

    One-offs

    +
    +
      + <% @one_time.each do |habit| %> + <%= render :partial => "habit", :locals => { :habit => habit } %> + <% end %> +
    +
    +
    +
    +
    -

    Store +

    Rewards <%= render 'money'%>

    diff --git a/app/views/habits/vote.js.erb b/app/views/habits/vote.js.erb index 4f270c49e0..518d1d55e6 100644 --- a/app/views/habits/vote.js.erb +++ b/app/views/habits/vote.js.erb @@ -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') %>"); diff --git a/config/routes.rb b/config/routes.rb index 853d7b86bf..614ba2b67d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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'