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