2018-04-11 23:17:19 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module RepositoryActions
|
2018-04-13 17:47:33 +08:00
|
|
|
class DuplicateCell
|
2018-04-19 19:04:16 +08:00
|
|
|
def initialize(cell, new_row, user, team)
|
2018-04-11 23:17:19 +08:00
|
|
|
@cell = cell
|
|
|
|
@new_row = new_row
|
2018-04-16 18:38:25 +08:00
|
|
|
@user = user
|
2018-04-19 19:04:16 +08:00
|
|
|
@team = team
|
2018-04-11 23:17:19 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def call
|
2019-06-06 23:28:59 +08:00
|
|
|
__send__("duplicate_#{@cell.value_type.split('::').last.underscore}")
|
2018-04-11 23:17:19 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2018-04-13 17:47:33 +08:00
|
|
|
def duplicate_repository_list_value
|
2018-04-11 23:17:19 +08:00
|
|
|
old_value = @cell.value
|
|
|
|
RepositoryListValue.create(
|
2018-04-16 18:38:25 +08:00
|
|
|
old_value.attributes.merge(
|
|
|
|
id: nil, created_by: @user, last_modified_by: @user,
|
2018-04-11 23:17:19 +08:00
|
|
|
repository_cell_attributes: {
|
|
|
|
repository_row: @new_row,
|
|
|
|
repository_column: @cell.repository_column
|
2018-04-16 18:38:25 +08:00
|
|
|
}
|
|
|
|
)
|
2018-04-11 23:17:19 +08:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2018-04-13 17:47:33 +08:00
|
|
|
def duplicate_repository_text_value
|
2018-04-11 23:17:19 +08:00
|
|
|
old_value = @cell.value
|
|
|
|
RepositoryTextValue.create(
|
2018-04-16 18:38:25 +08:00
|
|
|
old_value.attributes.merge(
|
|
|
|
id: nil, created_by: @user, last_modified_by: @user,
|
2018-04-11 23:17:19 +08:00
|
|
|
repository_cell_attributes: {
|
|
|
|
repository_row: @new_row,
|
|
|
|
repository_column: @cell.repository_column
|
2018-04-16 18:38:25 +08:00
|
|
|
}
|
|
|
|
)
|
2018-04-11 23:17:19 +08:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2018-04-13 17:47:33 +08:00
|
|
|
def duplicate_repository_asset_value
|
2018-04-11 23:17:19 +08:00
|
|
|
old_value = @cell.value
|
2019-07-09 16:28:15 +08:00
|
|
|
new_asset = old_value.asset.duplicate
|
2018-04-11 23:17:19 +08:00
|
|
|
RepositoryAssetValue.create(
|
|
|
|
old_value.attributes.merge(
|
2018-04-16 18:38:25 +08:00
|
|
|
id: nil, asset: new_asset, created_by: @user, last_modified_by: @user,
|
2018-04-11 23:17:19 +08:00
|
|
|
repository_cell_attributes: {
|
|
|
|
repository_row: @new_row,
|
|
|
|
repository_column: @cell.repository_column
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2018-04-13 17:47:33 +08:00
|
|
|
def duplicate_repository_date_value
|
2018-04-11 23:17:19 +08:00
|
|
|
old_value = @cell.value
|
|
|
|
RepositoryDateValue.create(
|
2018-04-16 18:38:25 +08:00
|
|
|
old_value.attributes.merge(
|
|
|
|
id: nil, created_by: @user, last_modified_by: @user,
|
2018-04-11 23:17:19 +08:00
|
|
|
repository_cell_attributes: {
|
|
|
|
repository_row: @new_row,
|
|
|
|
repository_column: @cell.repository_column
|
2018-04-16 18:38:25 +08:00
|
|
|
}
|
|
|
|
)
|
2018-04-11 23:17:19 +08:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|