Class: BacklogsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/backlogs_controller.rb

Constant Summary

Constants included from Localization

Localization::LOCALIZED_STRINGS

Instance Method Summary collapse

Methods inherited from ApplicationController

in_place_edit_for, #initialize

Methods included from ApplicationHelper

#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, #update_task, #with_detour

Methods included from Localization

#l, load_localized_strings, #valid_language?

Constructor Details

This class inherits a constructor from ApplicationController

Instance Method Details

#abort_taskObject



119
120
121
122
123
124
# File 'app/controllers/backlogs_controller.rb', line 119

def abort_task
  @task = Task.find params[:id]
  @task.abort
  load_tasks(@task.backlog)
  render :action => :finish_task, :layout => false
end

#createObject



50
51
52
53
54
55
56
57
58
# File 'app/controllers/backlogs_controller.rb', line 50

def create
  @backlog = Backlog.new(params[:backlog])
  if @backlog.save
    flash[:notice] = 'Backlog was successfully created.'
    redirect_to :action => :show, :id => @backlog
  else
    render :action => 'new'
  end
end

#destroyObject



80
81
82
83
84
# File 'app/controllers/backlogs_controller.rb', line 80

def destroy
  Backlog.find(params[:id]).destroy
  flash[:notice] = 'Backlog was successfully deleted.'
  redirect_to :action => 'index'
end

#editObject



60
61
62
63
# File 'app/controllers/backlogs_controller.rb', line 60

def edit
  @backlog = Backlog.find(params[:id])
  @work_accounts = WorkAccount.find(:all)
end

#edit_no_layoutObject



65
66
67
68
# File 'app/controllers/backlogs_controller.rb', line 65

def edit_no_layout
  edit
  render :partial => 'tasks'
end

#finish_taskObject



113
114
115
116
117
# File 'app/controllers/backlogs_controller.rb', line 113

def finish_task
  @task = Task.find(params[:id])
  @task.finish(Task::COMPLETED, true)
  load_tasks(@task.backlog)
end

#indexObject



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/backlogs_controller.rb', line 8

def index
  flash.keep
  if Task.find_started.size > 0
    redirect_to :controller => 'tasks', :action => :list_started
    return
  end
  if Backlog.count == 0
    redirect_to :action => :new
    return
  end
  most_urgent_backlog = Backlog.find(:first, :order => :id)
  redirect_to :action => :show, :id => most_urgent_backlog.id
end

#listObject



22
23
24
# File 'app/controllers/backlogs_controller.rb', line 22

def list
  @backlogs = Backlog.find(:all, :order => 'name')
end

#move_task_to_next_periodObject



144
145
146
147
148
149
150
151
152
153
154
# File 'app/controllers/backlogs_controller.rb', line 144

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_periodObject



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'app/controllers/backlogs_controller.rb', line 126

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.backlog)
      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

#newObject



45
46
47
48
# File 'app/controllers/backlogs_controller.rb', line 45

def new
  @backlog = Backlog.new
  @work_accounts = WorkAccount.find(:all)
end

#orderObject



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'app/controllers/backlogs_controller.rb', line 161

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_taskObject



156
157
158
159
# File 'app/controllers/backlogs_controller.rb', line 156

def reopen_task
  @task = Task.find(params[:id]).reopen
  load_tasks(@task.backlog)
end

#showObject



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/backlogs_controller.rb', line 26

def show
  if params[:id]
    @backlog = Backlog.find(params[:id])
  end
  unless @backlog
    @backlog = Backlog.find(:first)
    unless @backlog
      redirect_to :controller => 'backlogs', :action => :new
      return
    end
  end
  load_tasks(@backlog)
end

#show_no_layoutObject



40
41
42
43
# File 'app/controllers/backlogs_controller.rb', line 40

def show_no_layout
  show
  render :partial => 'tasks'
end

#updateObject



70
71
72
73
74
75
76
77
78
# File 'app/controllers/backlogs_controller.rb', line 70

def update
  @backlog = Backlog.find(params[:id])
  if @backlog.update_attributes(params[:backlog])
    flash[:notice] = 'Backlog was successfully updated.'
    back_or_redirect_to :action => :show, :id => @backlog
  else
    render :action => 'edit'
  end
end

#update_task_estimateObject



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
111
# File 'app/controllers/backlogs_controller.rb', line 86

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.backlog)
        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

#worksObject



177
178
179
180
181
182
183
184
185
186
187
# File 'app/controllers/backlogs_controller.rb', line 177

def works
  backlog = Backlog.find(params[:id])
  @report_filter = ReportFilter.new(params[:report_filter])
  @report_filter.title = "#{l :hours} for #{backlog.name} #{@report_filter.start_on && @report_filter.start_on.strftime('%Y-%m-%d - ')}#{@report_filter.end_on && @report_filter.end_on.strftime('%Y-%m-%d')}"
  @works = Work.paginate :conditions => ["completed_at BETWEEN ? AND ? AND task_id IN (SELECT id FROM tasks t where t.backlog_id = ?)", @report_filter.start_on, @report_filter.end_on, backlog.id], :page => params[:page], :per_page => @report_filter.page_size
  if params[:export] == 'excel'
    render :template => '/works/list_excel', :layout => false
  else
    render :template => '/works/list'
  end
end