Revision 1297:0a574315af3e .svn/pristine/a4

View differences:

.svn/pristine/a4/a43f7091da21bbe393f7564458e580e780857e6d.svn-base
1
<%= form_tag({}, :id => "status_by_form") do -%>
2
<fieldset>
3
<legend>
4
<%= l(:label_issues_by,
5
       select_tag('status_by',
6
                   status_by_options_for_select(criteria),
7
                   :id => 'status_by_select',
8
                   :data => {:remote => true, :method => 'post', :url => status_by_version_path(version)})).html_safe %>
9
</legend>
10
<% if counts.empty? %>
11
    <p><em><%= l(:label_no_data) %></em></p>
12
<% else %>
13
    <table>
14
    <% counts.each do |count| %>
15
    <tr>
16
        <td width="130px" align="right" >
17
          <% if count[:group] -%>
18
            <%= link_to(h(count[:group]), project_issues_path(version.project, :set_filter => 1, :status_id => '*', :fixed_version_id => version, "#{criteria}_id" => count[:group])) %>
19
          <% else -%>
20
            <%= link_to(l(:label_none), project_issues_path(version.project, :set_filter => 1, :status_id => '*', :fixed_version_id => version, "#{criteria}_id" => "!*")) %>
21
          <% end %>
22
        </td>
23
        <td width="240px">
24
            <%= progress_bar((count[:closed].to_f / count[:total])*100,
25
                  :legend => "#{count[:closed]}/#{count[:total]}",
26
                  :width => "#{(count[:total].to_f / max * 200).floor}px;") %>
27
        </td>
28
    </tr>
29
    <% end %>
30
    </table>
31
<% end %>
32
</fieldset>
33
<% end %>
.svn/pristine/a4/a4c45a7af3a5e670c765d740cec096dac5d5314d.svn-base
1
# Redmine - project management software
2
# Copyright (C) 2006-2012  Jean-Philippe Lang
3
#
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU General Public License
6
# as published by the Free Software Foundation; either version 2
7
# of the License, or (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17

  
18
class IssueStatus < ActiveRecord::Base
19
  before_destroy :check_integrity
20
  has_many :workflows, :class_name => 'WorkflowTransition', :foreign_key => "old_status_id"
21
  acts_as_list
22

  
23
  before_destroy :delete_workflow_rules
24
  after_save     :update_default
25

  
26
  validates_presence_of :name
27
  validates_uniqueness_of :name
28
  validates_length_of :name, :maximum => 30
29
  validates_inclusion_of :default_done_ratio, :in => 0..100, :allow_nil => true
30

  
31
  scope :sorted, order("#{table_name}.position ASC")
32
  scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)}
33

  
34
  def update_default
35
    IssueStatus.update_all({:is_default => false}, ['id <> ?', id]) if self.is_default?
36
  end
37

  
38
  # Returns the default status for new issues
39
  def self.default
40
    where(:is_default => true).first
41
  end
42

  
43
  # Update all the +Issues+ setting their done_ratio to the value of their +IssueStatus+
44
  def self.update_issue_done_ratios
45
    if Issue.use_status_for_done_ratio?
46
      IssueStatus.where("default_done_ratio >= 0").all.each do |status|
47
        Issue.update_all({:done_ratio => status.default_done_ratio}, {:status_id => status.id})
48
      end
49
    end
50

  
51
    return Issue.use_status_for_done_ratio?
52
  end
53

  
54
  # Returns an array of all statuses the given role can switch to
55
  # Uses association cache when called more than one time
56
  def new_statuses_allowed_to(roles, tracker, author=false, assignee=false)
57
    if roles && tracker
58
      role_ids = roles.collect(&:id)
59
      transitions = workflows.select do |w|
60
        role_ids.include?(w.role_id) &&
61
        w.tracker_id == tracker.id &&
62
        ((!w.author && !w.assignee) || (author && w.author) || (assignee && w.assignee))
63
      end
64
      transitions.map(&:new_status).compact.sort
65
    else
66
      []
67
    end
68
  end
69

  
70
  # Same thing as above but uses a database query
71
  # More efficient than the previous method if called just once
72
  def find_new_statuses_allowed_to(roles, tracker, author=false, assignee=false)
73
    if roles.present? && tracker
74
      conditions = "(author = :false AND assignee = :false)"
75
      conditions << " OR author = :true" if author
76
      conditions << " OR assignee = :true" if assignee
77

  
78
      workflows.
79
        includes(:new_status).
80
        where(["role_id IN (:role_ids) AND tracker_id = :tracker_id AND (#{conditions})",
81
          {:role_ids => roles.collect(&:id), :tracker_id => tracker.id, :true => true, :false => false}
82
          ]).all.
83
        map(&:new_status).compact.sort
84
    else
85
      []
86
    end
87
  end
88

  
89
  def <=>(status)
90
    position <=> status.position
91
  end
92

  
93
  def to_s; name end
94

  
95
  private
96

  
97
  def check_integrity
98
    raise "Can't delete status" if Issue.where(:status_id => id).any?
99
  end
100

  
101
  # Deletes associated workflows
102
  def delete_workflow_rules
103
    WorkflowRule.delete_all(["old_status_id = :id OR new_status_id = :id", {:id => id}])
104
  end
105
end

Also available in: Unified diff