Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
4807b45
Route changes for phase2
binoculars Nov 16, 2016
45ca1fb
Merge branch 'feature/branding' into feature/branding-phase2
binoculars Nov 18, 2016
ad2668a
Merge branch 'develop' of github.com:CenterForOpenScience/ember-prepr…
binoculars Nov 28, 2016
2e8f4da
WIP on phase-2 of branded preprints
binoculars Nov 29, 2016
f226122
Merge branch 'develop' of github.com:centerforopenscience/ember-prepr…
binoculars Jan 24, 2017
b671199
Update add-domains script
binoculars Jan 24, 2017
8f8d242
Update tests with their needed services
binoculars Jan 24, 2017
3499073
Created route-prefix helper
binoculars Jan 25, 2017
3d0b1eb
Add a utility for handling redirects and several tests
binoculars Jan 26, 2017
3041db0
Move the assets script in to ember-cli-build (use es5 for without babel)
binoculars Jan 26, 2017
09bb9a1
Add domain redirects for content route
binoculars Jan 27, 2017
f28a3a4
Update preprint button on index page to use theme.pathPrefix
binoculars Jan 29, 2017
c9cd22c
Fix path for redirect in content route
binoculars Jan 30, 2017
d238433
Add OSF host for branded navbar
binoculars Jan 30, 2017
287a2e7
Update 'edit preprint' button on content page with the correct link
binoculars Jan 30, 2017
2b48c33
Fix submit transition failure on submit/save
binoculars Jan 31, 2017
f723673
Merge branch 'develop' of github.com:centerforopenscience/ember-prepr…
binoculars Jan 31, 2017
2d198ca
Update add domains script
binoculars Feb 3, 2017
e8fd5f3
Merge branch 'develop' into feature/branding-phase2
binoculars Feb 6, 2017
868ef36
Merge branch 'develop' of github.com:centerforopenscience/ember-prepr…
binoculars Feb 14, 2017
d211a46
Add domains for new providers, bug fix in add-domains script
binoculars Feb 14, 2017
ea435ad
Update content route
binoculars Feb 15, 2017
8e96e60
Merge branch 'develop' of github.com:centerforopenscience/ember-prepr…
binoculars Mar 9, 2017
1f72e0c
Remove BITSS domain and update engrXiv domain
binoculars Mar 9, 2017
2cc81a8
Temporarily disable some providers
binoculars Mar 9, 2017
8d3b63c
Merge branch 'develop' of github.com:centerforopenscience/ember-prepr…
binoculars Mar 10, 2017
eb2a309
Enable AgriXiv domain
binoculars Mar 10, 2017
21e2f19
Use environment variable to enable provider domains
binoculars Mar 10, 2017
1e6a1d7
Enable and update PsyArXiv domain
binoculars Mar 13, 2017
b29b85f
Update add-domains script for enabling provider domains
binoculars Mar 13, 2017
867774c
Add docs and comments
binoculars Mar 17, 2017
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: 4 additions & 1 deletion .ember-cli
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@

Setting `disableAnalytics` to true will prevent any data from being sent.
*/
"disableAnalytics": true
"disableAnalytics": true,
"port": 4200,

"liveReloadPort": 41953 /* Needed for the TouchBar on the new MacBook Pros */
}
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ For local development, this is designed to run alongside (and from within) the f
to your `website/settings/local.py` file. Uncomment `'/preprints/': 'http://localhost:4200',` and restart your flask app.
4. Visit your app at http://localhost:5000/preprints/

### Provider Domains
1. Run `sudo ./scripts/add-domains.js`. This will add the domains to your `/etc/hosts`.
2. Visit your app at one of the provider domains with `https://local.<domain>:4200` (e.g. `http://local.socarxiv.org:4200`)

If you encounter problems, make sure that your version of ember-osf is up to date. If login fails, try logging in from
any other OSF page, then returning to the preprints app.

Expand Down
12 changes: 12 additions & 0 deletions app/components/error-page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Ember from 'ember';
import Analytics from '../mixins/analytics';

export default Ember.Component.extend(Analytics, {
theme: Ember.inject.service(),
classNames: ['preprint-error-page'],
label: '',
translationKey: '',
supportEmail: Ember.computed('theme.isProvider', 'theme.provider.emailSupport', function() {
return this.get('theme.isProvider') ? this.get('theme.provider.emailSupport') : 'support@osf.io';
})
});
5 changes: 4 additions & 1 deletion app/components/preprint-navbar-branded.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Ember from 'ember';
import OSFAgnosticAuthControllerMixin from 'ember-osf/mixins/osf-agnostic-auth-controller';
import Analytics from '../mixins/analytics';
import config from 'ember-get-config';

/**
* @module ember-preprints
* @submodule components
Expand All @@ -22,5 +24,6 @@ export default Ember.Component.extend(OSFAgnosticAuthControllerMixin, Analytics,
session: Ember.inject.service(),
theme: Ember.inject.service(),
tagName: 'nav',
classNames: ['navbar', 'branded-navbar', 'preprint-navbar']
classNames: ['navbar', 'branded-navbar', 'preprint-navbar'],
host: config.OSF.url,
});
2 changes: 1 addition & 1 deletion app/controllers/submit.js
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ export default Ember.Controller.extend(Analytics, BasicsValidations, NodeActions
window.location = window.location.pathname; //TODO Ember way to do this? In edit mode, already in content route.
} else {
this.transitionToRoute(
`${this.get('theme.isProvider') ? 'provider.' : ''}content`,
`${this.get('theme.isSubRoute') ? 'provider.' : ''}content`,
model
);
}
Expand Down
25 changes: 25 additions & 0 deletions app/helpers/route-prefix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Ember from 'ember';

/**
* @module ember-preprints
* @submodule helpers
*/

/**
* Needed for link-to for branded routing to get the correct route path
*
* @class route-prefix
*/
export default Ember.Helper.extend({
theme: Ember.inject.service(),

onSubRouteChange: Ember.observer('theme.isSubRoute', function() {
this.recompute();
}),

compute(params) {
const route = params.join('');

return this.get('theme.isSubRoute') ? `provider.${route}` : route;
}
});
7 changes: 1 addition & 6 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

{{content-for "head"}}

<link rel="stylesheet" href="{{rootURL}}preprints/assets/vendor.css">
<link rel="stylesheet" href="{{rootURL}}preprints/assets/preprint-service.css">
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,600,300,700' rel='stylesheet' type='text/css'>

{{content-for "head-footer"}}
Expand All @@ -29,13 +27,10 @@

{{content-for "cdn"}}

<script src="{{rootURL}}preprints/assets/vendor.js"></script>
<script src="{{rootURL}}preprints/assets/preprint-service.js"></script>
{{content-for "assets"}}

{{content-for "raven"}}

{{content-for "google-analytics"}}

{{content-for "body-footer"}}
</body>
</html>
30 changes: 13 additions & 17 deletions app/locales/en/translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default {
license: 'License',
},
application: {
// Nothing to translate
separator: ` | `
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this something we really need to expose to translations?

If the goal is only to DRY this code, consider using the ember-page-title addon config:
https://github.com/tim-evans/ember-page-title#api

},
content: {
header: {
Expand Down Expand Up @@ -94,6 +94,7 @@ export default {
},
powered_by: `Powered by ${brand}`,
search: `{{count}} searchable preprints`,
or: `or`,
as_of: `as of`,
example: `See an example`
},
Expand Down Expand Up @@ -122,27 +123,18 @@ export default {
paragraph: `Our advisory group includes leaders in preprints and scholarly communication`
}
},
'page-not-found': {
// Error pages
'page-not-found': { // 404
heading: `Page not found`,
paragraph: {
line1: `The page you were looking for is not found on the {{brand}} service.`,
line2: `If this should not have occurred and the issue persists, please report it to`
},
go_to: `Go to {{brand}}`
message: `The page you were looking for is not found on the {{brand}} service.`
},
'page-forbidden': {
'page-forbidden': { // 403
heading: `Forbidden`,
paragraph: {
line1: `User has restricted access to this page. If this should not have occurred and the issue persists, please report it to `,
},
go_to: `Go to {{brand}}`
message: `User has restricted access to this page.`
},
'resource-deleted': {
'resource-deleted': { // 410
heading: `Resource deleted`,
paragraph: {
line1: `User has deleted this content. If this should not have occurred and the issue persists, please report it to `,
},
go_to: `Go to {{brand}}`
message: `User has deleted this content.`
},
submit: {
add_heading: `Add Preprint`,
Expand Down Expand Up @@ -232,6 +224,10 @@ export default {
convert_confirmation_details_project: `Changes you make on this page are saved immediately. Create a new component under this project to avoid overwriting its details.`,
convert_confirmation_details_component: `Changes you make on this page are saved immediately. Create a new component under this component to avoid overwriting its details.`
},
'error-page': {
email_message: `If this should not have occurred and the issue persists, please report it to`,
go_to: `Go to {{brand}}`
},
'file-uploader': {
dropzone_message: `Drop preprint file here to upload`,
title_placeholder: `Enter preprint title`,
Expand Down
51 changes: 42 additions & 9 deletions app/router.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,37 @@
import Ember from 'ember';
import config from 'ember-get-config';

const {hostname} = window.location;

const provider = config
.PREPRINTS
.providers
// Exclude OSF
.slice(1)
// Filter out providers without a domain
.filter(p => p.domain)
.find(p =>
// Check if the hostname includes: the domain, the domain with dashes instead of periods, or just the id
hostname.includes(p.domain) ||
hostname.includes(p.domain.replace(/\./g, '-')) ||
Copy link
Contributor

Choose a reason for hiding this comment

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

When is this relevant, out of curiosity?

Copy link
Member Author

Choose a reason for hiding this comment

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

I had a conversation with @icereval a while back about how we might deploy this on staging/test. agrixiv-org.staging.osf.io was a likely naming scheme. Putting a dot in a subdomain creates another subdomain.

hostname.includes(p.id)
);

const Router = Ember.Router.extend({
location: config.locationType,
rootURL: config.rootURL,
metrics: Ember.inject.service(),
theme: Ember.inject.service(),

init() {
this._super(...arguments);

if (provider) {
this.set('theme.id', provider.id);
this.set('theme.isDomain', true);
}
},

didTransition() {
this._super(...arguments);
this._trackPage();
Expand All @@ -25,17 +50,25 @@ const Router = Ember.Router.extend({

Router.map(function() {
this.route('page-not-found', {path: '/*bad_url'});
this.route('index', {path: 'preprints'});
this.route('page-not-found', {path: 'preprints/page-not-found'});
this.route('submit', {path: 'preprints/submit'});
this.route('discover', {path: 'preprints/discover'});
this.route('content', {path: '/:preprint_id' });
this.route('provider', {path: 'preprints/:slug'}, function() {
this.route('content', {path: '/:preprint_id'});
this.route('discover');

if (provider) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does provider get recalculated properly when window.location changes? I would assume it does, since it works, but it seems weird that a const value changed would cause this Router.map to be rerun, assuming the preprint app is still a singleton across the different providers

Copy link
Member Author

Choose a reason for hiding this comment

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

Since changing the provider requires a full page reload, the entire app, including the router, will be evaluated each time.

this.route('index', {path: '/'});
this.route('submit');
this.route('discover');
this.route('page-not-found');
});
} else {
this.route('index', {path: 'preprints'});
this.route('submit', {path: 'preprints/submit'});
this.route('discover', {path: 'preprints/discover'});
this.route('provider', {path: 'preprints/:slug'}, function () {
this.route('content', {path: '/:preprint_id'});
this.route('discover');
this.route('submit');
});
this.route('page-not-found', {path: 'preprints/page-not-found'});
}

this.route('content', {path: '/:preprint_id'});
this.route('forbidden');
this.route('resource-deleted');
});
Expand Down
35 changes: 24 additions & 11 deletions app/routes/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import Analytics from '../mixins/analytics';
import config from 'ember-get-config';
import loadAll from 'ember-osf/utils/load-relationship';
import permissions from 'ember-osf/const/permissions';
import getRedirectUrl from '../utils/get-redirect-url';

const providers = config.PREPRINTS.providers;

// Error handling for API
const handlers = new Map([
Expand Down Expand Up @@ -67,7 +70,7 @@ export default Ember.Route.extend(Analytics, ResetScrollMixin, SetupSubmitContro
},
afterModel(preprint) {
const {origin, search} = window.location;
let contributors = Ember.A();
const contributors = Ember.A();

return preprint.get('provider')
.then(provider => {
Expand All @@ -82,20 +85,30 @@ export default Ember.Route.extend(Analytics, ResetScrollMixin, SetupSubmitContro
preprint.get('node')
]);

// Otherwise, redirect to the proper branded site.
// Hard redirect instead of transition, in anticipation of Phase 2 where providers will have their own domains.
const urlParts = [
origin
];
// Otherwise, find the correct provider and redirect
const configProvider = providers.find(p => p.id === providerId);

if (!configProvider)
throw new Error('Provider is not configured properly. Check the Ember configuration.');
Copy link
Contributor

Choose a reason for hiding this comment

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

There does not appear to be any .catch statement associated with this promise. (aside from whatever ember will do internally if the afterModel hook returns a rejected promise)

  • Is this an error the user should be notified about?
  • If so, should there be a translation string here?


if (!isOSF)
urlParts.push('preprints', providerId);
const {domain} = configProvider;
const urlParts = [];

urlParts.push(preprint.get('id'), search);
// Provider with a domain
if (this.get('theme.isDomain') || domain) {
urlParts.push(getRedirectUrl(window.location, domain));
// Provider without a domain
} else {
urlParts.push(origin);

const url = urlParts.join('/');
if (!isOSF)
urlParts.push('preprints', providerId);

urlParts.push(preprint.get('id'));
}

window.history.replaceState({}, document.title, url);
urlParts.push(search);
const url = urlParts.join('/').replace(/\/\/$/, '/');
window.location.replace(url);

return Promise.reject();
Expand Down
2 changes: 1 addition & 1 deletion app/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default Ember.Route.extend(Analytics, ResetScrollMixin, {
search(q) {
let route = 'discover';

if (this.get('theme.isProvider'))
if (this.get('theme.isSubRoute'))
route = `provider.${route}`;

this.transitionTo(route, { queryParams: { queryString: q } });
Expand Down
25 changes: 19 additions & 6 deletions app/routes/provider.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import Ember from 'ember';
import config from 'ember-get-config';
import getRedirectUrl from '../utils/get-redirect-url';

const providers = config.PREPRINTS.providers.slice(1);
const providerIds = providers.map(p => p.id);

/**
* @module ember-preprints
Expand All @@ -12,19 +16,28 @@ import config from 'ember-get-config';
export default Ember.Route.extend({
theme: Ember.inject.service(),

providerIds: config.PREPRINTS.providers
.slice(1)
.map(provider => provider.id),

beforeModel(transition) {
const {slug} = transition.params.provider;
const slugLower = (slug || '').toLowerCase();

if (this.get('providerIds').includes(slugLower)) {
if (providerIds.includes(slugLower)) {
const {domain} = providers.find(provider => provider.id === slugLower) || {};

// This should be caught by the proxy, but we'll redirect just in case it is not.
Copy link
Contributor

Choose a reason for hiding this comment

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

Note to self: "the proxy" refers to nginx handling domain redirect (before it hits ember)

if (domain) {
window.location.replace(
getRedirectUrl(window.location, domain, slug)
);

return;
}

if (slugLower !== slug) {
const {pathname} = window.location;
const pathRegex = new RegExp(`^/preprints/${slug}`);

window.location.pathname = pathname.replace(
new RegExp(`^/preprints/${slug}`),
pathRegex,
`/preprints/${slugLower}`
);
}
Expand Down
Loading