github.com/hernad/nomad@v1.6.112/ui/app/components/client-node-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 Component from '@ember/component';
     8  import { lazyClick } from '../helpers/lazy-click';
     9  import { watchRelationship } from 'nomad-ui/utils/properties/watch';
    10  import WithVisibilityDetection from 'nomad-ui/mixins/with-component-visibility-detection';
    11  import { computed } from '@ember/object';
    12  import { classNames, tagName } from '@ember-decorators/component';
    13  import classic from 'ember-classic-decorator';
    14  
    15  @classic
    16  @tagName('tr')
    17  @classNames('client-node-row', 'is-interactive')
    18  export default class ClientNodeRow extends Component.extend(
    19    WithVisibilityDetection
    20  ) {
    21    @service store;
    22  
    23    node = null;
    24  
    25    onClick() {}
    26  
    27    click(event) {
    28      lazyClick([this.onClick, event]);
    29    }
    30  
    31    didReceiveAttrs() {
    32      super.didReceiveAttrs();
    33      // Reload the node in order to get detail information
    34      const node = this.node;
    35      if (node) {
    36        node.reload().then(() => {
    37          this.watch.perform(node, 100);
    38        });
    39      }
    40    }
    41  
    42    visibilityHandler() {
    43      if (document.hidden) {
    44        this.watch.cancelAll();
    45      } else {
    46        const node = this.node;
    47        if (node) {
    48          this.watch.perform(node, 100);
    49        }
    50      }
    51    }
    52  
    53    willDestroy() {
    54      this.watch.cancelAll();
    55      super.willDestroy(...arguments);
    56    }
    57  
    58    @watchRelationship('allocations') watch;
    59  
    60    @computed('node.compositeStatus')
    61    get compositeStatusClass() {
    62      let compositeStatus = this.get('node.compositeStatus');
    63  
    64      if (compositeStatus === 'draining') {
    65        return 'status-text is-info';
    66      } else if (compositeStatus === 'ineligible') {
    67        return 'status-text is-warning';
    68      } else if (compositeStatus === 'down') {
    69        return 'status-text is-danger';
    70      } else {
    71        return '';
    72      }
    73    }
    74  }