mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-17 01:06:30 +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
|
value
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.import_from_text(text, attributes)
|
def self.import_from_text(text, attributes, _options = {})
|
||||||
value = new(attributes)
|
value = new(attributes)
|
||||||
column = attributes.dig(:repository_cell_attributes, :repository_column)
|
column = attributes.dig(:repository_cell_attributes, :repository_column)
|
||||||
text.split("\n").each do |item_text|
|
text.split("\n").each do |item_text|
|
||||||
|
|
|
@ -25,8 +25,9 @@ class RepositoryDateTimeValueBase < ApplicationRecord
|
||||||
save!
|
save!
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.import_from_text(text, attributes)
|
def self.import_from_text(text, attributes, options = {})
|
||||||
new(attributes.merge(data: DateTime.parse(text)))
|
date_format = options.dig(:user, :settings, :date_format) || Constants::DEFAULT_DATE_FORMAT
|
||||||
|
new(attributes.merge(data: DateTime.strptime(text, date_format)))
|
||||||
rescue ArgumentError
|
rescue ArgumentError
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
|
@ -51,7 +51,7 @@ class RepositoryListValue < ApplicationRecord
|
||||||
value
|
value
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.import_from_text(text, attributes)
|
def self.import_from_text(text, attributes, _options = {})
|
||||||
value = new(attributes)
|
value = new(attributes)
|
||||||
column = attributes.dig(:repository_cell_attributes, :repository_column)
|
column = attributes.dig(:repository_cell_attributes, :repository_column)
|
||||||
list_item = column.repository_list_items.find { |item| item.data == text }
|
list_item = column.repository_list_items.find { |item| item.data == text }
|
||||||
|
|
|
@ -34,7 +34,7 @@ class RepositoryNumberValue < ApplicationRecord
|
||||||
value
|
value
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.import_from_text(text, attributes)
|
def self.import_from_text(text, attributes, _options = {})
|
||||||
new(attributes.merge(data: BigDecimal(text)))
|
new(attributes.merge(data: BigDecimal(text)))
|
||||||
rescue ArgumentError
|
rescue ArgumentError
|
||||||
nil
|
nil
|
||||||
|
|
|
@ -44,7 +44,7 @@ class RepositoryStatusValue < ApplicationRecord
|
||||||
value
|
value
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.import_from_text(text, attributes)
|
def self.import_from_text(text, attributes, _options = {})
|
||||||
icon = text[0]
|
icon = text[0]
|
||||||
status = text[1..-1].strip
|
status = text[1..-1].strip
|
||||||
value = new(attributes)
|
value = new(attributes)
|
||||||
|
|
|
@ -33,7 +33,7 @@ class RepositoryTextValue < ApplicationRecord
|
||||||
value
|
value
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.import_from_text(text, attributes)
|
def self.import_from_text(text, attributes, _options = {})
|
||||||
return nil if text.blank?
|
return nil if text.blank?
|
||||||
|
|
||||||
new(attributes.merge(data: text.truncate(Constants::TEXT_MAX_LENGTH)))
|
new(attributes.merge(data: text.truncate(Constants::TEXT_MAX_LENGTH)))
|
||||||
|
|
|
@ -134,7 +134,11 @@ module RepositoryImportParser
|
||||||
repository_column: column,
|
repository_column: column,
|
||||||
importing: true } }
|
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?
|
next if cell_value.nil?
|
||||||
|
|
||||||
cell_value.repository_cell.value = cell_value
|
cell_value.repository_cell.value = cell_value
|
||||||
|
|
Loading…
Add table
Reference in a new issue