Commit 88c741dde062e320ad007a2c5ccb4e7bdc6cdacf

Authored by Dmitriy Zaporozhets
1 parent bb5e50e0

Refactor recent branches page

app/controllers/projects/branches_controller.rb
... ... @@ -11,6 +11,10 @@ class Projects::BranchesController < Projects::ApplicationController
11 11 @branches = Kaminari.paginate_array(@repository.branches).page(params[:page]).per(30)
12 12 end
13 13  
  14 + def recent
  15 + @branches = @repository.recent_branches
  16 + end
  17 +
14 18 def create
15 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 4 before_filter :authorize_code_access!
5 5 before_filter :require_non_empty_project
6 6  
7   - def show
8   - @activities = @repository.commits_with_refs(20)
9   - end
10   -
11 7 def stats
12 8 @stats = Gitlab::Git::Stats.new(@repository.raw, @repository.root_ref)
13 9 @graph = @stats.graph
... ...
app/models/repository.rb
... ... @@ -49,6 +49,12 @@ class Repository
49 49 tags.find { |tag| tag.name == name }
50 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 58 def add_branch(branch_name, ref)
53 59 Rails.cache.delete(cache_key(:branch_names))
54 60  
... ...
app/views/projects/branches/_filter.html.haml 0 → 100644
... ... @@ -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
1 1 = render "projects/commits/head"
2 2 .row
3 3 .span3
4   - = render "projects/repositories/filter"
  4 + = render "filter"
5 5 .span9
6 6 - unless @branches.empty?
7 7 %ul.bordered-list
... ...
app/views/projects/branches/recent.html.haml 0 → 100644
... ... @@ -0,0 +1,8 @@
  1 += render "projects/commits/head"
  2 +.row
  3 + .span3
  4 + = render "filter"
  5 + .span9
  6 + %ul.bordered-list
  7 + - @branches.each do |branch|
  8 + = render "projects/branches/branch", branch: branch
... ...
app/views/projects/commits/_head.html.haml
... ... @@ -7,7 +7,7 @@
7 7 = link_to 'Compare', project_compare_index_path(@project)
8 8  
9 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 11 Branches
12 12 %span.badge= @repository.branches.length
13 13  
... ...
app/views/projects/protected_branches/index.html.haml
1 1 = render "projects/commits/head"
2 2 .row
3 3 .span3
4   - = render "projects/repositories/filter"
  4 + = render "projects/branches/filter"
5 5 .span9
6 6 .alert.alert-info
7 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   -%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
... ... @@ -1,9 +0,0 @@
1   -= render "projects/commits/head"
2   -.row
3   - .span3
4   - = render "filter"
5   - .span9
6   - %ul.bordered-list
7   - - @activities.each do |update|
8   - = render "projects/branches/branch", branch: update.head
9   -
config/routes.rb
... ... @@ -225,8 +225,13 @@ Gitlab::Application.routes.draw do
225 225 end
226 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 234 resources :tags, only: [:index, :new, :create, :destroy]
229   - resources :branches, only: [:index, :new, :create, :destroy]
230 235 resources :protected_branches, only: [:index, :create, :destroy]
231 236  
232 237 resources :refs, only: [] do
... ...