github.com/hernad/nomad@v1.6.112/ui/app/components/server-agent-row.js (about) 1 /** 2 * Copyright (c) HashiCorp, Inc. 3 * SPDX-License-Identifier: MPL-2.0 4 */ 5 6 import { inject as service } from '@ember/service'; 7 import { alias } from '@ember/object/computed'; 8 import Component from '@ember/component'; 9 import { computed } from '@ember/object'; 10 import { lazyClick } from '../helpers/lazy-click'; 11 import { 12 classNames, 13 classNameBindings, 14 tagName, 15 } from '@ember-decorators/component'; 16 import classic from 'ember-classic-decorator'; 17 18 @classic 19 @tagName('tr') 20 @classNames('server-agent-row', 'is-interactive') 21 @classNameBindings('isActive:is-active') 22 export default class ServerAgentRow extends Component { 23 // TODO Switch back to the router service once the service behaves more like Route 24 // https://github.com/emberjs/ember.js/issues/15801 25 // router: inject.service('router'), 26 // eslint-disable-next-line ember/no-private-routing-service 27 @service('-routing') _router; 28 @alias('_router.router') router; 29 30 agent = null; 31 32 @computed('agent', 'router.currentURL') 33 get isActive() { 34 // TODO Switch back to the router service once the service behaves more like Route 35 // https://github.com/emberjs/ember.js/issues/15801 36 // const targetURL = this.get('router').urlFor('servers.server', this.get('agent')); 37 // const currentURL = `${this.get('router.rootURL').slice(0, -1)}${this.get('router.currentURL')}`; 38 39 const router = this.router; 40 const targetURL = router.generate('servers.server', this.agent); 41 const currentURL = `${router.get('rootURL').slice(0, -1)}${ 42 router.get('currentURL').split('?')[0] 43 }`; 44 45 // Account for potential URI encoding 46 return currentURL.replace(/%40/g, '@') === targetURL.replace(/%40/g, '@'); 47 } 48 49 goToAgent() { 50 const transition = () => 51 this.router.transitionTo('servers.server', this.agent); 52 lazyClick([transition, event]); 53 } 54 55 click() { 56 this.goToAgent(); 57 } 58 }