-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate local fields to custom fields
- Loading branch information
Showing
9 changed files
with
79 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,24 @@ | ||
- label = field_label(field_props) | ||
%div{ class: "form-group #{field_with(label,errors)}" } | ||
%div{ class: "form-group #{field_with(label, errors)}" } | ||
%label.control-label{ class: required?(field_props['required'] || false) } | ||
%abbr{ title: 'required' }= '*' if field_props['required'] || false | ||
= label.gsub('[', '[').gsub(']', ']').html_safe | ||
|
||
= f.input remove_field_prop_unicode(field_props), collection: field_props['values'].map { |f| [format_placeholder(f['label']), f['label'], id: "custom_field_property_properties_#{field_props['label'].gsub('"', '&qoute;').html_safe}_#{f['label'].html_safe}", 'data-value': f['local_label']] }, required: (field_props['required'] || false), input_html: { id: field_props['label'].gsub(' ', '_').gsub("'", ""), class: "#{field_props['ClassName']} #{I18n.locale.to_s != I18n.default_locale.to_s ? 'd-none' : ''}", multiple: field_props['multiple'].present?, name: "#{f.object_name}[#{remove_field_prop_unicode(field_props)}][]", placeholder: format_placeholder(field_props['placeholder']), 'data-label': field_props["local_label"].gsub(' ', '_').gsub("'", "") }, label: false | ||
= f.input "Local_label #{remove_local_field_prop_unicode(field_props)}", collection: field_props['values'].map { |f| [format_placeholder(f['local_label']), f['local_label'], id: "custom_field_property_properties_#{field_props["local_label"].gsub('"', '&qoute;').html_safe}_#{f['local_label'].html_safe}", 'data-value': f['label']] }, required: (field_props['required'] || false), input_html: { id: field_props["local_label"].gsub(' ', '_').gsub("'", ""), class: "#{field_props['ClassName']} #{I18n.locale.to_s == I18n.default_locale.to_s ? 'd-none1' : ''}", multiple: field_props['multiple'].present?, name: "#{f.object_name}[Local_label #{remove_local_field_prop_unicode(field_props)}][]", placeholder: format_placeholder(field_props['placeholder']), 'data-label': field_props["label"].gsub(' ', '_').gsub("'", "") }, label: false | ||
- collection = field_props['values'].map { |f| [format_placeholder(f['label']), f['label'], id: "custom_field_property_properties_#{field_props['label'].gsub('"', '&qoute;').html_safe}_#{f['label'].html_safe}", 'data-value': f['local_label']] } | ||
- if I18n.locale == :en || params[:locale] == 'en' | ||
= f.input remove_field_prop_unicode(field_props), | | ||
collection: collection, | | ||
required: (field_props['required'] || false), input_html: { id: field_props['label'].gsub(' ', '_').gsub("'", ""), | | ||
class: "#{field_props['ClassName']} #{I18n.locale.to_s != I18n.default_locale.to_s ? 'd-none' : ''}", multiple: field_props['multiple'].present?, | | ||
name: "#{f.object_name}[#{remove_field_prop_unicode(field_props)}][]", placeholder: format_placeholder(field_props['placeholder']), | | ||
'data-label': field_props["label"].gsub(' ', '_').gsub("'", "") }, label: false | ||
- else | ||
= f.input "Local_label #{remove_local_field_prop_unicode(field_props)}", | | ||
collection: field_props['values'].map { |f| [format_placeholder(f['local_label']), f['local_label'], id: "custom_field_property_properties_#{field_props["local_label"].gsub('"', '&qoute;').html_safe}_#{f['local_label'].html_safe}", 'data-value': f['label']] }, | | ||
required: (field_props['required'] || false), | | ||
input_html: { id: field_props["local_label"].gsub(' ', '_').gsub("'", ""), | ||
class: "#{field_props['ClassName']} #{I18n.locale.to_s == I18n.default_locale.to_s ? 'd-none1' : ''}", | ||
multiple: field_props['multiple'].present?, name: "#{f.object_name}[Local_label #{remove_local_field_prop_unicode(field_props)}][]", | ||
placeholder: format_placeholder(field_props['placeholder']), | ||
'data-label': field_props["local_label"].gsub(' ', '_').gsub("'", "") }, label: false | ||
%span.help-block | ||
= field_message(label, errors) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
namespace :custom_form_field do | ||
desc "Migrate local label and values for custom field/form" | ||
task migrate: :environment do | ||
Organization.without_shared.pluck(:short_name).each do |short_name| | ||
Apartment::Tenant.switch short_name | ||
|
||
ProgramStream.paper_trail.disable | ||
ProgramStream.all.each do |program_stream| | ||
enrollment = populate_local_fields(program_stream.enrollment) | ||
exit_program = populate_local_fields(program_stream.exit_program) | ||
program_stream.enrollment = enrollment | ||
program_stream.exit_program = exit_program | ||
program_stream.save | ||
end | ||
ProgramStream.paper_trail.enable | ||
|
||
Tracking.paper_trail.disable | ||
Tracking.all.each do |tracking| | ||
fields = populate_local_fields(tracking.fields) | ||
tracking.fields = fields | ||
tracking.save | ||
end | ||
Tracking.paper_trail.enable | ||
|
||
CustomField.paper_trail.disable | ||
CustomField.all.each do |custom_field| | ||
fields = populate_local_fields(custom_field.fields) | ||
custom_field.fields = fields | ||
custom_field.save | ||
end | ||
CustomField.paper_trail.enable | ||
end | ||
end | ||
end | ||
|
||
def populate_local_fields(fields) | ||
fields.map do |field_hash| | ||
if field_hash.has_key?('local_label') | ||
field_hash | ||
elsif field_hash.has_key?('values') | ||
field_hash.merge('local_label' => field_hash['label'], 'values' => field_hash['values'].map{|values| values.merge('local_value' => values['value'], 'local_label' => values['label']) }) | ||
else | ||
field_hash.merge('local_label' => field_hash['label']) | ||
end | ||
end | ||
end |