Commit 88c741dde062e320ad007a2c5ccb4e7bdc6cdacf
1 parent
bb5e50e0
Exists in
master
and in
4 other branches
Refactor recent branches page
Showing
11 changed files
with
44 additions
and
34 deletions
Show diff stats
app/controllers/projects/branches_controller.rb
@@ -11,6 +11,10 @@ class Projects::BranchesController < Projects::ApplicationController | @@ -11,6 +11,10 @@ class Projects::BranchesController < Projects::ApplicationController | ||
11 | @branches = Kaminari.paginate_array(@repository.branches).page(params[:page]).per(30) | 11 | @branches = Kaminari.paginate_array(@repository.branches).page(params[:page]).per(30) |
12 | end | 12 | end |
13 | 13 | ||
14 | + def recent | ||
15 | + @branches = @repository.recent_branches | ||
16 | + end | ||
17 | + | ||
14 | def create | 18 | def create |
15 | @repository.add_branch(params[:branch_name], params[:ref]) | 19 | @repository.add_branch(params[:branch_name], params[:ref]) |
16 | 20 |
app/controllers/projects/repositories_controller.rb
@@ -4,10 +4,6 @@ class Projects::RepositoriesController < Projects::ApplicationController | @@ -4,10 +4,6 @@ class Projects::RepositoriesController < Projects::ApplicationController | ||
4 | before_filter :authorize_code_access! | 4 | before_filter :authorize_code_access! |
5 | before_filter :require_non_empty_project | 5 | before_filter :require_non_empty_project |
6 | 6 | ||
7 | - def show | ||
8 | - @activities = @repository.commits_with_refs(20) | ||
9 | - end | ||
10 | - | ||
11 | def stats | 7 | def stats |
12 | @stats = Gitlab::Git::Stats.new(@repository.raw, @repository.root_ref) | 8 | @stats = Gitlab::Git::Stats.new(@repository.raw, @repository.root_ref) |
13 | @graph = @stats.graph | 9 | @graph = @stats.graph |
app/models/repository.rb
@@ -49,6 +49,12 @@ class Repository | @@ -49,6 +49,12 @@ class Repository | ||
49 | tags.find { |tag| tag.name == name } | 49 | tags.find { |tag| tag.name == name } |
50 | end | 50 | end |
51 | 51 | ||
52 | + def recent_branches(limit = 20) | ||
53 | + branches.sort do |a, b| | ||
54 | + a.commit.committed_date <=> b.commit.committed_date | ||
55 | + end[0..limit] | ||
56 | + end | ||
57 | + | ||
52 | def add_branch(branch_name, ref) | 58 | def add_branch(branch_name, ref) |
53 | Rails.cache.delete(cache_key(:branch_names)) | 59 | Rails.cache.delete(cache_key(:branch_names)) |
54 | 60 |
@@ -0,0 +1,17 @@ | @@ -0,0 +1,17 @@ | ||
1 | +%ul.nav.nav-pills.nav-stacked | ||
2 | + = nav_link(path: 'branches#recent') do | ||
3 | + = link_to 'Recent', recent_project_branches_path(@project) | ||
4 | + = nav_link(path: 'protected_branches#index') do | ||
5 | + = link_to project_protected_branches_path(@project) do | ||
6 | + Protected | ||
7 | + %i.icon-lock | ||
8 | + = nav_link(path: 'branches#index') do | ||
9 | + = link_to 'All branches', project_branches_path(@project) | ||
10 | + | ||
11 | + | ||
12 | +%hr | ||
13 | +- if can? current_user, :push_code, @project | ||
14 | + = link_to new_project_branch_path(@project), class: 'btn btn-create' do | ||
15 | + %i.icon-add-sign | ||
16 | + New branch | ||
17 | + |
app/views/projects/branches/index.html.haml
app/views/projects/commits/_head.html.haml
@@ -7,7 +7,7 @@ | @@ -7,7 +7,7 @@ | ||
7 | = link_to 'Compare', project_compare_index_path(@project) | 7 | = link_to 'Compare', project_compare_index_path(@project) |
8 | 8 | ||
9 | = nav_link(html_options: {class: branches_tab_class}) do | 9 | = nav_link(html_options: {class: branches_tab_class}) do |
10 | - = link_to project_repository_path(@project) do | 10 | + = link_to recent_project_branches_path(@project) do |
11 | Branches | 11 | Branches |
12 | %span.badge= @repository.branches.length | 12 | %span.badge= @repository.branches.length |
13 | 13 |
app/views/projects/protected_branches/index.html.haml
1 | = render "projects/commits/head" | 1 | = render "projects/commits/head" |
2 | .row | 2 | .row |
3 | .span3 | 3 | .span3 |
4 | - = render "projects/repositories/filter" | 4 | + = render "projects/branches/filter" |
5 | .span9 | 5 | .span9 |
6 | .alert.alert-info | 6 | .alert.alert-info |
7 | %p Protected branches designed to prevent push for all except #{link_to "masters", help_permissions_path, class: "vlink"}. | 7 | %p Protected branches designed to prevent push for all except #{link_to "masters", help_permissions_path, class: "vlink"}. |
app/views/projects/repositories/_filter.html.haml
@@ -1,17 +0,0 @@ | @@ -1,17 +0,0 @@ | ||
1 | -%ul.nav.nav-pills.nav-stacked | ||
2 | - = nav_link(path: 'repositories#show') do | ||
3 | - = link_to 'Recent', project_repository_path(@project) | ||
4 | - = nav_link(path: 'protected_branches#index') do | ||
5 | - = link_to project_protected_branches_path(@project) do | ||
6 | - Protected | ||
7 | - %i.icon-lock | ||
8 | - = nav_link(path: 'branches#index') do | ||
9 | - = link_to 'All branches', project_branches_path(@project) | ||
10 | - | ||
11 | - | ||
12 | -%hr | ||
13 | -- if can? current_user, :push_code, @project | ||
14 | - = link_to new_project_branch_path(@project), class: 'btn btn-create' do | ||
15 | - %i.icon-add-sign | ||
16 | - New branch | ||
17 | - |
app/views/projects/repositories/show.html.haml
config/routes.rb
@@ -225,8 +225,13 @@ Gitlab::Application.routes.draw do | @@ -225,8 +225,13 @@ Gitlab::Application.routes.draw do | ||
225 | end | 225 | end |
226 | end | 226 | end |
227 | 227 | ||
228 | + resources :branches, only: [:index, :new, :create, :destroy] do | ||
229 | + collection do | ||
230 | + get :recent | ||
231 | + end | ||
232 | + end | ||
233 | + | ||
228 | resources :tags, only: [:index, :new, :create, :destroy] | 234 | resources :tags, only: [:index, :new, :create, :destroy] |
229 | - resources :branches, only: [:index, :new, :create, :destroy] | ||
230 | resources :protected_branches, only: [:index, :create, :destroy] | 235 | resources :protected_branches, only: [:index, :create, :destroy] |
231 | 236 | ||
232 | resources :refs, only: [] do | 237 | resources :refs, only: [] do |