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