Skip to content

Commit

Permalink
submit the generated json to create the EMTs #2134
Browse files Browse the repository at this point in the history
  • Loading branch information
stuzart committed Feb 10, 2025
1 parent 9af984a commit 3a2b945
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 5 deletions.
11 changes: 10 additions & 1 deletion app/controllers/extended_metadata_types_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,17 @@ def create_from_ttl
respond_to do |format|
format.html
end
end


def submit_jsons
jsons = params['emt_jsons']
jsons.each do |json|
io = StringIO.new(json)
extended_metadata_type = Seek::ExtendedMetadataType::ExtendedMetadataTypeExtractor.extract_extended_metadata_type(io)
extended_metadata_type.save!
end
flash[:notice] = "#{jsons.length} #{t('extended_metadata_type').pluralize} were successfully created."
redirect_to administer_extended_metadata_types_path
end

def new
Expand Down
11 changes: 11 additions & 0 deletions app/views/extended_metadata_types/create_from_ttl.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,15 @@

<%= render partial: 'preview_json', locals: {json: json} %>

<% end %>

<%= form_tag submit_jsons_extended_metadata_types_path, method: "post" do %>
<% @jsons.each do |json| %>
<%= hidden_field_tag 'emt_jsons[]', JSON.generate(json) %>
<% end %>

<%= submit_tag('Create', class:'btn btn-primary') %>
or
<%= cancel_button administer_extended_metadata_types_path %>

<% end %>
7 changes: 3 additions & 4 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ en:
placeholder: "Placeholder"
collection: &collection "Collection"

observation_unit: &observation_unit "Observation Unit"
sample: &sample "Sample"
sample_type: &sample_type "Sample type"
extended_metadata_type: &extended_metadata_type "Extended Metadata Type"
template: &template "Template"
strain: &strain "Strain"
scale: "Scale"
Expand Down Expand Up @@ -241,6 +241,7 @@ en:
sample_type: *sample_type
strain: *strain
organism: *organism
extended_metadata_type: *extended_metadata_type
attributes:
person:
title: "Full name"
Expand Down Expand Up @@ -344,6 +345,4 @@ you can choose to have a %{project} linked to a site managed %{programme} instea

tooltips:
batch_permission_changes_button: "You can change the sharing policy and permissions for your items as a batch. A preview of selected items will be given before you choose new permissions for them."
publish_your_items_button: "Publish your owned items as a batch. A preview will be given before publishing"

extended_metadata_type: "Extended Metadata Type"
publish_your_items_button: "Publish your owned items as a batch. A preview will be given before publishing"
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@
get :administer
post :create
post :create_from_ttl
post :submit_jsons
end
member do
put :administer_update
Expand Down
13 changes: 13 additions & 0 deletions test/functional/extended_metadata_types_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -309,4 +309,17 @@ class ExtendedMetadataTypesControllerTest < ActionController::TestCase
assert_select 'table.extended-metadata-type-attributes tbody tr', count: 10
end

test 'submit jsons' do
person_emt = FactoryBot.create(:role_name_extended_metadata_type)
json1 = file_fixture('extended_metadata_type/valid_simple_emt.json').read
json2 = file_fixture('extended_metadata_type/valid_emt_with_linked_emt.json').read.gsub('PERSON_EMT_ID', person_emt.id.to_s)
person = FactoryBot.create(:admin)
login_as(person)
assert_difference('ExtendedMetadataType.count', 2) do
post :submit_jsons, params: { emt_jsons: [json1, json2] }
end
assert_redirected_to administer_extended_metadata_types_path
assert_equal '2 Extended Metadata Types were successfully created.', flash[:notice]
end

end

0 comments on commit 3a2b945

Please sign in to comment.