debian-mirror-gitlab/app/services/boards/lists/generate_service.rb

36 lines
814 B
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2016-09-13 17:45:13 +05:30
module Boards
module Lists
2018-03-17 18:26:18 +05:30
class GenerateService < Boards::BaseService
2016-11-03 12:29:30 +05:30
def execute(board)
2016-09-13 17:45:13 +05:30
return false unless board.lists.movable.empty?
List.transaction do
2016-11-03 12:29:30 +05:30
label_params.each { |params| create_list(board, params) }
2016-09-13 17:45:13 +05:30
end
true
end
private
2016-11-03 12:29:30 +05:30
def create_list(board, params)
2016-09-13 17:45:13 +05:30
label = find_or_create_label(params)
2018-03-17 18:26:18 +05:30
Lists::CreateService.new(parent, current_user, label_id: label.id).execute(board)
2016-09-13 17:45:13 +05:30
end
def find_or_create_label(params)
2018-03-17 18:26:18 +05:30
::Labels::FindOrCreateService.new(current_user, parent, params).execute
2016-09-13 17:45:13 +05:30
end
def label_params
[
2016-11-03 12:29:30 +05:30
{ name: 'To Do', color: '#F0AD4E' },
{ name: 'Doing', color: '#5CB85C' }
2016-09-13 17:45:13 +05:30
]
end
end
end
end