56 lines
1.6 KiB
TypeScript
Raw Normal View History

import Route from '@ember/routing/route';
import { get } from '@ember/object';
import { service } from '@ember-decorators/service';
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
import Configurator from 'wherehows-web/services/configurator';
import CurrentUser from 'wherehows-web/services/current-user';
import Metrics from 'ember-metrics';
export default class IndexRoute extends Route.extend(AuthenticatedRouteMixin) {
/**
* @type {CurrentUser}
*/
@service('current-user')
sessionUser: CurrentUser;
/**
* Metrics tracking service
* @type {Metrics}
*/
@service
metrics: Metrics;
/**
* Perform post model operations
* @param {EmberTransition} transition
* @return {Promise}
*/
async beforeModel(transition: EmberTransition) {
super.beforeModel(transition);
await this._trackCurrentUser();
this.replaceWithBrowseDatasetsRoute();
}
replaceWithBrowseDatasetsRoute() {
this.replaceWith('browse.entity', 'datasets');
}
/**
* On entry into route, track the currently logged in user
* @return {Promise.<void>}
* @private
*/
async _trackCurrentUser() {
const { tracking } = await Configurator.getConfig<undefined>();
2017-06-19 16:35:00 -07:00
// 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 (
2018-08-23 14:24:15 -07:00
tracking &&
2017-06-19 16:35:00 -07:00
tracking.isEnabled &&
get(this, 'sessionUser').trackCurrentUser(userId => get(this, 'metrics').identify({ userId }))
);
}
}