github.com/hernad/nomad@v1.6.112/ui/app/models/recommendation-summary.js (about)

     1  /**
     2   * Copyright (c) HashiCorp, Inc.
     3   * SPDX-License-Identifier: MPL-2.0
     4   */
     5  
     6  import Model from '@ember-data/model';
     7  import { attr, belongsTo, hasMany } from '@ember-data/model';
     8  import { get } from '@ember/object';
     9  import { action } from '@ember/object';
    10  
    11  export default class RecommendationSummary extends Model {
    12    @hasMany('recommendation') recommendations;
    13    @hasMany('recommendation', { defaultValue: () => [] })
    14    excludedRecommendations;
    15  
    16    @belongsTo('job') job;
    17    @attr('string') jobId;
    18    @attr('string') jobNamespace;
    19  
    20    @attr('date') submitTime;
    21    @attr('string') taskGroupName;
    22  
    23    // Set in the serialiser upon saving
    24    @attr('boolean', { defaultValue: false }) isProcessed;
    25  
    26    get taskGroup() {
    27      const taskGroups = get(this, 'job.taskGroups');
    28  
    29      if (taskGroups) {
    30        return taskGroups.findBy('name', this.taskGroupName);
    31      } else {
    32        return undefined;
    33      }
    34    }
    35  
    36    @action
    37    toggleRecommendation(recommendation) {
    38      if (this.excludedRecommendations.includes(recommendation)) {
    39        this.excludedRecommendations =
    40          this.excludedRecommendations.removeObject(recommendation);
    41      } else {
    42        this.excludedRecommendations.pushObject(recommendation);
    43      }
    44    }
    45  
    46    @action
    47    toggleAllRecommendationsForResource(resource, enabled) {
    48      if (enabled) {
    49        this.excludedRecommendations = this.excludedRecommendations.rejectBy(
    50          'resource',
    51          resource
    52        );
    53      } else {
    54        this.excludedRecommendations.pushObjects(
    55          this.recommendations.filterBy('resource', resource)
    56        );
    57      }
    58    }
    59  
    60    get slug() {
    61      return `${get(this, 'job.name')}/${this.taskGroupName}`;
    62    }
    63  }