Merge pull request #1036 from okriuchykhin/ok_SCI_2078

Implement importable selector for repository columns [SCI-2078]
This commit is contained in:
okriuchykhin 2018-03-13 13:14:53 +01:00 committed by GitHub
commit 262c21d145
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 3 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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',