2018-07-16 12:31:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-07-28 02:33:41 -04:00
|
|
|
module Boards
|
|
|
|
module Issues
|
2021-03-09 13:09:41 -05:00
|
|
|
class MoveService < Boards::BaseItemMoveService
|
2019-07-11 09:29:16 -04:00
|
|
|
def execute_multiple(issues)
|
2019-07-05 06:50:20 -04:00
|
|
|
return execute_multiple_empty_result if issues.empty?
|
2019-07-11 09:29:16 -04:00
|
|
|
|
2019-07-05 06:50:20 -04:00
|
|
|
handled_issues = []
|
2019-07-11 09:29:16 -04:00
|
|
|
last_inserted_issue_id = nil
|
2019-07-05 06:50:20 -04:00
|
|
|
count = issues.each.inject(0) do |moved_count, issue|
|
2021-03-09 13:09:41 -05:00
|
|
|
issue_modification_params = issuable_params(issue)
|
2019-07-05 06:50:20 -04:00
|
|
|
next moved_count if issue_modification_params.empty?
|
2019-07-11 09:29:16 -04:00
|
|
|
|
|
|
|
if last_inserted_issue_id
|
2019-07-05 06:50:20 -04:00
|
|
|
issue_modification_params[:move_between_ids] = move_below(last_inserted_issue_id)
|
2019-07-11 09:29:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
last_inserted_issue_id = issue.id
|
2021-03-09 13:09:41 -05:00
|
|
|
handled_issue = move_single_issuable(issue, issue_modification_params)
|
2019-07-05 06:50:20 -04:00
|
|
|
handled_issues << present_issue_entity(handled_issue) if handled_issue
|
|
|
|
handled_issue && handled_issue.valid? ? moved_count + 1 : moved_count
|
|
|
|
end
|
|
|
|
|
|
|
|
{
|
|
|
|
count: count,
|
|
|
|
success: count == issues.size,
|
|
|
|
issues: handled_issues
|
|
|
|
}
|
2016-07-28 02:33:41 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2019-07-05 06:50:20 -04:00
|
|
|
def present_issue_entity(issue)
|
|
|
|
::API::Entities::Issue.represent(issue)
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute_multiple_empty_result
|
|
|
|
@execute_multiple_empty_result ||= {
|
|
|
|
count: 0,
|
|
|
|
success: false,
|
|
|
|
issues: []
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def move_below(id)
|
|
|
|
move_between_ids({ move_after_id: nil, move_before_id: id })
|
|
|
|
end
|
|
|
|
|
2016-10-05 13:32:53 -04:00
|
|
|
def board
|
2017-08-28 17:56:49 -04:00
|
|
|
@board ||= parent.boards.find(params[:board_id])
|
2016-10-05 13:32:53 -04:00
|
|
|
end
|
|
|
|
|
2019-07-11 09:29:16 -04:00
|
|
|
def update(issue, issue_modification_params)
|
|
|
|
::Issues::UpdateService.new(issue.project, current_user, issue_modification_params).execute(issue)
|
2016-07-28 02:33:41 -04:00
|
|
|
end
|
|
|
|
|
2021-03-23 08:09:33 -04:00
|
|
|
def reposition_parent
|
|
|
|
{ board_group_id: board.group&.id }
|
2017-02-01 13:41:01 -05:00
|
|
|
end
|
2016-07-28 02:33:41 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
Boards::Issues::MoveService.prepend_mod_with('Boards::Issues::MoveService')
|