github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/ui/app/models/recommendation-summary.js (about) 1 import Model from '@ember-data/model'; 2 import { attr, belongsTo, hasMany } from '@ember-data/model'; 3 import { get } from '@ember/object'; 4 import { action } from '@ember/object'; 5 6 export default class RecommendationSummary extends Model { 7 @hasMany('recommendation') recommendations; 8 @hasMany('recommendation', { defaultValue: () => [] }) excludedRecommendations; 9 10 @belongsTo('job') job; 11 @attr('string') jobId; 12 @attr('string') jobNamespace; 13 14 @attr('date') submitTime; 15 @attr('string') taskGroupName; 16 17 // Set in the serialiser upon saving 18 @attr('boolean', { defaultValue: false }) isProcessed; 19 20 get taskGroup() { 21 const taskGroups = get(this, 'job.taskGroups'); 22 23 if (taskGroups) { 24 return taskGroups.findBy('name', this.taskGroupName); 25 } else { 26 return undefined; 27 } 28 } 29 30 @action 31 toggleRecommendation(recommendation) { 32 if (this.excludedRecommendations.includes(recommendation)) { 33 this.excludedRecommendations = this.excludedRecommendations.removeObject(recommendation); 34 } else { 35 this.excludedRecommendations.pushObject(recommendation); 36 } 37 } 38 39 @action 40 toggleAllRecommendationsForResource(resource, enabled) { 41 if (enabled) { 42 this.excludedRecommendations = this.excludedRecommendations.rejectBy('resource', resource); 43 } else { 44 this.excludedRecommendations.pushObjects(this.recommendations.filterBy('resource', resource)); 45 } 46 } 47 48 get slug() { 49 return `${get(this, 'job.name')}/${this.taskGroupName}`; 50 } 51 }