open-nomad/ui/app/components/server-agent-row.js

44 lines
1.6 KiB
JavaScript
Raw Normal View History

import { inject as service } from '@ember/service';
import { alias } from '@ember/object/computed';
import Component from '@ember/component';
import { computed } from '@ember/object';
import { lazyClick } from '../helpers/lazy-click';
import { classNames, classNameBindings, tagName } from '@ember-decorators/component';
import classic from 'ember-classic-decorator';
2017-09-19 14:47:10 +00:00
@classic
@tagName('tr')
@classNames('server-agent-row', 'is-interactive')
@classNameBindings('isActive:is-active')
export default class ServerAgentRow extends Component {
// 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'),
@service('-routing') _router;
@alias('_router.router') router;
2017-09-19 14:47:10 +00:00
agent = null;
2017-09-19 14:47:10 +00:00
@computed('agent', 'router.currentURL')
get isActive() {
// 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, '@');
}
2017-09-19 14:47:10 +00:00
click() {
2019-03-26 07:46:44 +00:00
const transition = () => this.router.transitionTo('servers.server', this.agent);
lazyClick([transition, event]);
}
}