Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a skeleton viewer for the new designs #2331

Closed
wants to merge 1 commit into from
Closed
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
5 changes: 3 additions & 2 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config --auto-gen-only-exclude`
# on 2025-01-30 20:21:06 UTC using RuboCop version 1.71.0.
# on 2025-02-03 20:11:42 UTC using RuboCop version 1.71.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand Down Expand Up @@ -33,10 +33,11 @@ Metrics/MethodLength:
- 'app/viewers/embed/viewer/m3_viewer.rb'
- 'lib/embed/request.rb'

# Offense count: 13
# Offense count: 15
RSpec/AnyInstance:
Exclude:
- 'spec/components/legacy/was_seed_component_spec.rb'
- 'spec/components/was_seed_component_spec.rb'
- 'spec/features/was_seed_viewer_spec.rb'
- 'spec/lib/embed/viewer/m3_viewer_spec.rb'
- 'spec/models/embed/purl_spec.rb'
Expand Down
1 change: 1 addition & 0 deletions app/assets/stylesheets/was_seed.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import url("companion_window.css");
30 changes: 30 additions & 0 deletions app/components/was_seed_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<%= render ::CompanionWindowsComponent.new(viewer:, stimulus_controller: 'file-auth fullscreen') do |component| %>
<% component.with_body do %>
<div class="sul-embed-body" style="width: 100%">
<div class='sul-embed-was-seed-column sul-embed-was-seed-info'>
<%= link_to viewer.archived_site_url, target: '_top' do %>
<div class="sul-embed-was-seed-preview">
<%= image_tag viewer.shelved_thumb, alt: '' %>
</div>
Stanford Web Archive Portal
<% end %>
</div>
<div class='sul-embed-was-seed-column sul-embed-was-seed-captures'>
<% if viewer.capture_list.length.positive? %>
<h1>
<%= "Captured #{pluralize(viewer.capture_list.length, 'time')} between #{viewer.format_memento_datetime(viewer.capture_list.first.datetime)} and #{viewer.format_memento_datetime(viewer.capture_list.last.datetime)}" %>
</h1>
<% end %>
<ul class='sul-embed-was-seed-list'>
<% viewer.capture_list.each do |memento| %>
<li class='sul-embed-was-seed-list-item'>
<%= link_to memento.url, target: '_top', class: 'sul-embed-stretched-link' do %>
<%= DateTime.parse(memento.datetime).utc %>
<% end %>
</li>
<% end %>
</ul>
</div>
</div>
<% end %>
<% end %>
12 changes: 12 additions & 0 deletions app/components/was_seed_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

class WasSeedComponent < ViewComponent::Base
def initialize(viewer:)
@viewer = viewer
end

attr_reader :viewer

delegate :purl_object, to: :viewer
delegate :druid, to: :purl_object
end
2 changes: 1 addition & 1 deletion app/controllers/embed_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def linted_params
rescue URI::InvalidURIError
raise ActionController::BadRequest
end
params.permit(:url, :maxwidth, :maxheight, :format, :fullheight, :new_component,
params.permit(:url, :maxwidth, :maxheight, :format, :fullheight, :new_viewer,
:hide_title, :hide_embed, :hide_download, :hide_search, :min_files_to_search,
:canvas_id, :canvas_index, :search, :suggested_search, :image_tools, :cdl_hold_record_id)
end
Expand Down
1 change: 1 addition & 0 deletions app/javascript/webarchive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "controllers"
2 changes: 2 additions & 0 deletions app/viewers/embed/viewer/common_viewer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class CommonViewer

attr_reader :purl_object, :embed_request

delegate :new_viewer?, to: :embed_request

def initialize(embed_request)
@embed_request = embed_request
@purl_object = embed_request.purl_object
Expand Down
6 changes: 3 additions & 3 deletions app/viewers/embed/viewer/was_seed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ class WasSeed < CommonViewer
delegate :druid, to: :@purl_object

def component
Legacy::WasSeedComponent
new_viewer? ? WasSeedComponent : Legacy::WasSeedComponent
end

def importmap
'legacy_webarchive'
new_viewer? ? 'webarchive' : 'legacy_webarchive'
end

def stylesheet
'legacy_was_seed.css'
new_viewer? ? 'was_seed.css' : 'legacy_was_seed.css'
end

def capture_list
Expand Down
1 change: 1 addition & 0 deletions config/importmap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

pin "media", preload: true
pin "legacy_webarchive", preload: true
pin "webarchive", preload: true
pin "legacy_file", preload: true
pin "document", preload: true
pin "legacy_3d", preload: true
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ en:
title: "3-D object viewer"
was_seed:
title: "File viewer"
content_list_heading: TBD
download_files:
zero: "No file available for download"
one: "1 file available for download"
Expand Down
5 changes: 5 additions & 0 deletions lib/embed/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ def hide_search?
params[:hide_search] == 'true'
end

# This is a temporary method that allows us to test new viewers before making them the default
def new_viewer?
params[:new_viewer] == 'true'
end

def min_files_to_search
params[:min_files_to_search]
end
Expand Down
53 changes: 53 additions & 0 deletions spec/components/was_seed_component_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe WasSeedComponent, type: :component do
include WasTimeMapFixtures

let(:embed_request) do
Embed::Request.new(url: 'http://purl.stanford.edu/abc123', new_viewer: 'true')
end
let(:viewer) { Embed::Viewer::WasSeed.new(embed_request) }
let(:purl) { build(:purl, :was_seed) }

before do
allow(Embed::Purl).to receive(:find).and_return(purl)
end

context 'with current timemap behavior' do
let(:fake_connection) do
instance_double(Faraday::Connection, get: instance_double(Faraday::Response, body: timemap, success?: true))
end

before do
allow_any_instance_of(Embed::WasTimeMap).to receive(:redirectable_connection).and_return(fake_connection)
render_inline(described_class.new(viewer:))
end

it 'displays Was Seed viewer body' do
# visible false because we display:none the container until we've loaded the CSS.
expect(page).to have_content 'Stanford Web Archive Portal'
expect(page).to have_content 'Captured 7 times between 18 July 2009 and 15 June 2011'
expect(page).to have_css '.sul-embed-was-seed-list-item', visible: :all, count: 7
end
end

context 'with new timemap behavior' do
let(:fake_connection) do
instance_double(Faraday::Connection, get: instance_double(Faraday::Response, body: timemap_new, success?: true))
end

before do
allow_any_instance_of(Embed::WasTimeMap).to receive(:redirectable_connection).and_return(fake_connection)
render_inline(described_class.new(viewer:))
end

it 'displays Was Seed viewer body' do
# visible false because we display:none the container until we've loaded the CSS.
expect(page).to have_content 'Stanford Web Archive Portal'
expect(page).to have_content 'Captured 7 times between 18 July 2009 and 15 June 2011'
expect(page).to have_css '.sul-embed-was-seed-list-item', visible: :all, count: 7
end
end
end