Commit 16970d07 authored by Phil Hughes's avatar Phil Hughes

Returns created todos to control rather than re-query

parent 8abd7b35
class Projects::TodosController < Projects::ApplicationController class Projects::TodosController < Projects::ApplicationController
def create def create
TodoService.new.mark_todo(issuable, current_user) todos = TodoService.new.mark_todo(issuable, current_user)
render json: { 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, count: current_user.todos.pending.count,
} }
end end
......
...@@ -148,7 +148,7 @@ class TodoService ...@@ -148,7 +148,7 @@ class TodoService
private private
def create_todos(users, attributes) def create_todos(users, attributes)
Array(users).each do |user| Array(users).map do |user|
next if pending_todos(user, attributes).exists? next if pending_todos(user, attributes).exists?
Todo.create(attributes.merge(user_id: user.id)) Todo.create(attributes.merge(user_id: user.id))
end end
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
%li %li
= link_to dashboard_todos_path, title: 'Todos', data: {toggle: 'tooltip', placement: 'bottom', container: 'body'} do = link_to dashboard_todos_path, title: 'Todos', data: {toggle: 'tooltip', placement: 'bottom', container: 'body'} do
= icon('bell fw') = 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 = todos_pending_count
- if current_user.can_create_project? - if current_user.can_create_project?
%li %li
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment