From df8579d52f7d72110c00d37710b83ae314ad5184 Mon Sep 17 00:00:00 2001 From: Anton Date: Fri, 17 Feb 2023 14:50:45 +0100 Subject: [PATCH] Add step table metadata during import/export and copy [SCI-7948] --- app/assets/javascripts/protocols/import_export/import.js | 1 + app/models/table.rb | 1 + app/utilities/protocols_exporter_v2.rb | 1 + app/utilities/protocols_importer_v2.rb | 1 + 4 files changed, 4 insertions(+) diff --git a/app/assets/javascripts/protocols/import_export/import.js b/app/assets/javascripts/protocols/import_export/import.js index 4cb415f01..685583b40 100644 --- a/app/assets/javascripts/protocols/import_export/import.js +++ b/app/assets/javascripts/protocols/import_export/import.js @@ -576,6 +576,7 @@ function importProtocolFromFile( var contents = tableNode.children('contents').text(); json.id = tableNode.attr('id'); json.name = tableNode.children('name').text(); + json.metadata = tableNode.children('metadata').text(); contents = hex2a(contents); contents = window.btoa(contents); json.contents = contents; diff --git a/app/models/table.rb b/app/models/table.rb index c6116a15e..b8395bb00 100644 --- a/app/models/table.rb +++ b/app/models/table.rb @@ -137,6 +137,7 @@ class Table < ApplicationRecord contents: contents.encode('UTF-8', 'UTF-8'), team: step.protocol.team, created_by: user, + metadata: metadata, last_modified_by: user ) diff --git a/app/utilities/protocols_exporter_v2.rb b/app/utilities/protocols_exporter_v2.rb index 0213f65a6..778189095 100644 --- a/app/utilities/protocols_exporter_v2.rb +++ b/app/utilities/protocols_exporter_v2.rb @@ -100,6 +100,7 @@ module ProtocolsExporterV2 "\n" \ "#{table.name}\n" \ "#{table.contents.unpack1('H*')}\n" \ + "#{table.metadata.to_json}\n" \ "\n" end diff --git a/app/utilities/protocols_importer_v2.rb b/app/utilities/protocols_importer_v2.rb index fefa99724..200a4feef 100644 --- a/app/utilities/protocols_importer_v2.rb +++ b/app/utilities/protocols_importer_v2.rb @@ -144,6 +144,7 @@ class ProtocolsImporterV2 table: Table.new( name: params['name'], contents: Base64.decode64(params['contents']), + metadata: JSON.parse(params['metadata'] || '{}'), created_by: @user, last_modified_by: @user, team: @team