fix hound

This commit is contained in:
zmagod 2017-06-21 15:01:55 +02:00
parent f66fb49b56
commit 18fd5b00ba
3 changed files with 27 additions and 34 deletions

View file

@ -197,7 +197,7 @@ class RepositoriesController < ApplicationController
respond_to do |format| respond_to do |format|
unless params[:file] unless params[:file]
repository_response(t("teams.parse_sheet.errors.no_file_selected")) repository_response(t('teams.parse_sheet.errors.no_file_selected'))
return return
end end
begin begin
@ -240,11 +240,10 @@ class RepositoriesController < ApplicationController
render json: {}, status: :ok render json: {}, status: :ok
else else
flash[:alert] = t('repositories.import_records.error_flash', flash[:alert] = t('repositories.import_records.error_flash',
message: status[:errors]) message: status[:errors])
render json: {}, status: :unprocessable_entity render json: {}, status: :unprocessable_entity
end end
end end
end end
end end

View file

@ -71,13 +71,13 @@ class Repository < ActiveRecord::Base
name_index = -1 name_index = -1
nr_of_added = 0 nr_of_added = 0
mappings.each.with_index do |(k, v), i| mappings.each.with_index do |(_k, value), index|
if v == '-1' if value == '-1'
# Fill blank space, so our indices stay the same # Fill blank space, so our indices stay the same
custom_fields << nil custom_fields << nil
name_index = i name_index = index
else else
cf = repository_columns.find_by_id(v) cf = repository_columns.find_by_id(value)
custom_fields << cf custom_fields << cf
end end
end end
@ -91,27 +91,23 @@ class Repository < ActiveRecord::Base
created_by: user, created_by: user,
last_modified_by: user) last_modified_by: user)
if record_row.save next unless record_row.save
sheet.row(i).each.with_index do |value, index| sheet.row(i).each.with_index do |value, index|
if custom_fields[index] if custom_fields[index]
# we're working with CustomField # we're working with CustomField
rep_column = RepositoryTextValue.new( rep_column = RepositoryTextValue.new(
data: value, data: value,
created_by: user, created_by: user,
last_modified_by: user, last_modified_by: user,
repository_cell_attributes: { repository_cell_attributes: {
repository_row: record_row, repository_row: record_row,
repository_column: custom_fields[index] repository_column: custom_fields[index]
} }
) )
error << rep_column.errors.messages unless rep_column.save
if !rep_column.save else
error << rep_column.errors.messages # This custom_field does not exist
end error << { '#{mappings[index]}': 'Does not exists' }
else
# This custom_field does not exist
error << { '#{mappings[index]}': 'Does not exists' }
end
end end
end end
end end

View file

@ -17,11 +17,9 @@ module ImportRepository
private private
def run_import_actions def run_import_actions
@repository.import_records( @repository.import_records(@repository.open_spreadsheet(@temp_file.file),
@repository.open_spreadsheet(@temp_file.file), @mappings,
@mappings, @user)
@user
)
end end
def run_checks def run_checks
@ -32,7 +30,7 @@ module ImportRepository
I18n.t('repositories.import_records.error_message.no_data_to_parse') I18n.t('repositories.import_records.error_message.no_data_to_parse')
} }
end end
unless @mappings.has_value?('-1') unless @mappings.value?('-1')
return { return {
status: :error, status: :error,
errors: errors: