Skip to content

Commit 6454407

Browse files
authored
Merge pull request #187 from MITLibraries/tco80-simulator
Tco80 simulator
2 parents 82719c1 + 6dc2be7 commit 6454407

15 files changed

+443
-13
lines changed

app/assets/stylesheets/application.scss

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
* files in this directory. Styles in this file should be added after the last require_* statement.
1111
* It is generally better to create a new file per style scope.
1212
*
13-
*= require_tree .
14-
*= require_self
1513
*/
1614

1715
@import "libraries-main";
16+
@import "partials/_search";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/* basic search bar */
2+
.basic-search {
3+
background-color: #989898;
4+
margin-bottom: 0rem;
5+
padding: 2.4rem 2rem 1.6rem 2rem;
6+
7+
details {
8+
&:first-of-type {
9+
margin-top: 1rem;
10+
}
11+
12+
.field-container {
13+
margin-top: 1rem;
14+
}
15+
}
16+
17+
.field-label {
18+
color: 999;
19+
display: block;
20+
margin-bottom: .25rem;
21+
font-size: $fs-small;
22+
font-weight: $fw-normal;
23+
}
24+
25+
.basic-search-input,
26+
summary {
27+
-webkit-appearance: none;
28+
border: none;
29+
border-radius: 0;
30+
box-shadow: none;
31+
width: 100%;
32+
margin-bottom: .8rem;
33+
padding: 6px 12px;
34+
margin-bottom: 0;
35+
}
36+
}

app/controllers/demo_controller.rb

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# frozen_string_literal: true
2+
3+
class DemoController < ApplicationController
4+
skip_before_action :require_user, only: %i[index view]
5+
6+
def index; end
7+
8+
def view
9+
@searchterm = params[:query]
10+
11+
@term = Term.find_by(phrase: @searchterm)
12+
13+
detections
14+
end
15+
16+
private
17+
18+
def detections
19+
@detections = {}
20+
21+
@detections[:citation] = Detector::Citation.new(@searchterm).detections
22+
@detections[:journals] = Detector::Journal.new(@searchterm).detections
23+
@detections[:lcsh] = Detector::Lcsh.new(@searchterm).detections
24+
@detections[:standard_identifiers] = Detector::StandardIdentifiers.new(@searchterm).detections
25+
@detections[:suggested_resources] = Detector::SuggestedResource.full_term_match(@searchterm)
26+
end
27+
end
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# frozen_string_literal: true
2+
3+
class InterventionController < ApplicationController
4+
skip_before_action :require_user
5+
6+
def doi
7+
@doi = params[:doi]
8+
9+
raise ActionController::RoutingError, 'Not Found' if params[:doi].blank?
10+
11+
@json = if ENV.fetch('LIBKEY_DOI', nil)
12+
LookupLibkey.info(doi: @doi)
13+
else
14+
LookupDoi.new.info(@doi)
15+
end
16+
17+
render 'doi', layout: false
18+
end
19+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Controller } from "@hotwired/stimulus"
2+
3+
export default class extends Controller {
4+
static values = { url: String }
5+
6+
connect() {
7+
this.load()
8+
}
9+
10+
load() {
11+
fetch(this.urlValue)
12+
.then(response => response.text())
13+
.then(html => this.element.innerHTML = html)
14+
}
15+
}

app/javascript/controllers/hello_controller.js

-7
This file was deleted.

app/javascript/controllers/index.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import { application } from "controllers/application"
44

55
// Eager load all controllers defined in the import map under controllers/**/*_controller
6-
import { eagerLoadControllersFrom } from "@hotwired/stimulus-loading"
7-
eagerLoadControllersFrom("controllers", application)
6+
// import { eagerLoadControllersFrom } from "@hotwired/stimulus-loading"
7+
// eagerLoadControllersFrom("controllers", application)
88

99
// Lazy load controllers as they appear in the DOM (remember not to preload controllers in import map!)
10-
// import { lazyLoadControllersFrom } from "@hotwired/stimulus-loading"
11-
// lazyLoadControllersFrom("controllers", application)
10+
import { lazyLoadControllersFrom } from "@hotwired/stimulus-loading"
11+
lazyLoadControllersFrom("controllers", application)

app/views/demo/_form.html.erb

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<%= form_with class: 'form-horizontal basic-search', data: { turbo: "false" } do |form| %>
2+
<div class="form-group">
3+
<%= form.label :query, "Search for:" %>
4+
<%= form.search_field :query, class: 'field field-text basic-search-input required', value: @searchterm %>
5+
<%= form.submit "Search" %>
6+
</div>
7+
<% end %>

app/views/demo/index.html.erb

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<%= render "form" %>

app/views/demo/view.html.erb

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<%= render "form" %>
2+
3+
<hr />
4+
5+
<% if @term.present? %>
6+
<div class="alert alert-banner success">
7+
<p><i class="fa fa-check-circle fa-lg"></i> We have seen this search term in non-simulation runs.</p>
8+
</div>
9+
<% else %>
10+
<div class="alert alert-banner">
11+
<p><i class="fa fa-info-circle fa-lg"></i> We have not seen this search term in non-simulation runs.</p>
12+
</div>
13+
<% end %>
14+
15+
<h2>Citation?</h2>
16+
<% if @detections[:citation].present? %>
17+
<p>We think this might be a citation.</p>
18+
<ul>
19+
<li>Score: <%= @detections[:citation][2] %></li>
20+
<li>Patterns:
21+
<ul>
22+
<% @detections[:citation][0].each do |p| %>
23+
<li><%= p[0] %>: <%= p[1] %></li>
24+
<% end %>
25+
</ul>
26+
</li>
27+
<li>APA Volume/Issue: <%= @detections[:citation][1][:apa_volume_issue] %>
28+
<li>Pages: <%= @detections[:citation][1][:pages] %>
29+
<li>Lastnames:
30+
<ul>
31+
<% @detections[:citation][1][:lastnames].each do |name| %>
32+
<li><%= name %></li>
33+
<% end %>
34+
</ul>
35+
</li>
36+
</ul>
37+
<% else %>
38+
<p>No citation detected.</p>
39+
<% end %>
40+
41+
<hr />
42+
43+
<h2>Identifiers</h2>
44+
<% if @detections[:standard_identifiers].present? %>
45+
<p>We found some identifiers.</p>
46+
<% if @detections[:standard_identifiers][:isbn].present? %>
47+
ISBN: <%= @detections[:standard_identifiers][:isbn] %>
48+
<% end %>
49+
50+
<% if @detections[:standard_identifiers][:issn].present? %>
51+
ISSN: <%= @detections[:standard_identifiers][:issn] %>
52+
<% end %>
53+
54+
<% if @detections[:standard_identifiers][:doi].present? %>
55+
DOI: <%= @detections[:standard_identifiers][:doi] %>
56+
57+
<div id="doi" data-controller="content-loader"
58+
data-content-loader-url-value="/intervention/doi?doi=<%= @detections[:standard_identifiers][:doi] %>"></div>
59+
60+
<% end %>
61+
62+
<% if @detections[:standard_identifiers][:pmid].present? %>
63+
PMID: <%= @detections[:standard_identifiers][:pmid] %>
64+
<% end %>
65+
<% else %>
66+
<p>No identifiers found.</p>
67+
<% end %>
68+
69+
<hr />
70+
71+
<h2>Journal names</h2>
72+
<% if @detections[:journals].present? %>
73+
<p>We found an exact journal name.</p>
74+
<% @detections[:journals].each do |j| %>
75+
<h3><%= j[:name] %></h3>
76+
<ul>
77+
<li>ISSNs: <%= j[:additional_info]['issns']&.join(', ') %></li>
78+
<li>Publisher: <%= j[:additional_info]['publisher'] %></li>
79+
<li>Alternate titles: <%= j[:additional_info]['alternate_titles']&.join('; ') %></li>
80+
<li>Abbreviated title: <%= j[:additional_info]['abbreviated_title'] %></li>
81+
</ul>
82+
<% end %>
83+
<% else %>
84+
<p>No exact journal name found.</p>
85+
<% end %>
86+
87+
<hr />
88+
89+
<h2>LCSH Subject headings</h2>
90+
<% if @detections[:lcsh].present? %>
91+
<p>We found an LCSH pattern. We have not validated whether this is a real LCSH heading.</p>
92+
<h3><%= @detections[:lcsh][:separator] %></h3>
93+
<% else %>
94+
<p>No LCSH pattern found.</p>
95+
<% end %>
96+
97+
<hr />
98+
99+
<h2>Suggested Resource</h2>
100+
<% if @detections[:suggested_resources].present? %>
101+
<p>Suggested resoure found.</p>
102+
103+
<% @detections[:suggested_resources].each do |sr| %>
104+
<h3><%= sr.title %></h3>
105+
<p>URL: <%= link_to(sr.url, sr.url) %></p>
106+
<% end %>
107+
108+
<% else %>
109+
<p>No suggested resoure found.</p>
110+
<% end %>

app/views/intervention/doi.html.erb

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<% return unless @json.present? %>
2+
3+
<div id="doi-fact" class="panel fact">
4+
<div class="panel-body">
5+
<div class="layout-1q3q layout-band">
6+
<div class="col1q">
7+
<% if @json[:journal_image].present? %>
8+
<%= image_tag(@json[:journal_image], style: ' display: block;
9+
margin-left: auto;
10+
margin-right: auto;
11+
') %>
12+
<% end %>
13+
</div>
14+
15+
<div class="col3q">
16+
<h3><%= @json[:title] %></h3>
17+
18+
<p>In: <%= @json[:journal_name] %></p>
19+
20+
<% if @json[:oa_status] %>
21+
<p>
22+
Open Access:
23+
<%= @json[:oa_status] %>
24+
</p>
25+
<% end %>
26+
27+
28+
<% if @json[:best_oa_location].present? %>
29+
<p><%= link_to('Open Access Link', @json[:best_oa_location]["url"]) %></p>
30+
<% end %>
31+
32+
<% if @json[:journal_link].present? %>
33+
<p><%= link_to('Browse issues', @json[:journal_link]) %></p>
34+
<% end %>
35+
36+
<p>
37+
<%= link_to('Check MIT Subscription Access', @json[:link_resolver_url], class: 'btn button-primary') %>
38+
</p>
39+
40+
</div>
41+
</div>
42+
43+
44+
45+
46+
47+
48+
</ul>
49+
</div>
50+
</div>

app/views/layouts/_head.html.erb

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<meta charset="utf-8">
2+
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
3+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
4+
<title><%= content_for?(:title) ? yield(:title) : " MIT Libraries" %></title>
5+
<%= csrf_meta_tags %>
6+
<%= csp_meta_tag %>
7+
8+
<%= yield :additional_meta_tag %>
9+
10+
<!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
11+
<!--[if lt IE 9]>
12+
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.6.1/html5shiv.js" type="text/javascript"></script>
13+
<![endif]-->
14+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/4.1.1/normalize.min.css" integrity="sha512-4oJiHyX3IWAdU3YotQW0piF3VIAU+vzoBYFoBj8fEzqXK9e9N3GUUvgRAgrQxDmtWnbwzZ27BD85R7oQEag55Q==" crossorigin="anonymous" referrerpolicy="no-referrer" />
15+
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:400,300,300italic,400italic,600,600italic,700,700italic&subset=latin,latin-ext" type="text/css">
16+
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbo-track': 'reload' %>
17+
18+
<!-- For all other devices -->
19+
<!-- Size should be 32 x 32 pixels -->
20+
<%= favicon_link_tag 'favicon.ico', :rel => 'shortcut icon' %>
21+
22+
<%= render partial: "layouts/js_exception_handler" %>
23+
<%= javascript_importmap_tags %>
24+
25+
<script src="https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.min.js" integrity="sha512-3n19xznO0ubPpSwYCRRBgHh63DrV+bdZfHK52b1esvId4GsfwStQNPJFjeQos2h3JwCmZl0/LgLxSKMAI55hgw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
26+
27+
<%= yield :additional_js %>
28+
29+
<% if (ENV['MATOMO_URL'].present? && ENV['MATOMO_SITE_ID'].present?) %>
30+
<!-- Matomo -->
31+
<script type="text/javascript">
32+
var _paq = window._paq || [];
33+
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
34+
_paq.push(['trackPageView']);
35+
_paq.push(['enableLinkTracking']);
36+
(function() {
37+
var u='<%= ENV['MATOMO_URL'] %>';
38+
_paq.push(['setTrackerUrl', u+'matomo.php']);
39+
_paq.push(['setSiteId', '<%= ENV['MATOMO_SITE_ID'] %>']);
40+
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
41+
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
42+
})();
43+
44+
// Lightly modified from https://github.com/turbolinks/turbolinks/issues/436
45+
// Send Matomo a new event when navigating to a new page using Turbolinks
46+
// (see https://developer.matomo.org/guides/spa-tracking)
47+
(function() {
48+
var previousPageUrl = null;
49+
addEventListener('turbo:load', function(event) {
50+
if (previousPageUrl) {
51+
_paq.push(['setReferrerUrl', previousPageUrl]);
52+
_paq.push(['setCustomUrl', window.location.href]);
53+
_paq.push(['setDocumentTitle', document.title]);
54+
if (event.data && event.data.timing) {
55+
_paq.push(['setGenerationTimeMs', event.data.timing.visitEnd - event.data.timing.visitStart]);
56+
}
57+
_paq.push(['trackPageView']);
58+
}
59+
previousPageUrl = window.location.href;
60+
});
61+
})();
62+
</script>
63+
<!-- End Matomo Code -->
64+
<% end %>

config/routes.rb

+7
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@
3939
resources :confirmation, only: [:new, :create]
4040
end
4141

42+
# Demo interface
43+
get '/demo', to: 'demo#index'
44+
post '/demo', to: 'demo#view'
45+
46+
# Interventions
47+
get '/intervention/doi', to: 'intervention#doi'
48+
4249
# Defines the root path route ("/")
4350
root to: 'static#index'
4451
end

0 commit comments

Comments
 (0)