Class: WorksController
Constant Summary
Localization::LOCALIZED_STRINGS
Instance Method Summary
collapse
in_place_edit_for, #initialize
#back_or_link_to, #detour?, #detour_to, #display_notice, #h, #image_button_to, #image_detour_to, #image_link_to, #image_link_to_remote, #insert, #record, #resolution_image, #t, #with_detour
#l, load_localized_strings, #valid_language?
Instance Method Details
#auto_complete_for_work_backlog_name ⇒ Object
162
163
164
165
166
167
168
169
|
# File 'app/controllers/works_controller.rb', line 162
def auto_complete_for_work_backlog_name
@backlogs = Backlog.find(:all,
:conditions => [ 'LOWER(name) LIKE ?',
'%' + params[:work][:backlog_name].downcase + '%' ],
:order => 'name ASC',
:limit => 16)
render :partial => '/backlogs/name_list'
end
|
#auto_complete_for_work_task_description ⇒ Object
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
# File 'app/controllers/works_controller.rb', line 171
def auto_complete_for_work_task_description
if backlog_name = params[:backlog_name]
if @backlog = Backlog.find_by_name(backlog_name)
@tasks = @backlog.tasks_with_children.select {|t| t.description.downcase =~ /#{params[:work][:task_description].downcase}/}
end
end
@tasks ||= Task.find(:all,
:conditions => [ "finished_at IS NULL AND LOWER(description) LIKE ?",
'%' + params[:work][:task_description].downcase + '%' ],
:order => 'description ASC',
:limit => 16)
render :partial => 'description_list'
end
|
#auto_complete_for_work_work_account_name ⇒ Object
153
154
155
156
157
158
159
160
|
# File 'app/controllers/works_controller.rb', line 153
def auto_complete_for_work_work_account_name
@accounts = WorkAccount.find(:all,
:conditions => [ 'LOWER(name) LIKE ?',
'%' + params[:work][:work_account_name].downcase + '%' ],
:order => 'name ASC',
:limit => 16)
render :partial => '/work_accounts/name_list'
end
|
#create ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'app/controllers/works_controller.rb', line 38
def create
if params[:work]
backlog_name = params[:work].delete(:backlog_name)
task_description = params[:work].delete(:task_description)
if backlog_name && backlog_name.size > 0 && task_description && task_description.size > 0
backlog = Backlog.find_by_name(backlog_name)
task = backlog.tasks_with_children.find{|t| t.description == task_description}
params[:work][:task_id] = task.id
end
account_name = params[:work].delete(:work_account_name)
if account_name && account_name.size > 0
account = WorkAccount.find_by_name(account_name)
params[:work][:work_account_id] = account.id
end
end
convert_hours_param
convert_start_time_param
@work = Work.new(params[:work])
@work.completed_at = Time.now unless @work.completed_at
@work.user_id = current_user.id
if @work.save
flash[:notice] = 'Work was successfully created.'
else
new
render :action => 'new'
return
end
@work.task.estimates.create!(params[:estimate]) if @work.task && params[:estimate]
back_or_redirect_to :controller => 'periods', :action => 'show', :id => @work.task && @work.task.period, :task_id => @work.task && @work.task.id
end
|
#daily_work_sheet ⇒ Object
130
131
132
133
134
135
136
137
|
# File 'app/controllers/works_controller.rb', line 130
def daily_work_sheet
@date = (params[:id] && Date.parse(params[:id])) || Date.today
@periods = []
@works = Work.find_work_for_day @date
@started_works = Task.find_started
@work = Work.new(:started_at => Time.now, :completed_at => Time.now)
render :layout => 'wide'
end
|
#destroy ⇒ Object
123
124
125
126
127
128
|
# File 'app/controllers/works_controller.rb', line 123
def destroy
work = Work.find(params[:id])
period = work.task && work.task.period
work.destroy
back_or_redirect_to :controller => 'periods', :action => :list_work, :id => period
end
|
#edit ⇒ Object
71
72
73
74
75
76
77
78
|
# File 'app/controllers/works_controller.rb', line 71
def edit
@work = Work.find(params[:id])
@work.attributes = params[:work]
@estimate = Estimate.new(params[:estimate])
@work_accounts = WorkAccount.find(:all)
@tasks = Task.find_open
@users = User.find(:all)
end
|
#index ⇒ Object
9
10
11
12
|
# File 'app/controllers/works_controller.rb', line 9
def index
list
render :action => 'list'
end
|
#list ⇒ Object
18
19
20
21
|
# File 'app/controllers/works_controller.rb', line 18
def list
@period = params[:id] && Period.find(params[:id])
@works = Work.paginate :order => 'completed_at', :page => params[:page]
end
|
#new ⇒ Object
27
28
29
30
31
32
33
34
35
36
|
# File 'app/controllers/works_controller.rb', line 27
def new
unless @work
@work = Work.new(params[:work])
@work.user = user
end
@estimate ||= Estimate.new(params[:estimate])
@work_accounts = WorkAccount.find(:all, :order => :name)
@tasks = Task.find_open
@users = User.find(:all)
end
|
#show ⇒ Object
23
24
25
|
# File 'app/controllers/works_controller.rb', line 23
def show
@work = Work.find(params[:id])
end
|
#timeliste ⇒ Object
145
146
147
148
149
150
151
|
# File 'app/controllers/works_controller.rb', line 145
def timeliste
@week = (params[:id] && params[:id].to_i) || Date.today.cweek
@backlogs = Work.work_totals_for_week(@week)
["Content-Type"] = "application/vnd.ms-excel"
["Content-Disposition"] = 'attachment; filename="export.xml"'
render :layout => false
end
|
#update ⇒ Object
80
81
82
83
84
85
86
87
88
|
# File 'app/controllers/works_controller.rb', line 80
def update
if update_work
back_or_redirect_to :controller => 'periods', :action => 'show', :id => @work.task.period, :task_id => @work.task.id
else
@task = @work.task
edit
render :action => 'edit'
end
end
|
#update_row ⇒ Object
90
91
92
93
94
|
# File 'app/controllers/works_controller.rb', line 90
def update_row
update_work
flash.discard
@field = params[:field] || 'started_at_time'
end
|
#update_time ⇒ Object
96
97
98
99
100
|
# File 'app/controllers/works_controller.rb', line 96
def update_time
update_work
flash.discard
@field = params[:field] || 'started_at_time'
end
|
#update_work ⇒ Object
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'app/controllers/works_controller.rb', line 102
def update_work
@work = Work.find(params[:id])
convert_start_time_param
convert_hours_param
if @work.update_attributes(params[:work])
flash[:notice] = 'Work was successfully updated.'
if @work.task
if params[:estimate]
if (@estimate = @work.task.estimates.create(params[:estimate])).errors.size == 0
return true
end
else
return true
end
else
return true
end
end
return false
end
|
#weekly_work_sheet ⇒ Object
139
140
141
142
143
|
# File 'app/controllers/works_controller.rb', line 139
def weekly_work_sheet
@week = (params[:id] && params[:id].to_i) || Date.today.cweek
@rows = Work.works_for_week(@week)
render :layout => 'wide'
end
|