Files
nomad/ui/app/models/recommendation-summary.js
Buck Doyle d4df1e0459 Add summary-filtering field
This only filters by slug for now… 🧐
2020-11-09 09:28:40 -06:00

53 lines
1.5 KiB
JavaScript

import Model from 'ember-data/model';
import { attr } from '@ember-data/model';
import { belongsTo, hasMany } from 'ember-data/relationships';
import { get } from '@ember/object';
import { action } from '@ember/object';
export default class RecommendationSummary extends Model {
@hasMany('recommendation') recommendations;
@hasMany('recommendation', { defaultValue: () => [] }) excludedRecommendations;
@belongsTo('job') job;
@attr('string') jobId;
@attr('string') jobNamespace;
@attr('date') submitTime;
@attr('string') taskGroupName;
// Set in the serialiser upon saving
@attr('boolean', { defaultValue: false }) isProcessed;
get taskGroup() {
const taskGroups = get(this, 'job.taskGroups');
if (taskGroups) {
return taskGroups.findBy('name', this.taskGroupName);
} else {
return undefined;
}
}
@action
toggleRecommendation(recommendation) {
if (this.excludedRecommendations.includes(recommendation)) {
this.excludedRecommendations = this.excludedRecommendations.removeObject(recommendation);
} else {
this.excludedRecommendations.pushObject(recommendation);
}
}
@action
toggleAllRecommendationsForResource(resource, enabled) {
if (enabled) {
this.excludedRecommendations = this.excludedRecommendations.rejectBy('resource', resource);
} else {
this.excludedRecommendations.pushObjects(this.recommendations.filterBy('resource', resource));
}
}
get slug() {
return `${get(this, 'job.name')}/${this.taskGroupName}`;
}
}