Skip to content

Commit 994cbb1

Browse files
authored
MMT-2230 (#608)
1 parent 5e6a0a8 commit 994cbb1

File tree

10 files changed

+333
-20
lines changed

10 files changed

+333
-20
lines changed

app/assets/javascripts/change_current_provider.coffee

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ $(document).ready ->
7474
"Managing this service's collection associations"
7575
when 'edit-tool'
7676
'Editing this tool'
77+
when 'clone-tool'
78+
'Cloning this tool'
7779

7880
$link.data('type', action)
7981
$modal.find('span.provider').text(provider)

app/controllers/tools_controller.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
class ToolsController < BasePublishedRecordController
33
include ManageMetadataHelper
44

5-
before_action :set_tool, only: [:show, :edit, :revisions] #, :clone, :destroy, :revert, :download_json]
6-
before_action :set_schema, only: [:show, :edit] #, :clone, :destroy]
5+
before_action :set_tool, only: [:show, :edit, :clone, :revisions] #, :destroy, :revert, :download_json]
6+
before_action :set_schema, only: [:show, :edit, :clone] #, :destroy]
77
before_action :ensure_supported_version, only: [:show, :edit]
8-
before_action :ensure_correct_provider, only: [:edit] #, :clone, :destroy]
8+
before_action :ensure_correct_provider, only: [:edit, :clone] #, :destroy]
99
before_action :set_preview, only: [:show]
1010

1111
# If clone is not defined like this performing the clone action leads to a `action not found error`

app/helpers/tools_helper.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module ToolsHelper
2+
def render_change_provider_tool_action_link(tool_action, concept_id, revision_id = nil)
3+
case tool_action
4+
when 'edit'
5+
link_to('Edit Service', edit_tool_path(concept_id, revision_id: revision_id), class: 'is-invisible', id: 'change-provider-tool-edit')
6+
when 'clone'
7+
link_to('Clone Service', clone_tool_path(concept_id, revision_id: revision_id), class: 'is-invisible', id: 'change-provider-tool-clone')
8+
when 'delete'
9+
link_to('Delete Service', tool_path(concept_id), method: :delete, class: 'is-invisible', id: 'change-provider-tool-delete')
10+
end
11+
end
12+
end

app/models/tool_draft.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ def create_from_tool(tool, user, native_id)
1515
draft = self.find_or_initialize_by(native_id: native_id)
1616
draft.entry_title = tool['LongName']
1717
draft.short_name = tool['Name']
18-
# else
19-
# # Cloned Record
20-
# draft = self.new
21-
# tool.delete('Name')
22-
# tool.delete('LongName')
18+
else
19+
# Cloned Record
20+
draft = self.new
21+
tool.delete('Name')
22+
tool.delete('LongName')
2323
end
2424

2525
draft.set_user_and_provider(user)

app/views/shared/_not_current_provider_modal.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<%= link_to 'Yes', service_collection_associations_path(options[:concept_id]), class: 'eui-btn--blue spinner is-invisible', id: 'not-current-provider-manage-service-associations-link' %>
3434
<% elsif options[:tool] %>
3535
<%= link_to 'Yes', edit_tool_path(options[:concept_id], revision_id: options[:revision_id]), class: 'eui-btn--blue spinner is-invisible', id: 'not-current-provider-edit-tool-link' %>
36-
<%#= link_to 'Yes', clone_tool_path(options[:concept_id], revision_id: options[:revision_id]), class: 'eui-btn--blue spinner is-invisible', id: 'not-current-provider-clone-tool-link' %>
36+
<%= link_to 'Yes', clone_tool_path(options[:concept_id], revision_id: options[:revision_id]), class: 'eui-btn--blue spinner is-invisible', id: 'not-current-provider-clone-tool-link' %>
3737
<%#= link_to 'Yes', tool_path(options[:concept_id]), method: :delete, class: 'eui-btn--blue spinner is-invisible', id: 'not-current-provider-delete-tool-link' %>
3838
<% end %>
3939

app/views/tools/show.html.erb

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@
2323
"#", id: "change-current-provider-banner-link",
2424
data: { "provider": @provider_id, action_link: "change-provider-tool-#{@record_action}" }) %>
2525
</p>
26-
<%# TODO: this method does not exist yet. It should be created and used when %>
27-
<%# additional actions are added to published Tool records %>
28-
<%#= render_change_provider_tool_action_link(@record_action, @concept_id, @revision_id) %>
26+
<%= render_change_provider_tool_action_link(@record_action, @concept_id, @revision_id) %>
2927
</div>
3028
<% end %>
3129

@@ -94,14 +92,11 @@
9492
<% end %>
9593
<% end %>
9694

97-
<%# TODO: All links commented out and disabled links added for MMT-2238 %>
98-
<%# links should be re-enabled with the appropriate ticket %>
99-
<%= link_to 'Clone Tool Record', '#', class: 'eui-btn--link bar-after disabled' %>
100-
<%# if current_provider?(@provider_id) %>
101-
<%#= link_to 'Clone Tool Record', clone_tool_path(revision_id: @revision_id), class: 'eui-btn--link bar-after' %>
102-
<%# elsif available_provider?(@provider_id) %>
103-
<%#= link_to 'Clone Tool Record', '#not-current-provider-modal', class: 'display-modal not-current-provider eui-btn--link bar-after', data: { 'provider': @provider_id, record_action: 'clone-tool' } %>
104-
<%# end %>
95+
<% if current_provider?(@provider_id) %>
96+
<%= link_to 'Clone Tool Record', clone_tool_path(revision_id: @revision_id), class: 'eui-btn--link bar-after' %>
97+
<% elsif available_provider?(@provider_id) %>
98+
<%= link_to 'Clone Tool Record', '#not-current-provider-modal', class: 'display-modal not-current-provider eui-btn--link bar-after', data: { 'provider': @provider_id, record_action: 'clone-tool' } %>
99+
<% end %>
105100

106101
<%= link_to 'Download JSON', '#', class: 'eui-btn--link disabled' %>
107102
<%#= link_to 'Download JSON', download_json_tool_path(@concept_id, revision_id: @revision_id), class: 'eui-btn--link', target: '_blank' %>

config/locales/en.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ en:
198198
flash:
199199
success: 'Tool Draft Published Successfully!'
200200
error: 'Tool Draft was not published successfully'
201+
clone:
202+
flash:
203+
notice: 'Records must have a unique Name and Long Name within a provider. Click here to enter a new Name and Long Name.'
201204
collection_associations:
202205
destroy:
203206
flash:

config/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
get '/services/:id/download_json(/:revision_id)' => 'services#download_json', as: 'download_json_service'
105105

106106
resources :tools, only: [:show, :create, :edit]
107+
get '/tools/:id/clone' => 'tools#clone', as: 'clone_tool'
107108
get '/tools/:id/revisions' => 'tools#revisions', as: 'tool_revisions'
108109

109110
resources :variable_drafts, controller: 'variable_drafts', draft_type: 'VariableDraft' do
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
describe 'Creating a tool draft from cloning a tool', reset_provider: true, js: true do
2+
before :all do
3+
@ingest_response, _concept_response, @native_id = publish_tool_draft
4+
end
5+
6+
after :all do
7+
delete_response = cmr_client.delete_tool('MMT_2', @native_id, 'token')
8+
9+
raise unless delete_response.success?
10+
end
11+
12+
context 'when cloning a published tool' do
13+
before do
14+
login
15+
16+
visit tool_path(@ingest_response['concept-id'])
17+
18+
click_on 'Clone Tool Record'
19+
end
20+
21+
it 'displays the draft preview page' do
22+
within '.eui-breadcrumbs' do
23+
expect(page).to have_content('Tool Drafts')
24+
end
25+
26+
expect(page).to have_content('Publish Tool Draft')
27+
expect(page).to have_content('Delete Tool Draft')
28+
expect(page).to have_content('Metadata Fields')
29+
expect(page).to have_content('Tool Information')
30+
end
31+
32+
it 'removes the Name and Long Name from the metadata' do
33+
within '#tool_draft_draft_name_preview' do
34+
expect(page).to have_css('p', text: 'No value for Name provided.')
35+
end
36+
37+
within '#tool_draft_draft_long_name_preview' do
38+
expect(page).to have_css('p', text: 'No value for Long Name provided.')
39+
end
40+
end
41+
42+
it 'creates a new native id for the draft' do
43+
draft = ToolDraft.last
44+
expect(draft.native_id).to eq("mmt_tool_#{draft.id}")
45+
end
46+
47+
it 'displays a message that the draft needs a unique Name' do
48+
expect(page).to have_content('Records must have a unique Name and Long Name within a provider. Click here to enter a new Name and Long Name.')
49+
end
50+
51+
context 'when clicking the banner message to enter a new Name' do
52+
before do
53+
click_on 'Click here to enter a new Name and Long Name.'
54+
end
55+
56+
it 'displays the empty Name and Long Name fields' do
57+
expect(page).to have_field('Name', with: '')
58+
expect(page).to have_field('Long Name', with: '')
59+
end
60+
end
61+
end
62+
end

0 commit comments

Comments
 (0)