19 |
19 |
|
20 |
20 |
safe_attributes :sprint_id, :if => lambda {|issue, user| user.allowed_to?(:edit_issues, issue.project)}
|
21 |
21 |
|
22 |
|
before_save :update_position, :if => lambda {|issue| issue.sprint_id_changed? and issue.is_pbi?}
|
|
22 |
before_save :update_positions_on_sprint_change, :if => lambda {|issue| issue.sprint_id_changed? and issue.is_pbi?}
|
23 |
23 |
|
24 |
24 |
before_save :update_sprint_of_children, :if => lambda {|issue| issue.sprint_id_changed? and issue.is_pbi?}
|
25 |
25 |
|
... | ... | |
224 |
224 |
case position
|
225 |
225 |
when "top"
|
226 |
226 |
move_issue_to_the_begin_of_the_sprint
|
227 |
|
save!
|
228 |
227 |
when "bottom"
|
229 |
228 |
move_issue_to_the_end_of_the_sprint
|
230 |
|
save!
|
231 |
229 |
when "before", "after"
|
232 |
230 |
if other_pbi_id.nil? or (other_pbi = Issue.find(other_pbi_id)).nil?
|
233 |
231 |
raise "Other PBI ID ##{other_pbi_id} is invalid"
|
... | ... | |
239 |
237 |
move_issue_respecting_to_pbi(other_pbi, position == "after")
|
240 |
238 |
end
|
241 |
239 |
end
|
|
240 |
self.save!
|
242 |
241 |
end
|
243 |
242 |
end
|
244 |
243 |
|
245 |
244 |
def is_first_pbi?
|
246 |
|
min = min_position
|
247 |
|
return ((!(position.nil?)) and (!(min.nil?)) and (position <= min))
|
|
245 |
self == sprint.pbis.first
|
248 |
246 |
end
|
249 |
247 |
|
250 |
248 |
def is_last_pbi?
|
251 |
|
max = max_position
|
252 |
|
return ((!(position.nil?)) and (!(max.nil?)) and (position >= max))
|
|
249 |
self == sprint.pbis.last
|
253 |
250 |
end
|
254 |
251 |
|
255 |
252 |
protected
|
... | ... | |
262 |
259 |
|
263 |
260 |
private
|
264 |
261 |
|
265 |
|
def update_position
|
|
262 |
def update_positions_on_sprint_change
|
266 |
263 |
if sprint_id_was.blank?
|
267 |
264 |
# New PBI into PB or Sprint
|
268 |
265 |
if @set_on_top
|
... | ... | |
281 |
278 |
# From Sprint to Sprint
|
282 |
279 |
move_issue_to_the_end_of_the_sprint
|
283 |
280 |
end
|
|
281 |
old_sprint.release_position(self)
|
284 |
282 |
end
|
285 |
283 |
end
|
286 |
284 |
|
287 |
|
def min_position
|
288 |
|
min = nil
|
289 |
|
sprint.pbis.each do |pbi|
|
290 |
|
min = pbi.position if min.nil? or (pbi.position < min)
|
|
285 |
def move_issue_to_the_begin_of_the_sprint
|
|
286 |
if first_pbi = sprint.pbis.first
|
|
287 |
move_issue_respecting_to_pbi(first_pbi, false)
|
|
288 |
else
|
|
289 |
self.position = 1
|
291 |
290 |
end
|
292 |
|
return min
|
293 |
291 |
end
|
294 |
292 |
|
295 |
|
def max_position
|
296 |
|
max = nil
|
297 |
|
sprint.pbis.each do |pbi|
|
298 |
|
max = pbi.position if max.nil? or (pbi.position > max)
|
|
293 |
def move_issue_to_the_end_of_the_sprint
|
|
294 |
if last_pbi = sprint.pbis.last
|
|
295 |
move_issue_respecting_to_pbi(last_pbi, true)
|
|
296 |
else
|
|
297 |
self.position = 1
|
299 |
298 |
end
|
300 |
|
return max
|
301 |
299 |
end
|
302 |
300 |
|
303 |
|
def move_issue_to_the_begin_of_the_sprint
|
304 |
|
min = min_position
|
305 |
|
self.position = min.nil? ? 1 : (min - 1)
|
306 |
|
end
|
307 |
|
|
308 |
|
def move_issue_to_the_end_of_the_sprint
|
309 |
|
max = max_position
|
310 |
|
self.position = max.nil? ? 1 : (max + 1)
|
311 |
|
end
|
312 |
|
|
313 |
301 |
def move_issue_respecting_to_pbi(other_pbi, after)
|
314 |
|
self.position = other_pbi.position
|
315 |
|
self.position += 1 if after
|
316 |
|
self.save!
|
317 |
|
sprint.pbis(:position_above => after ? self.position : self.position - 1).each do |next_pbi|
|
318 |
|
if next_pbi.id != self.id
|
319 |
|
next_pbi.position += 1
|
320 |
|
next_pbi.save!
|
|
302 |
new_position = 1
|
|
303 |
sprint.pbis.each do |pbi|
|
|
304 |
unless pbi == self
|
|
305 |
if pbi == other_pbi
|
|
306 |
if after
|
|
307 |
update_position(pbi, new_position)
|
|
308 |
new_position += 1
|
|
309 |
self.position = new_position
|
|
310 |
else
|
|
311 |
self.position = new_position
|
|
312 |
new_position += 1
|
|
313 |
update_position(pbi, new_position)
|
|
314 |
end
|
|
315 |
else
|
|
316 |
update_position(pbi, new_position)
|
|
317 |
end
|
|
318 |
new_position += 1
|
321 |
319 |
end
|
322 |
320 |
end
|
323 |
321 |
end
|
324 |
322 |
|
|
323 |
def update_position(pbi, new_position)
|
|
324 |
unless pbi.position == new_position
|
|
325 |
pbi.position = new_position
|
|
326 |
pbi.save!
|
|
327 |
end
|
|
328 |
end
|
|
329 |
|
325 |
330 |
def update_sprint_of_children
|
326 |
331 |
self.children.each do |child|
|
327 |
332 |
unless child.closed?
|