From 849b269d8734e825e9b1892f7809990a14a0162e Mon Sep 17 00:00:00 2001 From: Mojca Lorber Date: Tue, 13 Jun 2017 16:56:34 +0200 Subject: [PATCH 1/3] fix errors in repo table --- .../repositories/repository_datatable.js | 2 +- app/controllers/repository_rows_controller.rb | 73 ++++++++++--------- 2 files changed, 38 insertions(+), 37 deletions(-) diff --git a/app/assets/javascripts/repositories/repository_datatable.js b/app/assets/javascripts/repositories/repository_datatable.js index 61cff3be0..a1fc47553 100644 --- a/app/assets/javascripts/repositories/repository_datatable.js +++ b/app/assets/javascripts/repositories/repository_datatable.js @@ -670,7 +670,7 @@ function onClickSave() { if (input) { input.closest('.form-group').addClass('has-error'); input.parent().append("" + - val.value[0] + '
'); + val.data[0] + '
'); } }); }); diff --git a/app/controllers/repository_rows_controller.rb b/app/controllers/repository_rows_controller.rb index 2d52bdecc..ac2c4cf92 100644 --- a/app/controllers/repository_rows_controller.rb +++ b/app/controllers/repository_rows_controller.rb @@ -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,30 @@ 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] << { - "#{cell.repository_column.id}": cell_value.errors.messages + "#{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 +94,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,13 +103,13 @@ 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] << { - "#{cell.repository_column_id}": existing.value.errors.messages + "#{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 @@ -126,13 +125,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 @@ -145,24 +144,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 From 1bc46fe0cb9d4f4ed1d40cb06d822b950ab33a76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Zrim=C5=A1ek?= Date: Tue, 13 Jun 2017 18:12:42 +0200 Subject: [PATCH 2/3] Reverted the part of the repository row controller code that didn't needed changes. [SCI-1351] --- app/controllers/repository_rows_controller.rb | 69 +++++++++---------- 1 file changed, 34 insertions(+), 35 deletions(-) diff --git a/app/controllers/repository_rows_controller.rb b/app/controllers/repository_rows_controller.rb index ac2c4cf92..f501167ab 100644 --- a/app/controllers/repository_rows_controller.rb +++ b/app/controllers/repository_rows_controller.rb @@ -21,6 +21,7 @@ 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| @@ -36,30 +37,29 @@ class RepositoryRowsController < ApplicationController repository_column: column } ) - if cell_value.save - record_annotation_notification(record, cell_value.repository_cell) - else + unless cell_value.save 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 - 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 + render json: { id: record.id, + flash: t('repositories.create.success_flash', + record: escape_input(record.name), + repository: escape_input(@repository.name)) }, + status: :ok end end + rescue + respond_to do |format| + format.json { render json: errors, status: :bad_request } + end end def edit @@ -94,6 +94,7 @@ 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| @@ -103,13 +104,13 @@ class RepositoryRowsController < ApplicationController if existing # Cell exists and new value present, so update value existing.value.data = value - if existing.value.save - record_annotation_notification(@record, existing) - else + unless existing.value.save 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 @@ -125,13 +126,13 @@ class RepositoryRowsController < ApplicationController repository_column: column } ) - if value.save - record_annotation_notification(@record, value.repository_cell) - else + unless value.save 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 @@ -144,26 +145,24 @@ class RepositoryRowsController < ApplicationController end end + # Row sucessfully updated, so sending response to client respond_to do |format| format.json do - 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 + render json: { + id: @record.id, + flash: t( + 'repositories.update.success_flash', + record: escape_input(@record.name), + repository: escape_input(@repository.name) + ) + }, + status: :ok end end + rescue + respond_to do |format| + format.json { render json: errors, status: :bad_request } + end end def delete_records From cea6d15d3ed663d1a3237abde3415bd878534d13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Zrim=C5=A1ek?= Date: Tue, 13 Jun 2017 18:15:47 +0200 Subject: [PATCH 3/3] Fixed Hound warning. [SCI-1351] --- app/controllers/repository_rows_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/repository_rows_controller.rb b/app/controllers/repository_rows_controller.rb index f501167ab..69ed6a3cf 100644 --- a/app/controllers/repository_rows_controller.rb +++ b/app/controllers/repository_rows_controller.rb @@ -106,7 +106,8 @@ class RepositoryRowsController < ApplicationController existing.value.data = value unless existing.value.save errors[:repository_cells] << { - "#{existing.repository_column_id}": existing.value.errors.messages + "#{existing.repository_column_id}": + existing.value.errors.messages } raise ActiveRecord::RecordInvalid end