mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-21 15:14:14 +08:00
Merge pull request #4679 from artoscinote/ma_SCI_7192
Properly format Excell dates in import preview [SCI-7192]
This commit is contained in:
commit
28304668e7
2 changed files with 6 additions and 3 deletions
|
@ -1,15 +1,18 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module ImportRepository
|
||||
class ParseRepository
|
||||
include ActionView::Helpers::TextHelper
|
||||
def initialize(options)
|
||||
@file = options.fetch(:file)
|
||||
@date_format = options[:date_format]
|
||||
@repository = options.fetch(:repository)
|
||||
@session = options.fetch(:session)
|
||||
@sheet = SpreadsheetParser.open_spreadsheet(@file)
|
||||
end
|
||||
|
||||
def data
|
||||
header, columns = SpreadsheetParser.first_two_rows(@sheet)
|
||||
header, columns = SpreadsheetParser.first_two_rows(@sheet, date_format: @date_format)
|
||||
# Fill in fields for dropdown
|
||||
@repository.importable_repository_fields.transform_values! do |name|
|
||||
truncate(name, length: Constants::NAME_TRUNCATION_LENGTH_DROPDOWN)
|
||||
|
|
|
@ -35,12 +35,12 @@ class SpreadsheetParser
|
|||
end
|
||||
end
|
||||
|
||||
def self.first_two_rows(sheet)
|
||||
def self.first_two_rows(sheet, date_format: nil)
|
||||
rows = spreadsheet_enumerator(sheet)
|
||||
header = []
|
||||
columns = []
|
||||
rows.take(2).each_with_index do |row_values, i|
|
||||
row = parse_row(row_values, sheet, header: i.zero?)
|
||||
row = parse_row(row_values, sheet, header: i.zero?, date_format: date_format)
|
||||
if row && i.zero?
|
||||
header = row
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue