github.com/outbrain/consul@v1.4.5/ui-v2/app/controllers/dc/nodes/show.js (about)

     1  import Controller from '@ember/controller';
     2  import { get, set } from '@ember/object';
     3  import { getOwner } from '@ember/application';
     4  import WithFiltering from 'consul-ui/mixins/with-filtering';
     5  import qsaFactory from 'consul-ui/utils/dom/qsa-factory';
     6  import getComponentFactory from 'consul-ui/utils/get-component-factory';
     7  
     8  const $$ = qsaFactory();
     9  export default Controller.extend(WithFiltering, {
    10    queryParams: {
    11      s: {
    12        as: 'filter',
    13        replace: true,
    14      },
    15    },
    16    setProperties: function() {
    17      this._super(...arguments);
    18      // the default selected tab depends on whether you have any healthchecks or not
    19      // so check the length here.
    20      // This method is called immediately after `Route::setupController`, and done here rather than there
    21      // as this is a variable used purely for view level things, if the view was different we might not
    22      // need this variable
    23      set(this, 'selectedTab', get(this.item, 'Checks.length') > 0 ? 'health-checks' : 'services');
    24    },
    25    filter: function(item, { s = '' }) {
    26      const term = s.toLowerCase();
    27      return (
    28        get(item, 'Service')
    29          .toLowerCase()
    30          .indexOf(term) !== -1 ||
    31        get(item, 'ID')
    32          .toLowerCase()
    33          .indexOf(term) !== -1 ||
    34        (get(item, 'Tags') || []).some(function(item) {
    35          return item.toLowerCase().indexOf(term) !== -1;
    36        }) ||
    37        get(item, 'Port')
    38          .toString()
    39          .toLowerCase()
    40          .indexOf(term) !== -1
    41      );
    42    },
    43    actions: {
    44      change: function(e) {
    45        set(this, 'selectedTab', e.target.value);
    46        const getComponent = getComponentFactory(getOwner(this));
    47        // Ensure tabular-collections sizing is recalculated
    48        // now it is visible in the DOM
    49        [...$$('.tab-section input[type="radio"]:checked + div table')].forEach(function(item) {
    50          const component = getComponent(item);
    51          if (component && typeof component.didAppear === 'function') {
    52            getComponent(item).didAppear();
    53          }
    54        });
    55      },
    56      sortChecksByImportance: function(a, b) {
    57        const statusA = get(a, 'Status');
    58        const statusB = get(b, 'Status');
    59        switch (statusA) {
    60          case 'passing':
    61            // a = passing
    62            // unless b is also passing then a is less important
    63            return statusB === 'passing' ? 0 : 1;
    64          case 'critical':
    65            // a = critical
    66            // unless b is also critical then a is more important
    67            return statusB === 'critical' ? 0 : -1;
    68          case 'warning':
    69            // a = warning
    70            switch (statusB) {
    71              // b is passing so a is more important
    72              case 'passing':
    73                return -1;
    74              // b is critical so a is less important
    75              case 'critical':
    76                return 1;
    77              // a and b are both warning, therefore equal
    78              default:
    79                return 0;
    80            }
    81        }
    82        return 0;
    83      },
    84    },
    85  });