Class: IssueStatus

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/issue_status.rb

Overview

redMine - project management software Copyright (C) 2006 Jean-Philippe Lang

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.defaultObject

Returns the default status for new issues



33
34
35
# File 'app/models/issue_status.rb', line 33

def self.default
  find(:first, :conditions =>["is_default=?", true])
end

Instance Method Details

#<=>(status) ⇒ Object



59
60
61
# File 'app/models/issue_status.rb', line 59

def <=>(status)
  position <=> status.position
end

#after_saveObject



28
29
30
# File 'app/models/issue_status.rb', line 28

def after_save
  IssueStatus.update_all("is_default=#{connection.quoted_false}", ['id <> ?', id]) if self.is_default?
end

#find_new_statuses_allowed_to(role, tracker) ⇒ Object

Same thing as above but uses a database query More efficient than the previous method if called just once



46
47
48
49
50
51
# File 'app/models/issue_status.rb', line 46

def find_new_statuses_allowed_to(role, tracker)  
  new_statuses = workflows.find(:all, 
                                 :include => :new_status,
                                 :conditions => ["role_id=? and tracker_id=?", role.id, tracker.id]).collect{ |w| w.new_status }.compact  if role && tracker
  new_statuses ? new_statuses.sort{|x, y| x.position <=> y.position } : []
end

#new_status_allowed_to?(status, role, tracker) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
56
57
# File 'app/models/issue_status.rb', line 53

def new_status_allowed_to?(status, role, tracker)
  status && role && tracker ?
    !workflows.find(:first, :conditions => {:new_status_id => status.id, :role_id => role.id, :tracker_id => tracker.id}).nil? :
    false
end

#new_statuses_allowed_to(role, tracker) ⇒ Object

Returns an array of all statuses the given role can switch to Uses association cache when called more than one time



39
40
41
42
# File 'app/models/issue_status.rb', line 39

def new_statuses_allowed_to(role, tracker)
  new_statuses = workflows.select {|w| w.role_id == role.id && w.tracker_id == tracker.id}.collect{|w| w.new_status} if role && tracker
  new_statuses ? new_statuses.compact.sort{|x, y| x.position <=> y.position } : []
end

#to_sObject



63
# File 'app/models/issue_status.rb', line 63

def to_s; name end