Project

General

Profile

Defect #1376 » info_controller.rb

Jonathan Tee, 04/20/2015 09:49 PM

 
1
require 'rails/info'
2

    
3
class InfoController < ApplicationController
4
  unloadable
5
  
6
  before_filter :require_login
7

    
8
  helper :info
9
  include InfoHelper
10
  helper :graphviz
11
  include GraphvizHelper
12

    
13
  def permissions
14
    @roles = Role.sorted.all
15
    @permissions = Redmine::AccessControl.permissions.select { |p| !p.public? }
16
  end
17

    
18

    
19
  def workflows
20
    wfclass = nil
21
    if Redmine::VERSION::MAJOR == 2 and Redmine::VERSION::MINOR < 1
22
      wfclass = Workflow
23
    else
24
      wfclass = WorkflowTransition
25
    end
26
    #@workflow_counts = wfclass.count_by_tracker_and_role
27
    #@workflow_all_ng_roles = find_all_ng_roles(@workflow_counts)
28

    
29
    #@roles = Role.find(:all, :order => 'builtin, position')
30
    @roles = Role.order(:builtin, :position)
31
    #@role = Role.find_by_id(params[:role_id])
32
    @role = Role.where(:id => params[:role_id]).first
33

    
34
    #@trackers = Tracker.find(:all, :order => 'position')
35
    @trackers = Tracker.order(:position)
36
    #@tracker = Tracker.find_by_id(params[:tracker_id]) 
37
    @tracker = Tracker.where(:id => params[:tracker_id]).first 
38

    
39
    @workflow_counts = count_by_tracker_and_role(@roles, @trackers)
40
    @workflow_all_ng_roles = find_all_ng_roles(@workflow_counts)  
41
    
42
    if @tracker && @tracker.issue_statuses.any?
43
      @statuses = @tracker.issue_statuses
44
    end
45
    #@statuses ||= IssueStatus.find(:all, :order => 'position')
46
    @statuses ||= IssueStatus.order(:position)
47

    
48
    if (@tracker && @role && @statuses.any?)
49
      #workflows = wfclass.all(:conditions => {:role_id => @role.id, :tracker_id => @tracker.id})
50
      workflows = wfclass.where(role_id: @role.id, tracker_id: @tracker.id)
51
      @workflows = {}
52
      @workflows['always'] = workflows.select {|w| !w.author && !w.assignee}
53
      @workflows['author'] = workflows.select {|w| w.author}
54
      @workflows['assignee'] = workflows.select {|w| w.assignee}
55
    end
56
      
57
  end
58

    
59

    
60
  def settings
61
    # Mail Notification
62
    @notifiables = []
63
    Redmine::Notifiable.all.each {|notifiable|
64
      if notifiable.parent.present?
65
        next	if (Setting.notified_events.include?(notifiable.parent))
66
      end
67
      @notifiables << notifiable
68
    }
69
    @deliveries = ActionMailer::Base.perform_deliveries
70

    
71
    # Repository
72
    #@commit_fix_status = IssueStatus.find_by_id(Setting[:commit_fix_status_id])
73
    @commit_fix_status = IssueStatus.where(:id => Setting.commit_update_keywords.first['status_id'])
74
    unless (@commit_fix_status)
75
      @commit_fix_status = l(:label_no_change_option)
76
    end
77
    @commit_fix_done_ratio = Setting[:commit_fix_done_ratio]
78
    if (!@commit_fix_done_ratio or @commit_fix_done_ratio.empty?)
79
      @commit_fix_done_ratio = l(:label_no_change_option)
80
    end
81

    
82
    @commit_logtime_enabled = Setting[:commit_logtime_enabled]
83
    if (@commit_logtime_enabled)
84
      @commit_logtime_enabled = (0 < @commit_logtime_enabled.to_i)
85
    end
86
    @commit_logtime_activity_name = l(:label_default)
87
    if (@commit_logtime_enabled)
88
      aid = Setting[:commit_logtime_activity_id]
89
      if (aid and 0 < aid.to_i)
90
        #activity = TimeEntryActivity.find_by_id(aid)
91
        activity = TimeEntryActivity.where(:id => aid)
92
        @commit_logtime_activity_name = activity.name	if (activity)
93
      end
94
    end
95

    
96
  end
97
  
98

    
99
  def plugins
100
    @plugins = Redmine::Plugin.all
101
  end
102

    
103

    
104
  def show
105
    @icat = params[:id]
106
    case @icat
107
    when 'permissions'; permissions;
108
    when 'workflows'; workflows;
109
    when 'settings'; settings;
110
    when 'plugins'; plugins;
111
    when 'version'
112
      @db_adapter_name = ActiveRecord::Base.connection.adapter_name 
113
    end
114
  end
115

    
116

    
117
  def index
118
  end
119

    
120
  
121
  private
122
  def find_all_ng_roles(workflow_counts)
123
    logger.info "workflow_counts: #{workflow_counts}"
124
    roles_map = {}
125
    workflow_counts.each do |tracker, roles|
126
      roles.each do |role, count|
127
        roles_map[role] = 0	unless roles_map[role]
128
        roles_map[role] += count
129
      end
130
    end
131
    all_ng_roles = []
132
    roles_map.each {|role, count|
133
      all_ng_roles << role	if (count == 0)
134
    }
135
    return all_ng_roles
136
  end
137

    
138

    
139
  private
140
  def count_by_tracker_and_role(roles, trackers)
141
    counts = WorkflowTransition.connection.select_all("SELECT role_id, tracker_id, count(id) AS c FROM #{WorkflowTransition.table_name} GROUP BY role_id, tracker_id")
142
	
143
    result = []
144
    trackers.each do |tracker|
145
      t = []
146
      roles.each do |role|
147
	row = counts.detect {|c| c['role_id'].to_s == role.id.to_s && c['tracker_id'].to_s == tracker.id.to_s}
148
	t << [role, (row.nil? ? 0 : row['c'].to_i)]
149
      end
150
      result << [tracker, t]
151
    end	
152
    return result
153
  end
154

    
155
end
    (1-1/1)