2017-02-13 15:05:30 -08:00
|
|
|
import Ember from 'ember';
|
2017-05-22 19:55:07 -07:00
|
|
|
import ApplicationRouteMixin from 'ember-simple-auth/mixins/application-route-mixin';
|
2017-02-13 15:05:30 -08:00
|
|
|
|
2017-06-19 16:35:00 -07:00
|
|
|
const { Route, run, get, inject: { service }, testing } = Ember;
|
2017-03-24 21:35:35 -07:00
|
|
|
|
|
|
|
export default Route.extend(ApplicationRouteMixin, {
|
2017-03-26 00:56:19 -07:00
|
|
|
// Injected Ember#Service for the current user
|
2017-03-26 13:45:06 -07:00
|
|
|
sessionUser: service('current-user'),
|
2017-03-26 00:56:19 -07:00
|
|
|
|
2017-06-19 14:50:56 -07:00
|
|
|
/**
|
|
|
|
* Runtime application configuration options
|
|
|
|
* @type {Ember.Service}
|
|
|
|
*/
|
|
|
|
configurator: service(),
|
|
|
|
|
2017-04-08 11:40:23 -07:00
|
|
|
/**
|
|
|
|
* Metrics tracking service
|
|
|
|
* @type {Ember.Service}
|
|
|
|
*/
|
|
|
|
metrics: service(),
|
|
|
|
|
2017-03-26 00:56:19 -07:00
|
|
|
/**
|
2017-06-19 14:50:56 -07:00
|
|
|
* Attempt to load the current user and application configuration options
|
2017-03-26 00:56:19 -07:00
|
|
|
* @returns {Promise}
|
|
|
|
*/
|
|
|
|
beforeModel() {
|
2017-04-08 11:40:23 -07:00
|
|
|
this._super(...arguments);
|
|
|
|
|
2017-06-19 14:50:56 -07:00
|
|
|
return Promise.all([this._loadCurrentUser(), this._loadConfig()]);
|
2017-03-26 00:56:19 -07:00
|
|
|
},
|
|
|
|
|
2017-06-19 11:46:05 -07:00
|
|
|
/**
|
|
|
|
* Returns an object containing properties for the application route
|
|
|
|
* @return {{feedbackMail: {href: string, target: string, title: string}}}
|
|
|
|
* @override
|
|
|
|
*/
|
2017-06-19 16:35:00 -07:00
|
|
|
async model() {
|
|
|
|
const isInternal = await get(this, 'configurator.getConfig')('isInternal');
|
|
|
|
|
2017-06-19 11:46:05 -07:00
|
|
|
/**
|
|
|
|
* properties for the navigation link to allow a user to provide feedback
|
|
|
|
* @type {{href: string, target: string, title: string}}
|
|
|
|
*/
|
|
|
|
const feedbackMail = {
|
|
|
|
href: 'mailto:wherehows-dev@linkedin.com?subject=WhereHows Feedback',
|
|
|
|
target: '_blank',
|
|
|
|
title: 'Provide Feedback'
|
|
|
|
};
|
|
|
|
|
2017-06-19 16:35:00 -07:00
|
|
|
const brand = {
|
|
|
|
logo: isInternal ? '/assets/assets/images/wherehows-logo.png' : ''
|
|
|
|
};
|
|
|
|
|
|
|
|
return { feedbackMail, brand };
|
2017-06-19 11:46:05 -07:00
|
|
|
},
|
|
|
|
|
2017-04-08 11:40:23 -07:00
|
|
|
/**
|
|
|
|
* Perform post model operations
|
|
|
|
* @return {Promise}
|
|
|
|
*/
|
|
|
|
afterModel() {
|
|
|
|
this._super(...arguments);
|
|
|
|
|
2017-06-19 16:35:00 -07:00
|
|
|
return Promise.all([this._setupMetricsTrackers(), this._trackCurrentUser()]);
|
2017-04-08 11:40:23 -07:00
|
|
|
},
|
|
|
|
|
2017-03-26 00:56:19 -07:00
|
|
|
/**
|
|
|
|
* Augments sessionAuthenticated.
|
|
|
|
* @override ApplicationRouteMixin.sessionAuthenticated
|
|
|
|
*/
|
|
|
|
sessionAuthenticated() {
|
|
|
|
this._super(...arguments);
|
|
|
|
this._loadCurrentUser();
|
|
|
|
},
|
|
|
|
|
2017-04-07 09:11:40 -07:00
|
|
|
/**
|
|
|
|
* __It reloads the Ember.js application__ by redirecting the browser
|
|
|
|
* to the application's root URL so that all in-memory data (such as Ember
|
|
|
|
* Data stores etc.) gets cleared.
|
|
|
|
* @override ApplicationRouteMixin.sessionInvalidated
|
|
|
|
* @link https://github.com/simplabs/ember-simple-auth/issues/1048
|
|
|
|
*/
|
|
|
|
sessionInvalidated() {
|
|
|
|
if (!testing) {
|
|
|
|
window.location.replace('/');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-03-26 00:56:19 -07:00
|
|
|
/**
|
|
|
|
* Internal method to invoke the currentUser service's load method
|
|
|
|
* If an exception occurs during the load for the current user,
|
|
|
|
* invalidate the session.
|
|
|
|
* @returns {Promise<T, V>|RSVP.Promise<any>|Ember.RSVP.Promise<any, any>|Promise.<T>}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
_loadCurrentUser() {
|
2017-05-22 19:55:07 -07:00
|
|
|
return get(this, 'sessionUser').load().catch(() => get(this, 'sessionUser').invalidateSession());
|
2017-03-26 00:56:19 -07:00
|
|
|
},
|
|
|
|
|
2017-06-19 14:50:56 -07:00
|
|
|
/**
|
|
|
|
* Loads the application configuration object
|
|
|
|
* @return {Promise.<any>|void}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
_loadConfig() {
|
|
|
|
return get(this, 'configurator.load')();
|
|
|
|
},
|
|
|
|
|
2017-04-08 11:40:23 -07:00
|
|
|
/**
|
|
|
|
* Requests app configuration props then if enabled, sets up metrics
|
|
|
|
* tracking using the supported trackers
|
|
|
|
* @return {Promise.<TResult>}
|
|
|
|
* @private
|
|
|
|
*/
|
2017-06-19 16:35:00 -07:00
|
|
|
async _setupMetricsTrackers() {
|
|
|
|
const { tracking = {} } = await get(this, 'configurator.getConfig')();
|
|
|
|
|
|
|
|
if (tracking.isEnabled) {
|
|
|
|
const metrics = get(this, 'metrics');
|
|
|
|
const { trackers = {} } = tracking;
|
|
|
|
const { piwikSiteId, piwikUrl = '//piwik.corp.linkedin.com/piwik/' } = trackers.piwik;
|
|
|
|
|
|
|
|
metrics.activateAdapters([
|
|
|
|
{
|
|
|
|
name: 'Piwik',
|
|
|
|
environments: ['all'],
|
|
|
|
config: {
|
|
|
|
piwikUrl,
|
|
|
|
siteId: piwikSiteId
|
2017-05-22 19:55:07 -07:00
|
|
|
}
|
2017-06-19 16:35:00 -07:00
|
|
|
}
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tracks the currently logged in user
|
|
|
|
* @return {Promise.<isEnabled|((feature:string)=>boolean)|*>}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
async _trackCurrentUser() {
|
|
|
|
const { tracking = {} } = await get(this, 'configurator.getConfig')();
|
|
|
|
|
|
|
|
// Check if tracking is enabled prior to invoking
|
|
|
|
// Passes an anonymous function to track the currently logged in user using the singleton `current-user` service
|
|
|
|
return (
|
|
|
|
tracking.isEnabled &&
|
|
|
|
get(this, 'sessionUser').trackCurrentUser(userId => get(this, 'metrics').identify({ userId }))
|
|
|
|
);
|
2017-04-08 11:40:23 -07:00
|
|
|
},
|
|
|
|
|
2017-02-13 15:05:30 -08:00
|
|
|
init() {
|
|
|
|
this._super(...arguments);
|
2017-03-24 21:35:35 -07:00
|
|
|
run.scheduleOnce('afterRender', this, 'processLegacyDomOperations');
|
2017-02-13 15:05:30 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
processLegacyDomOperations() {
|
2017-03-24 21:35:35 -07:00
|
|
|
// TODO: DSS-6122 Refactor Remove tree legacy operations & references
|
2017-02-13 15:05:30 -08:00
|
|
|
window.legacyMain();
|
|
|
|
}
|
2017-03-24 21:35:35 -07:00
|
|
|
});
|