dustin / money

My money tracking app. There are many like it, but this one is mine.

This URL has Read+Write access

money / app / controllers / allowance_tasks_controller.rb
d7bc7e85 » dustin 2008-05-24 Renamed AllowanceController... 1 class AllowanceTasksController < ApplicationController
894dc1ac » dustin 2007-12-25 Working allowance controller. 2
aae0a452 » dustin 2008-05-24 Making allowance tasks rest... 3 def index
ac1148db » dustin 2007-12-25 Added task list. 4 title "Allowance Tasks You've Created"
63a07856 » dustin 2007-12-29 Break created tasks list do... 5 @tasks=AllowanceTask.find_all_by_creator_id(current_user.id,
6 :order => 'allowance_tasks.name', :include => :owner).group_by(&:owner)
7 @weekly_sums = {}
8 @tasks.each do |owner,tasks|
9 @weekly_sums[owner] = tasks.reject(&:deleted).inject(0.0) {|c,i| c + i.weekly_value}
10 end
ac1148db » dustin 2007-12-25 Added task list. 11 end
12
e09f4a32 » dustin 2007-12-26 Preliminary work on creati... 13 def new
14 title "Create an allowance task"
ff380a38 » dustin 2007-12-26 Added administrative functi... 15 @users=User.find :all, :conditions => ["id != ?", current_user.id], :order => 'name'
16 @accounts = Hash.new {|h,k| h[k] = []}
17 MoneyAccount.find(:all, :conditions => ["active = ?", true], :order => 'name').each do |a|
18 if current_user.groups.include? a.group
19 @accounts[a.group_id] << a
20 end
21 end
22 @categories = Hash.new {|h,k| h[k] = []}
23 Category.find(:all, :order => 'name').each do |c|
24 if current_user.groups.include? c.group
25 @categories[c.group_id] << c
26 end
27 end
28 @groups = current_user.groups
aae0a452 » dustin 2008-05-24 Making allowance tasks rest... 29 end
ff380a38 » dustin 2007-12-26 Added administrative functi... 30
aae0a452 » dustin 2008-05-24 Making allowance tasks rest... 31 def create
32 @task=AllowanceTask.new params[:allowance_task]
33 @task.creator = current_user
34 @task.save!
35 flash[:info] = "Created new task: #{@task.name}"
36 redirect_to allowance_tasks_path
e09f4a32 » dustin 2007-12-26 Preliminary work on creati... 37 end
38
f563d9ff » dustin 2007-12-26 Added the ability to deacti... 39 # Toggle the active state of a task
4f527c14 » dustin 2008-05-24 Use PUT for enabling and di... 40 def update
f563d9ff » dustin 2007-12-26 Added the ability to deacti... 41 task=AllowanceTask.find params[:id].to_i
42 active = (params[:active] == 'true')
43 task.deleted = !active
44 task.save!
45 render :action => (active ? :activate : :deactivate)
46 end
47
894dc1ac » dustin 2007-12-25 Working allowance controller. 48 def complete
49 tids = params['task'].keys.map(&:to_i)
50 # To prevent fraud, only include task IDs from those available.
51 available = AllowanceTask.find_available(current_user)
52 tasks = available.find_all {|n| tids.include? n.id}
53 AllowanceTask.transaction do
54 tasks.each {|t| t.perform!}
55 end
d7bc7e85 » dustin 2008-05-24 Renamed AllowanceController... 56 redirect_to home_path
894dc1ac » dustin 2007-12-25 Working allowance controller. 57 end
58
59 end