Skip to content

Commit

Permalink
Merge pull request #18 from MITLibraries/cleanup_work
Browse files Browse the repository at this point in the history
Cleanup work
  • Loading branch information
JPrevost authored Nov 21, 2023
2 parents 172794c + 5cfd39d commit 731dc4e
Show file tree
Hide file tree
Showing 13 changed files with 267 additions and 32 deletions.
5 changes: 2 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ gem 'importmap-rails'
# Build JSON APIs with ease [https://github.com/rails/jbuilder]
gem 'jbuilder'

gem 'mitlibraries-theme', git: 'https://github.com/mitlibraries/mitlibraries-theme', tag: 'v1.0.2'

# Use the Puma web server [https://github.com/puma/puma]
gem 'puma', '>= 5.0'

Expand Down Expand Up @@ -71,9 +73,6 @@ group :development do
# Add annotations to model, test, fixtures when run
gem 'annotate'

# GraphQL query editor
gem 'graphiql-rails'

# RuboCop is a Ruby static code analyzer (a.k.a. linter) and code formatter.
gem 'rubocop'
gem 'rubocop-capybara'
Expand Down
23 changes: 19 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
GIT
remote: https://github.com/mitlibraries/mitlibraries-theme
revision: bbd5bb9f8f977251651a41be47b59aa5bd1b22c1
tag: v1.0.2
specs:
mitlibraries-theme (1.0.2)
rails (>= 6, < 8)
sassc-rails (~> 2)

GEM
remote: https://rubygems.org/
specs:
Expand Down Expand Up @@ -121,9 +130,6 @@ GEM
rake
globalid (1.2.1)
activesupport (>= 6.1)
graphiql-rails (1.9.0)
railties
sprockets-rails
graphql (2.1.6)
racc (~> 1.4)
hashdiff (1.0.1)
Expand Down Expand Up @@ -261,6 +267,14 @@ GEM
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
rubyzip (2.3.2)
sassc (2.4.0)
ffi (~> 1.9)
sassc-rails (2.1.2)
railties (>= 4.0.0)
sassc (>= 2.0)
sprockets (> 3.0)
sprockets-rails
tilt
selenium-webdriver (4.15.0)
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
Expand All @@ -286,6 +300,7 @@ GEM
railties (>= 6.0.0)
stringio (3.0.9)
thor (1.3.0)
tilt (2.3.0)
timeout (0.4.1)
turbo-rails (1.5.0)
actionpack (>= 6.0.0)
Expand Down Expand Up @@ -327,11 +342,11 @@ DEPENDENCIES
capybara
debug
dotenv-rails
graphiql-rails
graphql
http
importmap-rails
jbuilder
mitlibraries-theme!
pg
puma (>= 5.0)
rails (~> 7.1.2)
Expand Down
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
# tacos
# TACOS: Tool for Analyzing and Categorization Of Searchterms

## Required Environment Variables

`LINKRESOLVER_BASEURL`: base url for our link resolver. `https://mit.primo.exlibrisgroup.com/discovery/openurl?institution=01MIT_INST&rfr_id=info:sid/mit.tacos.api&vid=01MIT_INST:MIT` is probably the best value unless you are doing something interesting.

`UNPAYWALL_EMAIL`: email address to include in API call as required in their [documentation](https://unpaywall.org/products/api). Your personal email is appropriate for development. Deployed and for tests, use the timdex moira list email.

## Documentation

[Architecture Decisions](docs/architecture-decisions/)

### Explanation/Overview

[Work Activity Analysis](docs/explanation/work-activity-analysis.md)

[Pattern Detection and Enhancement](docs/explanation/pattern_detection_and_enhancement.md)

### Reference

[Class Diagram](docs/reference/classes.md)
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@
*= require_tree .
*= require_self
*/

@import "libraries-main";
1 change: 1 addition & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
class ApplicationController < ActionController::Base
helper Mitlibraries::Theme::Engine.helpers
end
5 changes: 3 additions & 2 deletions app/controllers/graphql_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class GraphqlController < ApplicationController
# If accessing from outside this domain, nullify the session
# This allows for outside API access while preventing CSRF attacks,
# but you'll have to authenticate your user separately
# protect_from_forgery with: :null_session
protect_from_forgery with: :null_session

def execute
variables = prepare_variables(params[:variables])
Expand All @@ -14,10 +14,11 @@ def execute
# Query context goes here, for example:
# current_user: current_user,
}
result = TacosSchema.execute(query, variables: variables, context: context, operation_name: operation_name)
result = TacosSchema.execute(query, variables:, context:, operation_name:)
render json: result
rescue StandardError => e
raise e unless Rails.env.development?

handle_error_in_development(e)
end

Expand Down
3 changes: 3 additions & 0 deletions app/controllers/static_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class StaticController < ApplicationController
def index; end
end
14 changes: 14 additions & 0 deletions app/views/layouts/_site_nav.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div class="wrap-outer-header-local layout-band">
<div class="wrap-header-local">
<div class="local-identity">
<h2 class="title title-site"><a href="/">TACOS</a></h2>
</div>
<div class="wrap-local-nav">
<div class="wrap-bar">
<nav class="local-nav" aria-label="Main menu">
<%= nav_link_to("Home", root_path) %>
</nav>
</div>
</div>
</div>
</div>
16 changes: 0 additions & 16 deletions app/views/layouts/application.html.erb

This file was deleted.

27 changes: 27 additions & 0 deletions app/views/static/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<%= content_for(:title, "TACOS") %>

<div class="layout-3q1q layoutband">
<div class="col3q">
<div class="about-timdex box-content">
<h3 class="title">About TACOS</h3>

<p>TACOS is an anonymous searchterm analysis system.</p>

<p>TACOS aims to be a combination of data collection of anonymous searchterms from our various systems,
algorithmic detection of patterns (such as ISSN, ISBN, DOI, PMID), data lookups of facts about detected
patterns, and a staff workflow to categorize searchterms our algorithmic approach cannot yet understand.</p>

<p>The hope is that TACOS will provide insight into what a user is intending to search for _before_ we ask a
traditional search system to process that search.</p>

<div class="well">
TACOS is coming soon!
</div>
</div>
</div>

<aside class="col1q-r">
<p>Imagine a cool logo here</p>
</aside>

</div>
9 changes: 3 additions & 6 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
Rails.application.routes.draw do
if Rails.env.development?
mount GraphiQL::Rails::Engine, at: "/graphiql", graphql_path: "/graphql"
end
post "/graphql", to: "graphql#execute"
post '/graphql', to: 'graphql#execute'
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html

# Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.
# Can be used by load balancers and uptime monitors to verify that the app is live.
get "up" => "rails/health#show", as: :rails_health_check
get 'up' => 'rails/health#show', as: :rails_health_check

# Defines the root path route ("/")
# root "posts#index"
root to: 'static#index'
end
178 changes: 178 additions & 0 deletions public/playground.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
<!--
* Copyright (c) 2021 GraphQL Contributors
* All rights reserved.
*
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
-->
<!DOCTYPE html>
<html>
<head>
<style>
body {
height: 100%;
margin: 0;
width: 100%;
overflow: hidden;
}

#graphiql {
height: 100vh;
}
</style>

<!--
This GraphiQL example depends on Promise and fetch, which are available in
modern browsers, but can be "polyfilled" for older browsers.
GraphiQL itself depends on React DOM.
If you do not want to rely on a CDN, you can host these files locally or
include them directly in your favored resource bundler.
-->
<script crossorigin src="https://unpkg.com/react@17/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@17/umd/react-dom.development.js"></script>
<!--
These two files can be found in the npm module, however you may wish to
copy them directly into your environment, or perhaps include them in your
favored resource bundler.
-->
<link rel="stylesheet" href="https://unpkg.com/graphiql/graphiql.min.css" />
</head>

<body>
<div id="graphiql">Loading...</div>
<script src="https://unpkg.com/graphiql/graphiql.min.js" type="application/javascript"></script>
<script>
/**
* This GraphiQL example illustrates how to use some of GraphiQL's props
* in order to enable reading and updating the URL parameters, making
* link sharing of queries a little bit easier.
*
* This is only one example of this kind of feature, GraphiQL exposes
* various React params to enable interesting integrations.
*
* Sourced from: https://github.com/graphql/graphiql/blob/bcb27538d9074afdac3ff56074046965b456e57a/packages/graphiql/resources/renderExample.js
*/

// Parse the search string to get url parameters.
var search = window.location.search;
var parameters = {};
search
.substr(1)
.split("&")
.forEach(function (entry) {
var eq = entry.indexOf("=");
if (eq >= 0) {
parameters[decodeURIComponent(entry.slice(0, eq))] = decodeURIComponent(entry.slice(eq + 1));
}
});

// If variables was provided, try to format it.
if (parameters.variables) {
try {
parameters.variables = JSON.stringify(JSON.parse(parameters.variables), null, 2);
} catch (e) {
// Do nothing, we want to display the invalid JSON as a string, rather
// than present an error.
}
}

// When the query and variables string is edited, update the URL bar so
// that it can be easily shared.
function onEditQuery(newQuery) {
parameters.query = newQuery;
updateURL();
}

function onEditVariables(newVariables) {
parameters.variables = newVariables;
updateURL();
}

function onEditOperationName(newOperationName) {
parameters.operationName = newOperationName;
updateURL();
}

function updateURL() {
var newSearch =
"?" +
Object.keys(parameters)
.filter(function (key) {
return Boolean(parameters[key]);
})
.map(function (key) {
return encodeURIComponent(key) + "=" + encodeURIComponent(parameters[key]);
})
.join("&");
history.replaceState(null, null, newSearch);
}

// Defines a GraphQL fetcher using the fetch API. You're not required to
// use fetch, and could instead implement graphQLFetcher however you like,
// as long as it returns a Promise or Observable.
function graphQLFetcher(graphQLParams) {
// This should allow for the playground to use the local GraphQL endpoint in all of our environments,
// including localhost, pr builds, staging environments, and production.
// For this to work, we must host the static playground.html on the same server that runs the graphql endpoint.
// In other words, even those this is a static page, we can't host it in our documentation server or we'd need
// to rework how the graphql endpoint is calculated.
const api = location.origin + "/graphql";
console.log(api);
return fetch(api, {
method: "post",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
},
body: JSON.stringify(graphQLParams),
credentials: "omit",
})
.then(function (response) {
return response.text();
})
.then(function (responseBody) {
try {
return JSON.parse(responseBody);
} catch (error) {
return responseBody;
}
});
}

// Render <GraphiQL /> into the body.
// See the README in the top level of this module to learn more about
// how you can customize GraphiQL by providing different values or
// additional child elements.
ReactDOM.render(
React.createElement(GraphiQL, {
fetcher: graphQLFetcher,
query: parameters.query,
variables: parameters.variables,
operationName: parameters.operationName,
onEditQuery: onEditQuery,
onEditVariables: onEditVariables,
defaultVariableEditorOpen: true,
onEditOperationName: onEditOperationName,
}),
document.getElementById("graphiql")
);
</script>
</body>
</html>

0 comments on commit 731dc4e

Please sign in to comment.