Commit 3bc9dee7db05ff1425ce694b807397e4da6c9181

Group repository clones nicely when viewing a project

Commit diff

app/controllers/projects_controller.rb

 
2626
2727 def show
2828 @project = Project.find_by_slug!(params[:id])
29 @repositories = @project.repositories
29 @repositories = @project.repositories.group_by(&:parent)
3030
3131 respond_to do |format|
3232 format.html
toggle raw diff

app/models/project.rb

 
22 acts_as_taggable
33
44 belongs_to :user
5 has_many :repositories, :order => "mainline desc, created_at desc",
5 has_many :repositories, :order => "mainline desc, created_at asc",
66 :dependent => :destroy
77 has_one :mainline_repository, :conditions => ["mainline = ?", true],
88 :class_name => "Repository"
toggle raw diff

app/views/projects/show.html.erb

 
2828 <th>Created</th>
2929 <th></th>
3030 </thead>
31 <% @repositories.each do |repos| -%>
32 <tr class="<%= cycle("even", "odd") -%><%= repos.mainline? ? ' mainline' : '' -%>">
33 <td>
31 <% @repositories.each do |repos, clones| -%>
32 <% next if repos.nil? -%>
33 <tr class="<%= cycle("even", "odd") -%> mainline">
34 <td class="name">
3435 <%= link_to h(repos.name), project_repository_path(@project, repos) -%>
35 <!-- <% if repos.mainline? -%> <small><em>(Mainline)</em></small><% end -%> -->
3636 </td>
3737 <td>
38 <% if repos.mainline? -%>
39 <%= h(@project.slug) -%> (<%= link_to h(repos.user.login), user_path(repos.user) -%>)
40 <% else -%>
41 <%= link_to h(repos.user.login), user_path(repos.user) -%>
42 <% end -%>
38 <%= h(@project.slug) -%> (<%= link_to h(repos.user.login), user_path(repos.user) -%>)
4339 </td>
4440 <td>
4541 <%= repos.created_at.to_s(:short) -%>
4642 </td>
4743 <td><%= link_to "browse", project_repository_browse_path(@project, repos) -%></td>
4844 </tr>
45 <% clones.each do |repos| -%>
46 <tr class="<%= cycle("even", "odd") -%> clone">
47 <td class="name">
48 <%= link_to h(repos.name), project_repository_path(@project, repos) -%>
49 </td>
50 <td>
51 <%= link_to h(repos.user.login), user_path(repos.user) -%>
52 </td>
53 <td>
54 <%= repos.created_at.to_s(:short) -%>
55 </td>
56 <td><%= link_to "browse", project_repository_browse_path(@project, repos) -%></td>
57 </tr>
58 <% end -%>
4959 <% end -%>
5060</table>
5161
toggle raw diff

lib/core_ext.rb

 
22 def to_sentence(options={})
33 super({:skip_last_comma => true}.merge(options))
44 end
5end
6
7module Enumerable
8 # http://dev.rubyonrails.org/changeset/8516
9 def group_by
10 inject([]) do |groups, element|
11 value = yield(element)
12 if (last_group = groups.last) && last_group.first == value
13 last_group.last << element
14 else
15 groups << [value, [element]]
16 end
17 groups
18 end
19 end if RUBY_VERSION < '1.9'
520end
toggle raw diff

public/images/clone_indent.png

 
toggle raw diff

public/stylesheets/base.css

 
344344 padding: 5px;
345345 border-bottom: 1px solid #ccc;
346346}
347table.repository_list tr.clone td.name {
348 background: url("/images/clone_indent.png") 10px 50% no-repeat;
349 padding-left: 20px;
350}
351
347352.infobox {
348353 background: #efefef;
349354 padding: 10px;
toggle raw diff