update document name on clone
This commit is contained in:
@@ -12,7 +12,13 @@ module Templates
|
|||||||
template.preferences = original_template.preferences.deep_dup
|
template.preferences = original_template.preferences.deep_dup
|
||||||
template.name = name.presence || "#{original_template.name} (#{I18n.t('clone')})"
|
template.name = name.presence || "#{original_template.name} (#{I18n.t('clone')})"
|
||||||
|
|
||||||
template.assign_attributes(original_template.slice(:folder_id, :schema))
|
template.assign_attributes(original_template.slice(:folder_id, :schema).deep_dup)
|
||||||
|
|
||||||
|
if name.present? && template.schema.size == 1 &&
|
||||||
|
original_template.schema.first['name'] == original_template.name &&
|
||||||
|
template.name != "#{original_template.name} (#{I18n.t('clone')})"
|
||||||
|
template.schema.first['name'] = template.name
|
||||||
|
end
|
||||||
|
|
||||||
template.folder = TemplateFolders.find_or_create_by_name(author, folder_name) if folder_name.present?
|
template.folder = TemplateFolders.find_or_create_by_name(author, folder_name) if folder_name.present?
|
||||||
|
|
||||||
|
|||||||
@@ -7,10 +7,7 @@ module Templates
|
|||||||
def call(template:, original_template:, documents: [])
|
def call(template:, original_template:, documents: [])
|
||||||
schema_uuids_replacements = {}
|
schema_uuids_replacements = {}
|
||||||
|
|
||||||
cloned_schema = original_template.schema.deep_dup
|
template.schema.each_with_index do |schema_item, index|
|
||||||
cloned_fields = template.fields.deep_dup
|
|
||||||
|
|
||||||
cloned_schema.each_with_index do |schema_item, index|
|
|
||||||
new_schema_item_uuid = SecureRandom.uuid
|
new_schema_item_uuid = SecureRandom.uuid
|
||||||
|
|
||||||
schema_uuids_replacements[schema_item['attachment_uuid']] = new_schema_item_uuid
|
schema_uuids_replacements[schema_item['attachment_uuid']] = new_schema_item_uuid
|
||||||
@@ -21,7 +18,7 @@ module Templates
|
|||||||
schema_item['name'] = new_name if new_name.present?
|
schema_item['name'] = new_name if new_name.present?
|
||||||
end
|
end
|
||||||
|
|
||||||
cloned_fields.each do |field|
|
template.fields.each do |field|
|
||||||
next if field['areas'].blank?
|
next if field['areas'].blank?
|
||||||
|
|
||||||
field['areas'].each do |area|
|
field['areas'].each do |area|
|
||||||
@@ -29,7 +26,7 @@ module Templates
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
template.update!(schema: cloned_schema, fields: cloned_fields)
|
template.save!
|
||||||
|
|
||||||
original_template.schema_documents.map do |document|
|
original_template.schema_documents.map do |document|
|
||||||
new_document =
|
new_document =
|
||||||
|
|||||||
Reference in New Issue
Block a user