summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorBrett Walker <bwalker@gitlab.com>2019-01-21 16:17:01 -0600
committerFatih Acet <acetfatih@gmail.com>2019-01-30 23:18:16 +0100
commit10649c49ab371cce3119ffcccfa4c3d479f79ae4 (patch)
treedf5205a2db32a3bc5095bb0a57567738680759e7 /app
parentff1e64902821eaa09dbdfb6acc382b33ed7f2e37 (diff)
downloadgitlab-ce-10649c49ab371cce3119ffcccfa4c3d479f79ae4.tar.gz
Added 'handle_update_task' for new task handling
Diffstat (limited to 'app')
-rw-r--r--app/controllers/concerns/issuable_actions.rb3
-rw-r--r--app/controllers/projects/issues_controller.rb2
-rw-r--r--app/services/issues/update_service.rb62
3 files changed, 64 insertions, 3 deletions
diff --git a/app/controllers/concerns/issuable_actions.rb b/app/controllers/concerns/issuable_actions.rb
index f0b4198b2d9..1c55cd340ec 100644
--- a/app/controllers/concerns/issuable_actions.rb
+++ b/app/controllers/concerns/issuable_actions.rb
@@ -163,12 +163,11 @@ module IssuableActions
format.json do
# We want to pass back the latest valid data, so reload the model
- @issuable.reload
render json: {
errors: [
"Someone edited this #{issuable.human_class_name} at the same time you did. Please refresh your browser and make sure your changes will not unintentionally remove theirs."
],
- data: serializer.represent(@issuable)
+ data: serializer.represent(@issuable.reload) # rubocop:disable Gitlab/ModuleWithInstanceVariables
}, status: :conflict
end
end
diff --git a/app/controllers/projects/issues_controller.rb b/app/controllers/projects/issues_controller.rb
index aed28d49f5e..df602e74cf2 100644
--- a/app/controllers/projects/issues_controller.rb
+++ b/app/controllers/projects/issues_controller.rb
@@ -246,7 +246,7 @@ class Projects::IssuesController < Projects::ApplicationController
task_num
lock_version
discussion_locked
- ] + [{ label_ids: [], assignee_ids: [], update_task: [:line_number, :line_source, :checked] }]
+ ] + [{ label_ids: [], assignee_ids: [], update_task: [:index, :checked, :line_number, :line_source] }]
end
def authenticate_new_issue!
diff --git a/app/services/issues/update_service.rb b/app/services/issues/update_service.rb
index e992d682c79..c9292ed5738 100644
--- a/app/services/issues/update_service.rb
+++ b/app/services/issues/update_service.rb
@@ -8,6 +8,7 @@ module Issues
handle_move_between_ids(issue)
filter_spam_check_params
change_issue_duplicate(issue)
+ handle_update_task(issue)
move_issue_to_new_project(issue) || update(issue)
end
@@ -118,6 +119,67 @@ module Issues
end
end
+ def handle_update_task(issue)
+ update_task_params = params.delete(:update_task)
+ return unless update_task_params
+
+ checkbox_index = update_task_params[:index]
+ currently_checked = !update_task_params[:checked]
+ changed_line_number = update_task_params[:line_number]
+ changed_line_source = update_task_params[:line_source] + "\n"
+
+ source_lines = issue.description.lines
+ markdown_task = source_lines[changed_line_number - 1]
+
+ # binding.pry
+
+ if markdown_task == changed_line_source
+ source_checkbox = /(\[[\sxX]\])/.match(markdown_task)
+
+ if source_checkbox
+ if currently_checked
+ if source_checkbox[1] == '[x]'
+ changed_line_source.sub!(/(\[[xX]\])/, '[ ]')
+ else
+ # it's already checked by someone else, nothing to do
+ ignore = true
+ end
+ else
+ if source_checkbox[1] == '[ ]'
+ changed_line_source.sub!(/(\[[\s]\])/, '[x]')
+ else
+ # it's already unchecked by someone else, nothing to do
+ ignore = true
+ end
+ end
+ end
+
+ unless ignore
+ # replace line with proper checkbox
+ source_lines[changed_line_number - 1] = changed_line_source
+
+ params[:description] = source_lines.join
+
+ # if we update the description_html field at the same time,
+ # the cache won't be considered invalid (unless something else
+ # changed)
+ html = Nokogiri::HTML.fragment(issue.description_html)
+ html_checkbox = html.css('.task-list-item-checkbox')[checkbox_index - 1]
+ # html_checkbox = html.css(".task-list-item[data-sourcepos^='#{changed_line_number}:'] > input.task-list-item-checkbox").first
+
+ if currently_checked
+ # checkboxes[checkbox_index - 1].remove_attribute('checked')
+ html_checkbox.remove_attribute('checked')
+ else
+ # checkboxes[checkbox_index - 1][:checked] = 'checked'
+ html_checkbox[:checked] = 'checked'
+ end
+
+ params[:description_html] = html.to_html
+ end
+ end
+ end
+
# rubocop: disable CodeReuse/ActiveRecord
def get_issue_if_allowed(id, board_group_id = nil)
return unless id