From d0e794cc1a7eba4d438841d6a661bc41687e624e Mon Sep 17 00:00:00 2001 From: Jeroen van Baarsen Date: Sat, 17 May 2014 11:36:39 +0200 Subject: [PATCH 1/2] 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 | 3 ++- app/views/projects/branches/_branch.html.haml | 2 +- app/views/projects/branches/destroy.js.haml | 5 +++++ app/views/projects/commits/_head.html.haml | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 app/views/projects/branches/destroy.js.haml diff --git a/app/controllers/projects/branches_controller.rb b/app/controllers/projects/branches_controller.rb index ab8892bbf0..a3ff8b91ea 100644 --- a/app/controllers/projects/branches_controller.rb +++ b/app/controllers/projects/branches_controller.rb @@ -23,11 +23,12 @@ class Projects::BranchesController < Projects::ApplicationController end def destroy + @branch = @repository.find_branch(params[:id]) DeleteBranchService.new.execute(project, params[:id], current_user) respond_to do |format| format.html { redirect_to project_branches_path(@project) } - format.js { render nothing: true } + format.js end end end diff --git a/app/views/projects/branches/_branch.html.haml b/app/views/projects/branches/_branch.html.haml index 2abcd00ee8..54a7b934dd 100644 --- a/app/views/projects/branches/_branch.html.haml +++ b/app/views/projects/branches/_branch.html.haml @@ -1,5 +1,5 @@ - commit = @repository.commit(branch.target) -%li +%li(class="js-branch-#{branch.name}") %h4 = link_to project_tree_path(@project, branch.name) do %strong= truncate(branch.name, length: 60) diff --git a/app/views/projects/branches/destroy.js.haml b/app/views/projects/branches/destroy.js.haml new file mode 100644 index 0000000000..2cba6d3745 --- /dev/null +++ b/app/views/projects/branches/destroy.js.haml @@ -0,0 +1,5 @@ +:plain + $(".js-branch-#{@branch.name}").remove(); + $('.js-recentbranch-count').html("#{@repository.recent_branches.count}") + $('.js-protectedbranch-count').html("#{@project.protected_branches.count}") + $('.js-totalbranch-count').html("#{@repository.branch_names.count}") diff --git a/app/views/projects/commits/_head.html.haml b/app/views/projects/commits/_head.html.haml index 0facfc4b5f..1bb4d9bfab 100644 --- a/app/views/projects/commits/_head.html.haml +++ b/app/views/projects/commits/_head.html.haml @@ -9,7 +9,7 @@ = nav_link(html_options: {class: branches_tab_class}) do = link_to project_branches_path(@project) do Branches - %span.badge= @repository.branches.size + %span.badge.js-totalbranch-count= @repository.branches.size = nav_link(controller: :tags) do = link_to project_tags_path(@project) do From 4ac56fa1db2286848b1bed9df3aeec8685c4cbd3 Mon Sep 17 00:00:00 2001 From: Jeroen van Baarsen Date: Fri, 23 May 2014 20:26:31 +0200 Subject: [PATCH 2/2] Changed some stuff around after rebase --- app/controllers/projects/branches_controller.rb | 2 +- app/views/projects/branches/destroy.js.haml | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/app/controllers/projects/branches_controller.rb b/app/controllers/projects/branches_controller.rb index a3ff8b91ea..3c8e7ec73f 100644 --- a/app/controllers/projects/branches_controller.rb +++ b/app/controllers/projects/branches_controller.rb @@ -23,8 +23,8 @@ class Projects::BranchesController < Projects::ApplicationController end def destroy - @branch = @repository.find_branch(params[:id]) DeleteBranchService.new.execute(project, params[:id], current_user) + @branch_name = params[:id] respond_to do |format| format.html { redirect_to project_branches_path(@project) } diff --git a/app/views/projects/branches/destroy.js.haml b/app/views/projects/branches/destroy.js.haml index 2cba6d3745..ec1661c0aa 100644 --- a/app/views/projects/branches/destroy.js.haml +++ b/app/views/projects/branches/destroy.js.haml @@ -1,5 +1,3 @@ :plain - $(".js-branch-#{@branch.name}").remove(); - $('.js-recentbranch-count').html("#{@repository.recent_branches.count}") - $('.js-protectedbranch-count').html("#{@project.protected_branches.count}") - $('.js-totalbranch-count').html("#{@repository.branch_names.count}") + $(".js-branch-#{@branch_name}").remove(); + $('.js-totalbranch-count').html("#{@repository.branches.size}")