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