Browse Source

Import helper methods

pull/1594/head
Kat 3 years ago
parent
commit
bbecf25681
  1. 41
      app/services/bulk_upload/lettings/year2022/row_parser.rb
  2. 41
      app/services/bulk_upload/lettings/year2023/row_parser.rb
  3. 41
      app/services/bulk_upload/sales/year2022/row_parser.rb

41
app/services/bulk_upload/lettings/year2022/row_parser.rb

@ -1,6 +1,7 @@
class BulkUpload::Lettings::Year2022::RowParser class BulkUpload::Lettings::Year2022::RowParser
include ActiveModel::Model include ActiveModel::Model
include ActiveModel::Attributes include ActiveModel::Attributes
include InterruptionScreenHelper
QUESTIONS = { QUESTIONS = {
field_1: "What is the letting type?", field_1: "What is the letting type?",
@ -1384,44 +1385,4 @@ private
def scheme def scheme
@scheme ||= Scheme.find_by_id_on_multiple_fields(field_4) @scheme ||= Scheme.find_by_id_on_multiple_fields(field_4)
end end
def display_title_text(title_text, log)
return "" if title_text.nil?
translation_params = {}
arguments = title_text["arguments"] || {}
arguments.each do |argument|
value = get_value_from_argument(log, argument)
translation_params[argument["i18n_template"].to_sym] = value
end
I18n.t(title_text["translation"], **translation_params).to_s
end
def display_informative_text(informative_text, log)
return "" unless informative_text["arguments"]
translation_params = {}
informative_text["arguments"].each do |argument|
value = get_value_from_argument(log, argument)
translation_params[argument["i18n_template"].to_sym] = value
end
begin
translation = I18n.t(informative_text["translation"], **translation_params)
translation.to_s.html_safe
rescue I18n::MissingInterpolationArgument => e
Rails.logger.error(e.message)
""
end
end
def get_value_from_argument(log, argument)
if argument["label"]
log.form.get_question(argument["key"], log).answer_label(log).downcase
elsif argument["arguments_for_key"]
log.public_send(argument["key"], argument["arguments_for_key"])
else
log.public_send(argument["key"])
end
end
end end

41
app/services/bulk_upload/lettings/year2023/row_parser.rb

@ -1,6 +1,7 @@
class BulkUpload::Lettings::Year2023::RowParser class BulkUpload::Lettings::Year2023::RowParser
include ActiveModel::Model include ActiveModel::Model
include ActiveModel::Attributes include ActiveModel::Attributes
include InterruptionScreenHelper
QUESTIONS = { QUESTIONS = {
field_1: "Which organisation owns this property?", field_1: "Which organisation owns this property?",
@ -1408,44 +1409,4 @@ private
0 0
end end
end end
def display_title_text(title_text, log)
return "" if title_text.nil?
translation_params = {}
arguments = title_text["arguments"] || {}
arguments.each do |argument|
value = get_value_from_argument(log, argument)
translation_params[argument["i18n_template"].to_sym] = value
end
I18n.t(title_text["translation"], **translation_params).to_s
end
def display_informative_text(informative_text, log)
return "" unless informative_text["arguments"]
translation_params = {}
informative_text["arguments"].each do |argument|
value = get_value_from_argument(log, argument)
translation_params[argument["i18n_template"].to_sym] = value
end
begin
translation = I18n.t(informative_text["translation"], **translation_params)
translation.to_s.html_safe
rescue I18n::MissingInterpolationArgument => e
Rails.logger.error(e.message)
""
end
end
def get_value_from_argument(log, argument)
if argument["label"]
log.form.get_question(argument["key"], log).answer_label(log).downcase
elsif argument["arguments_for_key"]
log.public_send(argument["key"], argument["arguments_for_key"])
else
log.public_send(argument["key"])
end
end
end end

41
app/services/bulk_upload/sales/year2022/row_parser.rb

@ -1,6 +1,7 @@
class BulkUpload::Sales::Year2022::RowParser class BulkUpload::Sales::Year2022::RowParser
include ActiveModel::Model include ActiveModel::Model
include ActiveModel::Attributes include ActiveModel::Attributes
include InterruptionScreenHelper
QUESTIONS = { QUESTIONS = {
field_1: "What is the purchaser code?", field_1: "What is the purchaser code?",
@ -962,44 +963,4 @@ private
end end
end end
end end
def display_title_text(title_text, log)
return "" if title_text.nil?
translation_params = {}
arguments = title_text["arguments"] || {}
arguments.each do |argument|
value = get_value_from_argument(log, argument)
translation_params[argument["i18n_template"].to_sym] = value
end
I18n.t(title_text["translation"], **translation_params).to_s
end
def display_informative_text(informative_text, log)
return "" unless informative_text["arguments"]
translation_params = {}
informative_text["arguments"].each do |argument|
value = get_value_from_argument(log, argument)
translation_params[argument["i18n_template"].to_sym] = value
end
begin
translation = I18n.t(informative_text["translation"], **translation_params)
translation.to_s.html_safe
rescue I18n::MissingInterpolationArgument => e
Rails.logger.error(e.message)
""
end
end
def get_value_from_argument(log, argument)
if argument["label"]
log.form.get_question(argument["key"], log).answer_label(log).downcase
elsif argument["arguments_for_key"]
log.public_send(argument["key"], argument["arguments_for_key"])
else
log.public_send(argument["key"])
end
end
end end

Loading…
Cancel
Save