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: 1 addition & 1 deletion app/controllers/tools_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
class ToolsController < BasePublishedRecordController
include ManageMetadataHelper

before_action :set_tool, only: [:show, :edit] #, :clone, :destroy, :revisions, :revert, :download_json]
before_action :set_tool, only: [:show, :edit, :revisions] #, :clone, :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]
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/manage_metadata_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def resource_type
end

def display_header_subtitle(metadata, type)
return unless type.downcase.include?('variable') || type.downcase.include?('service')
return unless ['variable', 'service', 'tool'].any? { |type_fragment| type.downcase.include?(type_fragment) }

metadata['LongName'] || 'Long Name Not Provided'
end
Expand Down
119 changes: 119 additions & 0 deletions app/views/tools/revisions.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<% content_for :header_title do %>
<h2><%= fetch_entry_id(@tool, 'tools') %></h2>
<p class="subtitle"><%= display_header_subtitle(@tool, 'tool') %></p>
<% end %>

<% if @errors && !@errors.empty? %>
<section class="errors">
<div class="eui-banner--danger">
<div class="eui-banner__message">
<ul class="no-bullet">
<% @errors.each do |error| %>
<li>
<%= "#{error[:field]}, " if error[:field] %>
<%= error[:error] %>
<% if error[:request_id] %>
<a href="javascript:feedback.showForm({details: '\nFill in details above this line. Please try to be as specific as possible.\n--------------------\n\nRequest ID: <%= error[:request_id] %>'});">Click here to submit feedback</a>
Copy link
Collaborator

@charleshuang80 charleshuang80 Jul 8, 2020

Choose a reason for hiding this comment

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

I did not know we had forms on some of our pages go through the Feedback Module. I think we should see if Rosy and Alicia know that this is being done for revisions and some drafts, and see if they would like to use it in other locations.

<% end %>
</li>
<% end %>
</ul>
</div>
</div>
</section>
<% end %>

<div class="row row-content">
<section>
<h2>Revision History</h2>
</section>
<% if @error %>
<section class="errors">
<div class="eui-banner--danger">
<p class="eui-banner__message">
<i class="fa fa-exclamation-triangle"></i> This tool could not be updated. You may <%= link_to 'edit', edit_tool_path(revision_id: @revision_id) %> the tool to resolve these issues.
</p>
</div>
</section>
<% end %>
<div class="row">
<section>
<table id="tool-revisions-table">
<thead>
<tr>
<th>Description</th>
<th>Revision Date</th>
<th>Action by</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<% @revisions.each_with_index do |revision, index| %>
<% revision_id = revision['meta']['revision-id'] %>
<tr class='<%= cycle("alt", "") %>'>
<td>
<% title = "View revision #{revision_id}" %>
<%= revision_id %> -
<% if revision['meta']['deleted'] == true %>
Deleted
<% elsif index == 0 %>
Published
<%# Uncomment in MMT-2232 %>
<%#= link_to 'View', tool_path(revision_id: revision_id), title: title %>
<% else %>
Revision
<%# Uncomment in MMT-2232 %>
<%#= link_to 'View', tool_path(revision_id: revision_id), title: title %>
<% end %>
</td>
<td>
<%= revision['meta']['revision-date'] %>
</td>
<td>
<%= revision['meta']['user-id'] %>
</td>
<td>
<% if @revisions.first['meta']['deleted'] == true %>
<% phrase = 'Reinstate' %>
<% confirm_phrase = 'Are you sure you want to reinstate this record?' %>
<% action = 'reinstate-tool' %>
<% else %>
<% phrase = 'Revert to this Revision' %>
<% confirm_phrase = 'Are you sure you want to revert to this revision?' %>
<% action = 'revert-tool' %>
<% end %>

<% unless index == 0 || revision['meta']['deleted'] == true %>
<%# Uncomment in MMT-2233 %>
<%# if current_provider?(@provider_id) %>
<%#= link_to phrase, "#revert-revisions-modal-#{revision_id}", class: 'display-modal' %>
<%# elsif available_provider?(@provider_id) %>
<%#= link_to phrase, "#not-current-provider-modal-#{revision_id}", class: 'display-modal not-current-provider', data: { 'provider': @provider_id, record_action: action } %>
<%# end %>
<!-- <div id="revert-revisions-modal-<%#= revision_id %>" class="eui-modal-content">
<a href="#" class="modal-close float-r"><i class="fa fa-times"></i><span class="is-invisible">Close</span></a>
<p><%#= confirm_phrase %></p>
<p>
<a href="javascript:void(0)" class="eui-btn modal-close">No</a>
<%#= link_to 'Yes', revert_tool_path(revision_id: revision_id), class: 'eui-btn--blue spinner' %>
</p>
</div>
<%#= render partial: "shared/not_current_provider_modal", locals: {
modal_index: revision_id,
options: {
revisions: true,
tool: @tool,
concept_id: @concept_id,
revision_id: revision_id
}
} %>
</div> -->
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
</section>
</div>
</div>
3 changes: 1 addition & 2 deletions app/views/tools/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@
} %>
</p>
<p>
<%= link_to 'Revisions', '#', class: 'eui-btn--link disabled' %>
<%#= link_to "Revisions (#{@revisions.size})", tool_revisions_path, class: 'eui-btn--link disabled' %>
<%= link_to "Revisions (#{@revisions.size})", tool_revisions_path, class: 'eui-btn--link' %>
</p>
</section>

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/revisions' => 'tools#revisions', as: 'tool_revisions'

resources :variable_drafts, controller: 'variable_drafts', draft_type: 'VariableDraft' do
member do
Expand Down
2 changes: 0 additions & 2 deletions spec/features/services/revision_list_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'rails_helper'

describe 'Service revision list', reset_provider: true, js: true do
context 'when viewing a published service' do
before do
Expand Down
90 changes: 90 additions & 0 deletions spec/features/tools/revision_list_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
describe 'Tool revision list', reset_provider: true, js: true do
context 'when viewing a published tool' do
before :all do
@ingest_response, @concept_response, @native_id = publish_tool_draft(revision_count: 2)
end

# TODO: remove after CMR-6332
after :all do
delete_response = cmr_client.delete_tool('MMT_2', @native_id, 'token')

raise unless delete_response.success?
end

before do
login

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

it 'displays the number of revisions' do
expect(page).to have_content('Revisions (2)')
end

context 'when clicking on the revision link' do
before do
wait_for_cmr
click_on 'Revisions'
end

it 'displays the revision page' do
expect(page).to have_content('Revision History')
end

it 'displays the tool long name' do
expect(page).to have_content(@concept_response.body['LongName'])
end

it 'displays when the revision was made' do
expect(page).to have_content(today_string, count: 2)
end

it 'displays what user made the revision' do
expect(page).to have_content('typical', count: 2)
end

# TODO: Uncomment in MMT-2233
# it 'displays the correct phrasing for reverting records' do
# expect(page).to have_content('Revert to this Revision', count: 1)
# end

# TODO: Uncomment in MMT-2232
# context 'when viewing an old revision' do
# link_text = 'You are viewing an older revision of this tool. Click here to view the latest published version.'
# before do
# all('a', text: 'View').last.click
# end
#
# it 'displays a message that the revision is old' do
# expect(page).to have_link(link_text)
# end
#
# it 'does not display a link to manage collection associations' do
# expect(page).to have_no_link('Manage Collection Associations')
# end
#
# context 'when clicking the message' do
# before do
# click_on link_text
# end
#
# it 'displays the latest revision to the user' do
# expect(page).to have_no_link(link_text)
# end
# end
# end
end

context 'when searching for the tool' do
before do
full_search(record_type: 'Tools', keyword: @concept_response.body['LongName'], provider: 'MMT_2')
end

it 'only displays the latest revision' do
within '#tool-search-results' do
expect(page).to have_content(@concept_response.body['LongName'], count: 1)
end
end
end
end
end