Merge pull request #7404 from lasniscinote/gl_SCI_10490

(dev) Create a new column during import into inventory [SCI-10490]
This commit is contained in:
Martin Artnik 2024-04-02 13:59:04 +02:00 committed by GitHub
commit 71d286bf26
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 1 deletions

View file

@ -39,10 +39,18 @@ module RepositoryImportParser
def fetch_columns
@mappings.each_with_index do |(_, value), index|
value = JSON.parse(value) rescue value
value = value.to_s unless value.is_a?(Hash)
if value == '-1'
# Fill blank space, so our indices stay the same
@columns << nil
@name_index = index
# creating a custom option column
elsif value.is_a?(Hash)
new_repository_column = @repository.repository_columns.create!(created_by: @user, name: value['name']+rand(10000).to_s, data_type: "Repository#{value['type']}Value")
@columns << new_repository_column
else
@columns << @repository_columns.where(data_type: Extends::REPOSITORY_IMPORTABLE_TYPES)
.preload(Extends::REPOSITORY_IMPORT_COLUMN_PRELOADS)

View file

@ -38,7 +38,7 @@
<% @import_data.header.each.with_index do |th, index| %>
<th style="min-width: 150px" title="<%= th %>">
<%= f.select("mappings[#{index.to_s}]",
options_from_collection_for_select(@import_data.available_fields,
options_from_collection_for_select(@import_data.available_fields.merge({{name: 'new text option', type: 'Text'}.to_json => "new_text_option"}, {{name: 'new list option', type: 'List'}.to_json => "new_list_option"}),
:first,
:last),
{ include_blank: t('repositories.parse_sheet.do_not_include_column'), hide_label: true },