From 0beb64511d5030e37e46bac0016c5f400260c7cd Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Tue, 28 Mar 2023 13:29:02 +0200 Subject: [PATCH] Fix saving of big tables on steps [SCI-8216] --- app/controllers/step_elements/tables_controller.rb | 10 ++++++++-- app/javascript/vue/protocol/step_elements/table.vue | 9 ++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app/controllers/step_elements/tables_controller.rb b/app/controllers/step_elements/tables_controller.rb index 52d426ffe..1a81b1bd4 100644 --- a/app/controllers/step_elements/tables_controller.rb +++ b/app/controllers/step_elements/tables_controller.rb @@ -25,7 +25,13 @@ module StepElements def update ActiveRecord::Base.transaction do - @table.update!(table_params) + @table.assign_attributes(table_params.except(:metadata)) + begin + @table.metadata = JSON.parse(table_params[:metadata]) + rescue JSON::ParserError + @table.metadata = {} + end + @table.save! log_step_activity(:table_edited, { table_name: @table.name }) end @@ -61,7 +67,7 @@ module StepElements private def table_params - params.permit(:name, :contents, metadata: {}) + params.permit(:name, :contents, :metadata) end def load_table diff --git a/app/javascript/vue/protocol/step_elements/table.vue b/app/javascript/vue/protocol/step_elements/table.vue index f4ab3d3f0..47a1636e9 100644 --- a/app/javascript/vue/protocol/step_elements/table.vue +++ b/app/javascript/vue/protocol/step_elements/table.vue @@ -156,9 +156,8 @@ updateTable() { if (this.editingTable == false) return; - let tableData = JSON.stringify({data: this.tableObject.getData()}); - this.element.attributes.orderable.contents = tableData; - this.element.attributes.orderable.metadata = {cells: this.tableObject.getCellsMeta().map( + this.element.attributes.orderable.contents = JSON.stringify({ data: this.tableObject.getData() }); + this.element.attributes.orderable.metadata = JSON.stringify({ cells: this.tableObject.getCellsMeta().map( (x) => { if (x) { return { @@ -169,8 +168,8 @@ } else { return null } - }).filter(e => { return e !== null}) - }; + }).filter(e => { return e !== null }) + }); this.update(); this.editingTable = false; },