Fix date import for repository

This commit is contained in:
aignatov-bio 2020-03-05 14:34:31 +01:00
parent f201826eb8
commit 4af992ef35
7 changed files with 13 additions and 8 deletions

View file

@ -53,7 +53,7 @@ class RepositoryChecklistValue < ApplicationRecord
value
end
def self.import_from_text(text, attributes)
def self.import_from_text(text, attributes, _options = {})
value = new(attributes)
column = attributes.dig(:repository_cell_attributes, :repository_column)
text.split("\n").each do |item_text|

View file

@ -25,8 +25,9 @@ class RepositoryDateTimeValueBase < ApplicationRecord
save!
end
def self.import_from_text(text, attributes)
new(attributes.merge(data: DateTime.parse(text)))
def self.import_from_text(text, attributes, options = {})
date_format = options.dig(:user, :settings, :date_format) || Constants::DEFAULT_DATE_FORMAT
new(attributes.merge(data: DateTime.strptime(text, date_format)))
rescue ArgumentError
nil
end

View file

@ -51,7 +51,7 @@ class RepositoryListValue < ApplicationRecord
value
end
def self.import_from_text(text, attributes)
def self.import_from_text(text, attributes, _options = {})
value = new(attributes)
column = attributes.dig(:repository_cell_attributes, :repository_column)
list_item = column.repository_list_items.find { |item| item.data == text }

View file

@ -34,7 +34,7 @@ class RepositoryNumberValue < ApplicationRecord
value
end
def self.import_from_text(text, attributes)
def self.import_from_text(text, attributes, _options = {})
new(attributes.merge(data: BigDecimal(text)))
rescue ArgumentError
nil

View file

@ -44,7 +44,7 @@ class RepositoryStatusValue < ApplicationRecord
value
end
def self.import_from_text(text, attributes)
def self.import_from_text(text, attributes, _options = {})
icon = text[0]
status = text[1..-1].strip
value = new(attributes)

View file

@ -33,7 +33,7 @@ class RepositoryTextValue < ApplicationRecord
value
end
def self.import_from_text(text, attributes)
def self.import_from_text(text, attributes, _options = {})
return nil if text.blank?
new(attributes.merge(data: text.truncate(Constants::TEXT_MAX_LENGTH)))

View file

@ -134,7 +134,11 @@ module RepositoryImportParser
repository_column: column,
importing: true } }
cell_value = column.data_type.constantize.import_from_text(value, cell_value_attributes)
cell_value = column.data_type.constantize.import_from_text(
value,
cell_value_attributes,
user: @user.as_json
)
next if cell_value.nil?
cell_value.repository_cell.value = cell_value