diff --git a/Gemfile b/Gemfile index 9e57b7d02..ecbe52f2f 100644 --- a/Gemfile +++ b/Gemfile @@ -75,8 +75,6 @@ gem 'aasm' gem 'browser' -gem 'nokogiri-diff', '~> 0.2.0' # for comparing xml documents - # collections metadata preview # run this command to work from a local copy of the gem's repo # bundle config local.cmr_metadata_preview /path/to/local/git/repository diff --git a/app/assets/javascripts/change_current_provider.coffee b/app/assets/javascripts/change_current_provider.coffee index 54255c96e..18caae746 100644 --- a/app/assets/javascripts/change_current_provider.coffee +++ b/app/assets/javascripts/change_current_provider.coffee @@ -4,6 +4,9 @@ $(document).ready -> overlay: 0.6 closeButton: '.modal-close' + $('a.loss-report').on 'click', (element) -> + $('#loss-report-modal').hide() + # Handle not-current-provider-modal $('a.not-current-provider').on 'click', (element) -> provider = $(element.target).data('provider') @@ -106,7 +109,7 @@ $(document).ready -> # Click the link that the user needs if linkType == 'delete-collection' && $('.collection-granule-count').text() != 'Granules (0)' $('#display-granules-modal').click() - else + else $(link)[0].click() # Change current provider diff --git a/app/assets/stylesheets/components/_buttons.scss b/app/assets/stylesheets/components/_buttons.scss index aa7db57f0..10708a3be 100644 --- a/app/assets/stylesheets/components/_buttons.scss +++ b/app/assets/stylesheets/components/_buttons.scss @@ -26,7 +26,23 @@ &:hover { background-color: darken($red, 6%); } -} +} + +.eui-btn--steel-blue { + @extend .eui-btn; + + background-color: $steel-blue; + color: $white !important; + padding: 0.5em 1em; + + &:hover { + background-color: darken($steel-blue, 6%); + } +} + +.button-spacing { + margin-right: 0.625em; +} button { &:disabled { @@ -36,4 +52,4 @@ button { background-color: lighten($dolphin-grey, 10%); } } -} \ No newline at end of file +} diff --git a/app/assets/stylesheets/components/_search.scss b/app/assets/stylesheets/components/_search.scss index 09b7679c3..04071974b 100644 --- a/app/assets/stylesheets/components/_search.scss +++ b/app/assets/stylesheets/components/_search.scss @@ -64,12 +64,12 @@ } } } - .search-dropdown-short { /* smaller dropdown if radio buttons are hidden in DMMT */ + .search-dropdown-short { /* smaller dropdown if radio buttons are hidden in DMMT */ width: 100%; height: 45px; } - - .search-dropdown-wide { /* wider dropdown if UMM-T is enabled */ + + .search-dropdown-wide { /* wider dropdown if UMM-T is enabled */ right: 0px; // causes dropdown width to extend to the left max-width: 440px; } @@ -79,12 +79,12 @@ border-right: 1px solid $dolphin-grey; border-bottom: 1px solid $steel-blue; } - + #search-submit-button { text-align: left; width: 172px; // 11.92em } - + .search-field-wide { width: 241px; } diff --git a/app/controllers/collections_controller.rb b/app/controllers/collections_controller.rb index 379c13641..77ea18871 100644 --- a/app/controllers/collections_controller.rb +++ b/app/controllers/collections_controller.rb @@ -120,7 +120,7 @@ def loss_report # When a user wants to use MMT to edit metadata that currently exists in a non-UMM form, # it's important that they're able to see if any data loss occurs in the translation to umm. # This method is needed to reference the appropriate helper and view for the lossiness report. - # If translated_collections contains an :error field, the error message will appear. + # If translated_collections contains an :error field, the error message will appear. # this checks the 'hide_items' url parameter that is can be manually added. Its primary use is for developers # that need to debug using the text_output diff --git a/app/views/collections/show.html.erb b/app/views/collections/show.html.erb index 208a3c432..23b2956b5 100644 --- a/app/views/collections/show.html.erb +++ b/app/views/collections/show.html.erb @@ -57,10 +57,15 @@

- <% if current_provider?(@provider_id) %> - <%= link_to 'Edit Collection Record', edit_collection_path(revision_id: @revision_id), class: 'eui-btn--link bar-after' %> - <% elsif available_provider?(@provider_id) %> - <%= link_to 'Edit Collection Record', '#not-current-provider-modal', class: 'display-modal not-current-provider eui-btn--link bar-after', data: { provider: @provider_id, record_action: 'edit-collection' } %> + <% native_format = @revisions.first.fetch('meta', {})['format'] %> + <% if !native_format.include?('umm') && (current_provider?(@provider_id) || available_provider?(@provider_id)) %> + <%= link_to 'Edit Collection Record', '#loss-report-modal', class: 'display-modal eui-btn--link bar-after' %> + <% else %> + <% if current_provider?(@provider_id) %> + <%= link_to 'Edit Collection Record', edit_collection_path(revision_id: @revision_id), class: 'eui-btn--link bar-after' %> + <% elsif available_provider?(@provider_id) %> + <%= link_to 'Edit Collection Record', '#not-current-provider-modal', class: 'display-modal not-current-provider eui-btn--link bar-after', data: { provider: @provider_id, record_action: 'edit-collection' } %> + <% end %> <% end %> <% if current_provider?(@provider_id) %> @@ -112,12 +117,19 @@ draft: @draft, draft_id: @draft.try(:id) } } %> + <%= render partial: 'shared/loss_report_modal', locals: { + options: { + provider_id: @provider_id, + native_format: native_format, + concept_id: @concept_id, + revision_id: @revision_id } + } %>

class="modal-close float-r"> -

This collection has <%= @num_granules %> associated <%= 'granule'.pluralize(@num_granules) %>.

-

Deleting this collection will delete all associated granules.

+

This collection has <%= @num_granules %> associated <%= 'granule'.pluralize(@num_granules) %>.

+

Deleting this collection will delete all associated granules.

Please confirm that you wish to continue by entering '<%= CollectionsHelper::DELETE_CONFIRMATION_TEXT %>' below.

<%= form_tag(collection_path, method: :delete, class: 'granules-confirmation-form') do %> <%= text_field_tag('confirmation-text', nil, class: 'full-width') %> diff --git a/app/views/shared/_loss_report_modal.html.erb b/app/views/shared/_loss_report_modal.html.erb new file mode 100644 index 000000000..782090c89 --- /dev/null +++ b/app/views/shared/_loss_report_modal.html.erb @@ -0,0 +1,18 @@ +
+ +
+

Conversion to UMM Format Required

+

The native format of this collection is <%= options[:native_format].split('/').last.gsub('+xml','').upcase %>. Editing this record using the MMT will convert it to UMM-JSON, which may result in data loss. Select 'View Loss Report' to see how the conversion will affect this record.

+

+ <%= link_to 'View Loss Report', loss_report_collections_path(options[:concept_id], format: 'json'), class: 'eui-btn eui-btn--steel-blue', target: :_blank %> + + <% if current_provider?(options[:provider_id]) %> + <%= link_to 'Edit Collection', edit_collection_path(revision_id: options[:revision_id]), class: 'eui-btn--blue modal-close button-spacing' %> + <% elsif available_provider?(options[:provider_id]) %> + <%= link_to 'Edit Collection', '#not-current-provider-modal', class: 'eui-btn--blue loss-report button-spacing display-modal not-current-provider', data: { provider: options[:provider_id], record_action: 'edit-collection' } %> + <% end %> + + <%= link_to 'Cancel', 'javascript:void(0);', class: 'eui-btn modal-close' %> +

+
+
diff --git a/spec/features/collection_drafts/create_collection_draft_from_dif10_collection_spec.rb b/spec/features/collection_drafts/create_collection_draft_from_dif10_collection_spec.rb index 5d7796289..6ee0cccf9 100644 --- a/spec/features/collection_drafts/create_collection_draft_from_dif10_collection_spec.rb +++ b/spec/features/collection_drafts/create_collection_draft_from_dif10_collection_spec.rb @@ -29,6 +29,10 @@ before do click_on 'Edit Collection Record' + within '#loss-report-modal' do + click_on 'Edit Collection' + end + within '.metadata' do click_on 'Spatial Information', match: :first end diff --git a/spec/features/collections/loss_report_modal_spec.rb b/spec/features/collections/loss_report_modal_spec.rb new file mode 100644 index 000000000..777291160 --- /dev/null +++ b/spec/features/collections/loss_report_modal_spec.rb @@ -0,0 +1,127 @@ + +describe 'loss report modal', js: true do + # this is an echo collection (SEDAC provider) + let(:cmr_response) { cmr_client.get_collections({'EntryTitle': 'Anthropogenic Biomes of the World, Version 2: 1700'}) } + let(:concept_id) { cmr_response.body.dig('items',0,'meta','concept-id') } + + context 'when user clicks Edit Collection Record for a non-UMM collection' do + context 'when provider context does not need to be changed' do + + before do + login(provider: 'SEDAC', providers: %w[SEDAC]) + visit collection_path(concept_id) + click_on 'Edit Collection Record' + end + + it 'displays the loss-report-modal with correct links' do + within '#loss-report-modal' do + expect(page).to have_content("The native format of this collection is ECHO10. Editing this record using the MMT will convert it to UMM-JSON, which may result in data loss. Select 'View Loss Report' to see how the conversion will affect this record.") + expect(page).to have_link('View Loss Report', href: loss_report_collections_path(concept_id, format: 'json')) + expect(page).to have_link('Edit Collection', href: edit_collection_path(id: concept_id)) + expect(page).to have_link('Cancel', href: 'javascript:void(0);') + end + end + + context 'when the "Edit Collection" button is clicked' do + before do + within '#loss-report-modal' do + click_on 'Edit Collection' + end + end + it 'opens collection draft without displaying the not-current-provider-modal' do + expect(page).to have_content('Metadata Fields') + expect(page).to have_content('Collection Information') + expect(page).to have_content('Acquisition Information') + expect(page).to have_content('Data Contacts') + expect(page).to have_content('Metadata Information') + expect(page).to have_no_css('#not-current-provider-modal') + end + end + + context 'when the "View Loss Report" button is clicked' do + before do + within '#loss-report-modal' do + click_on 'View Loss Report' + end + end + it 'does not close the loss-report-modal and does not open the not-current-provider-modal' do + expect(page).to have_no_css('#not-current-provider-modal') + within '#loss-report-modal' do + expect(page).to have_content("The native format of this collection is ECHO10. Editing this record using the MMT will convert it to UMM-JSON, which may result in data loss. Select 'View Loss Report' to see how the conversion will affect this record.") + end + end + end + + context 'when the "Cancel" button is clicked' do + before do + within '#loss-report-modal' do + click_on 'Cancel' + end + end + it 'closes loss-report-modal and does not open the not-current-provider-modal' do + expect(page).to have_no_content('Metadata Preview') + expect(page).to have_link('Edit Collection Record', href: '#loss-report-modal') + expect(page).to have_no_css('#not-current-provider-modal') + expect(page).to have_no_css('#loss-report-modal') + end + end + end + + context 'when provider context needs to be changed and the required provider context is available' do + + before do + login(provider: 'LARC', providers: %w[SEDAC LARC]) + visit collection_path(concept_id) + click_on 'Edit Collection Record' + end + + it 'displays the loss-report-modal with correct links' do + within '#loss-report-modal' do + expect(page).to have_content("The native format of this collection is ECHO10. Editing this record using the MMT will convert it to UMM-JSON, which may result in data loss. Select 'View Loss Report' to see how the conversion will affect this record.") + expect(page).to have_link('View Loss Report', href: loss_report_collections_path(concept_id, format: 'json')) + expect(page).to have_link('Edit Collection', href: '#not-current-provider-modal') + expect(page).to have_link('Cancel', href: 'javascript:void(0);') + end + end + + context 'when the "Edit Collection" button is clicked' do + before do + within '#loss-report-modal' do + click_on 'Edit Collection' + end + end + it 'closes loss-report-modal and opens the not-current-provider-modal' do + expect(page).to have_no_css('#loss-report-modal') + within '#not-current-provider-modal' do + expect(page).to have_link('Yes', href: '#') + expect(page).to have_link('No', href: 'javascript:void(0)') + end + end + end + + context 'when the "View Loss Report" button is clicked' do + before do + within '#loss-report-modal' do + click_on 'View Loss Report' + end + end + it 'does not close the loss-report-modal and does not open the not-current-provider-modal' do + expect(page).to have_content("The native format of this collection is ECHO10. Editing this record using the MMT will convert it to UMM-JSON, which may result in data loss. Select 'View Loss Report' to see how the conversion will affect this record.") + expect(page).to have_no_css('#not-current-provider-modal') + end + end + + context 'when the "Cancel" button is clicked' do + before do + within '#loss-report-modal' do + click_on 'Cancel' + end + end + it 'closes loss-report-modal and does not open the not-current-provider-modal' do + expect(page).to have_no_css('#not-current-provider-modal') + expect(page).to have_no_css('#loss-report-modal') + end + end + end + end +end