Skip to content

Commit

Permalink
Move the assets script in to ember-cli-build (use es5 for without babel)
Browse files Browse the repository at this point in the history
Update default ember cli settings
  • Loading branch information
binoculars committed Jan 26, 2017
1 parent 3d0b1eb commit 3041db0
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 41 deletions.
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 */
}
27 changes: 0 additions & 27 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,33 +29,6 @@

{{content-for "assets"}}

<script>
(function() {
var origin = window.location.origin;

window.isProviderDomain = window.providerDomains.some(function(domain) {
return ~origin.indexOf(domain);
});

var prefix = '/' + (window.isProviderDomain ? '' : 'preprints/') + 'assets/';

[
'vendor',
'preprint-service'
].forEach(function (name) {
var script = document.createElement('script');
script.src = prefix + name + window.assetSuffix + '.js';
script.async = false;
document.body.appendChild(script);

var link = document.createElement('link');
link.rel = 'stylesheet';
link.href = prefix + name + window.assetSuffix + '.css';
document.head.appendChild(link);
});
})();
</script>

{{content-for "raven"}}

{{content-for "body-footer"}}
Expand Down
34 changes: 23 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 @@ -68,20 +71,28 @@ export default Ember.Route.extend(Analytics, ResetScrollMixin, SetupSubmitContro
if ((!themeId && isOSF) || themeId === providerId)
return;

// If we made it to this point, we're not on the the correct page
let url;

// If we're on a branded domain, we need to redirect to the
if (this.get('theme.isDomain')) {
const {domain} = providers.find(p => p.id === providerId) || providers[0];
url = getRedirectUrl(window.location, domain);
// Otherwise, redirect to the branded page
// Hard redirect instead of transition, in anticipation of Phase 2 where providers will have their own domains.
const {origin, search} = window.location;
} else {
const {origin, search} = window.location;

const urlParts = [
origin
];
const urlParts = [
origin
];

if (!isOSF)
urlParts.push('preprints', providerId);
if (!isOSF)
urlParts.push('preprints', providerId);

urlParts.push(preprint.get('id'), search);
urlParts.push(preprint.get('id'), search);

const url = urlParts.join('/');
url = urlParts.join('/');
}

window.history.replaceState({}, document.title, url);
window.location.replace(url);
Expand All @@ -91,8 +102,9 @@ export default Ember.Route.extend(Analytics, ResetScrollMixin, SetupSubmitContro
this.set('node', node);

if (this.get('editMode')) {
let userPermissions = this.get('node.currentUserPermissions') || [];
if (userPermissions.indexOf(permissions.ADMIN) === -1) {
const userPermissions = this.get('node.currentUserPermissions') || [];

if (!userPermissions.includes(permissions.ADMIN)) {
this.replaceWith('forbidden'); // Non-admin trying to access edit form.
}
}
Expand Down
27 changes: 25 additions & 2 deletions ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,31 @@ module.exports = function(defaults) {
enabled: true,
content: `
<script>
window.assetSuffix = '${config.ASSET_SUFFIX ? '-' + config.ASSET_SUFFIX : ''}';
window.providerDomains = ${JSON.stringify(providerDomains)};
window.assetSuffix = '${config.ASSET_SUFFIX ? '-' + config.ASSET_SUFFIX : ''}';
(function(providerDomains) {
var origin = window.location.origin;
var isProviderDomain = providerDomains.some(function(domain) {
return ~origin.indexOf(domain);
});
var prefix = '/' + (isProviderDomain ? '' : 'preprints/') + 'assets/';
[
'vendor',
'preprint-service'
].forEach(function (name) {
var script = document.createElement('script');
script.src = prefix + name + window.assetSuffix + '.js';
script.async = false;
document.body.appendChild(script);
var link = document.createElement('link');
link.rel = 'stylesheet';
link.href = prefix + name + window.assetSuffix + '.css';
document.head.appendChild(link);
});
})(${JSON.stringify(providerDomains)});
</script>`
}
},
Expand Down

0 comments on commit 3041db0

Please sign in to comment.