Commit d0e794cc1a7eba4d438841d6a661bc41687e624e

Authored by Jeroen van Baarsen
1 parent 3e1853c5

Make sure the branch counter gets updated

When you delete a branch, the counters wont get updated automaticly,
this happends because of the JS nature of the original call. I've
fixed this by responding with a JS file, and recalculate the counters.

Fixes: #6030
app/controllers/projects/branches_controller.rb
@@ -23,11 +23,12 @@ class Projects::BranchesController < Projects::ApplicationController @@ -23,11 +23,12 @@ class Projects::BranchesController < Projects::ApplicationController
23 end 23 end
24 24
25 def destroy 25 def destroy
  26 + @branch = @repository.find_branch(params[:id])
26 DeleteBranchService.new.execute(project, params[:id], current_user) 27 DeleteBranchService.new.execute(project, params[:id], current_user)
27 28
28 respond_to do |format| 29 respond_to do |format|
29 format.html { redirect_to project_branches_path(@project) } 30 format.html { redirect_to project_branches_path(@project) }
30 - format.js { render nothing: true } 31 + format.js
31 end 32 end
32 end 33 end
33 end 34 end
app/views/projects/branches/_branch.html.haml
1 - commit = @repository.commit(branch.target) 1 - commit = @repository.commit(branch.target)
2 -%li 2 +%li(class="js-branch-#{branch.name}")
3 %h4 3 %h4
4 = link_to project_tree_path(@project, branch.name) do 4 = link_to project_tree_path(@project, branch.name) do
5 %strong= truncate(branch.name, length: 60) 5 %strong= truncate(branch.name, length: 60)
app/views/projects/branches/destroy.js.haml 0 → 100644
@@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
  1 +:plain
  2 + $(".js-branch-#{@branch.name}").remove();
  3 + $('.js-recentbranch-count').html("#{@repository.recent_branches.count}")
  4 + $('.js-protectedbranch-count').html("#{@project.protected_branches.count}")
  5 + $('.js-totalbranch-count').html("#{@repository.branch_names.count}")
app/views/projects/commits/_head.html.haml
@@ -9,7 +9,7 @@ @@ -9,7 +9,7 @@
9 = nav_link(html_options: {class: branches_tab_class}) do 9 = nav_link(html_options: {class: branches_tab_class}) do
10 = link_to project_branches_path(@project) do 10 = link_to project_branches_path(@project) do
11 Branches 11 Branches
12 - %span.badge= @repository.branches.size 12 + %span.badge.js-totalbranch-count= @repository.branches.size
13 13
14 = nav_link(controller: :tags) do 14 = nav_link(controller: :tags) do
15 = link_to project_tags_path(@project) do 15 = link_to project_tags_path(@project) do