open-nomad/ui/app/models/recommendation-summary.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

59 lines
1.5 KiB
JavaScript
Raw Normal View History

import Model from '@ember-data/model';
import { attr, belongsTo, hasMany } from '@ember-data/model';
import { get } from '@ember/object';
import { action } from '@ember/object';
export default class RecommendationSummary extends Model {
@hasMany('recommendation') recommendations;
2021-12-28 16:08:12 +00:00
@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)) {
2021-12-28 16:08:12 +00:00
this.excludedRecommendations =
this.excludedRecommendations.removeObject(recommendation);
} else {
this.excludedRecommendations.pushObject(recommendation);
}
}
@action
toggleAllRecommendationsForResource(resource, enabled) {
if (enabled) {
2021-12-28 16:08:12 +00:00
this.excludedRecommendations = this.excludedRecommendations.rejectBy(
'resource',
resource
);
} else {
2021-12-28 16:08:12 +00:00
this.excludedRecommendations.pushObjects(
this.recommendations.filterBy('resource', resource)
);
}
}
get slug() {
return `${get(this, 'job.name')}/${this.taskGroupName}`;
}
}