Commit 7a167cf1f74b4e74c4ba9de715585a1251165c5b
1 parent
a466b217
Exists in
master
and in
4 other branches
Move branches list to own controller with pagination. Ability to remove branches from UI
Showing
11 changed files
with
75 additions
and
54 deletions
Show diff stats
app/assets/javascripts/main.js.coffee
... | ... | @@ -62,6 +62,9 @@ $ -> |
62 | 62 | # Click a .one_click_select field, select the contents |
63 | 63 | $(".one_click_select").on 'click', -> $(@).select() |
64 | 64 | |
65 | + $('.remove-row').bind 'ajax:success', -> | |
66 | + $(this).closest('li').fadeOut() | |
67 | + | |
65 | 68 | # Click a .appear-link, appear-data fadeout |
66 | 69 | $(".appear-link").on 'click', (e) -> |
67 | 70 | $('.appear-data').fadeIn() | ... | ... |
... | ... | @@ -0,0 +1,24 @@ |
1 | +class Projects::BranchesController < Projects::ApplicationController | |
2 | + # Authorize | |
3 | + before_filter :authorize_read_project! | |
4 | + before_filter :require_non_empty_project | |
5 | + | |
6 | + before_filter :authorize_admin_project!, only: [:destroy, :create] | |
7 | + | |
8 | + def index | |
9 | + @branches = Kaminari.paginate_array(@repository.branches).page(params[:page]).per(30) | |
10 | + end | |
11 | + | |
12 | + def create | |
13 | + # TODO: implement | |
14 | + end | |
15 | + | |
16 | + def destroy | |
17 | + @project.repository.rm_branch(params[:id]) | |
18 | + | |
19 | + respond_to do |format| | |
20 | + format.html { redirect_to project_branches_path } | |
21 | + format.js { render nothing: true } | |
22 | + end | |
23 | + end | |
24 | +end | ... | ... |
app/controllers/projects/repositories_controller.rb
... | ... | @@ -8,10 +8,6 @@ class Projects::RepositoriesController < Projects::ApplicationController |
8 | 8 | @activities = @repository.commits_with_refs(20) |
9 | 9 | end |
10 | 10 | |
11 | - def branches | |
12 | - @branches = @repository.branches | |
13 | - end | |
14 | - | |
15 | 11 | def tags |
16 | 12 | @tags = @repository.tags |
17 | 13 | end | ... | ... |
app/models/repository.rb
1 | 1 | class Repository |
2 | + include Gitlab::ShellAdapter | |
3 | + | |
2 | 4 | attr_accessor :raw_repository |
3 | 5 | |
4 | 6 | def initialize(path_with_namespace, default_branch) |
... | ... | @@ -33,6 +35,10 @@ class Repository |
33 | 35 | commits |
34 | 36 | end |
35 | 37 | |
38 | + def rm_branch(branch_name) | |
39 | + gitlab_shell.rm_branch(path_with_namespace, branch_name) | |
40 | + end | |
41 | + | |
36 | 42 | def round_commit_count |
37 | 43 | if commit_count > 10000 |
38 | 44 | '10000+' | ... | ... |
... | ... | @@ -0,0 +1,27 @@ |
1 | +- commit = Commit.new(Gitlab::Git::Commit.new(branch.commit)) | |
2 | +%li | |
3 | + %h4 | |
4 | + = link_to project_commits_path(@project, branch.name) do | |
5 | + %strong= truncate(branch.name, length: 60) | |
6 | + - if branch.name == @repository.root_ref | |
7 | + %span.label.label-info default | |
8 | + - if @project.protected_branch? branch.name | |
9 | + %span.label.label-success | |
10 | + %i.icon-lock | |
11 | + .pull-right | |
12 | + - if can?(current_user, :download_code, @project) | |
13 | + = link_to archive_project_repository_path(@project, ref: branch.name), class: 'btn grouped btn-small' do | |
14 | + %i.icon-download-alt | |
15 | + - if can?(current_user, :admin_project, @project) && branch.name != @repository.root_ref | |
16 | + = link_to project_branch_path(@project, branch.name), class: 'btn grouped btn-small remove-row', method: :delete, confirm: 'Removed branch cannot be restored. Are you sure?', remote: true do | |
17 | + %i.icon-trash | |
18 | + | |
19 | + %p | |
20 | + = link_to project_commit_path(@project, commit.id), class: 'commit_short_id' do | |
21 | + = commit.short_id | |
22 | + = image_tag gravatar_icon(commit.author_email), class: "avatar s16", alt: '' | |
23 | + %span.light | |
24 | + = gfm escape_once(truncate(commit.title, length: 40)) | |
25 | + %span | |
26 | + = time_ago_in_words(commit.committed_date) | |
27 | + ago | ... | ... |
... | ... | @@ -0,0 +1,10 @@ |
1 | += render "projects/commits/head" | |
2 | +.row | |
3 | + .span3 | |
4 | + = render "projects/repositories/filter" | |
5 | + .span9 | |
6 | + - unless @branches.empty? | |
7 | + %ul.bordered-list | |
8 | + - @branches.each do |branch| | |
9 | + = render "projects/branches/branch", branch: branch | |
10 | + = paginate @branches, theme: 'gitlab' | ... | ... |
app/views/projects/repositories/_branch.html.haml
... | ... | @@ -1,26 +0,0 @@ |
1 | -- commit = Commit.new(Gitlab::Git::Commit.new(branch.commit)) | |
2 | -%tr | |
3 | - %td | |
4 | - = link_to project_commits_path(@project, branch.name) do | |
5 | - - if @project.protected_branch? branch.name | |
6 | - %i.icon-lock | |
7 | - - else | |
8 | - %i.icon-unlock | |
9 | - %strong= truncate(branch.name, length: 60) | |
10 | - - if branch.name == @repository.root_ref | |
11 | - %span.label default | |
12 | - %td | |
13 | - = link_to project_commit_path(@project, commit.id), class: 'commit_short_id' do | |
14 | - = commit.short_id | |
15 | - = image_tag gravatar_icon(commit.author_email), class: "avatar s16", alt: '' | |
16 | - %span.light | |
17 | - = gfm escape_once(truncate(commit.title, length: 40)) | |
18 | - %span | |
19 | - = time_ago_in_words(commit.committed_date) | |
20 | - ago | |
21 | - %td | |
22 | - - if can? current_user, :download_code, @project | |
23 | - = link_to archive_project_repository_path(@project, ref: branch.name) do | |
24 | - %i.icon-download-alt | |
25 | - Download | |
26 | - |
app/views/projects/repositories/_filter.html.haml
... | ... | @@ -5,5 +5,5 @@ |
5 | 5 | = link_to project_protected_branches_path(@project) do |
6 | 6 | Protected |
7 | 7 | %i.icon-lock |
8 | - = nav_link(path: 'repositories#branches') do | |
9 | - = link_to 'All branches', branches_project_repository_path(@project) | |
8 | + = nav_link(path: 'branches#index') do | |
9 | + = link_to 'All branches', project_branches_path(@project) | ... | ... |
app/views/projects/repositories/branches.html.haml
... | ... | @@ -1,15 +0,0 @@ |
1 | -= render "projects/commits/head" | |
2 | -.row | |
3 | - .span3 | |
4 | - = render "filter" | |
5 | - .span9 | |
6 | - - unless @branches.empty? | |
7 | - %table | |
8 | - %thead | |
9 | - %tr | |
10 | - %th Name | |
11 | - %th Last commit | |
12 | - %th | |
13 | - %tbody | |
14 | - - @branches.each do |branch| | |
15 | - = render "projects/repositories/branch", branch: branch |
app/views/projects/repositories/show.html.haml
... | ... | @@ -3,12 +3,7 @@ |
3 | 3 | .span3 |
4 | 4 | = render "filter" |
5 | 5 | .span9 |
6 | - %table | |
7 | - %thead | |
8 | - %tr | |
9 | - %th Name | |
10 | - %th Last commit | |
11 | - %th | |
6 | + %ul.bordered-list | |
12 | 7 | - @activities.each do |update| |
13 | - = render "branch", branch: update.head | |
8 | + = render "projects/branches/branch", branch: update.head | |
14 | 9 | ... | ... |
config/routes.rb