##// END OF EJS Templates
Pretty URL for the repository browser (Cyril Mougel)...
Jean-Philippe Lang -
r867:d46e3a501e7b
parent child
Show More
@@ -1,257 +1,257
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require 'SVG/Graph/Bar'
19 19 require 'SVG/Graph/BarHorizontal'
20 20 require 'digest/sha1'
21 21
22 22 class RepositoriesController < ApplicationController
23 23 layout 'base'
24 24 before_filter :find_repository, :except => :edit
25 25 before_filter :find_project, :only => :edit
26 26 before_filter :authorize
27 27 accept_key_auth :revisions
28 28
29 29 def edit
30 30 @repository = @project.repository
31 31 if !@repository
32 32 @repository = Repository.factory(params[:repository_scm])
33 33 @repository.project = @project
34 34 end
35 35 if request.post?
36 36 @repository.attributes = params[:repository]
37 37 @repository.save
38 38 end
39 39 render(:update) {|page| page.replace_html "tab-content-repository", :partial => 'projects/settings/repository'}
40 40 end
41 41
42 42 def destroy
43 43 @repository.destroy
44 44 redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'repository'
45 45 end
46 46
47 47 def show
48 48 # check if new revisions have been committed in the repository
49 49 @repository.fetch_changesets if Setting.autofetch_changesets?
50 50 # get entries for the browse frame
51 51 @entries = @repository.entries('')
52 52 # latest changesets
53 53 @changesets = @repository.changesets.find(:all, :limit => 10, :order => "committed_on DESC")
54 54 show_error and return unless @entries || @changesets.any?
55 55 end
56 56
57 57 def browse
58 58 @entries = @repository.entries(@path, @rev)
59 59 if request.xhr?
60 60 @entries ? render(:partial => 'dir_list_content') : render(:nothing => true)
61 61 else
62 62 show_error unless @entries
63 63 end
64 64 end
65 65
66 66 def changes
67 67 @entry = @repository.scm.entry(@path, @rev)
68 68 show_error and return unless @entry
69 69 @changesets = @repository.changesets_for_path(@path)
70 70 end
71 71
72 72 def revisions
73 73 @changeset_count = @repository.changesets.count
74 74 @changeset_pages = Paginator.new self, @changeset_count,
75 75 25,
76 76 params['page']
77 77 @changesets = @repository.changesets.find(:all,
78 78 :limit => @changeset_pages.items_per_page,
79 79 :offset => @changeset_pages.current.offset)
80 80
81 81 respond_to do |format|
82 82 format.html { render :layout => false if request.xhr? }
83 83 format.atom { render_feed(@changesets, :title => "#{@project.name}: #{l(:label_revision_plural)}") }
84 84 end
85 85 end
86 86
87 87 def entry
88 88 @content = @repository.scm.cat(@path, @rev)
89 89 show_error and return unless @content
90 90 if 'raw' == params[:format]
91 91 send_data @content, :filename => @path.split('/').last
92 92 end
93 93 end
94 94
95 95 def revision
96 96 @changeset = @repository.changesets.find_by_revision(@rev)
97 97 show_error and return unless @changeset
98 98 @changes_count = @changeset.changes.size
99 99 @changes_pages = Paginator.new self, @changes_count, 150, params['page']
100 100 @changes = @changeset.changes.find(:all,
101 101 :limit => @changes_pages.items_per_page,
102 102 :offset => @changes_pages.current.offset)
103 103
104 104 render :action => "revision", :layout => false if request.xhr?
105 105 end
106 106
107 107 def diff
108 108 @rev_to = params[:rev_to] ? params[:rev_to].to_i : (@rev - 1)
109 109 @diff_type = ('sbs' == params[:type]) ? 'sbs' : 'inline'
110 110
111 111 @cache_key = "repositories/diff/#{@repository.id}/" + Digest::MD5.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}")
112 112 unless read_fragment(@cache_key)
113 @diff = @repository.diff(@path, @rev, @rev_to, type)
113 @diff = @repository.diff(@path, @rev, @rev_to, @diff_type)
114 114 show_error and return unless @diff
115 115 end
116 116 end
117 117
118 118 def stats
119 119 end
120 120
121 121 def graph
122 122 data = nil
123 123 case params[:graph]
124 124 when "commits_per_month"
125 125 data = graph_commits_per_month(@repository)
126 126 when "commits_per_author"
127 127 data = graph_commits_per_author(@repository)
128 128 end
129 129 if data
130 130 headers["Content-Type"] = "image/svg+xml"
131 131 send_data(data, :type => "image/svg+xml", :disposition => "inline")
132 132 else
133 133 render_404
134 134 end
135 135 end
136 136
137 137 private
138 138 def find_project
139 139 @project = Project.find(params[:id])
140 140 rescue ActiveRecord::RecordNotFound
141 141 render_404
142 142 end
143 143
144 144 def find_repository
145 145 @project = Project.find(params[:id])
146 146 @repository = @project.repository
147 147 render_404 and return false unless @repository
148 @path = params[:path].squeeze('/') if params[:path]
148 @path = params[:path].join('/') unless params[:path].nil?
149 149 @path ||= ''
150 150 @rev = params[:rev].to_i if params[:rev]
151 151 rescue ActiveRecord::RecordNotFound
152 152 render_404
153 153 end
154 154
155 155 def show_error
156 156 flash.now[:error] = l(:notice_scm_error)
157 157 render :nothing => true, :layout => true
158 158 end
159 159
160 160 def graph_commits_per_month(repository)
161 161 @date_to = Date.today
162 162 @date_from = @date_to << 11
163 163 @date_from = Date.civil(@date_from.year, @date_from.month, 1)
164 164 commits_by_day = repository.changesets.count(:all, :group => :commit_date, :conditions => ["commit_date BETWEEN ? AND ?", @date_from, @date_to])
165 165 commits_by_month = [0] * 12
166 166 commits_by_day.each {|c| commits_by_month[c.first.to_date.months_ago] += c.last }
167 167
168 168 changes_by_day = repository.changes.count(:all, :group => :commit_date, :conditions => ["commit_date BETWEEN ? AND ?", @date_from, @date_to])
169 169 changes_by_month = [0] * 12
170 170 changes_by_day.each {|c| changes_by_month[c.first.to_date.months_ago] += c.last }
171 171
172 172 fields = []
173 173 month_names = l(:actionview_datehelper_select_month_names_abbr).split(',')
174 174 12.times {|m| fields << month_names[((Date.today.month - 1 - m) % 12)]}
175 175
176 176 graph = SVG::Graph::Bar.new(
177 177 :height => 300,
178 178 :width => 500,
179 179 :fields => fields.reverse,
180 180 :stack => :side,
181 181 :scale_integers => true,
182 182 :step_x_labels => 2,
183 183 :show_data_values => false,
184 184 :graph_title => l(:label_commits_per_month),
185 185 :show_graph_title => true
186 186 )
187 187
188 188 graph.add_data(
189 189 :data => commits_by_month[0..11].reverse,
190 190 :title => l(:label_revision_plural)
191 191 )
192 192
193 193 graph.add_data(
194 194 :data => changes_by_month[0..11].reverse,
195 195 :title => l(:label_change_plural)
196 196 )
197 197
198 198 graph.burn
199 199 end
200 200
201 201 def graph_commits_per_author(repository)
202 202 commits_by_author = repository.changesets.count(:all, :group => :committer)
203 203 commits_by_author.sort! {|x, y| x.last <=> y.last}
204 204
205 205 changes_by_author = repository.changes.count(:all, :group => :committer)
206 206 h = changes_by_author.inject({}) {|o, i| o[i.first] = i.last; o}
207 207
208 208 fields = commits_by_author.collect {|r| r.first}
209 209 commits_data = commits_by_author.collect {|r| r.last}
210 210 changes_data = commits_by_author.collect {|r| h[r.first] || 0}
211 211
212 212 fields = fields + [""]*(10 - fields.length) if fields.length<10
213 213 commits_data = commits_data + [0]*(10 - commits_data.length) if commits_data.length<10
214 214 changes_data = changes_data + [0]*(10 - changes_data.length) if changes_data.length<10
215 215
216 216 graph = SVG::Graph::BarHorizontal.new(
217 217 :height => 300,
218 218 :width => 500,
219 219 :fields => fields,
220 220 :stack => :side,
221 221 :scale_integers => true,
222 222 :show_data_values => false,
223 223 :rotate_y_labels => false,
224 224 :graph_title => l(:label_commits_per_author),
225 225 :show_graph_title => true
226 226 )
227 227
228 228 graph.add_data(
229 229 :data => commits_data,
230 230 :title => l(:label_revision_plural)
231 231 )
232 232
233 233 graph.add_data(
234 234 :data => changes_data,
235 235 :title => l(:label_change_plural)
236 236 )
237 237
238 238 graph.burn
239 239 end
240 240
241 241 end
242 242
243 243 class Date
244 244 def months_ago(date = Date.today)
245 245 (date.year - self.year)*12 + (date.month - self.month)
246 246 end
247 247
248 248 def weeks_ago(date = Date.today)
249 249 (date.year - self.year)*52 + (date.cweek - self.cweek)
250 250 end
251 251 end
252 252
253 253 class String
254 254 def with_leading_slash
255 255 starts_with?('/') ? self : "/#{self}"
256 256 end
257 257 end
@@ -1,29 +1,28
1 <% form_tag({:controller => 'repositories', :action => 'diff', :id => @project}, :method => :get) do %>
1 <% form_tag({:controller => 'repositories', :action => 'diff', :id => @project, :path => path}, :method => :get) do %>
2 2 <table class="list">
3 3 <thead><tr>
4 4 <th>#</th>
5 5 <th></th>
6 6 <th></th>
7 7 <th><%= l(:label_date) %></th>
8 8 <th><%= l(:field_author) %></th>
9 9 <th><%= l(:field_comments) %></th>
10 10 </tr></thead>
11 11 <tbody>
12 12 <% show_diff = entry && entry.is_file? && revisions.size > 1 %>
13 13 <% line_num = 1 %>
14 14 <% revisions.each do |changeset| %>
15 15 <tr class="<%= cycle 'odd', 'even' %>">
16 16 <td class="id"><%= link_to changeset.revision, :action => 'revision', :id => project, :rev => changeset.revision %></th>
17 17 <td class="checkbox"><%= radio_button_tag('rev', changeset.revision, (line_num==1), :id => "cb-#{line_num}", :onclick => "$('cbto-#{line_num+1}').checked=true;") if show_diff && (line_num < revisions.size) %></td>
18 18 <td class="checkbox"><%= radio_button_tag('rev_to', changeset.revision, (line_num==2), :id => "cbto-#{line_num}", :onclick => "if ($('cb-#{line_num}').checked==true) {$('cb-#{line_num-1}').checked=true;}") if show_diff && (line_num > 1) %></td>
19 19 <td align="center" style="width:15%"><%= format_time(changeset.committed_on) %></td>
20 20 <td align="center" style="width:15%"><em><%=h changeset.committer %></em></td>
21 21 <td align="left"><%= textilizable(changeset.comments) %></td>
22 22 </tr>
23 23 <% line_num += 1 %>
24 24 <% end %>
25 25 </tbody>
26 26 </table>
27 <%= hidden_field_tag 'path', path %>
28 27 <%= submit_tag(l(:label_view_diff), :class => 'small', :name => nil) if show_diff %>
29 28 <% end %>
@@ -1,27 +1,34
1 1 ActionController::Routing::Routes.draw do |map|
2 2 # Add your own custom routes here.
3 3 # The priority is based upon order of creation: first created -> highest priority.
4 4
5 5 # Here's a sample route:
6 6 # map.connect 'products/:id', :controller => 'catalog', :action => 'view'
7 7 # Keep in mind you can assign values other than :controller and :action
8 8
9 9 map.home '', :controller => 'welcome'
10 10
11 11 map.connect 'wiki/:id/:page/:action', :controller => 'wiki', :page => nil
12 12 map.connect 'roles/workflow/:id/:role_id/:tracker_id', :controller => 'roles', :action => 'workflow'
13 13 map.connect 'help/:ctrl/:page', :controller => 'help'
14 14 #map.connect ':controller/:action/:id/:sort_key/:sort_order'
15 15
16 16 map.connect 'issues/:issue_id/relations/:action/:id', :controller => 'issue_relations'
17 17 map.connect 'projects/:project_id/boards/:action/:id', :controller => 'boards'
18 18 map.connect 'boards/:board_id/topics/:action/:id', :controller => 'messages'
19
20 map.with_options :controller => 'repositories' do |omap|
21 omap.repositories_show 'repositories/browse/:id/*path', :action => 'browse'
22 omap.repositories_changes 'repositories/changes/:id/*path', :action => 'changes'
23 omap.repositories_diff 'repositories/diff/:id/*path', :action => 'diff'
24 omap.repositories_entry 'repositories/entry/:id/*path', :action => 'entry'
25 end
19 26
20 27 # Allow downloading Web Service WSDL as a file with an extension
21 28 # instead of a file named 'wsdl'
22 29 map.connect ':controller/service.wsdl', :action => 'wsdl'
23 30
24 31
25 32 # Install the default route as the lowest priority.
26 33 map.connect ':controller/:action/:id'
27 34 end
General Comments 0
You need to be logged in to leave comments. Login now