Merge pull request #683 from mlorb/ml_sci_1351_v2

Fix multiple errors handling on fields in repositories tables [SCI-1351]
This commit is contained in:
mlorb 2017-06-14 13:16:35 +02:00 committed by GitHub
commit 385c197077

View file

@ -21,7 +21,6 @@ class RepositoryRowsController < ApplicationController
record.name = record_params[:name] unless record_params[:name].blank?
unless record.save
errors[:default_fields] = record.errors.messages
raise ActiveRecord::RecordInvalid
end
if params[:repository_cells]
params[:repository_cells].each do |key, value|
@ -37,29 +36,31 @@ class RepositoryRowsController < ApplicationController
repository_column: column
}
)
unless cell_value.save
if cell_value.save
record_annotation_notification(record, cell_value.repository_cell)
else
errors[:repository_cells] << {
"#{column.id}": cell_value.errors.messages
}
raise ActiveRecord::RecordInvalid
end
record_annotation_notification(record, cell_value.repository_cell)
end
end
end
respond_to do |format|
format.json do
render json: { id: record.id,
flash: t('repositories.create.success_flash',
record: escape_input(record.name),
repository: escape_input(@repository.name)) },
status: :ok
if errors[:default_fields].empty? && errors[:repository_cells].empty?
render json: { id: record.id,
flash: t('repositories.create.success_flash',
record: escape_input(record.name),
repository: escape_input(@repository.name)) },
status: :ok
else
render json: errors,
status: :bad_request
end
end
end
rescue
respond_to do |format|
format.json { render json: errors, status: :bad_request }
end
end
def edit
@ -94,7 +95,6 @@ class RepositoryRowsController < ApplicationController
@record.name = record_params[:name].blank? ? nil : record_params[:name]
unless @record.save
errors[:default_fields] = @record.errors.messages
raise ActiveRecord::RecordInvalid
end
if params[:repository_cells]
params[:repository_cells].each do |key, value|
@ -104,14 +104,14 @@ class RepositoryRowsController < ApplicationController
if existing
# Cell exists and new value present, so update value
existing.value.data = value
unless existing.value.save
if existing.value.save
record_annotation_notification(@record, existing)
else
errors[:repository_cells] << {
"#{existing.repository_column_id}":
existing.value.errors.messages
}
raise ActiveRecord::RecordInvalid
end
record_annotation_notification(@record, existing)
else
# Looks like it is a new cell, so we need to create new value, cell
# will be created automatically
@ -127,13 +127,13 @@ class RepositoryRowsController < ApplicationController
repository_column: column
}
)
unless value.save
if value.save
record_annotation_notification(@record, value.repository_cell)
else
errors[:repository_cells] << {
"#{cell.repository_column_id}": value.errors.messages
}
raise ActiveRecord::RecordInvalid
end
record_annotation_notification(@record, value.repository_cell)
end
end
# Clean up empty cells, not present in updated record
@ -146,24 +146,26 @@ class RepositoryRowsController < ApplicationController
end
end
# Row sucessfully updated, so sending response to client
respond_to do |format|
format.json do
render json: {
id: @record.id,
flash: t(
'repositories.update.success_flash',
record: escape_input(@record.name),
repository: escape_input(@repository.name)
)
},
status: :ok
if errors[:default_fields].empty? && errors[:repository_cells].empty?
# Row sucessfully updated, so sending response to client
render json: {
id: @record.id,
flash: t(
'repositories.update.success_flash',
record: escape_input(@record.name),
repository: escape_input(@repository.name)
)
},
status: :ok
else
# Errors
render json: errors,
status: :bad_request
end
end
end
rescue
respond_to do |format|
format.json { render json: errors, status: :bad_request }
end
end
def delete_records