@@ -1,336 +1,339 | |||||
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 | if request.xhr? |
|
80 | if request.xhr? | |
81 | @entries ? render(:partial => 'dir_list_content') : render(:nothing => true) |
|
81 | @entries ? render(:partial => 'dir_list_content') : render(:nothing => true) | |
82 | else |
|
82 | else | |
83 | (show_error_not_found; return) unless @entries |
|
83 | (show_error_not_found; return) unless @entries | |
84 | @changesets = @repository.latest_changesets(@path, @rev) |
|
84 | @changesets = @repository.latest_changesets(@path, @rev) | |
85 | @properties = @repository.properties(@path, @rev) |
|
85 | @properties = @repository.properties(@path, @rev) | |
86 | render :action => 'show' |
|
86 | render :action => 'show' | |
87 | end |
|
87 | end | |
88 | end |
|
88 | end | |
89 |
|
89 | |||
90 | alias_method :browse, :show |
|
90 | alias_method :browse, :show | |
91 |
|
91 | |||
92 | def changes |
|
92 | def changes | |
93 | @entry = @repository.entry(@path, @rev) |
|
93 | @entry = @repository.entry(@path, @rev) | |
94 | (show_error_not_found; return) unless @entry |
|
94 | (show_error_not_found; return) unless @entry | |
95 | @changesets = @repository.latest_changesets(@path, @rev, Setting.repository_log_display_limit.to_i) |
|
95 | @changesets = @repository.latest_changesets(@path, @rev, Setting.repository_log_display_limit.to_i) | |
96 | @properties = @repository.properties(@path, @rev) |
|
96 | @properties = @repository.properties(@path, @rev) | |
|
97 | @changeset = @repository.find_changeset_by_name(@rev) | |||
97 | end |
|
98 | end | |
98 |
|
99 | |||
99 | def revisions |
|
100 | def revisions | |
100 | @changeset_count = @repository.changesets.count |
|
101 | @changeset_count = @repository.changesets.count | |
101 | @changeset_pages = Paginator.new self, @changeset_count, |
|
102 | @changeset_pages = Paginator.new self, @changeset_count, | |
102 | per_page_option, |
|
103 | per_page_option, | |
103 | params['page'] |
|
104 | params['page'] | |
104 | @changesets = @repository.changesets.find(:all, |
|
105 | @changesets = @repository.changesets.find(:all, | |
105 | :limit => @changeset_pages.items_per_page, |
|
106 | :limit => @changeset_pages.items_per_page, | |
106 | :offset => @changeset_pages.current.offset, |
|
107 | :offset => @changeset_pages.current.offset, | |
107 | :include => [:user, :repository]) |
|
108 | :include => [:user, :repository]) | |
108 |
|
109 | |||
109 | respond_to do |format| |
|
110 | respond_to do |format| | |
110 | format.html { render :layout => false if request.xhr? } |
|
111 | format.html { render :layout => false if request.xhr? } | |
111 | format.atom { render_feed(@changesets, :title => "#{@project.name}: #{l(:label_revision_plural)}") } |
|
112 | format.atom { render_feed(@changesets, :title => "#{@project.name}: #{l(:label_revision_plural)}") } | |
112 | end |
|
113 | end | |
113 | end |
|
114 | end | |
114 |
|
115 | |||
115 | def entry |
|
116 | def entry | |
116 | @entry = @repository.entry(@path, @rev) |
|
117 | @entry = @repository.entry(@path, @rev) | |
117 | (show_error_not_found; return) unless @entry |
|
118 | (show_error_not_found; return) unless @entry | |
118 |
|
119 | |||
119 | # If the entry is a dir, show the browser |
|
120 | # If the entry is a dir, show the browser | |
120 | (show; return) if @entry.is_dir? |
|
121 | (show; return) if @entry.is_dir? | |
121 |
|
122 | |||
122 | @content = @repository.cat(@path, @rev) |
|
123 | @content = @repository.cat(@path, @rev) | |
123 | (show_error_not_found; return) unless @content |
|
124 | (show_error_not_found; return) unless @content | |
124 | if 'raw' == params[:format] || @content.is_binary_data? || (@entry.size && @entry.size > Setting.file_max_size_displayed.to_i.kilobyte) |
|
125 | if 'raw' == params[:format] || @content.is_binary_data? || (@entry.size && @entry.size > Setting.file_max_size_displayed.to_i.kilobyte) | |
125 | # Force the download |
|
126 | # Force the download | |
126 | send_data @content, :filename => @path.split('/').last |
|
127 | send_data @content, :filename => @path.split('/').last | |
127 | else |
|
128 | else | |
128 | # Prevent empty lines when displaying a file with Windows style eol |
|
129 | # Prevent empty lines when displaying a file with Windows style eol | |
129 | @content.gsub!("\r\n", "\n") |
|
130 | @content.gsub!("\r\n", "\n") | |
|
131 | @changeset = @repository.find_changeset_by_name(@rev) | |||
130 | end |
|
132 | end | |
131 | end |
|
133 | end | |
132 |
|
134 | |||
133 | def annotate |
|
135 | def annotate | |
134 | @entry = @repository.entry(@path, @rev) |
|
136 | @entry = @repository.entry(@path, @rev) | |
135 | (show_error_not_found; return) unless @entry |
|
137 | (show_error_not_found; return) unless @entry | |
136 |
|
138 | |||
137 | @annotate = @repository.scm.annotate(@path, @rev) |
|
139 | @annotate = @repository.scm.annotate(@path, @rev) | |
138 | (render_error l(:error_scm_annotate); return) if @annotate.nil? || @annotate.empty? |
|
140 | (render_error l(:error_scm_annotate); return) if @annotate.nil? || @annotate.empty? | |
|
141 | @changeset = @repository.find_changeset_by_name(@rev) | |||
139 | end |
|
142 | end | |
140 |
|
143 | |||
141 | def revision |
|
144 | def revision | |
142 | raise ChangesetNotFound if @rev.blank? |
|
145 | raise ChangesetNotFound if @rev.blank? | |
143 | @changeset = @repository.find_changeset_by_name(@rev) |
|
146 | @changeset = @repository.find_changeset_by_name(@rev) | |
144 | raise ChangesetNotFound unless @changeset |
|
147 | raise ChangesetNotFound unless @changeset | |
145 |
|
148 | |||
146 | respond_to do |format| |
|
149 | respond_to do |format| | |
147 | format.html |
|
150 | format.html | |
148 | format.js {render :layout => false} |
|
151 | format.js {render :layout => false} | |
149 | end |
|
152 | end | |
150 | rescue ChangesetNotFound |
|
153 | rescue ChangesetNotFound | |
151 | show_error_not_found |
|
154 | show_error_not_found | |
152 | end |
|
155 | end | |
153 |
|
156 | |||
154 | def diff |
|
157 | def diff | |
155 | if params[:format] == 'diff' |
|
158 | if params[:format] == 'diff' | |
156 | @diff = @repository.diff(@path, @rev, @rev_to) |
|
159 | @diff = @repository.diff(@path, @rev, @rev_to) | |
157 | (show_error_not_found; return) unless @diff |
|
160 | (show_error_not_found; return) unless @diff | |
158 | filename = "changeset_r#{@rev}" |
|
161 | filename = "changeset_r#{@rev}" | |
159 | filename << "_r#{@rev_to}" if @rev_to |
|
162 | filename << "_r#{@rev_to}" if @rev_to | |
160 | send_data @diff.join, :filename => "#{filename}.diff", |
|
163 | send_data @diff.join, :filename => "#{filename}.diff", | |
161 | :type => 'text/x-patch', |
|
164 | :type => 'text/x-patch', | |
162 | :disposition => 'attachment' |
|
165 | :disposition => 'attachment' | |
163 | else |
|
166 | else | |
164 | @diff_type = params[:type] || User.current.pref[:diff_type] || 'inline' |
|
167 | @diff_type = params[:type] || User.current.pref[:diff_type] || 'inline' | |
165 | @diff_type = 'inline' unless %w(inline sbs).include?(@diff_type) |
|
168 | @diff_type = 'inline' unless %w(inline sbs).include?(@diff_type) | |
166 |
|
169 | |||
167 | # Save diff type as user preference |
|
170 | # Save diff type as user preference | |
168 | if User.current.logged? && @diff_type != User.current.pref[:diff_type] |
|
171 | if User.current.logged? && @diff_type != User.current.pref[:diff_type] | |
169 | User.current.pref[:diff_type] = @diff_type |
|
172 | User.current.pref[:diff_type] = @diff_type | |
170 | User.current.preference.save |
|
173 | User.current.preference.save | |
171 | end |
|
174 | end | |
172 |
|
175 | |||
173 | @cache_key = "repositories/diff/#{@repository.id}/" + Digest::MD5.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}") |
|
176 | @cache_key = "repositories/diff/#{@repository.id}/" + Digest::MD5.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}") | |
174 | unless read_fragment(@cache_key) |
|
177 | unless read_fragment(@cache_key) | |
175 | @diff = @repository.diff(@path, @rev, @rev_to) |
|
178 | @diff = @repository.diff(@path, @rev, @rev_to) | |
176 | show_error_not_found unless @diff |
|
179 | show_error_not_found unless @diff | |
177 | end |
|
180 | end | |
178 |
|
181 | |||
179 | @changeset = @repository.find_changeset_by_name(@rev) |
|
182 | @changeset = @repository.find_changeset_by_name(@rev) | |
180 | @changeset_to = @rev_to ? @repository.find_changeset_by_name(@rev_to) : nil |
|
183 | @changeset_to = @rev_to ? @repository.find_changeset_by_name(@rev_to) : nil | |
181 | @diff_format_revisions = @repository.diff_format_revisions(@changeset, @changeset_to) |
|
184 | @diff_format_revisions = @repository.diff_format_revisions(@changeset, @changeset_to) | |
182 | end |
|
185 | end | |
183 | end |
|
186 | end | |
184 |
|
187 | |||
185 | def stats |
|
188 | def stats | |
186 | end |
|
189 | end | |
187 |
|
190 | |||
188 | def graph |
|
191 | def graph | |
189 | data = nil |
|
192 | data = nil | |
190 | case params[:graph] |
|
193 | case params[:graph] | |
191 | when "commits_per_month" |
|
194 | when "commits_per_month" | |
192 | data = graph_commits_per_month(@repository) |
|
195 | data = graph_commits_per_month(@repository) | |
193 | when "commits_per_author" |
|
196 | when "commits_per_author" | |
194 | data = graph_commits_per_author(@repository) |
|
197 | data = graph_commits_per_author(@repository) | |
195 | end |
|
198 | end | |
196 | if data |
|
199 | if data | |
197 | headers["Content-Type"] = "image/svg+xml" |
|
200 | headers["Content-Type"] = "image/svg+xml" | |
198 | send_data(data, :type => "image/svg+xml", :disposition => "inline") |
|
201 | send_data(data, :type => "image/svg+xml", :disposition => "inline") | |
199 | else |
|
202 | else | |
200 | render_404 |
|
203 | render_404 | |
201 | end |
|
204 | end | |
202 | end |
|
205 | end | |
203 |
|
206 | |||
204 | private |
|
207 | private | |
205 |
|
208 | |||
206 | REV_PARAM_RE = %r{\A[a-f0-9]*\Z}i |
|
209 | REV_PARAM_RE = %r{\A[a-f0-9]*\Z}i | |
207 |
|
210 | |||
208 | def find_repository |
|
211 | def find_repository | |
209 | @project = Project.find(params[:id]) |
|
212 | @project = Project.find(params[:id]) | |
210 | @repository = @project.repository |
|
213 | @repository = @project.repository | |
211 | (render_404; return false) unless @repository |
|
214 | (render_404; return false) unless @repository | |
212 | @path = params[:path].join('/') unless params[:path].nil? |
|
215 | @path = params[:path].join('/') unless params[:path].nil? | |
213 | @path ||= '' |
|
216 | @path ||= '' | |
214 | @rev = params[:rev].blank? ? @repository.default_branch : params[:rev].strip |
|
217 | @rev = params[:rev].blank? ? @repository.default_branch : params[:rev].strip | |
215 | @rev_to = params[:rev_to] |
|
218 | @rev_to = params[:rev_to] | |
216 |
|
219 | |||
217 | unless @rev.to_s.match(REV_PARAM_RE) && @rev.to_s.match(REV_PARAM_RE) |
|
220 | unless @rev.to_s.match(REV_PARAM_RE) && @rev.to_s.match(REV_PARAM_RE) | |
218 | if @repository.branches.blank? |
|
221 | if @repository.branches.blank? | |
219 | raise InvalidRevisionParam |
|
222 | raise InvalidRevisionParam | |
220 | end |
|
223 | end | |
221 | end |
|
224 | end | |
222 | rescue ActiveRecord::RecordNotFound |
|
225 | rescue ActiveRecord::RecordNotFound | |
223 | render_404 |
|
226 | render_404 | |
224 | rescue InvalidRevisionParam |
|
227 | rescue InvalidRevisionParam | |
225 | show_error_not_found |
|
228 | show_error_not_found | |
226 | end |
|
229 | end | |
227 |
|
230 | |||
228 | def show_error_not_found |
|
231 | def show_error_not_found | |
229 | render_error :message => l(:error_scm_not_found), :status => 404 |
|
232 | render_error :message => l(:error_scm_not_found), :status => 404 | |
230 | end |
|
233 | end | |
231 |
|
234 | |||
232 | # Handler for Redmine::Scm::Adapters::CommandFailed exception |
|
235 | # Handler for Redmine::Scm::Adapters::CommandFailed exception | |
233 | def show_error_command_failed(exception) |
|
236 | def show_error_command_failed(exception) | |
234 | render_error l(:error_scm_command_failed, exception.message) |
|
237 | render_error l(:error_scm_command_failed, exception.message) | |
235 | end |
|
238 | end | |
236 |
|
239 | |||
237 | def graph_commits_per_month(repository) |
|
240 | def graph_commits_per_month(repository) | |
238 | @date_to = Date.today |
|
241 | @date_to = Date.today | |
239 | @date_from = @date_to << 11 |
|
242 | @date_from = @date_to << 11 | |
240 | @date_from = Date.civil(@date_from.year, @date_from.month, 1) |
|
243 | @date_from = Date.civil(@date_from.year, @date_from.month, 1) | |
241 | commits_by_day = repository.changesets.count(:all, :group => :commit_date, :conditions => ["commit_date BETWEEN ? AND ?", @date_from, @date_to]) |
|
244 | commits_by_day = repository.changesets.count(:all, :group => :commit_date, :conditions => ["commit_date BETWEEN ? AND ?", @date_from, @date_to]) | |
242 | commits_by_month = [0] * 12 |
|
245 | commits_by_month = [0] * 12 | |
243 | commits_by_day.each {|c| commits_by_month[c.first.to_date.months_ago] += c.last } |
|
246 | commits_by_day.each {|c| commits_by_month[c.first.to_date.months_ago] += c.last } | |
244 |
|
247 | |||
245 | changes_by_day = repository.changes.count(:all, :group => :commit_date, :conditions => ["commit_date BETWEEN ? AND ?", @date_from, @date_to]) |
|
248 | changes_by_day = repository.changes.count(:all, :group => :commit_date, :conditions => ["commit_date BETWEEN ? AND ?", @date_from, @date_to]) | |
246 | changes_by_month = [0] * 12 |
|
249 | changes_by_month = [0] * 12 | |
247 | changes_by_day.each {|c| changes_by_month[c.first.to_date.months_ago] += c.last } |
|
250 | changes_by_day.each {|c| changes_by_month[c.first.to_date.months_ago] += c.last } | |
248 |
|
251 | |||
249 | fields = [] |
|
252 | fields = [] | |
250 | 12.times {|m| fields << month_name(((Date.today.month - 1 - m) % 12) + 1)} |
|
253 | 12.times {|m| fields << month_name(((Date.today.month - 1 - m) % 12) + 1)} | |
251 |
|
254 | |||
252 | graph = SVG::Graph::Bar.new( |
|
255 | graph = SVG::Graph::Bar.new( | |
253 | :height => 300, |
|
256 | :height => 300, | |
254 | :width => 800, |
|
257 | :width => 800, | |
255 | :fields => fields.reverse, |
|
258 | :fields => fields.reverse, | |
256 | :stack => :side, |
|
259 | :stack => :side, | |
257 | :scale_integers => true, |
|
260 | :scale_integers => true, | |
258 | :step_x_labels => 2, |
|
261 | :step_x_labels => 2, | |
259 | :show_data_values => false, |
|
262 | :show_data_values => false, | |
260 | :graph_title => l(:label_commits_per_month), |
|
263 | :graph_title => l(:label_commits_per_month), | |
261 | :show_graph_title => true |
|
264 | :show_graph_title => true | |
262 | ) |
|
265 | ) | |
263 |
|
266 | |||
264 | graph.add_data( |
|
267 | graph.add_data( | |
265 | :data => commits_by_month[0..11].reverse, |
|
268 | :data => commits_by_month[0..11].reverse, | |
266 | :title => l(:label_revision_plural) |
|
269 | :title => l(:label_revision_plural) | |
267 | ) |
|
270 | ) | |
268 |
|
271 | |||
269 | graph.add_data( |
|
272 | graph.add_data( | |
270 | :data => changes_by_month[0..11].reverse, |
|
273 | :data => changes_by_month[0..11].reverse, | |
271 | :title => l(:label_change_plural) |
|
274 | :title => l(:label_change_plural) | |
272 | ) |
|
275 | ) | |
273 |
|
276 | |||
274 | graph.burn |
|
277 | graph.burn | |
275 | end |
|
278 | end | |
276 |
|
279 | |||
277 | def graph_commits_per_author(repository) |
|
280 | def graph_commits_per_author(repository) | |
278 | commits_by_author = repository.changesets.count(:all, :group => :committer) |
|
281 | commits_by_author = repository.changesets.count(:all, :group => :committer) | |
279 | commits_by_author.to_a.sort! {|x, y| x.last <=> y.last} |
|
282 | commits_by_author.to_a.sort! {|x, y| x.last <=> y.last} | |
280 |
|
283 | |||
281 | changes_by_author = repository.changes.count(:all, :group => :committer) |
|
284 | changes_by_author = repository.changes.count(:all, :group => :committer) | |
282 | h = changes_by_author.inject({}) {|o, i| o[i.first] = i.last; o} |
|
285 | h = changes_by_author.inject({}) {|o, i| o[i.first] = i.last; o} | |
283 |
|
286 | |||
284 | fields = commits_by_author.collect {|r| r.first} |
|
287 | fields = commits_by_author.collect {|r| r.first} | |
285 | commits_data = commits_by_author.collect {|r| r.last} |
|
288 | commits_data = commits_by_author.collect {|r| r.last} | |
286 | changes_data = commits_by_author.collect {|r| h[r.first] || 0} |
|
289 | changes_data = commits_by_author.collect {|r| h[r.first] || 0} | |
287 |
|
290 | |||
288 | fields = fields + [""]*(10 - fields.length) if fields.length<10 |
|
291 | fields = fields + [""]*(10 - fields.length) if fields.length<10 | |
289 | commits_data = commits_data + [0]*(10 - commits_data.length) if commits_data.length<10 |
|
292 | commits_data = commits_data + [0]*(10 - commits_data.length) if commits_data.length<10 | |
290 | changes_data = changes_data + [0]*(10 - changes_data.length) if changes_data.length<10 |
|
293 | changes_data = changes_data + [0]*(10 - changes_data.length) if changes_data.length<10 | |
291 |
|
294 | |||
292 | # Remove email adress in usernames |
|
295 | # Remove email adress in usernames | |
293 | fields = fields.collect {|c| c.gsub(%r{<.+@.+>}, '') } |
|
296 | fields = fields.collect {|c| c.gsub(%r{<.+@.+>}, '') } | |
294 |
|
297 | |||
295 | graph = SVG::Graph::BarHorizontal.new( |
|
298 | graph = SVG::Graph::BarHorizontal.new( | |
296 | :height => 400, |
|
299 | :height => 400, | |
297 | :width => 800, |
|
300 | :width => 800, | |
298 | :fields => fields, |
|
301 | :fields => fields, | |
299 | :stack => :side, |
|
302 | :stack => :side, | |
300 | :scale_integers => true, |
|
303 | :scale_integers => true, | |
301 | :show_data_values => false, |
|
304 | :show_data_values => false, | |
302 | :rotate_y_labels => false, |
|
305 | :rotate_y_labels => false, | |
303 | :graph_title => l(:label_commits_per_author), |
|
306 | :graph_title => l(:label_commits_per_author), | |
304 | :show_graph_title => true |
|
307 | :show_graph_title => true | |
305 | ) |
|
308 | ) | |
306 |
|
309 | |||
307 | graph.add_data( |
|
310 | graph.add_data( | |
308 | :data => commits_data, |
|
311 | :data => commits_data, | |
309 | :title => l(:label_revision_plural) |
|
312 | :title => l(:label_revision_plural) | |
310 | ) |
|
313 | ) | |
311 |
|
314 | |||
312 | graph.add_data( |
|
315 | graph.add_data( | |
313 | :data => changes_data, |
|
316 | :data => changes_data, | |
314 | :title => l(:label_change_plural) |
|
317 | :title => l(:label_change_plural) | |
315 | ) |
|
318 | ) | |
316 |
|
319 | |||
317 | graph.burn |
|
320 | graph.burn | |
318 | end |
|
321 | end | |
319 |
|
322 | |||
320 | end |
|
323 | end | |
321 |
|
324 | |||
322 | class Date |
|
325 | class Date | |
323 | def months_ago(date = Date.today) |
|
326 | def months_ago(date = Date.today) | |
324 | (date.year - self.year)*12 + (date.month - self.month) |
|
327 | (date.year - self.year)*12 + (date.month - self.month) | |
325 | end |
|
328 | end | |
326 |
|
329 | |||
327 | def weeks_ago(date = Date.today) |
|
330 | def weeks_ago(date = Date.today) | |
328 | (date.year - self.year)*52 + (date.cweek - self.cweek) |
|
331 | (date.year - self.year)*52 + (date.cweek - self.cweek) | |
329 | end |
|
332 | end | |
330 | end |
|
333 | end | |
331 |
|
334 | |||
332 | class String |
|
335 | class String | |
333 | def with_leading_slash |
|
336 | def with_leading_slash | |
334 | starts_with?('/') ? self : "/#{self}" |
|
337 | starts_with?('/') ? self : "/#{self}" | |
335 | end |
|
338 | end | |
336 | end |
|
339 | end |
@@ -1,21 +1,21 | |||||
1 | <%= link_to 'root', :action => 'show', :id => @project, :path => '', :rev => @rev %> |
|
1 | <%= link_to 'root', :action => 'show', :id => @project, :path => '', :rev => @rev %> | |
2 | <% |
|
2 | <% | |
3 | dirs = path.split('/') |
|
3 | dirs = path.split('/') | |
4 | if 'file' == kind |
|
4 | if 'file' == kind | |
5 | filename = dirs.pop |
|
5 | filename = dirs.pop | |
6 | end |
|
6 | end | |
7 | link_path = '' |
|
7 | link_path = '' | |
8 | dirs.each do |dir| |
|
8 | dirs.each do |dir| | |
9 | next if dir.blank? |
|
9 | next if dir.blank? | |
10 | link_path << '/' unless link_path.empty? |
|
10 | link_path << '/' unless link_path.empty? | |
11 | link_path << "#{dir}" |
|
11 | link_path << "#{dir}" | |
12 | %> |
|
12 | %> | |
13 | / <%= link_to h(dir), :action => 'show', :id => @project, :path => to_path_param(link_path), :rev => @rev %> |
|
13 | / <%= link_to h(dir), :action => 'show', :id => @project, :path => to_path_param(link_path), :rev => @rev %> | |
14 | <% end %> |
|
14 | <% end %> | |
15 | <% if filename %> |
|
15 | <% if filename %> | |
16 | / <%= link_to h(filename), :action => 'changes', :id => @project, :path => to_path_param("#{link_path}/#{filename}"), :rev => @rev %> |
|
16 | / <%= link_to h(filename), :action => 'changes', :id => @project, :path => to_path_param("#{link_path}/#{filename}"), :rev => @rev %> | |
17 | <% end %> |
|
17 | <% end %> | |
18 |
|
18 | |||
19 |
<%= "@ #{h revision}" if |
|
19 | <%= "@ #{h format_revision(@changeset)}" if @changeset %> | |
20 |
|
20 | |||
21 | <% html_title(with_leading_slash(path)) -%> |
|
21 | <% html_title(with_leading_slash(path)) -%> |
General Comments 0
You need to be logged in to leave comments.
Login now