@@ -1,359 +1,358 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2009 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2009 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_key_auth :revisions |
|
33 | accept_key_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 |
|
39 | if !@repository | |
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 | @repository.attributes = params[:repository] |
|
44 | @repository.attributes = params[:repository] | |
45 | @repository.save |
|
45 | @repository.save | |
46 | end |
|
46 | end | |
47 | render(:update) do |page| |
|
47 | render(:update) do |page| | |
48 | page.replace_html "tab-content-repository", :partial => 'projects/settings/repository' |
|
48 | page.replace_html "tab-content-repository", :partial => 'projects/settings/repository' | |
49 | if @repository && !@project.repository |
|
49 | if @repository && !@project.repository | |
50 | @project.reload #needed to reload association |
|
50 | @project.reload #needed to reload association | |
51 | page.replace_html "main-menu", render_main_menu(@project) |
|
51 | page.replace_html "main-menu", render_main_menu(@project) | |
52 | end |
|
52 | end | |
53 | end |
|
53 | end | |
54 | end |
|
54 | end | |
55 |
|
55 | |||
56 | def committers |
|
56 | def committers | |
57 | @committers = @repository.committers |
|
57 | @committers = @repository.committers | |
58 | @users = @project.users |
|
58 | @users = @project.users | |
59 | additional_user_ids = @committers.collect(&:last).collect(&:to_i) - @users.collect(&:id) |
|
59 | additional_user_ids = @committers.collect(&:last).collect(&:to_i) - @users.collect(&:id) | |
60 | @users += User.find_all_by_id(additional_user_ids) unless additional_user_ids.empty? |
|
60 | @users += User.find_all_by_id(additional_user_ids) unless additional_user_ids.empty? | |
61 | @users.compact! |
|
61 | @users.compact! | |
62 | @users.sort! |
|
62 | @users.sort! | |
63 | if request.post? && params[:committers].is_a?(Hash) |
|
63 | if request.post? && params[:committers].is_a?(Hash) | |
64 | # Build a hash with repository usernames as keys and corresponding user ids as values |
|
64 | # Build a hash with repository usernames as keys and corresponding user ids as values | |
65 | @repository.committer_ids = params[:committers].values.inject({}) {|h, c| h[c.first] = c.last; h} |
|
65 | @repository.committer_ids = params[:committers].values.inject({}) {|h, c| h[c.first] = c.last; h} | |
66 | flash[:notice] = l(:notice_successful_update) |
|
66 | flash[:notice] = l(:notice_successful_update) | |
67 | redirect_to :action => 'committers', :id => @project |
|
67 | redirect_to :action => 'committers', :id => @project | |
68 | end |
|
68 | end | |
69 | end |
|
69 | end | |
70 |
|
70 | |||
71 | def destroy |
|
71 | def destroy | |
72 | @repository.destroy |
|
72 | @repository.destroy | |
73 | redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'repository' |
|
73 | redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'repository' | |
74 | end |
|
74 | end | |
75 |
|
75 | |||
76 | def show |
|
76 | def show | |
77 | @repository.fetch_changesets if Setting.autofetch_changesets? && @path.empty? |
|
77 | @repository.fetch_changesets if Setting.autofetch_changesets? && @path.empty? | |
78 |
|
78 | |||
79 | @entries = @repository.entries(@path, @rev) |
|
79 | @entries = @repository.entries(@path, @rev) | |
80 | @changeset = @repository.find_changeset_by_name(@rev) |
|
80 | @changeset = @repository.find_changeset_by_name(@rev) | |
81 | if request.xhr? |
|
81 | if request.xhr? | |
82 | @entries ? render(:partial => 'dir_list_content') : render(:nothing => true) |
|
82 | @entries ? render(:partial => 'dir_list_content') : render(:nothing => true) | |
83 | else |
|
83 | else | |
84 | (show_error_not_found; return) unless @entries |
|
84 | (show_error_not_found; return) unless @entries | |
85 | @changesets = @repository.latest_changesets(@path, @rev) |
|
85 | @changesets = @repository.latest_changesets(@path, @rev) | |
86 | @properties = @repository.properties(@path, @rev) |
|
86 | @properties = @repository.properties(@path, @rev) | |
87 | render :action => 'show' |
|
87 | render :action => 'show' | |
88 | end |
|
88 | end | |
89 | end |
|
89 | end | |
90 |
|
90 | |||
91 | alias_method :browse, :show |
|
91 | alias_method :browse, :show | |
92 |
|
92 | |||
93 | def changes |
|
93 | def changes | |
94 | @entry = @repository.entry(@path, @rev) |
|
94 | @entry = @repository.entry(@path, @rev) | |
95 | (show_error_not_found; return) unless @entry |
|
95 | (show_error_not_found; return) unless @entry | |
96 | @changesets = @repository.latest_changesets(@path, @rev, Setting.repository_log_display_limit.to_i) |
|
96 | @changesets = @repository.latest_changesets(@path, @rev, Setting.repository_log_display_limit.to_i) | |
97 | @properties = @repository.properties(@path, @rev) |
|
97 | @properties = @repository.properties(@path, @rev) | |
98 | @changeset = @repository.find_changeset_by_name(@rev) |
|
98 | @changeset = @repository.find_changeset_by_name(@rev) | |
99 | end |
|
99 | end | |
100 |
|
100 | |||
101 | def revisions |
|
101 | def revisions | |
102 | @changeset_count = @repository.changesets.count |
|
102 | @changeset_count = @repository.changesets.count | |
103 | @changeset_pages = Paginator.new self, @changeset_count, |
|
103 | @changeset_pages = Paginator.new self, @changeset_count, | |
104 | per_page_option, |
|
104 | per_page_option, | |
105 | params['page'] |
|
105 | params['page'] | |
106 | @changesets = @repository.changesets.find(:all, |
|
106 | @changesets = @repository.changesets.find(:all, | |
107 | :limit => @changeset_pages.items_per_page, |
|
107 | :limit => @changeset_pages.items_per_page, | |
108 | :offset => @changeset_pages.current.offset, |
|
108 | :offset => @changeset_pages.current.offset, | |
109 | :include => [:user, :repository]) |
|
109 | :include => [:user, :repository]) | |
110 |
|
110 | |||
111 | respond_to do |format| |
|
111 | respond_to do |format| | |
112 | format.html { render :layout => false if request.xhr? } |
|
112 | format.html { render :layout => false if request.xhr? } | |
113 | format.atom { render_feed(@changesets, :title => "#{@project.name}: #{l(:label_revision_plural)}") } |
|
113 | format.atom { render_feed(@changesets, :title => "#{@project.name}: #{l(:label_revision_plural)}") } | |
114 | end |
|
114 | end | |
115 | end |
|
115 | end | |
116 |
|
116 | |||
117 | def entry |
|
117 | def entry | |
118 | @entry = @repository.entry(@path, @rev) |
|
118 | @entry = @repository.entry(@path, @rev) | |
119 | (show_error_not_found; return) unless @entry |
|
119 | (show_error_not_found; return) unless @entry | |
120 |
|
120 | |||
121 | # If the entry is a dir, show the browser |
|
121 | # If the entry is a dir, show the browser | |
122 | (show; return) if @entry.is_dir? |
|
122 | (show; return) if @entry.is_dir? | |
123 |
|
123 | |||
124 | @content = @repository.cat(@path, @rev) |
|
124 | @content = @repository.cat(@path, @rev) | |
125 | (show_error_not_found; return) unless @content |
|
125 | (show_error_not_found; return) unless @content | |
126 | if 'raw' == params[:format] || |
|
126 | if 'raw' == params[:format] || | |
127 | (@content.size && @content.size > Setting.file_max_size_displayed.to_i.kilobyte) || |
|
127 | (@content.size && @content.size > Setting.file_max_size_displayed.to_i.kilobyte) || | |
128 | ! is_entry_text_data?(@content, @path) |
|
128 | ! is_entry_text_data?(@content, @path) | |
129 | # Force the download |
|
129 | # Force the download | |
130 | send_opt = { :filename => filename_for_content_disposition(@path.split('/').last) } |
|
130 | send_opt = { :filename => filename_for_content_disposition(@path.split('/').last) } | |
131 | send_type = Redmine::MimeType.of(@path) |
|
131 | send_type = Redmine::MimeType.of(@path) | |
132 | send_opt[:type] = send_type.to_s if send_type |
|
132 | send_opt[:type] = send_type.to_s if send_type | |
133 | send_data @content, send_opt |
|
133 | send_data @content, send_opt | |
134 | else |
|
134 | else | |
135 | # Prevent empty lines when displaying a file with Windows style eol |
|
135 | # Prevent empty lines when displaying a file with Windows style eol | |
136 | # TODO: UTF-16 |
|
136 | # TODO: UTF-16 | |
137 | # Is this needs? AttachmentsController reads file simply. |
|
137 | # Is this needs? AttachmentsController reads file simply. | |
138 | @content.gsub!("\r\n", "\n") |
|
138 | @content.gsub!("\r\n", "\n") | |
139 | @changeset = @repository.find_changeset_by_name(@rev) |
|
139 | @changeset = @repository.find_changeset_by_name(@rev) | |
140 | end |
|
140 | end | |
141 | end |
|
141 | end | |
142 |
|
142 | |||
143 | def is_entry_text_data?(ent, path) |
|
143 | def is_entry_text_data?(ent, path) | |
144 | # UTF-16 contains "\x00". |
|
144 | # UTF-16 contains "\x00". | |
145 | # It is very strict that file contains less than 30% of ascii symbols |
|
145 | # It is very strict that file contains less than 30% of ascii symbols | |
146 | # in non Western Europe. |
|
146 | # in non Western Europe. | |
147 | return true if Redmine::MimeType.is_type?('text', path) |
|
147 | return true if Redmine::MimeType.is_type?('text', path) | |
148 | # Ruby 1.8.6 has a bug of integer divisions. |
|
148 | # Ruby 1.8.6 has a bug of integer divisions. | |
149 | # http://apidock.com/ruby/v1_8_6_287/String/is_binary_data%3F |
|
149 | # http://apidock.com/ruby/v1_8_6_287/String/is_binary_data%3F | |
150 | return false if ent.is_binary_data? |
|
150 | return false if ent.is_binary_data? | |
151 | true |
|
151 | true | |
152 | end |
|
152 | end | |
153 | private :is_entry_text_data? |
|
153 | private :is_entry_text_data? | |
154 |
|
154 | |||
155 | def annotate |
|
155 | def annotate | |
156 | @entry = @repository.entry(@path, @rev) |
|
156 | @entry = @repository.entry(@path, @rev) | |
157 | (show_error_not_found; return) unless @entry |
|
157 | (show_error_not_found; return) unless @entry | |
158 |
|
158 | |||
159 | @annotate = @repository.scm.annotate(@path, @rev) |
|
159 | @annotate = @repository.scm.annotate(@path, @rev) | |
160 | (render_error l(:error_scm_annotate); return) if @annotate.nil? || @annotate.empty? |
|
160 | (render_error l(:error_scm_annotate); return) if @annotate.nil? || @annotate.empty? | |
161 | @changeset = @repository.find_changeset_by_name(@rev) |
|
161 | @changeset = @repository.find_changeset_by_name(@rev) | |
162 | end |
|
162 | end | |
163 |
|
163 | |||
164 | def revision |
|
164 | def revision | |
165 | raise ChangesetNotFound if @rev.blank? |
|
165 | raise ChangesetNotFound if @rev.blank? | |
166 | @changeset = @repository.find_changeset_by_name(@rev) |
|
166 | @changeset = @repository.find_changeset_by_name(@rev) | |
167 | raise ChangesetNotFound unless @changeset |
|
167 | raise ChangesetNotFound unless @changeset | |
168 |
|
168 | |||
169 | respond_to do |format| |
|
169 | respond_to do |format| | |
170 | format.html |
|
170 | format.html | |
171 | format.js {render :layout => false} |
|
171 | format.js {render :layout => false} | |
172 | end |
|
172 | end | |
173 | rescue ChangesetNotFound |
|
173 | rescue ChangesetNotFound | |
174 | show_error_not_found |
|
174 | show_error_not_found | |
175 | end |
|
175 | end | |
176 |
|
176 | |||
177 | def diff |
|
177 | def diff | |
178 | if params[:format] == 'diff' |
|
178 | if params[:format] == 'diff' | |
179 | @diff = @repository.diff(@path, @rev, @rev_to) |
|
179 | @diff = @repository.diff(@path, @rev, @rev_to) | |
180 | (show_error_not_found; return) unless @diff |
|
180 | (show_error_not_found; return) unless @diff | |
181 | filename = "changeset_r#{@rev}" |
|
181 | filename = "changeset_r#{@rev}" | |
182 | filename << "_r#{@rev_to}" if @rev_to |
|
182 | filename << "_r#{@rev_to}" if @rev_to | |
183 | send_data @diff.join, :filename => "#{filename}.diff", |
|
183 | send_data @diff.join, :filename => "#{filename}.diff", | |
184 | :type => 'text/x-patch', |
|
184 | :type => 'text/x-patch', | |
185 | :disposition => 'attachment' |
|
185 | :disposition => 'attachment' | |
186 | else |
|
186 | else | |
187 | @diff_type = params[:type] || User.current.pref[:diff_type] || 'inline' |
|
187 | @diff_type = params[:type] || User.current.pref[:diff_type] || 'inline' | |
188 | @diff_type = 'inline' unless %w(inline sbs).include?(@diff_type) |
|
188 | @diff_type = 'inline' unless %w(inline sbs).include?(@diff_type) | |
189 |
|
189 | |||
190 | # Save diff type as user preference |
|
190 | # Save diff type as user preference | |
191 | if User.current.logged? && @diff_type != User.current.pref[:diff_type] |
|
191 | if User.current.logged? && @diff_type != User.current.pref[:diff_type] | |
192 | User.current.pref[:diff_type] = @diff_type |
|
192 | User.current.pref[:diff_type] = @diff_type | |
193 | User.current.preference.save |
|
193 | User.current.preference.save | |
194 | end |
|
194 | end | |
195 |
|
195 | @cache_key = "repositories/diff/#{@repository.id}/" + Digest::MD5.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}") | ||
196 | @cache_key = "repositories/diff/#{@repository.id}/" + Digest::MD5.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}") |
|
|||
197 | unless read_fragment(@cache_key) |
|
196 | unless read_fragment(@cache_key) | |
198 | @diff = @repository.diff(@path, @rev, @rev_to) |
|
197 | @diff = @repository.diff(@path, @rev, @rev_to) | |
199 | show_error_not_found unless @diff |
|
198 | show_error_not_found unless @diff | |
200 | end |
|
199 | end | |
201 |
|
200 | |||
202 | @changeset = @repository.find_changeset_by_name(@rev) |
|
201 | @changeset = @repository.find_changeset_by_name(@rev) | |
203 | @changeset_to = @rev_to ? @repository.find_changeset_by_name(@rev_to) : nil |
|
202 | @changeset_to = @rev_to ? @repository.find_changeset_by_name(@rev_to) : nil | |
204 | @diff_format_revisions = @repository.diff_format_revisions(@changeset, @changeset_to) |
|
203 | @diff_format_revisions = @repository.diff_format_revisions(@changeset, @changeset_to) | |
205 | end |
|
204 | end | |
206 | end |
|
205 | end | |
207 |
|
206 | |||
208 | def stats |
|
207 | def stats | |
209 | end |
|
208 | end | |
210 |
|
209 | |||
211 | def graph |
|
210 | def graph | |
212 | data = nil |
|
211 | data = nil | |
213 | case params[:graph] |
|
212 | case params[:graph] | |
214 | when "commits_per_month" |
|
213 | when "commits_per_month" | |
215 | data = graph_commits_per_month(@repository) |
|
214 | data = graph_commits_per_month(@repository) | |
216 | when "commits_per_author" |
|
215 | when "commits_per_author" | |
217 | data = graph_commits_per_author(@repository) |
|
216 | data = graph_commits_per_author(@repository) | |
218 | end |
|
217 | end | |
219 | if data |
|
218 | if data | |
220 | headers["Content-Type"] = "image/svg+xml" |
|
219 | headers["Content-Type"] = "image/svg+xml" | |
221 | send_data(data, :type => "image/svg+xml", :disposition => "inline") |
|
220 | send_data(data, :type => "image/svg+xml", :disposition => "inline") | |
222 | else |
|
221 | else | |
223 | render_404 |
|
222 | render_404 | |
224 | end |
|
223 | end | |
225 | end |
|
224 | end | |
226 |
|
225 | |||
227 | private |
|
226 | private | |
228 |
|
227 | |||
229 | REV_PARAM_RE = %r{\A[a-f0-9]*\Z}i |
|
228 | REV_PARAM_RE = %r{\A[a-f0-9]*\Z}i | |
230 |
|
229 | |||
231 | def find_repository |
|
230 | def find_repository | |
232 | @project = Project.find(params[:id]) |
|
231 | @project = Project.find(params[:id]) | |
233 | @repository = @project.repository |
|
232 | @repository = @project.repository | |
234 | (render_404; return false) unless @repository |
|
233 | (render_404; return false) unless @repository | |
235 | @path = params[:path].join('/') unless params[:path].nil? |
|
234 | @path = params[:path].join('/') unless params[:path].nil? | |
236 | @path ||= '' |
|
235 | @path ||= '' | |
237 | @rev = params[:rev].blank? ? @repository.default_branch : params[:rev].strip |
|
236 | @rev = params[:rev].blank? ? @repository.default_branch : params[:rev].strip | |
238 | @rev_to = params[:rev_to] |
|
237 | @rev_to = params[:rev_to] | |
239 |
|
238 | |||
240 | unless @rev.to_s.match(REV_PARAM_RE) && @rev_to.to_s.match(REV_PARAM_RE) |
|
239 | unless @rev.to_s.match(REV_PARAM_RE) && @rev_to.to_s.match(REV_PARAM_RE) | |
241 | if @repository.branches.blank? |
|
240 | if @repository.branches.blank? | |
242 | raise InvalidRevisionParam |
|
241 | raise InvalidRevisionParam | |
243 | end |
|
242 | end | |
244 | end |
|
243 | end | |
245 | rescue ActiveRecord::RecordNotFound |
|
244 | rescue ActiveRecord::RecordNotFound | |
246 | render_404 |
|
245 | render_404 | |
247 | rescue InvalidRevisionParam |
|
246 | rescue InvalidRevisionParam | |
248 | show_error_not_found |
|
247 | show_error_not_found | |
249 | end |
|
248 | end | |
250 |
|
249 | |||
251 | def show_error_not_found |
|
250 | def show_error_not_found | |
252 | render_error :message => l(:error_scm_not_found), :status => 404 |
|
251 | render_error :message => l(:error_scm_not_found), :status => 404 | |
253 | end |
|
252 | end | |
254 |
|
253 | |||
255 | # Handler for Redmine::Scm::Adapters::CommandFailed exception |
|
254 | # Handler for Redmine::Scm::Adapters::CommandFailed exception | |
256 | def show_error_command_failed(exception) |
|
255 | def show_error_command_failed(exception) | |
257 | render_error l(:error_scm_command_failed, exception.message) |
|
256 | render_error l(:error_scm_command_failed, exception.message) | |
258 | end |
|
257 | end | |
259 |
|
258 | |||
260 | def graph_commits_per_month(repository) |
|
259 | def graph_commits_per_month(repository) | |
261 | @date_to = Date.today |
|
260 | @date_to = Date.today | |
262 | @date_from = @date_to << 11 |
|
261 | @date_from = @date_to << 11 | |
263 | @date_from = Date.civil(@date_from.year, @date_from.month, 1) |
|
262 | @date_from = Date.civil(@date_from.year, @date_from.month, 1) | |
264 | commits_by_day = repository.changesets.count(:all, :group => :commit_date, :conditions => ["commit_date BETWEEN ? AND ?", @date_from, @date_to]) |
|
263 | commits_by_day = repository.changesets.count( | |
|
264 | :all, :group => :commit_date, | |||
|
265 | :conditions => ["commit_date BETWEEN ? AND ?", @date_from, @date_to]) | |||
265 | commits_by_month = [0] * 12 |
|
266 | commits_by_month = [0] * 12 | |
266 | commits_by_day.each {|c| commits_by_month[c.first.to_date.months_ago] += c.last } |
|
267 | commits_by_day.each {|c| commits_by_month[c.first.to_date.months_ago] += c.last } | |
267 |
|
268 | |||
268 | changes_by_day = repository.changes.count(:all, :group => :commit_date, :conditions => ["commit_date BETWEEN ? AND ?", @date_from, @date_to]) |
|
269 | changes_by_day = repository.changes.count( | |
|
270 | :all, :group => :commit_date, | |||
|
271 | :conditions => ["commit_date BETWEEN ? AND ?", @date_from, @date_to]) | |||
269 | changes_by_month = [0] * 12 |
|
272 | changes_by_month = [0] * 12 | |
270 | changes_by_day.each {|c| changes_by_month[c.first.to_date.months_ago] += c.last } |
|
273 | changes_by_day.each {|c| changes_by_month[c.first.to_date.months_ago] += c.last } | |
271 |
|
274 | |||
272 | fields = [] |
|
275 | fields = [] | |
273 | 12.times {|m| fields << month_name(((Date.today.month - 1 - m) % 12) + 1)} |
|
276 | 12.times {|m| fields << month_name(((Date.today.month - 1 - m) % 12) + 1)} | |
274 |
|
277 | |||
275 | graph = SVG::Graph::Bar.new( |
|
278 | graph = SVG::Graph::Bar.new( | |
276 | :height => 300, |
|
279 | :height => 300, | |
277 | :width => 800, |
|
280 | :width => 800, | |
278 | :fields => fields.reverse, |
|
281 | :fields => fields.reverse, | |
279 | :stack => :side, |
|
282 | :stack => :side, | |
280 | :scale_integers => true, |
|
283 | :scale_integers => true, | |
281 | :step_x_labels => 2, |
|
284 | :step_x_labels => 2, | |
282 | :show_data_values => false, |
|
285 | :show_data_values => false, | |
283 | :graph_title => l(:label_commits_per_month), |
|
286 | :graph_title => l(:label_commits_per_month), | |
284 | :show_graph_title => true |
|
287 | :show_graph_title => true | |
285 | ) |
|
288 | ) | |
286 |
|
289 | |||
287 | graph.add_data( |
|
290 | graph.add_data( | |
288 | :data => commits_by_month[0..11].reverse, |
|
291 | :data => commits_by_month[0..11].reverse, | |
289 | :title => l(:label_revision_plural) |
|
292 | :title => l(:label_revision_plural) | |
290 | ) |
|
293 | ) | |
291 |
|
294 | |||
292 | graph.add_data( |
|
295 | graph.add_data( | |
293 | :data => changes_by_month[0..11].reverse, |
|
296 | :data => changes_by_month[0..11].reverse, | |
294 | :title => l(:label_change_plural) |
|
297 | :title => l(:label_change_plural) | |
295 | ) |
|
298 | ) | |
296 |
|
299 | |||
297 | graph.burn |
|
300 | graph.burn | |
298 | end |
|
301 | end | |
299 |
|
302 | |||
300 | def graph_commits_per_author(repository) |
|
303 | def graph_commits_per_author(repository) | |
301 | commits_by_author = repository.changesets.count(:all, :group => :committer) |
|
304 | commits_by_author = repository.changesets.count(:all, :group => :committer) | |
302 | commits_by_author.to_a.sort! {|x, y| x.last <=> y.last} |
|
305 | commits_by_author.to_a.sort! {|x, y| x.last <=> y.last} | |
303 |
|
306 | |||
304 | changes_by_author = repository.changes.count(:all, :group => :committer) |
|
307 | changes_by_author = repository.changes.count(:all, :group => :committer) | |
305 | h = changes_by_author.inject({}) {|o, i| o[i.first] = i.last; o} |
|
308 | h = changes_by_author.inject({}) {|o, i| o[i.first] = i.last; o} | |
306 |
|
309 | |||
307 | fields = commits_by_author.collect {|r| r.first} |
|
310 | fields = commits_by_author.collect {|r| r.first} | |
308 | commits_data = commits_by_author.collect {|r| r.last} |
|
311 | commits_data = commits_by_author.collect {|r| r.last} | |
309 | changes_data = commits_by_author.collect {|r| h[r.first] || 0} |
|
312 | changes_data = commits_by_author.collect {|r| h[r.first] || 0} | |
310 |
|
313 | |||
311 | fields = fields + [""]*(10 - fields.length) if fields.length<10 |
|
314 | fields = fields + [""]*(10 - fields.length) if fields.length<10 | |
312 | commits_data = commits_data + [0]*(10 - commits_data.length) if commits_data.length<10 |
|
315 | commits_data = commits_data + [0]*(10 - commits_data.length) if commits_data.length<10 | |
313 | changes_data = changes_data + [0]*(10 - changes_data.length) if changes_data.length<10 |
|
316 | changes_data = changes_data + [0]*(10 - changes_data.length) if changes_data.length<10 | |
314 |
|
317 | |||
315 | # Remove email adress in usernames |
|
318 | # Remove email adress in usernames | |
316 | fields = fields.collect {|c| c.gsub(%r{<.+@.+>}, '') } |
|
319 | fields = fields.collect {|c| c.gsub(%r{<.+@.+>}, '') } | |
317 |
|
320 | |||
318 | graph = SVG::Graph::BarHorizontal.new( |
|
321 | graph = SVG::Graph::BarHorizontal.new( | |
319 | :height => 400, |
|
322 | :height => 400, | |
320 | :width => 800, |
|
323 | :width => 800, | |
321 | :fields => fields, |
|
324 | :fields => fields, | |
322 | :stack => :side, |
|
325 | :stack => :side, | |
323 | :scale_integers => true, |
|
326 | :scale_integers => true, | |
324 | :show_data_values => false, |
|
327 | :show_data_values => false, | |
325 | :rotate_y_labels => false, |
|
328 | :rotate_y_labels => false, | |
326 | :graph_title => l(:label_commits_per_author), |
|
329 | :graph_title => l(:label_commits_per_author), | |
327 | :show_graph_title => true |
|
330 | :show_graph_title => true | |
328 | ) |
|
331 | ) | |
329 |
|
||||
330 | graph.add_data( |
|
332 | graph.add_data( | |
331 | :data => commits_data, |
|
333 | :data => commits_data, | |
332 | :title => l(:label_revision_plural) |
|
334 | :title => l(:label_revision_plural) | |
333 | ) |
|
335 | ) | |
334 |
|
||||
335 | graph.add_data( |
|
336 | graph.add_data( | |
336 | :data => changes_data, |
|
337 | :data => changes_data, | |
337 | :title => l(:label_change_plural) |
|
338 | :title => l(:label_change_plural) | |
338 | ) |
|
339 | ) | |
339 |
|
||||
340 | graph.burn |
|
340 | graph.burn | |
341 | end |
|
341 | end | |
342 |
|
||||
343 | end |
|
342 | end | |
344 |
|
343 | |||
345 | class Date |
|
344 | class Date | |
346 | def months_ago(date = Date.today) |
|
345 | def months_ago(date = Date.today) | |
347 | (date.year - self.year)*12 + (date.month - self.month) |
|
346 | (date.year - self.year)*12 + (date.month - self.month) | |
348 | end |
|
347 | end | |
349 |
|
348 | |||
350 | def weeks_ago(date = Date.today) |
|
349 | def weeks_ago(date = Date.today) | |
351 | (date.year - self.year)*52 + (date.cweek - self.cweek) |
|
350 | (date.year - self.year)*52 + (date.cweek - self.cweek) | |
352 | end |
|
351 | end | |
353 | end |
|
352 | end | |
354 |
|
353 | |||
355 | class String |
|
354 | class String | |
356 | def with_leading_slash |
|
355 | def with_leading_slash | |
357 | starts_with?('/') ? self : "/#{self}" |
|
356 | starts_with?('/') ? self : "/#{self}" | |
358 | end |
|
357 | end | |
359 | end |
|
358 | end |
General Comments 0
You need to be logged in to leave comments.
Login now