diff options
author | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-06-14 23:09:48 -0300 |
---|---|---|
committer | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-06-17 16:17:43 -0300 |
commit | 2878c990052f78fae3cde21a1d2cd90dd5a85461 (patch) | |
tree | 6b026bd7ec4c80c2f46deef6e2009496a024b200 /app | |
parent | bb4a1ef6c1ed4d367e6126ad64033e0286da6f15 (diff) | |
download | gitlab-ce-2878c990052f78fae3cde21a1d2cd90dd5a85461.tar.gz |
Ensure Todos counters doesn't count Todos for projects pending delete
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/dashboard/todos_controller.rb | 21 | ||||
-rw-r--r-- | app/finders/todos_finder.rb | 2 | ||||
-rw-r--r-- | app/helpers/todos_helper.rb | 4 |
3 files changed, 11 insertions, 16 deletions
diff --git a/app/controllers/dashboard/todos_controller.rb b/app/controllers/dashboard/todos_controller.rb index 7842fb9ce63..3a2db3e6eeb 100644 --- a/app/controllers/dashboard/todos_controller.rb +++ b/app/controllers/dashboard/todos_controller.rb @@ -1,5 +1,7 @@ class Dashboard::TodosController < Dashboard::ApplicationController - before_action :find_todos, only: [:index, :destroy, :destroy_all] + include TodosHelper + + before_action :find_todos, only: [:index, :destroy_all] def index @todos = @todos.page(params[:page]) @@ -8,14 +10,10 @@ class Dashboard::TodosController < Dashboard::ApplicationController def destroy TodoService.new.mark_todos_as_done([todo], current_user) - todo_notice = 'Todo was successfully marked as done.' - respond_to do |format| - format.html { redirect_to dashboard_todos_path, notice: todo_notice } + format.html { redirect_to dashboard_todos_path, notice: 'Todo was successfully marked as done.' } format.js { head :ok } - format.json do - render json: { count: @todos.size, done_count: current_user.todos_done_count } - end + format.json { render json: { count: todos_pending_count, done_count: todos_done_count } } end end @@ -25,20 +23,17 @@ class Dashboard::TodosController < Dashboard::ApplicationController respond_to do |format| format.html { redirect_to dashboard_todos_path, notice: 'All todos were marked as done.' } format.js { head :ok } - format.json do - find_todos - render json: { count: @todos.size, done_count: current_user.todos_done_count } - end + format.json { render json: { count: todos_pending_count, done_count: todos_done_count } } end end private def todo - @todo ||= current_user.todos.find(params[:id]) + @todo ||= find_todos.find(params[:id]) end def find_todos - @todos = TodosFinder.new(current_user, params).execute + @todos ||= TodosFinder.new(current_user, params).execute end end diff --git a/app/finders/todos_finder.rb b/app/finders/todos_finder.rb index aa47c6c157e..58a00f88af7 100644 --- a/app/finders/todos_finder.rb +++ b/app/finders/todos_finder.rb @@ -123,7 +123,7 @@ class TodosFinder end def by_state(items) - case params[:state] + case params[:state].to_s when 'done' items.done else diff --git a/app/helpers/todos_helper.rb b/app/helpers/todos_helper.rb index c7aeed4b9fc..e1d8517f712 100644 --- a/app/helpers/todos_helper.rb +++ b/app/helpers/todos_helper.rb @@ -1,10 +1,10 @@ module TodosHelper def todos_pending_count - current_user.todos_pending_count + TodosFinder.new(current_user, state: :pending).execute.count end def todos_done_count - current_user.todos_done_count + TodosFinder.new(current_user, state: :done).execute.count end def todo_action_name(todo) |