mirror of
https://github.com/kemko/nomad.git
synced 2026-01-09 11:55:42 +03:00
53 lines
1.5 KiB
JavaScript
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}`;
|
|
}
|
|
}
|