##// END OF EJS Templates
Moved Date months/weeks calculations used in Graph to lib....
Etienne Massip -
r8420:59789c799761
parent child
Show More
@@ -0,0 +1,5
1 require File.dirname(__FILE__) + '/date/calculations'
2
3 class Date #:nodoc:
4 include Redmine::CoreExtensions::Date::Calculations
5 end
@@ -0,0 +1,35
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 module Redmine #:nodoc:
19 module CoreExtensions #:nodoc:
20 module Date #:nodoc:
21 # Custom date calculations
22 module Calculations
23 # Returns difference with specified date in months
24 def months_ago(date = self.class.today)
25 (date.year - self.year)*12 + (date.month - self.month)
26 end
27
28 # Returns difference with specified date in weeks
29 def weeks_ago(date = self.class.today)
30 (date.year - self.year)*52 + (date.cweek - self.cweek)
31 end
32 end
33 end
34 end
35 end
@@ -1,377 +1,368
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
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
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.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require 'SVG/Graph/Bar'
18 require 'SVG/Graph/Bar'
19 require 'SVG/Graph/BarHorizontal'
19 require 'SVG/Graph/BarHorizontal'
20 require 'digest/sha1'
20 require 'digest/sha1'
21
21
22 class ChangesetNotFound < Exception; end
22 class ChangesetNotFound < Exception; end
23 class InvalidRevisionParam < Exception; end
23 class InvalidRevisionParam < Exception; end
24
24
25 class RepositoriesController < ApplicationController
25 class RepositoriesController < ApplicationController
26 menu_item :repository
26 menu_item :repository
27 menu_item :settings, :only => :edit
27 menu_item :settings, :only => :edit
28 default_search_scope :changesets
28 default_search_scope :changesets
29
29
30 before_filter :find_repository, :except => :edit
30 before_filter :find_repository, :except => :edit
31 before_filter :find_project, :only => :edit
31 before_filter :find_project, :only => :edit
32 before_filter :authorize
32 before_filter :authorize
33 accept_rss_auth :revisions
33 accept_rss_auth :revisions
34
34
35 rescue_from Redmine::Scm::Adapters::CommandFailed, :with => :show_error_command_failed
35 rescue_from Redmine::Scm::Adapters::CommandFailed, :with => :show_error_command_failed
36
36
37 def edit
37 def edit
38 @repository = @project.repository
38 @repository = @project.repository
39 if !@repository && !params[:repository_scm].blank?
39 if !@repository && !params[:repository_scm].blank?
40 @repository = Repository.factory(params[:repository_scm])
40 @repository = Repository.factory(params[:repository_scm])
41 @repository.project = @project if @repository
41 @repository.project = @project if @repository
42 end
42 end
43 if request.post? && @repository
43 if request.post? && @repository
44 p1 = params[:repository]
44 p1 = params[:repository]
45 p = {}
45 p = {}
46 p_extra = {}
46 p_extra = {}
47 p1.each do |k, v|
47 p1.each do |k, v|
48 if k =~ /^extra_/
48 if k =~ /^extra_/
49 p_extra[k] = v
49 p_extra[k] = v
50 else
50 else
51 p[k] = v
51 p[k] = v
52 end
52 end
53 end
53 end
54 @repository.attributes = p
54 @repository.attributes = p
55 @repository.merge_extra_info(p_extra)
55 @repository.merge_extra_info(p_extra)
56 @repository.save
56 @repository.save
57 end
57 end
58 render(:update) do |page|
58 render(:update) do |page|
59 page.replace_html "tab-content-repository",
59 page.replace_html "tab-content-repository",
60 :partial => 'projects/settings/repository'
60 :partial => 'projects/settings/repository'
61 if @repository && !@project.repository
61 if @repository && !@project.repository
62 @project.reload # needed to reload association
62 @project.reload # needed to reload association
63 page.replace_html "main-menu", render_main_menu(@project)
63 page.replace_html "main-menu", render_main_menu(@project)
64 end
64 end
65 end
65 end
66 end
66 end
67
67
68 def committers
68 def committers
69 @committers = @repository.committers
69 @committers = @repository.committers
70 @users = @project.users
70 @users = @project.users
71 additional_user_ids = @committers.collect(&:last).collect(&:to_i) - @users.collect(&:id)
71 additional_user_ids = @committers.collect(&:last).collect(&:to_i) - @users.collect(&:id)
72 @users += User.find_all_by_id(additional_user_ids) unless additional_user_ids.empty?
72 @users += User.find_all_by_id(additional_user_ids) unless additional_user_ids.empty?
73 @users.compact!
73 @users.compact!
74 @users.sort!
74 @users.sort!
75 if request.post? && params[:committers].is_a?(Hash)
75 if request.post? && params[:committers].is_a?(Hash)
76 # Build a hash with repository usernames as keys and corresponding user ids as values
76 # Build a hash with repository usernames as keys and corresponding user ids as values
77 @repository.committer_ids = params[:committers].values.inject({}) {|h, c| h[c.first] = c.last; h}
77 @repository.committer_ids = params[:committers].values.inject({}) {|h, c| h[c.first] = c.last; h}
78 flash[:notice] = l(:notice_successful_update)
78 flash[:notice] = l(:notice_successful_update)
79 redirect_to :action => 'committers', :id => @project
79 redirect_to :action => 'committers', :id => @project
80 end
80 end
81 end
81 end
82
82
83 def destroy
83 def destroy
84 @repository.destroy
84 @repository.destroy
85 redirect_to :controller => 'projects',
85 redirect_to :controller => 'projects',
86 :action => 'settings',
86 :action => 'settings',
87 :id => @project,
87 :id => @project,
88 :tab => 'repository'
88 :tab => 'repository'
89 end
89 end
90
90
91 def show
91 def show
92 @repository.fetch_changesets if Setting.autofetch_changesets? && @path.empty?
92 @repository.fetch_changesets if Setting.autofetch_changesets? && @path.empty?
93
93
94 @entries = @repository.entries(@path, @rev)
94 @entries = @repository.entries(@path, @rev)
95 @changeset = @repository.find_changeset_by_name(@rev)
95 @changeset = @repository.find_changeset_by_name(@rev)
96 if request.xhr?
96 if request.xhr?
97 @entries ? render(:partial => 'dir_list_content') : render(:nothing => true)
97 @entries ? render(:partial => 'dir_list_content') : render(:nothing => true)
98 else
98 else
99 (show_error_not_found; return) unless @entries
99 (show_error_not_found; return) unless @entries
100 @changesets = @repository.latest_changesets(@path, @rev)
100 @changesets = @repository.latest_changesets(@path, @rev)
101 @properties = @repository.properties(@path, @rev)
101 @properties = @repository.properties(@path, @rev)
102 render :action => 'show'
102 render :action => 'show'
103 end
103 end
104 end
104 end
105
105
106 alias_method :browse, :show
106 alias_method :browse, :show
107
107
108 def changes
108 def changes
109 @entry = @repository.entry(@path, @rev)
109 @entry = @repository.entry(@path, @rev)
110 (show_error_not_found; return) unless @entry
110 (show_error_not_found; return) unless @entry
111 @changesets = @repository.latest_changesets(@path, @rev, Setting.repository_log_display_limit.to_i)
111 @changesets = @repository.latest_changesets(@path, @rev, Setting.repository_log_display_limit.to_i)
112 @properties = @repository.properties(@path, @rev)
112 @properties = @repository.properties(@path, @rev)
113 @changeset = @repository.find_changeset_by_name(@rev)
113 @changeset = @repository.find_changeset_by_name(@rev)
114 end
114 end
115
115
116 def revisions
116 def revisions
117 @changeset_count = @repository.changesets.count
117 @changeset_count = @repository.changesets.count
118 @changeset_pages = Paginator.new self, @changeset_count,
118 @changeset_pages = Paginator.new self, @changeset_count,
119 per_page_option,
119 per_page_option,
120 params['page']
120 params['page']
121 @changesets = @repository.changesets.find(:all,
121 @changesets = @repository.changesets.find(:all,
122 :limit => @changeset_pages.items_per_page,
122 :limit => @changeset_pages.items_per_page,
123 :offset => @changeset_pages.current.offset,
123 :offset => @changeset_pages.current.offset,
124 :include => [:user, :repository, :parents])
124 :include => [:user, :repository, :parents])
125
125
126 respond_to do |format|
126 respond_to do |format|
127 format.html { render :layout => false if request.xhr? }
127 format.html { render :layout => false if request.xhr? }
128 format.atom { render_feed(@changesets, :title => "#{@project.name}: #{l(:label_revision_plural)}") }
128 format.atom { render_feed(@changesets, :title => "#{@project.name}: #{l(:label_revision_plural)}") }
129 end
129 end
130 end
130 end
131
131
132 def entry
132 def entry
133 @entry = @repository.entry(@path, @rev)
133 @entry = @repository.entry(@path, @rev)
134 (show_error_not_found; return) unless @entry
134 (show_error_not_found; return) unless @entry
135
135
136 # If the entry is a dir, show the browser
136 # If the entry is a dir, show the browser
137 (show; return) if @entry.is_dir?
137 (show; return) if @entry.is_dir?
138
138
139 @content = @repository.cat(@path, @rev)
139 @content = @repository.cat(@path, @rev)
140 (show_error_not_found; return) unless @content
140 (show_error_not_found; return) unless @content
141 if 'raw' == params[:format] ||
141 if 'raw' == params[:format] ||
142 (@content.size && @content.size > Setting.file_max_size_displayed.to_i.kilobyte) ||
142 (@content.size && @content.size > Setting.file_max_size_displayed.to_i.kilobyte) ||
143 ! is_entry_text_data?(@content, @path)
143 ! is_entry_text_data?(@content, @path)
144 # Force the download
144 # Force the download
145 send_opt = { :filename => filename_for_content_disposition(@path.split('/').last) }
145 send_opt = { :filename => filename_for_content_disposition(@path.split('/').last) }
146 send_type = Redmine::MimeType.of(@path)
146 send_type = Redmine::MimeType.of(@path)
147 send_opt[:type] = send_type.to_s if send_type
147 send_opt[:type] = send_type.to_s if send_type
148 send_data @content, send_opt
148 send_data @content, send_opt
149 else
149 else
150 # Prevent empty lines when displaying a file with Windows style eol
150 # Prevent empty lines when displaying a file with Windows style eol
151 # TODO: UTF-16
151 # TODO: UTF-16
152 # Is this needs? AttachmentsController reads file simply.
152 # Is this needs? AttachmentsController reads file simply.
153 @content.gsub!("\r\n", "\n")
153 @content.gsub!("\r\n", "\n")
154 @changeset = @repository.find_changeset_by_name(@rev)
154 @changeset = @repository.find_changeset_by_name(@rev)
155 end
155 end
156 end
156 end
157
157
158 def is_entry_text_data?(ent, path)
158 def is_entry_text_data?(ent, path)
159 # UTF-16 contains "\x00".
159 # UTF-16 contains "\x00".
160 # It is very strict that file contains less than 30% of ascii symbols
160 # It is very strict that file contains less than 30% of ascii symbols
161 # in non Western Europe.
161 # in non Western Europe.
162 return true if Redmine::MimeType.is_type?('text', path)
162 return true if Redmine::MimeType.is_type?('text', path)
163 # Ruby 1.8.6 has a bug of integer divisions.
163 # Ruby 1.8.6 has a bug of integer divisions.
164 # http://apidock.com/ruby/v1_8_6_287/String/is_binary_data%3F
164 # http://apidock.com/ruby/v1_8_6_287/String/is_binary_data%3F
165 return false if ent.is_binary_data?
165 return false if ent.is_binary_data?
166 true
166 true
167 end
167 end
168 private :is_entry_text_data?
168 private :is_entry_text_data?
169
169
170 def annotate
170 def annotate
171 @entry = @repository.entry(@path, @rev)
171 @entry = @repository.entry(@path, @rev)
172 (show_error_not_found; return) unless @entry
172 (show_error_not_found; return) unless @entry
173
173
174 @annotate = @repository.scm.annotate(@path, @rev)
174 @annotate = @repository.scm.annotate(@path, @rev)
175 if @annotate.nil? || @annotate.empty?
175 if @annotate.nil? || @annotate.empty?
176 (render_error l(:error_scm_annotate); return)
176 (render_error l(:error_scm_annotate); return)
177 end
177 end
178 ann_buf_size = 0
178 ann_buf_size = 0
179 @annotate.lines.each do |buf|
179 @annotate.lines.each do |buf|
180 ann_buf_size += buf.size
180 ann_buf_size += buf.size
181 end
181 end
182 if ann_buf_size > Setting.file_max_size_displayed.to_i.kilobyte
182 if ann_buf_size > Setting.file_max_size_displayed.to_i.kilobyte
183 (render_error l(:error_scm_annotate_big_text_file); return)
183 (render_error l(:error_scm_annotate_big_text_file); return)
184 end
184 end
185 @changeset = @repository.find_changeset_by_name(@rev)
185 @changeset = @repository.find_changeset_by_name(@rev)
186 end
186 end
187
187
188 def revision
188 def revision
189 raise ChangesetNotFound if @rev.blank?
189 raise ChangesetNotFound if @rev.blank?
190 @changeset = @repository.find_changeset_by_name(@rev)
190 @changeset = @repository.find_changeset_by_name(@rev)
191 raise ChangesetNotFound unless @changeset
191 raise ChangesetNotFound unless @changeset
192
192
193 respond_to do |format|
193 respond_to do |format|
194 format.html
194 format.html
195 format.js {render :layout => false}
195 format.js {render :layout => false}
196 end
196 end
197 rescue ChangesetNotFound
197 rescue ChangesetNotFound
198 show_error_not_found
198 show_error_not_found
199 end
199 end
200
200
201 def diff
201 def diff
202 if params[:format] == 'diff'
202 if params[:format] == 'diff'
203 @diff = @repository.diff(@path, @rev, @rev_to)
203 @diff = @repository.diff(@path, @rev, @rev_to)
204 (show_error_not_found; return) unless @diff
204 (show_error_not_found; return) unless @diff
205 filename = "changeset_r#{@rev}"
205 filename = "changeset_r#{@rev}"
206 filename << "_r#{@rev_to}" if @rev_to
206 filename << "_r#{@rev_to}" if @rev_to
207 send_data @diff.join, :filename => "#{filename}.diff",
207 send_data @diff.join, :filename => "#{filename}.diff",
208 :type => 'text/x-patch',
208 :type => 'text/x-patch',
209 :disposition => 'attachment'
209 :disposition => 'attachment'
210 else
210 else
211 @diff_type = params[:type] || User.current.pref[:diff_type] || 'inline'
211 @diff_type = params[:type] || User.current.pref[:diff_type] || 'inline'
212 @diff_type = 'inline' unless %w(inline sbs).include?(@diff_type)
212 @diff_type = 'inline' unless %w(inline sbs).include?(@diff_type)
213
213
214 # Save diff type as user preference
214 # Save diff type as user preference
215 if User.current.logged? && @diff_type != User.current.pref[:diff_type]
215 if User.current.logged? && @diff_type != User.current.pref[:diff_type]
216 User.current.pref[:diff_type] = @diff_type
216 User.current.pref[:diff_type] = @diff_type
217 User.current.preference.save
217 User.current.preference.save
218 end
218 end
219 @cache_key = "repositories/diff/#{@repository.id}/" +
219 @cache_key = "repositories/diff/#{@repository.id}/" +
220 Digest::MD5.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}-#{current_language}")
220 Digest::MD5.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}-#{current_language}")
221 unless read_fragment(@cache_key)
221 unless read_fragment(@cache_key)
222 @diff = @repository.diff(@path, @rev, @rev_to)
222 @diff = @repository.diff(@path, @rev, @rev_to)
223 show_error_not_found unless @diff
223 show_error_not_found unless @diff
224 end
224 end
225
225
226 @changeset = @repository.find_changeset_by_name(@rev)
226 @changeset = @repository.find_changeset_by_name(@rev)
227 @changeset_to = @rev_to ? @repository.find_changeset_by_name(@rev_to) : nil
227 @changeset_to = @rev_to ? @repository.find_changeset_by_name(@rev_to) : nil
228 @diff_format_revisions = @repository.diff_format_revisions(@changeset, @changeset_to)
228 @diff_format_revisions = @repository.diff_format_revisions(@changeset, @changeset_to)
229 end
229 end
230 end
230 end
231
231
232 def stats
232 def stats
233 end
233 end
234
234
235 def graph
235 def graph
236 data = nil
236 data = nil
237 case params[:graph]
237 case params[:graph]
238 when "commits_per_month"
238 when "commits_per_month"
239 data = graph_commits_per_month(@repository)
239 data = graph_commits_per_month(@repository)
240 when "commits_per_author"
240 when "commits_per_author"
241 data = graph_commits_per_author(@repository)
241 data = graph_commits_per_author(@repository)
242 end
242 end
243 if data
243 if data
244 headers["Content-Type"] = "image/svg+xml"
244 headers["Content-Type"] = "image/svg+xml"
245 send_data(data, :type => "image/svg+xml", :disposition => "inline")
245 send_data(data, :type => "image/svg+xml", :disposition => "inline")
246 else
246 else
247 render_404
247 render_404
248 end
248 end
249 end
249 end
250
250
251 private
251 private
252
252
253 REV_PARAM_RE = %r{\A[a-f0-9]*\Z}i
253 REV_PARAM_RE = %r{\A[a-f0-9]*\Z}i
254
254
255 def find_repository
255 def find_repository
256 @project = Project.find(params[:id])
256 @project = Project.find(params[:id])
257 @repository = @project.repository
257 @repository = @project.repository
258 (render_404; return false) unless @repository
258 (render_404; return false) unless @repository
259 @path = params[:path].join('/') unless params[:path].nil?
259 @path = params[:path].join('/') unless params[:path].nil?
260 @path ||= ''
260 @path ||= ''
261 @rev = params[:rev].blank? ? @repository.default_branch : params[:rev].to_s.strip
261 @rev = params[:rev].blank? ? @repository.default_branch : params[:rev].to_s.strip
262 @rev_to = params[:rev_to]
262 @rev_to = params[:rev_to]
263
263
264 unless @rev.to_s.match(REV_PARAM_RE) && @rev_to.to_s.match(REV_PARAM_RE)
264 unless @rev.to_s.match(REV_PARAM_RE) && @rev_to.to_s.match(REV_PARAM_RE)
265 if @repository.branches.blank?
265 if @repository.branches.blank?
266 raise InvalidRevisionParam
266 raise InvalidRevisionParam
267 end
267 end
268 end
268 end
269 rescue ActiveRecord::RecordNotFound
269 rescue ActiveRecord::RecordNotFound
270 render_404
270 render_404
271 rescue InvalidRevisionParam
271 rescue InvalidRevisionParam
272 show_error_not_found
272 show_error_not_found
273 end
273 end
274
274
275 def show_error_not_found
275 def show_error_not_found
276 render_error :message => l(:error_scm_not_found), :status => 404
276 render_error :message => l(:error_scm_not_found), :status => 404
277 end
277 end
278
278
279 # Handler for Redmine::Scm::Adapters::CommandFailed exception
279 # Handler for Redmine::Scm::Adapters::CommandFailed exception
280 def show_error_command_failed(exception)
280 def show_error_command_failed(exception)
281 render_error l(:error_scm_command_failed, exception.message)
281 render_error l(:error_scm_command_failed, exception.message)
282 end
282 end
283
283
284 def graph_commits_per_month(repository)
284 def graph_commits_per_month(repository)
285 @date_to = Date.today
285 @date_to = Date.today
286 @date_from = @date_to << 11
286 @date_from = @date_to << 11
287 @date_from = Date.civil(@date_from.year, @date_from.month, 1)
287 @date_from = Date.civil(@date_from.year, @date_from.month, 1)
288 commits_by_day = repository.changesets.count(
288 commits_by_day = repository.changesets.count(
289 :all, :group => :commit_date,
289 :all, :group => :commit_date,
290 :conditions => ["commit_date BETWEEN ? AND ?", @date_from, @date_to])
290 :conditions => ["commit_date BETWEEN ? AND ?", @date_from, @date_to])
291 commits_by_month = [0] * 12
291 commits_by_month = [0] * 12
292 commits_by_day.each {|c| commits_by_month[c.first.to_date.months_ago] += c.last }
292 commits_by_day.each {|c| commits_by_month[c.first.to_date.months_ago] += c.last }
293
293
294 changes_by_day = repository.changes.count(
294 changes_by_day = repository.changes.count(
295 :all, :group => :commit_date,
295 :all, :group => :commit_date,
296 :conditions => ["commit_date BETWEEN ? AND ?", @date_from, @date_to])
296 :conditions => ["commit_date BETWEEN ? AND ?", @date_from, @date_to])
297 changes_by_month = [0] * 12
297 changes_by_month = [0] * 12
298 changes_by_day.each {|c| changes_by_month[c.first.to_date.months_ago] += c.last }
298 changes_by_day.each {|c| changes_by_month[c.first.to_date.months_ago] += c.last }
299
299
300 fields = []
300 fields = []
301 12.times {|m| fields << month_name(((Date.today.month - 1 - m) % 12) + 1)}
301 12.times {|m| fields << month_name(((Date.today.month - 1 - m) % 12) + 1)}
302
302
303 graph = SVG::Graph::Bar.new(
303 graph = SVG::Graph::Bar.new(
304 :height => 300,
304 :height => 300,
305 :width => 800,
305 :width => 800,
306 :fields => fields.reverse,
306 :fields => fields.reverse,
307 :stack => :side,
307 :stack => :side,
308 :scale_integers => true,
308 :scale_integers => true,
309 :step_x_labels => 2,
309 :step_x_labels => 2,
310 :show_data_values => false,
310 :show_data_values => false,
311 :graph_title => l(:label_commits_per_month),
311 :graph_title => l(:label_commits_per_month),
312 :show_graph_title => true
312 :show_graph_title => true
313 )
313 )
314
314
315 graph.add_data(
315 graph.add_data(
316 :data => commits_by_month[0..11].reverse,
316 :data => commits_by_month[0..11].reverse,
317 :title => l(:label_revision_plural)
317 :title => l(:label_revision_plural)
318 )
318 )
319
319
320 graph.add_data(
320 graph.add_data(
321 :data => changes_by_month[0..11].reverse,
321 :data => changes_by_month[0..11].reverse,
322 :title => l(:label_change_plural)
322 :title => l(:label_change_plural)
323 )
323 )
324
324
325 graph.burn
325 graph.burn
326 end
326 end
327
327
328 def graph_commits_per_author(repository)
328 def graph_commits_per_author(repository)
329 commits_by_author = repository.changesets.count(:all, :group => :committer)
329 commits_by_author = repository.changesets.count(:all, :group => :committer)
330 commits_by_author.to_a.sort! {|x, y| x.last <=> y.last}
330 commits_by_author.to_a.sort! {|x, y| x.last <=> y.last}
331
331
332 changes_by_author = repository.changes.count(:all, :group => :committer)
332 changes_by_author = repository.changes.count(:all, :group => :committer)
333 h = changes_by_author.inject({}) {|o, i| o[i.first] = i.last; o}
333 h = changes_by_author.inject({}) {|o, i| o[i.first] = i.last; o}
334
334
335 fields = commits_by_author.collect {|r| r.first}
335 fields = commits_by_author.collect {|r| r.first}
336 commits_data = commits_by_author.collect {|r| r.last}
336 commits_data = commits_by_author.collect {|r| r.last}
337 changes_data = commits_by_author.collect {|r| h[r.first] || 0}
337 changes_data = commits_by_author.collect {|r| h[r.first] || 0}
338
338
339 fields = fields + [""]*(10 - fields.length) if fields.length<10
339 fields = fields + [""]*(10 - fields.length) if fields.length<10
340 commits_data = commits_data + [0]*(10 - commits_data.length) if commits_data.length<10
340 commits_data = commits_data + [0]*(10 - commits_data.length) if commits_data.length<10
341 changes_data = changes_data + [0]*(10 - changes_data.length) if changes_data.length<10
341 changes_data = changes_data + [0]*(10 - changes_data.length) if changes_data.length<10
342
342
343 # Remove email adress in usernames
343 # Remove email adress in usernames
344 fields = fields.collect {|c| c.gsub(%r{<.+@.+>}, '') }
344 fields = fields.collect {|c| c.gsub(%r{<.+@.+>}, '') }
345
345
346 graph = SVG::Graph::BarHorizontal.new(
346 graph = SVG::Graph::BarHorizontal.new(
347 :height => 400,
347 :height => 400,
348 :width => 800,
348 :width => 800,
349 :fields => fields,
349 :fields => fields,
350 :stack => :side,
350 :stack => :side,
351 :scale_integers => true,
351 :scale_integers => true,
352 :show_data_values => false,
352 :show_data_values => false,
353 :rotate_y_labels => false,
353 :rotate_y_labels => false,
354 :graph_title => l(:label_commits_per_author),
354 :graph_title => l(:label_commits_per_author),
355 :show_graph_title => true
355 :show_graph_title => true
356 )
356 )
357 graph.add_data(
357 graph.add_data(
358 :data => commits_data,
358 :data => commits_data,
359 :title => l(:label_revision_plural)
359 :title => l(:label_revision_plural)
360 )
360 )
361 graph.add_data(
361 graph.add_data(
362 :data => changes_data,
362 :data => changes_data,
363 :title => l(:label_change_plural)
363 :title => l(:label_change_plural)
364 )
364 )
365 graph.burn
365 graph.burn
366 end
366 end
367 end
367 end
368
368
369 class Date
370 def months_ago(date = Date.today)
371 (date.year - self.year)*12 + (date.month - self.month)
372 end
373
374 def weeks_ago(date = Date.today)
375 (date.year - self.year)*52 + (date.cweek - self.cweek)
376 end
377 end
General Comments 0
You need to be logged in to leave comments. Login now