2023-04-10 15:36:59 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
2021-02-17 21:01:44 +00:00
|
|
|
import Model from '@ember-data/model';
|
|
|
|
import { attr, belongsTo, hasMany } from '@ember-data/model';
|
2020-10-29 12:46:42 +00:00
|
|
|
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;
|
2020-10-29 12:46:42 +00:00
|
|
|
|
|
|
|
@belongsTo('job') job;
|
2020-11-04 18:22:24 +00:00
|
|
|
@attr('string') jobId;
|
|
|
|
@attr('string') jobNamespace;
|
2020-10-29 12:46:42 +00:00
|
|
|
|
|
|
|
@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);
|
2020-10-29 12:46:42 +00:00
|
|
|
} 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
|
|
|
|
);
|
2020-10-29 12:46:42 +00:00
|
|
|
} else {
|
2021-12-28 16:08:12 +00:00
|
|
|
this.excludedRecommendations.pushObjects(
|
|
|
|
this.recommendations.filterBy('resource', resource)
|
|
|
|
);
|
2020-10-29 12:46:42 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-04 18:22:24 +00:00
|
|
|
|
|
|
|
get slug() {
|
2020-11-09 15:28:40 +00:00
|
|
|
return `${get(this, 'job.name')}/${this.taskGroupName}`;
|
2020-11-04 18:22:24 +00:00
|
|
|
}
|
2020-10-29 12:46:42 +00:00
|
|
|
}
|