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
|
2018-04-13 17:47:33 +08:00
|
|
|
self.send("duplicate_#{@cell.value_type.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
|
|
|
|
new_asset = create_new_asset(old_value.asset)
|
|
|
|
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
|
|
|
|
|
|
|
|
# reuses the same code we have in copy protocols action
|
|
|
|
def create_new_asset(old_asset)
|
|
|
|
new_asset = Asset.new_empty(
|
|
|
|
old_asset.file_file_name,
|
|
|
|
old_asset.file_file_size
|
|
|
|
)
|
|
|
|
new_asset.created_by = old_asset.created_by
|
2018-04-16 18:38:25 +08:00
|
|
|
new_asset.team = @team
|
|
|
|
new_asset.last_modified_by = @user
|
2018-04-11 23:17:19 +08:00
|
|
|
new_asset.file_processing = true if old_asset.is_image?
|
|
|
|
new_asset.file = old_asset.file
|
|
|
|
new_asset.save
|
|
|
|
|
|
|
|
return unless new_asset.valid?
|
|
|
|
|
|
|
|
if new_asset.is_image?
|
|
|
|
new_asset.file.reprocess!(:large)
|
|
|
|
new_asset.file.reprocess!(:medium)
|
|
|
|
end
|
|
|
|
|
2018-07-02 18:58:49 +08:00
|
|
|
new_asset.post_process_file(new_asset.team)
|
2018-04-11 23:17:19 +08:00
|
|
|
|
|
|
|
new_asset
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|