Commit 20d382a8 authored by Phil Hughes's avatar Phil Hughes

Moved todo creation over to project todos controller

parent f8a8999a
...@@ -58,6 +58,8 @@ class @Sidebar ...@@ -58,6 +58,8 @@ class @Sidebar
dataType: 'json' dataType: 'json'
data: data:
todo_id: $this.attr('data-id') todo_id: $this.attr('data-id')
issuable_id: $this.data('issuable')
issuable_type: $this.data('issuable-type')
beforeSend: -> beforeSend: ->
$this.disable() $this.disable()
$todoLoading.removeClass 'hidden' $todoLoading.removeClass 'hidden'
......
...@@ -164,20 +164,6 @@ class Projects::IssuesController < Projects::ApplicationController ...@@ -164,20 +164,6 @@ class Projects::IssuesController < Projects::ApplicationController
end end
end end
def todo
json_data = Hash.new
if params[:todo_id].nil?
TodoService.new.mark_todo(issue, current_user)
json_data[:todo] = current_user.todos.find_by(state: :pending, action: Todo::MARKED, target_id: issue.id)
else
current_user.todos.find_by_id(params[:todo_id]).update(state: :done)
end
render json: json_data.merge({ count: current_user.todos.pending.count })
end
protected protected
def issue def issue
......
...@@ -260,20 +260,6 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -260,20 +260,6 @@ class Projects::MergeRequestsController < Projects::ApplicationController
render json: response render json: response
end end
def todo
json_data = Hash.new
if params[:todo_id].nil?
TodoService.new.mark_todo(merge_request, current_user)
json_data[:todo] = current_user.todos.find_by(state: :pending, action: Todo::MARKED, target_id: merge_request.id)
else
current_user.todos.find_by_id(params[:todo_id]).update(state: :done)
end
render json: json_data.merge({ count: current_user.todos.pending.count })
end
protected protected
def selected_target_project def selected_target_project
......
class Projects::TodosController < Projects::ApplicationController
def create
json_data = Hash.new
if params[:todo_id].nil?
TodoService.new.mark_todo(issuable, current_user)
json_data[:todo] = current_user.todos.find_by(state: :pending, action: Todo::MARKED, target_id: issuable.id)
else
current_user.todos.find_by_id(params[:todo_id]).update(state: :done)
end
render json: json_data.merge({ count: current_user.todos.pending.count })
end
private
def issuable
@issuable ||= begin
case params[:issuable_type]
when "issue"
@project.issues.find(params[:issuable_id])
when "merge_request"
@project.merge_requests.find(params[:issuable_id])
end
end
end
end
...@@ -67,16 +67,6 @@ module IssuablesHelper ...@@ -67,16 +67,6 @@ module IssuablesHelper
end end
end end
def issuable_todo_path(issuable)
project = issuable.project
if issuable.kind_of?(MergeRequest)
todo_namespace_project_merge_request_path(project.namespace, project, issuable.iid, :json)
else
todo_namespace_project_issue_path(project.namespace, project, issuable.iid, :json)
end
end
def has_todo(issuable) def has_todo(issuable)
unless current_user.nil? unless current_user.nil?
current_user.todos.find_by(target_id: issuable.id, state: :pending) current_user.todos.find_by(target_id: issuable.id, state: :pending)
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
%a.gutter-toggle.pull-right.js-sidebar-toggle{ role: "button", href: "#", aria: { label: "Toggle sidebar" } } %a.gutter-toggle.pull-right.js-sidebar-toggle{ role: "button", href: "#", aria: { label: "Toggle sidebar" } }
= sidebar_gutter_toggle_icon = sidebar_gutter_toggle_icon
- if current_user - if current_user
%button.btn.btn-default.issuable-header-btn.pull-right.js-issuable-todo{ type: "button", aria: { label: (todo.nil? ? "Add Todo" : "Mark Done") }, data: { todo_text: "Add Todo", mark_text: "Mark Done", id: (todo.id unless todo.nil?), url: issuable_todo_path(issuable) } } %button.btn.btn-default.issuable-header-btn.pull-right.js-issuable-todo{ type: "button", aria: { label: (todo.nil? ? "Add Todo" : "Mark Done") }, data: { todo_text: "Add Todo", mark_text: "Mark Done", id: (todo.id unless todo.nil?), issuable: issuable.id, issuable_type: issuable.class.name.underscore, url: namespace_project_todos_path(@project.namespace, @project, :json) } }
%span.js-issuable-todo-text %span.js-issuable-todo-text
- if todo.nil? - if todo.nil?
Add Todo Add Todo
......
...@@ -679,7 +679,6 @@ Rails.application.routes.draw do ...@@ -679,7 +679,6 @@ Rails.application.routes.draw do
post :toggle_subscription post :toggle_subscription
post :toggle_award_emoji post :toggle_award_emoji
post :remove_wip post :remove_wip
post :todo
end end
collection do collection do
...@@ -760,7 +759,6 @@ Rails.application.routes.draw do ...@@ -760,7 +759,6 @@ Rails.application.routes.draw do
get :referenced_merge_requests get :referenced_merge_requests
get :related_branches get :related_branches
get :can_create_branch get :can_create_branch
post :todo
end end
collection do collection do
post :bulk_update post :bulk_update
...@@ -791,6 +789,8 @@ Rails.application.routes.draw do ...@@ -791,6 +789,8 @@ Rails.application.routes.draw do
end end
end end
resources :todos, only: [:create], constraints: { id: /\d+/ }
resources :uploads, only: [:create] do resources :uploads, only: [:create] do
collection do collection do
get ":secret/:filename", action: :show, as: :show, constraints: { filename: /[^\/]+/ } get ":secret/:filename", action: :show, as: :show, constraints: { filename: /[^\/]+/ }
......
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