Commit 6ca921ae85b3b7a92d9d21d395dbb69d32ab66f0

Authored by Dmitriy Zaporozhets
2 parents be1b4080 ba7b85d0

Merge pull request #1064 from iamntz/menus_updater

Live issues counter updates
app/assets/javascripts/application.js
@@ -20,10 +20,26 @@ @@ -20,10 +20,26 @@
20 //= require_tree . 20 //= require_tree .
21 21
22 $(document).ready(function(){ 22 $(document).ready(function(){
  23 +
23 $(".one_click_select").live("click", function(){ 24 $(".one_click_select").live("click", function(){
24 $(this).select(); 25 $(this).select();
25 }); 26 });
26 27
  28 +
  29 + $('body').on('ajax:complete, ajax:beforeSend, submit', 'form', function(e){
  30 + var buttons = $('[type="submit"]', this);
  31 + switch( e.type ){
  32 + case 'ajax:beforeSend':
  33 + case 'submit':
  34 + buttons.attr('disabled', 'disabled');
  35 + break;
  36 + case ' ajax:complete':
  37 + default:
  38 + buttons.removeAttr('disabled');
  39 + break;
  40 + }
  41 + })
  42 +
27 $(".account-box").mouseenter(showMenu); 43 $(".account-box").mouseenter(showMenu);
28 $(".account-box").mouseleave(resetMenu); 44 $(".account-box").mouseleave(resetMenu);
29 45
app/assets/javascripts/issues.js
@@ -73,4 +73,25 @@ function issuesPage(){ @@ -73,4 +73,25 @@ function issuesPage(){
73 $("#milestone_id, #assignee_id, #label_name").on("change", function(){ 73 $("#milestone_id, #assignee_id, #label_name").on("change", function(){
74 $(this).closest("form").submit(); 74 $(this).closest("form").submit();
75 }); 75 });
  76 +
  77 + $('body').on('ajax:success', '.close_issue, .reopen_issue, #new_issue', function(){
  78 + var t = $(this),
  79 + totalIssues,
  80 + reopen = t.hasClass('reopen_issue'),
  81 + newIssue = false;
  82 + if( this.id == 'new_issue' ){
  83 + newIssue = true;
  84 + }
  85 + $('.issue_counter, #new_issue').each(function(){
  86 + var issue = $(this);
  87 + totalIssues = parseInt( $(this).html(), 10 );
  88 +
  89 + if( newIssue || ( reopen && issue.closest('.main_menu').length ) ){
  90 + $(this).html( totalIssues+1 );
  91 + }else {
  92 + $(this).html( totalIssues-1 );
  93 + }
  94 + });
  95 +
  96 + });
76 } 97 }
app/assets/stylesheets/common.scss
@@ -695,4 +695,4 @@ li.note { @@ -695,4 +695,4 @@ li.note {
695 border:1px solid #B8B; 695 border:1px solid #B8B;
696 } 696 }
697 } 697 }
698 -} 698 -}
  699 +}
699 \ No newline at end of file 700 \ No newline at end of file
app/views/issues/_issues.html.haml
@@ -6,7 +6,9 @@ @@ -6,7 +6,9 @@
6 .row 6 .row
7 .span7= paginate @issues, :remote => true, :theme => "gitlab" 7 .span7= paginate @issues, :remote => true, :theme => "gitlab"
8 .span3.right 8 .span3.right
9 - %span.cgray.right #{@issues.total_count} issues for this filter 9 + %span.cgray.right
  10 + %span.issue_counter #{@issues.total_count}
  11 + issues for this filter
10 - else 12 - else
11 %li 13 %li
12 %h4.nothing_here_message Nothing to show here 14 %h4.nothing_here_message Nothing to show here
app/views/issues/_show.html.haml
@@ -12,9 +12,9 @@ @@ -12,9 +12,9 @@
12 = issue.notes.count 12 = issue.notes.count
13 - if can? current_user, :modify_issue, issue 13 - if can? current_user, :modify_issue, issue
14 - if issue.closed 14 - if issue.closed
15 - = link_to 'Reopen', project_issue_path(issue.project, issue, :issue => {:closed => false }, :status_only => true), :method => :put, :class => "btn small grouped", :remote => true 15 + = link_to 'Reopen', project_issue_path(issue.project, issue, :issue => {:closed => false }, :status_only => true), :method => :put, :class => "btn small grouped reopen_issue", :remote => true
16 - else 16 - else
17 - = link_to 'Resolve', project_issue_path(issue.project, issue, :issue => {:closed => true }, :status_only => true), :method => :put, :class => "success btn small grouped", :remote => true 17 + = link_to 'Resolve', project_issue_path(issue.project, issue, :issue => {:closed => true }, :status_only => true), :method => :put, :class => "success btn small grouped close_issue", :remote => true
18 = link_to edit_project_issue_path(issue.project, issue), :class => "btn small edit-issue-link", :remote => true do 18 = link_to edit_project_issue_path(issue.project, issue), :class => "btn small edit-issue-link", :remote => true do
19 %i.icon-edit 19 %i.icon-edit
20 Edit 20 Edit
@@ -35,6 +35,4 @@ @@ -35,6 +35,4 @@
35   35  
36 36
37 - if issue.upvotes > 0 37 - if issue.upvotes > 0
38 - %span.badge.badge-success= "+#{issue.upvotes}"  
39 -  
40 - 38 + %span.badge.badge-success= "+#{issue.upvotes}"
41 \ No newline at end of file 39 \ No newline at end of file
app/views/issues/index.html.haml
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 .issues_content 2 .issues_content
3 %h3.page_title 3 %h3.page_title
4 Issues 4 Issues
5 - %small (#{@issues.total_count}) 5 + %small (<span class=issue_counter>#{@issues.total_count}</span>)
6 .right 6 .right
7 .span5 7 .span5
8 - if can? current_user, :write_issue, @project 8 - if can? current_user, :write_issue, @project
@@ -45,4 +45,4 @@ @@ -45,4 +45,4 @@
45 :javascript 45 :javascript
46 $(function(){ 46 $(function(){
47 issuesPage(); 47 issuesPage();
48 - }) 48 - })
  49 + })
49 \ No newline at end of file 50 \ No newline at end of file
app/views/layouts/_project_menu.html.haml
@@ -17,14 +17,14 @@ @@ -17,14 +17,14 @@
17 %li{:class => tab_class(:issues)} 17 %li{:class => tab_class(:issues)}
18 = link_to project_issues_filter_path(@project) do 18 = link_to project_issues_filter_path(@project) do
19 Issues 19 Issues
20 - %span.count= @project.issues.opened.count 20 + %span.count.issue_counter= @project.issues.opened.count
21 21
22 - if @project.repo_exists? 22 - if @project.repo_exists?
23 - if @project.merge_requests_enabled 23 - if @project.merge_requests_enabled
24 %li{:class => tab_class(:merge_requests)} 24 %li{:class => tab_class(:merge_requests)}
25 = link_to project_merge_requests_path(@project) do 25 = link_to project_merge_requests_path(@project) do
26 Merge Requests 26 Merge Requests
27 - %span.count= @project.merge_requests.opened.count 27 + %span.count.merge_counter= @project.merge_requests.opened.count
28 28
29 - if @project.wall_enabled 29 - if @project.wall_enabled
30 %li{:class => tab_class(:wall)} 30 %li{:class => tab_class(:wall)}