mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-01 05:02:50 +08:00
Merge pull request #1036 from okriuchykhin/ok_SCI_2078
Implement importable selector for repository columns [SCI-2078]
This commit is contained in:
commit
262c21d145
4 changed files with 13 additions and 3 deletions
|
@ -56,12 +56,13 @@ class Repository < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def available_repository_fields
|
||||
def importable_repository_fields
|
||||
fields = {}
|
||||
# First and foremost add record name
|
||||
fields['-1'] = I18n.t('repositories.default_column')
|
||||
# Add all other custom columns
|
||||
repository_columns.order(:created_at).each do |rc|
|
||||
next unless rc.importable?
|
||||
fields[rc.id] = rc.name
|
||||
end
|
||||
fields
|
||||
|
|
|
@ -24,4 +24,8 @@ class RepositoryColumn < ApplicationRecord
|
|||
def update_repository_table_state
|
||||
RepositoryTableState.update_state(self, nil, created_by)
|
||||
end
|
||||
|
||||
def importable?
|
||||
Extends::REPOSITORY_IMPORTABLE_TYPES.include?(data_type.to_sym)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,12 +11,12 @@ module ImportRepository
|
|||
def data
|
||||
header, columns = SpreadsheetParser.first_two_rows(@sheet)
|
||||
# Fill in fields for dropdown
|
||||
@repository.available_repository_fields.transform_values! do |name|
|
||||
@repository.importable_repository_fields.transform_values! do |name|
|
||||
truncate(name, length: Constants::NAME_TRUNCATION_LENGTH_DROPDOWN)
|
||||
end
|
||||
Data.new(header,
|
||||
columns,
|
||||
@repository.available_repository_fields,
|
||||
@repository.importable_repository_fields,
|
||||
@repository)
|
||||
end
|
||||
|
||||
|
|
|
@ -44,6 +44,11 @@ class Extends
|
|||
RepositoryDateValue: 1,
|
||||
RepositoryListValue: 2,
|
||||
RepositoryAssetValue: 3 }
|
||||
|
||||
# Data types which can be imported to repository,
|
||||
# name should match record in REPOSITORY_DATA_TYPES
|
||||
REPOSITORY_IMPORTABLE_TYPES = %i(RepositoryTextValue RepositoryListValue)
|
||||
|
||||
# Extra attributes used for search in repositories, text columns
|
||||
# are only supported
|
||||
REPOSITORY_EXTRA_SEARCH_ATTR = ['repository_text_values.data',
|
||||
|
|
Loading…
Reference in a new issue