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';
|
2021-12-28 16:08:12 +00:00
|
|
|
import {
|
|
|
|
classNames,
|
|
|
|
classNameBindings,
|
|
|
|
tagName,
|
|
|
|
} from '@ember-decorators/component';
|
2020-06-10 13:49:16 +00:00
|
|
|
import classic from 'ember-classic-decorator';
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@classic
|
|
|
|
@tagName('tr')
|
|
|
|
@classNames('server-agent-row', 'is-interactive')
|
|
|
|
@classNameBindings('isActive:is-active')
|
|
|
|
export default class ServerAgentRow extends Component {
|
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'),
|
2021-02-17 21:01:44 +00:00
|
|
|
// eslint-disable-next-line ember/no-private-routing-service
|
2020-06-10 13:49:16 +00:00
|
|
|
@service('-routing') _router;
|
|
|
|
@alias('_router.router') router;
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
agent = null;
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@computed('agent', 'router.currentURL')
|
|
|
|
get isActive() {
|
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')}`;
|
|
|
|
|
2019-03-26 07:46:44 +00:00
|
|
|
const router = this.router;
|
|
|
|
const targetURL = router.generate('servers.server', this.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, '@');
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2022-08-17 16:59:33 +00:00
|
|
|
goToAgent() {
|
2021-12-28 16:08:12 +00:00
|
|
|
const transition = () =>
|
|
|
|
this.router.transitionTo('servers.server', this.agent);
|
2017-09-26 18:57:46 +00:00
|
|
|
lazyClick([transition, event]);
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2022-08-17 16:59:33 +00:00
|
|
|
|
|
|
|
click() {
|
|
|
|
this.goToAgent();
|
|
|
|
}
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|