Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/assets/javascripts/change_current_provider.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ $(document).ready ->
"Managing this service's collection associations"
when 'edit-tool'
'Editing this tool'
when 'clone-tool'
'Cloning this tool'

$link.data('type', action)
$modal.find('span.provider').text(provider)
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/tools_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
class ToolsController < BasePublishedRecordController
include ManageMetadataHelper

before_action :set_tool, only: [:show, :edit, :revisions] #, :clone, :destroy, :revert, :download_json]
before_action :set_schema, only: [:show, :edit] #, :clone, :destroy]
before_action :set_tool, only: [:show, :edit, :clone, :revisions] #, :destroy, :revert, :download_json]
before_action :set_schema, only: [:show, :edit, :clone] #, :destroy]
before_action :ensure_supported_version, only: [:show, :edit]
before_action :ensure_correct_provider, only: [:edit] #, :clone, :destroy]
before_action :ensure_correct_provider, only: [:edit, :clone] #, :destroy]
before_action :set_preview, only: [:show]

# If clone is not defined like this performing the clone action leads to a `action not found error`
Expand Down
12 changes: 12 additions & 0 deletions app/helpers/tools_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module ToolsHelper
def render_change_provider_tool_action_link(tool_action, concept_id, revision_id = nil)
case tool_action
when 'edit'
link_to('Edit Service', edit_tool_path(concept_id, revision_id: revision_id), class: 'is-invisible', id: 'change-provider-tool-edit')
when 'clone'
link_to('Clone Service', clone_tool_path(concept_id, revision_id: revision_id), class: 'is-invisible', id: 'change-provider-tool-clone')
when 'delete'
link_to('Delete Service', tool_path(concept_id), method: :delete, class: 'is-invisible', id: 'change-provider-tool-delete')
end
end
end
10 changes: 5 additions & 5 deletions app/models/tool_draft.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ def create_from_tool(tool, user, native_id)
draft = self.find_or_initialize_by(native_id: native_id)
draft.entry_title = tool['LongName']
draft.short_name = tool['Name']
# else
# # Cloned Record
# draft = self.new
# tool.delete('Name')
# tool.delete('LongName')
else
# Cloned Record
draft = self.new
tool.delete('Name')
tool.delete('LongName')
end

draft.set_user_and_provider(user)
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/_not_current_provider_modal.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<%= 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' %>
<% elsif options[:tool] %>
<%= 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' %>
<%#= 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' %>
<%= 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' %>
<%#= link_to 'Yes', tool_path(options[:concept_id]), method: :delete, class: 'eui-btn--blue spinner is-invisible', id: 'not-current-provider-delete-tool-link' %>
<% end %>

Expand Down
17 changes: 6 additions & 11 deletions app/views/tools/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
"#", id: "change-current-provider-banner-link",
data: { "provider": @provider_id, action_link: "change-provider-tool-#{@record_action}" }) %>
</p>
<%# TODO: this method does not exist yet. It should be created and used when %>
<%# additional actions are added to published Tool records %>
<%#= render_change_provider_tool_action_link(@record_action, @concept_id, @revision_id) %>
<%= render_change_provider_tool_action_link(@record_action, @concept_id, @revision_id) %>
</div>
<% end %>

Expand Down Expand Up @@ -94,14 +92,11 @@
<% end %>
<% end %>

<%# TODO: All links commented out and disabled links added for MMT-2238 %>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If not all the links are being enabled, should we keep the comments and possibly move them down to be near links that are still disabled?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving it around was going to cause more merge conflicts, so I decided to remove it. Especially since I expect to have all of these links working by the end of the week.

<%# links should be re-enabled with the appropriate ticket %>
<%= link_to 'Clone Tool Record', '#', class: 'eui-btn--link bar-after disabled' %>
<%# if current_provider?(@provider_id) %>
<%#= link_to 'Clone Tool Record', clone_tool_path(revision_id: @revision_id), class: 'eui-btn--link bar-after' %>
<%# elsif available_provider?(@provider_id) %>
<%#= 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' } %>
<%# end %>
<% if current_provider?(@provider_id) %>
<%= link_to 'Clone Tool Record', clone_tool_path(revision_id: @revision_id), class: 'eui-btn--link bar-after' %>
<% elsif available_provider?(@provider_id) %>
<%= 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' } %>
<% end %>

<%= link_to 'Download JSON', '#', class: 'eui-btn--link disabled' %>
<%#= link_to 'Download JSON', download_json_tool_path(@concept_id, revision_id: @revision_id), class: 'eui-btn--link', target: '_blank' %>
Expand Down
3 changes: 3 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ en:
flash:
success: 'Tool Draft Published Successfully!'
error: 'Tool Draft was not published successfully'
clone:
flash:
notice: 'Records must have a unique Name and Long Name within a provider. Click here to enter a new Name and Long Name.'
collection_associations:
destroy:
flash:
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
get '/services/:id/download_json(/:revision_id)' => 'services#download_json', as: 'download_json_service'

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

resources :variable_drafts, controller: 'variable_drafts', draft_type: 'VariableDraft' do
Expand Down
62 changes: 62 additions & 0 deletions spec/features/tool_drafts/create_tool_draft_from_cloning_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
describe 'Creating a tool draft from cloning a tool', reset_provider: true, js: true do
before :all do
@ingest_response, _concept_response, @native_id = publish_tool_draft
end

after :all do
delete_response = cmr_client.delete_tool('MMT_2', @native_id, 'token')

raise unless delete_response.success?
end

context 'when cloning a published tool' do
before do
login

visit tool_path(@ingest_response['concept-id'])

click_on 'Clone Tool Record'
end

it 'displays the draft preview page' do
within '.eui-breadcrumbs' do
expect(page).to have_content('Tool Drafts')
end

expect(page).to have_content('Publish Tool Draft')
expect(page).to have_content('Delete Tool Draft')
expect(page).to have_content('Metadata Fields')
expect(page).to have_content('Tool Information')
end

it 'removes the Name and Long Name from the metadata' do
within '#tool_draft_draft_name_preview' do
expect(page).to have_css('p', text: 'No value for Name provided.')
end

within '#tool_draft_draft_long_name_preview' do
expect(page).to have_css('p', text: 'No value for Long Name provided.')
end
end

it 'creates a new native id for the draft' do
draft = ToolDraft.last
expect(draft.native_id).to eq("mmt_tool_#{draft.id}")
end

it 'displays a message that the draft needs a unique Name' do
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.')
end

context 'when clicking the banner message to enter a new Name' do
before do
click_on 'Click here to enter a new Name and Long Name.'
end

it 'displays the empty Name and Long Name fields' do
expect(page).to have_field('Name', with: '')
expect(page).to have_field('Long Name', with: '')
end
end
end
end
Loading