github.com/manicqin/nomad@v0.9.5/ui/app/components/server-agent-row.js (about)

     1  import { inject as service } from '@ember/service';
     2  import { alias } from '@ember/object/computed';
     3  import Component from '@ember/component';
     4  import { computed } from '@ember/object';
     5  import { lazyClick } from '../helpers/lazy-click';
     6  
     7  export default Component.extend({
     8    // TODO Switch back to the router service once the service behaves more like Route
     9    // https://github.com/emberjs/ember.js/issues/15801
    10    // router: inject.service('router'),
    11    _router: service('-routing'),
    12    router: alias('_router.router'),
    13  
    14    tagName: 'tr',
    15    classNames: ['server-agent-row', 'is-interactive'],
    16    classNameBindings: ['isActive:is-active'],
    17  
    18    agent: null,
    19    isActive: computed('agent', 'router.currentURL', function() {
    20      // TODO Switch back to the router service once the service behaves more like Route
    21      // https://github.com/emberjs/ember.js/issues/15801
    22      // const targetURL = this.get('router').urlFor('servers.server', this.get('agent'));
    23      // const currentURL = `${this.get('router.rootURL').slice(0, -1)}${this.get('router.currentURL')}`;
    24  
    25      const router = this.router;
    26      const targetURL = router.generate('servers.server', this.agent);
    27      const currentURL = `${router.get('rootURL').slice(0, -1)}${
    28        router.get('currentURL').split('?')[0]
    29      }`;
    30  
    31      // Account for potential URI encoding
    32      return currentURL.replace(/%40/g, '@') === targetURL.replace(/%40/g, '@');
    33    }),
    34  
    35    click() {
    36      const transition = () => this.router.transitionTo('servers.server', this.agent);
    37      lazyClick([transition, event]);
    38    },
    39  });