summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhil Hughes <me@iamphill.com>2016-06-08 09:29:19 +0100
committerPhil Hughes <me@iamphill.com>2016-06-14 08:36:07 +0100
commit20d382a891d92197620eb4e72526577a916292d7 (patch)
treebf9dcaddb8c33e9d7c6e15f07a3ecef1d010933f
parentf8a8999a2069dedd9ca21bde2b726a077c057576 (diff)
downloadgitlab-ce-20d382a891d92197620eb4e72526577a916292d7.tar.gz
Moved todo creation over to project todos controller
-rw-r--r--app/assets/javascripts/right_sidebar.js.coffee2
-rw-r--r--app/controllers/projects/issues_controller.rb14
-rw-r--r--app/controllers/projects/merge_requests_controller.rb14
-rw-r--r--app/controllers/projects/todos_controller.rb28
-rw-r--r--app/helpers/issuables_helper.rb10
-rw-r--r--app/views/shared/issuable/_sidebar.html.haml2
-rw-r--r--config/routes.rb4
7 files changed, 33 insertions, 41 deletions
diff --git a/app/assets/javascripts/right_sidebar.js.coffee b/app/assets/javascripts/right_sidebar.js.coffee
index ce8de7515dd..18abec4f51e 100644
--- a/app/assets/javascripts/right_sidebar.js.coffee
+++ b/app/assets/javascripts/right_sidebar.js.coffee
@@ -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'
diff --git a/app/controllers/projects/issues_controller.rb b/app/controllers/projects/issues_controller.rb
index 5678d584d4a..4e2d3bebb2e 100644
--- a/app/controllers/projects/issues_controller.rb
+++ b/app/controllers/projects/issues_controller.rb
@@ -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
diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb
index f0eba453caa..67e7187c10d 100644
--- a/app/controllers/projects/merge_requests_controller.rb
+++ b/app/controllers/projects/merge_requests_controller.rb
@@ -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
diff --git a/app/controllers/projects/todos_controller.rb b/app/controllers/projects/todos_controller.rb
new file mode 100644
index 00000000000..21745977860
--- /dev/null
+++ b/app/controllers/projects/todos_controller.rb
@@ -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
diff --git a/app/helpers/issuables_helper.rb b/app/helpers/issuables_helper.rb
index 2ae7f5c5f32..8dbc51a689f 100644
--- a/app/helpers/issuables_helper.rb
+++ b/app/helpers/issuables_helper.rb
@@ -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)
diff --git a/app/views/shared/issuable/_sidebar.html.haml b/app/views/shared/issuable/_sidebar.html.haml
index 26052c47b0f..17f623b3461 100644
--- a/app/views/shared/issuable/_sidebar.html.haml
+++ b/app/views/shared/issuable/_sidebar.html.haml
@@ -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
diff --git a/config/routes.rb b/config/routes.rb
index d018fa742cc..ef198a5e87a 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -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: /[^\/]+/ }