mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-27 10:08:11 +08:00
Fix date import for repository
This commit is contained in:
parent
f201826eb8
commit
4af992ef35
7 changed files with 13 additions and 8 deletions
|
@ -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|
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 }
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)))
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue