Class: ProjectsController
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, #l, #record, #resolution_image, #t, #update_task, #with_detour
Instance Method Details
#abort_task ⇒ Object
118
119
120
121
122
123
|
# File 'app/controllers/projects_controller.rb', line 118
def abort_task
@task = Task.find params[:id]
@task.abort
load_tasks(@task.project)
render :action => :finish_task, :layout => false
end
|
#create ⇒ Object
48
49
50
51
52
53
54
55
56
|
# File 'app/controllers/projects_controller.rb', line 48
def create
@project = Project.new(params[:project])
if @project.save
flash[:notice] = 'Project was successfully created.'
redirect_to :action => :show, :id => @project
else
render :action => 'new'
end
end
|
#destroy ⇒ Object
77
78
79
80
81
82
83
|
# File 'app/controllers/projects_controller.rb', line 77
def destroy
project = Project.find(params[:id])
project.work_lock_subscribers.delete_all
project.destroy
flash[:notice] = 'Project was successfully deleted.'
redirect_to :action => 'index'
end
|
#edit ⇒ Object
58
59
60
|
# File 'app/controllers/projects_controller.rb', line 58
def edit
@project = Project.find(params[:id])
end
|
#edit_no_layout ⇒ Object
62
63
64
65
|
# File 'app/controllers/projects_controller.rb', line 62
def edit_no_layout
edit
render :partial => 'tasks'
end
|
#finish_task ⇒ Object
112
113
114
115
116
|
# File 'app/controllers/projects_controller.rb', line 112
def finish_task
@task = Task.find(params[:id])
@task.finish(Task::COMPLETED, true)
load_tasks(@task.project)
end
|
#index ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'app/controllers/projects_controller.rb', line 7
def index
flash.keep
if Task.find_started.size > 0
redirect_to :controller => 'tasks', :action => :list_started
return
end
if Project.count == 0
redirect_to :action => :new
return
end
most_urgent_project = Project.find(:first, :order => :id)
redirect_to :action => :show, :id => most_urgent_project.id
end
|
#list ⇒ Object
21
22
23
|
# File 'app/controllers/projects_controller.rb', line 21
def list
@projects = Project.find(:all, :order => 'name')
end
|
#move_task_to_next_period ⇒ Object
143
144
145
146
147
148
149
150
151
152
153
|
# File 'app/controllers/projects_controller.rb', line 143
def move_task_to_next_period
@task = Task.find(params[:id])
if @task.period
next_period = @task.period.lower_item
next_period = next_period.lower_item while next_period && next_period.passed?
params[:period_id] = next_period && next_period.id
move_task_to_period
else
rjs_redirect_to :controller => 'tasks', :action => :edit, :id => @task
end
end
|
#move_task_to_period ⇒ Object
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
# File 'app/controllers/projects_controller.rb', line 125
def move_task_to_period
params[:id] = $1 if params[:id] =~ /^task_(\d*)/
@task = Task.find(params[:id])
if request.post?
period = params[:period_id] && Period.find(params[:period_id])
if period && period.active_or_future?
next_task = @task.higher_item ? @task.higher_item : @task.lower_item ? @task.lower_item : @task
@task.move_to_period period
load_tasks(@task.project)
render :action => :move_task_to_period, :layout => false
else
rjs_detour_to :controller => 'periods', :action => :new, :period => {:party_id => @task.period.party_id}, :layout => false
end
else
redirect_to :controller => 'periods', :action => :show, :id => @task.period, :task_id => @task.id, :layout => false
end
end
|
#new ⇒ Object
44
45
46
|
# File 'app/controllers/projects_controller.rb', line 44
def new
@project = Project.new
end
|
#order ⇒ Object
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
# File 'app/controllers/projects_controller.rb', line 160
def order
params.keys.find {|k| k =~ /active_tasks_(.*)/}
period_id = $1
if period_id
period = period_id.empty? ? nil : Period.find(period_id)
tasks = params["active_tasks_#{period_id}"].select {|id| not id.empty?}
tasks.each_with_index do |id,idx|
task = Task.find(id)
task = task.move_to_period(period) if task.period != period
task.insert_at(idx + 1)
task.save!
end
end
render :text => 'alert("Updated sort order");'
end
|
#reopen_task ⇒ Object
155
156
157
158
|
# File 'app/controllers/projects_controller.rb', line 155
def reopen_task
@task = Task.find(params[:id]).reopen
load_tasks(@task.project)
end
|
#show ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'app/controllers/projects_controller.rb', line 25
def show
if params[:id]
@project = Project.find(params[:id])
end
unless @project
@project = Project.find(:first)
unless @project
redirect_to :controller => 'projects', :action => :new
return
end
end
load_tasks(@project)
end
|
#show_no_layout ⇒ Object
39
40
41
42
|
# File 'app/controllers/projects_controller.rb', line 39
def show_no_layout
show
render :partial => 'tasks'
end
|
#update ⇒ Object
67
68
69
70
71
72
73
74
75
|
# File 'app/controllers/projects_controller.rb', line 67
def update
@project = Project.find(params[:id])
if @project.update_attributes(params[:project])
flash[:notice] = 'Project was successfully updated.'
back_or_redirect_to :action => :show, :id => @project
else
render :action => 'edit'
end
end
|
#update_task_estimate ⇒ Object
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'app/controllers/projects_controller.rb', line 85
def update_task_estimate
if params[:id]
@task = Task.find_by_id(params[:id])
if params[:estimate] && params[:estimate][:todo]
begin
Float(params[:estimate][:todo])
@task.estimate(params[:estimate][:todo])
@period = @task.period
@success, flash[:notice] = true, 'Estimate updated'
rescue ArgumentError => e
@success, flash[:notice] = false, "Estimate was not numeric"
end
if @task.finished?
load_tasks(@task.project)
render :action => 'finish_task', :layout => false
else
render :template => '/tasks/update_estimate', :layout => false
end
else
return false, "Estimate is missing."
end
else
@estimate = Estimate.new
return false, 'Task id is missing.'
end
end
|