summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhil Hughes <me@iamphill.com>2016-06-09 16:12:59 +0100
committerPhil Hughes <me@iamphill.com>2016-06-14 08:36:07 +0100
commit16970d07e84f5967eccd928c9f9d9d7b027e91ac (patch)
tree77e73edae67682582df676fcd73b53917c2776eb
parent8abd7b35ff20214c072658a4e92e0418ae9e936a (diff)
downloadgitlab-ce-16970d07e84f5967eccd928c9f9d9d7b027e91ac.tar.gz
Returns created todos to control rather than re-query
-rw-r--r--app/controllers/projects/todos_controller.rb4
-rw-r--r--app/services/todo_service.rb2
-rw-r--r--app/views/layouts/header/_default.html.haml2
3 files changed, 4 insertions, 4 deletions
diff --git a/app/controllers/projects/todos_controller.rb b/app/controllers/projects/todos_controller.rb
index 64e70a5bcc6..a51bd5e2b49 100644
--- a/app/controllers/projects/todos_controller.rb
+++ b/app/controllers/projects/todos_controller.rb
@@ -1,9 +1,9 @@
class Projects::TodosController < Projects::ApplicationController
def create
- TodoService.new.mark_todo(issuable, current_user)
+ todos = TodoService.new.mark_todo(issuable, current_user)
render json: {
- todo: current_user.todos.find_by(state: :pending, action: Todo::MARKED, target_id: issuable.id),
+ todo: todos,
count: current_user.todos.pending.count,
}
end
diff --git a/app/services/todo_service.rb b/app/services/todo_service.rb
index 5a192e54f25..e1f9ea64dc4 100644
--- a/app/services/todo_service.rb
+++ b/app/services/todo_service.rb
@@ -148,7 +148,7 @@ class TodoService
private
def create_todos(users, attributes)
- Array(users).each do |user|
+ Array(users).map do |user|
next if pending_todos(user, attributes).exists?
Todo.create(attributes.merge(user_id: user.id))
end
diff --git a/app/views/layouts/header/_default.html.haml b/app/views/layouts/header/_default.html.haml
index ebc9f01675a..a0f560a13ec 100644
--- a/app/views/layouts/header/_default.html.haml
+++ b/app/views/layouts/header/_default.html.haml
@@ -27,7 +27,7 @@
%li
= link_to dashboard_todos_path, title: 'Todos', data: {toggle: 'tooltip', placement: 'bottom', container: 'body'} do
= icon('bell fw')
- %span.badge.todos-pending-count{ class: ("hidden" if todos_pending_count == 0)}
+ %span.badge.todos-pending-count{ class: ("hidden" if todos_pending_count == 0) }
= todos_pending_count
- if current_user.can_create_project?
%li