Auto-Close parent after his children are closed.

Added by Matt Daemow about 4 years ago

Like in topic.

How to make parent issue autoclose after all his sub-issues are closed/resolved.

Regards.

//Solved

issue_helper

def parent_close
roots = Issue.root
a = Issue.find(roots).descendants.count
b = Issue.find(roots).descendants.where(:status_id == 5).count
if (a = = b)
roots.update_attribute(:status_id, 5)
end
end

issue_controller

before_filter :parent_close, :only =>[:index]

Replies (2)

RE: Auto-Close parent after his children are closed. - Added by Steven Wong about 4 years ago

Nice, could you make a patch or plugin?

Thanks so much.

RE: Auto-Close parent after his children are closed. - Added by Matt Daemow about 4 years ago

nooope, not interested in :P

but little update

def parent_close
Issue.roots.each do |root|
all = root.descendants.count
closed = root.descendants.select{|hash| hash["status_id"] ((5) || (6))}.count
opened = root.descendants.select{|hash| hash["status_id"] 1}.count
opened = root.descendants.select{|hash| hash["status_id"] 3}.count
various = root.descendants.select{|hash| hash["status_id"] ((2) || (4))}.count
if (all closed)
root.update_attribute(:status_id, 5)
elsif (all opened)
root.update_attribute(:status_id, 1)
elsif (all == resolved)
root.update_attribute(:status_id, 3)
elsif (various > 0)
root.update_attribute(:status_id, 1)
end
end
end

cool if someone could refactor it.
Peace.

(1-2/2)