github.com/hernad/nomad@v1.6.112/ui/app/serializers/deployment.js (about)

     1  /**
     2   * Copyright (c) HashiCorp, Inc.
     3   * SPDX-License-Identifier: MPL-2.0
     4   */
     5  
     6  import { get } from '@ember/object';
     7  import { assign } from '@ember/polyfills';
     8  import ApplicationSerializer from './application';
     9  import classic from 'ember-classic-decorator';
    10  
    11  @classic
    12  export default class DeploymentSerializer extends ApplicationSerializer {
    13    attrs = {
    14      versionNumber: 'JobVersion',
    15    };
    16  
    17    mapToArray = [{ beforeName: 'TaskGroups', afterName: 'TaskGroupSummaries' }];
    18  
    19    normalize(typeHash, hash) {
    20      if (hash) {
    21        hash.PlainJobId = hash.JobID;
    22        hash.Namespace =
    23          hash.Namespace || get(hash, 'Job.Namespace') || 'default';
    24  
    25        // Ember Data doesn't support multiple inverses. This means that since jobs have
    26        // two relationships to a deployment (hasMany deployments, and belongsTo latestDeployment),
    27        // the deployment must in turn have two relationships to the job, despite it being the
    28        // same job.
    29        hash.JobID = hash.JobForLatestID = JSON.stringify([
    30          hash.JobID,
    31          hash.Namespace,
    32        ]);
    33      }
    34  
    35      return super.normalize(typeHash, hash);
    36    }
    37  
    38    extractRelationships(modelClass, hash) {
    39      const namespace = this.store
    40        .adapterFor(modelClass.modelName)
    41        .get('namespace');
    42      const id = this.extractId(modelClass, hash);
    43  
    44      return assign(
    45        {
    46          allocations: {
    47            links: {
    48              related: `/${namespace}/deployment/allocations/${id}`,
    49            },
    50          },
    51        },
    52        super.extractRelationships(modelClass, hash)
    53      );
    54    }
    55  }