Moved todo creation over to project todos controller

This commit is contained in:
Phil Hughes 2016-06-08 09:29:19 +01:00
parent f8a8999a20
commit 20d382a891
7 changed files with 33 additions and 41 deletions

View File

@ -58,6 +58,8 @@ class @Sidebar
dataType: 'json'
data:
todo_id: $this.attr('data-id')
issuable_id: $this.data('issuable')
issuable_type: $this.data('issuable-type')
beforeSend: ->
$this.disable()
$todoLoading.removeClass 'hidden'

View File

@ -164,20 +164,6 @@ class Projects::IssuesController < Projects::ApplicationController
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
def issue

View File

@ -260,20 +260,6 @@ class Projects::MergeRequestsController < Projects::ApplicationController
render json: response
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
def selected_target_project

View File

@ -0,0 +1,28 @@
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

View File

@ -67,16 +67,6 @@ module IssuablesHelper
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)
unless current_user.nil?
current_user.todos.find_by(target_id: issuable.id, state: :pending)

View File

@ -9,7 +9,7 @@
%a.gutter-toggle.pull-right.js-sidebar-toggle{ role: "button", href: "#", aria: { label: "Toggle sidebar" } }
= sidebar_gutter_toggle_icon
- 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
- if todo.nil?
Add Todo

View File

@ -679,7 +679,6 @@ Rails.application.routes.draw do
post :toggle_subscription
post :toggle_award_emoji
post :remove_wip
post :todo
end
collection do
@ -760,7 +759,6 @@ Rails.application.routes.draw do
get :referenced_merge_requests
get :related_branches
get :can_create_branch
post :todo
end
collection do
post :bulk_update
@ -791,6 +789,8 @@ Rails.application.routes.draw do
end
end
resources :todos, only: [:create], constraints: { id: /\d+/ }
resources :uploads, only: [:create] do
collection do
get ":secret/:filename", action: :show, as: :show, constraints: { filename: /[^\/]+/ }