diff --git a/Gemfile b/Gemfile index 6c36ba7d6772e099f47047840866959d6a38b367..7a2969901eaf677cbd8910d1ed73aa512b835479 100644 --- a/Gemfile +++ b/Gemfile @@ -74,6 +74,7 @@ gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] # Additional Project Gems # #Have to use feature branch because devise is yet to be patched for omniauth 2 - https://github.com/heartcombo/devise/pull/5327 +gem 'dotenv-rails', require: 'dotenv/rails-now' gem 'devise', github: 'heartcombo/devise', branch: 'ca-omniauth-2' gem 'omniauth-facebook' gem 'omniauth-google-oauth2' diff --git a/app/helpers/goals_helper.rb b/app/helpers/goals_helper.rb index 5c440c6b525ab43fda393231d7937644954bfba7..347c578bb21ab9f5cd7fc64f05304070d3143275 100644 --- a/app/helpers/goals_helper.rb +++ b/app/helpers/goals_helper.rb @@ -2,7 +2,7 @@ module GoalsHelper def getHabitsAmount(current_user) amount = 0 current_user.habits.each do |habit| - amount = amount + 1 + amount = amount + 1 end return amount end @@ -13,7 +13,7 @@ module GoalsHelper @goals.each do |goal| if goal.counter != amount - goal.counter = amount + goal.counter = amount end if goal.counter >= goal.target goal.completed = "true" @@ -26,19 +26,19 @@ module GoalsHelper @goals = Goals.where(goalType: "habitStreak").or(Goals.where(goalType: "monthlyHabitStreak")) @goals.each do |goal| - if Habit.exists?(goal.habit_id) - @habit = Habit.find(goal.habit_id) - currentStreak = @habit.streak - - if goal.counter != currentStreak - goal.counter = currentStreak - end - if goal.counter >= goal.target - goal.completed = "true" - end - goal.save + if Habit.exists?(goal.habit_id) + @habit = Habit.find(goal.habit_id) + currentStreak = @habit.streak + + if goal.counter != currentStreak + goal.counter = currentStreak + end + if goal.counter >= goal.target + goal.completed = "true" + end + goal.save else - goal.destroy + goal.destroy end end end @@ -84,9 +84,9 @@ module GoalsHelper end elsif @allgoals.exists?(title: "First") else - @goal = Goals.new(:title => "First", :description => "Create your first habit", :counter => "0", :target => "1", :user_id => current_user.id, - :goaltype => "habitAmount", :completed => "false") - @goal.save + @goal = Goals.new(:title => "First", :description => "Create your first habit", :counter => "0", :target => "1", :user_id => current_user.id, + :goaltype => "habitAmount", :completed => "false") + @goal.save end updateHabitAmountGoals end @@ -97,9 +97,9 @@ module GoalsHelper @habits.each do |habit| if @goals.exists?(title: habit.title) else - @goal = Goals.new(:title => habit.title, :description => "Reach Target", :counter => habit.streak, :target => habit.target, - :user_id => current_user.id, :goaltype => "habitStreak", :completed => "false", :habit_id => habit.id) - @goal.save + @goal = Goals.new(:title => habit.title, :description => "Reach Target", :counter => habit.streak, :target => habit.target, + :user_id => current_user.id, :goaltype => "habitStreak", :completed => "false", :habit_id => habit.id) + @goal.save end end updateHabitStreakGoals @@ -143,7 +143,7 @@ module GoalsHelper @habit = @emptyhabits.order("RANDOM()").first() @goal = Goals.new(:title => "Start tracking " + @habit.title, :description => "Reach a streak of 10 for " + @habit.title, :counter => @habit.streak, :target => 10, - :user_id => current_user.id, :goaltype => "monthlyHabitStreak", :completed => "false", :habit_id => @habit.id) + :user_id => current_user.id, :goaltype => "monthlyHabitStreak", :completed => "false", :habit_id => @habit.id) @goal.save end @@ -165,15 +165,15 @@ module GoalsHelper end @goal = Goals.new(:title => "Increase " + @maxhabit.title + " streak", :description => "Your " + @maxhabit.title + " streak is in the top " + percentile.to_s + "% for highest ongoing streak, keep this going this month", - :counter => @maxhabit.streak, :target => @maxhabit.streak + 25, - :user_id => current_user.id, :goaltype => "monthlyHabitStreak", :completed => "false", :habit_id => @maxhabit.id) + :counter => @maxhabit.streak, :target => @maxhabit.streak + 25, + :user_id => current_user.id, :goaltype => "monthlyHabitStreak", :completed => "false", :habit_id => @maxhabit.id) @goal.save @streakhabits = Habit.where("(max_streak - streak) < 30").where("(max_streak - streak) >= 0").where(user_id: current_user.id) @habit = @streakhabits.order("RANDOM()").first() @goal = Goals.new(:title => "Streak Beater", :description => "Beat your maximum streak for " + @habit.title, :counter => @habit.streak, :target => @habit.max_streak, - :user_id => current_user.id, :goaltype => "monthlyHabitStreak", :completed => "false", :habit_id => @habit.id) + :user_id => current_user.id, :goaltype => "monthlyHabitStreak", :completed => "false", :habit_id => @habit.id) @goal.save end end diff --git a/config/application.rb b/config/application.rb index 9ca9b27f807d241a48ee61e116a24910e175d466..4f8634731d07e245d2bdbbffed2d94ae0a9369a5 100644 --- a/config/application.rb +++ b/config/application.rb @@ -6,12 +6,12 @@ require 'rails/all' # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) +Dotenv::Railtie.load module Group10HabitTracker class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. config.load_defaults 5.2 - # Settings in config/environments/* take precedence over those specified here. # Application configuration can go into files in config/initializers # -- all .rb files in that directory are automatically loaded after loading