2017-12-15 21:39:18 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
|
|
|
import { alias } from '@ember/object/computed';
|
|
|
|
import Component from '@ember/component';
|
|
|
|
import { computed } from '@ember/object';
|
2017-09-26 18:57:46 +00:00
|
|
|
import { lazyClick } from '../helpers/lazy-click';
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
export default Component.extend({
|
2017-12-13 19:03:11 +00:00
|
|
|
// TODO Switch back to the router service once the service behaves more like Route
|
|
|
|
// https://github.com/emberjs/ember.js/issues/15801
|
2017-09-19 14:47:10 +00:00
|
|
|
// router: inject.service('router'),
|
2017-12-15 21:39:18 +00:00
|
|
|
_router: service('-routing'),
|
|
|
|
router: alias('_router.router'),
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
tagName: 'tr',
|
|
|
|
classNames: ['server-agent-row', 'is-interactive'],
|
|
|
|
classNameBindings: ['isActive:is-active'],
|
|
|
|
|
|
|
|
agent: null,
|
|
|
|
isActive: computed('agent', 'router.currentURL', function() {
|
2017-12-13 19:03:11 +00:00
|
|
|
// TODO Switch back to the router service once the service behaves more like Route
|
|
|
|
// https://github.com/emberjs/ember.js/issues/15801
|
2017-09-19 14:47:10 +00:00
|
|
|
// const targetURL = this.get('router').urlFor('servers.server', this.get('agent'));
|
|
|
|
// const currentURL = `${this.get('router.rootURL').slice(0, -1)}${this.get('router.currentURL')}`;
|
|
|
|
|
|
|
|
const router = this.get('router');
|
|
|
|
const targetURL = router.generate('servers.server', this.get('agent'));
|
2018-07-10 02:03:08 +00:00
|
|
|
const currentURL = `${router.get('rootURL').slice(0, -1)}${
|
|
|
|
router.get('currentURL').split('?')[0]
|
|
|
|
}`;
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2018-07-10 02:03:08 +00:00
|
|
|
// Account for potential URI encoding
|
|
|
|
return currentURL.replace(/%40/g, '@') === targetURL.replace(/%40/g, '@');
|
2017-09-19 14:47:10 +00:00
|
|
|
}),
|
|
|
|
|
|
|
|
click() {
|
2017-09-26 18:57:46 +00:00
|
|
|
const transition = () => this.get('router').transitionTo('servers.server', this.get('agent'));
|
|
|
|
lazyClick([transition, event]);
|
2017-09-19 14:47:10 +00:00
|
|
|
},
|
|
|
|
});
|