github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/ui/app/serializers/deployment.js (about)

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