Commit 10649c49 authored by Brett Walker's avatar Brett Walker Committed by Fatih Acet

Added 'handle_update_task' for new task handling

parent ff1e6490
...@@ -163,12 +163,11 @@ module IssuableActions ...@@ -163,12 +163,11 @@ module IssuableActions
format.json do format.json do
# We want to pass back the latest valid data, so reload the model # We want to pass back the latest valid data, so reload the model
@issuable.reload
render json: { render json: {
errors: [ 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." "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 }, status: :conflict
end end
end end
......
...@@ -246,7 +246,7 @@ class Projects::IssuesController < Projects::ApplicationController ...@@ -246,7 +246,7 @@ class Projects::IssuesController < Projects::ApplicationController
task_num task_num
lock_version lock_version
discussion_locked 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 end
def authenticate_new_issue! def authenticate_new_issue!
......
...@@ -8,6 +8,7 @@ module Issues ...@@ -8,6 +8,7 @@ module Issues
handle_move_between_ids(issue) handle_move_between_ids(issue)
filter_spam_check_params filter_spam_check_params
change_issue_duplicate(issue) change_issue_duplicate(issue)
handle_update_task(issue)
move_issue_to_new_project(issue) || update(issue) move_issue_to_new_project(issue) || update(issue)
end end
...@@ -118,6 +119,67 @@ module Issues ...@@ -118,6 +119,67 @@ module Issues
end end
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 # rubocop: disable CodeReuse/ActiveRecord
def get_issue_if_allowed(id, board_group_id = nil) def get_issue_if_allowed(id, board_group_id = nil)
return unless id return unless id
......
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