github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/ui/app/models/service-fragment.js (about)

     1  import { attr } from '@ember-data/model';
     2  import Fragment from 'ember-data-model-fragments/fragment';
     3  import { fragment } from 'ember-data-model-fragments/attributes';
     4  import { computed } from '@ember/object';
     5  import classic from 'ember-classic-decorator';
     6  
     7  @classic
     8  export default class Service extends Fragment {
     9    @attr('string') name;
    10    @attr('string') portLabel;
    11    @attr() tags;
    12    @attr() canary_tags;
    13    @attr('string') onUpdate;
    14    @attr('string') provider;
    15    @fragment('consul-connect') connect;
    16    @attr() groupName;
    17    @attr() taskName;
    18    get refID() {
    19      return `${this.groupName || this.taskName}-${this.name}`;
    20    }
    21    @attr({ defaultValue: () => [] }) healthChecks;
    22  
    23    @computed('healthChecks.[]')
    24    get mostRecentChecks() {
    25      // Get unique check names, then get the most recent one
    26      return this.get('healthChecks')
    27        .mapBy('Check')
    28        .uniq()
    29        .map((name) => {
    30          return this.get('healthChecks')
    31            .sortBy('Timestamp')
    32            .reverse()
    33            .find((x) => x.Check === name);
    34        })
    35        .sortBy('Check');
    36    }
    37  
    38    @computed('mostRecentChecks.[]')
    39    get mostRecentCheckStatus() {
    40      // Get unique check names, then get the most recent one
    41      return this.get('mostRecentChecks')
    42        .mapBy('Status')
    43        .reduce((acc, curr) => {
    44          acc[curr] = (acc[curr] || 0) + 1;
    45          return acc;
    46        }, {});
    47    }
    48  }