open-nomad/ui/mirage/serializers/recommendation.js
Buck Doyle 31b4ed7a6d
Add DAS UI code from enterprise (#9192)
This is a few combined iterations on the DAS feature.
2020-10-29 07:46:42 -05:00

31 lines
866 B
JavaScript

import ApplicationSerializer from './application';
export default ApplicationSerializer.extend({
embed: true,
include: ['task', 'task.task-group'],
serialize() {
var json = ApplicationSerializer.prototype.serialize.apply(this, arguments);
if (json instanceof Array) {
json.forEach(recommendationJson => serializeRecommendation(recommendationJson, this.schema));
} else {
serializeRecommendation(json, this.schema);
}
return json;
},
});
function serializeRecommendation(recommendation, schema) {
const taskJson = recommendation.Task;
recommendation.Task = taskJson.Name;
const taskGroup = schema.taskGroups.find(taskJson.TaskGroupID);
recommendation.Group = taskGroup.name;
recommendation.JobID = taskGroup.job.id;
recommendation.Namespace = taskGroup.job.namespace || 'default';
return recommendation;
}