github.com/outbrain/consul@v1.4.5/ui-v2/app/models/service.js (about)

     1  import Model from 'ember-data/model';
     2  import attr from 'ember-data/attr';
     3  import { computed, get } from '@ember/object';
     4  
     5  export const PRIMARY_KEY = 'uid';
     6  export const SLUG_KEY = 'Name';
     7  
     8  export default Model.extend({
     9    [PRIMARY_KEY]: attr('string'),
    10    [SLUG_KEY]: attr('string'),
    11    Tags: attr({
    12      defaultValue: function() {
    13        return [];
    14      },
    15    }),
    16    Kind: attr('string'),
    17    ExternalSources: attr(),
    18    Meta: attr(),
    19    Address: attr('string'),
    20    Port: attr('number'),
    21    EnableTagOverride: attr('boolean'),
    22    CreateIndex: attr('number'),
    23    ModifyIndex: attr('number'),
    24    // TODO: These should be typed
    25    ChecksPassing: attr(),
    26    ChecksCritical: attr(),
    27    ChecksWarning: attr(),
    28    Nodes: attr(),
    29    Datacenter: attr('string'),
    30    Node: attr(),
    31    Service: attr(),
    32    Checks: attr(),
    33    passing: computed('ChecksPassing', 'Checks', function() {
    34      let num = 0;
    35      // TODO: use typeof
    36      if (get(this, 'ChecksPassing') !== undefined) {
    37        num = get(this, 'ChecksPassing');
    38      } else {
    39        num = get(get(this, 'Checks').filterBy('Status', 'passing'), 'length');
    40      }
    41      return {
    42        length: num,
    43      };
    44    }),
    45    hasStatus: function(status) {
    46      let num = 0;
    47      switch (status) {
    48        case 'passing':
    49          num = get(this, 'ChecksPassing');
    50          break;
    51        case 'critical':
    52          num = get(this, 'ChecksCritical');
    53          break;
    54        case 'warning':
    55          num = get(this, 'ChecksWarning');
    56          break;
    57        case '': // all
    58          num = 1;
    59          break;
    60      }
    61      return num > 0;
    62    },
    63  });