From be1ead22e098d88b2c51a2c947100c955749df21 Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Tue, 13 Mar 2018 11:36:05 +0100 Subject: [PATCH] Implement importable selector for repository columns [SCI-2078] --- app/models/repository.rb | 3 ++- app/models/repository_column.rb | 4 ++++ app/services/import_repository/parse_repository.rb | 4 ++-- config/initializers/extends.rb | 5 +++++ 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/models/repository.rb b/app/models/repository.rb index f7ff892b6..6c0a16563 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -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 diff --git a/app/models/repository_column.rb b/app/models/repository_column.rb index ff3e8bb5f..f87f87fd4 100644 --- a/app/models/repository_column.rb +++ b/app/models/repository_column.rb @@ -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 diff --git a/app/services/import_repository/parse_repository.rb b/app/services/import_repository/parse_repository.rb index 222b71274..cf23fedd1 100644 --- a/app/services/import_repository/parse_repository.rb +++ b/app/services/import_repository/parse_repository.rb @@ -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 diff --git a/config/initializers/extends.rb b/config/initializers/extends.rb index fd6975eaf..94b75b154 100644 --- a/config/initializers/extends.rb +++ b/config/initializers/extends.rb @@ -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',