github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/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: () => [] }) 9 excludedRecommendations; 10 11 @belongsTo('job') job; 12 @attr('string') jobId; 13 @attr('string') jobNamespace; 14 15 @attr('date') submitTime; 16 @attr('string') taskGroupName; 17 18 // Set in the serialiser upon saving 19 @attr('boolean', { defaultValue: false }) isProcessed; 20 21 get taskGroup() { 22 const taskGroups = get(this, 'job.taskGroups'); 23 24 if (taskGroups) { 25 return taskGroups.findBy('name', this.taskGroupName); 26 } else { 27 return undefined; 28 } 29 } 30 31 @action 32 toggleRecommendation(recommendation) { 33 if (this.excludedRecommendations.includes(recommendation)) { 34 this.excludedRecommendations = 35 this.excludedRecommendations.removeObject(recommendation); 36 } else { 37 this.excludedRecommendations.pushObject(recommendation); 38 } 39 } 40 41 @action 42 toggleAllRecommendationsForResource(resource, enabled) { 43 if (enabled) { 44 this.excludedRecommendations = this.excludedRecommendations.rejectBy( 45 'resource', 46 resource 47 ); 48 } else { 49 this.excludedRecommendations.pushObjects( 50 this.recommendations.filterBy('resource', resource) 51 ); 52 } 53 } 54 55 get slug() { 56 return `${get(this, 'job.name')}/${this.taskGroupName}`; 57 } 58 }