github.com/hspak/nomad@v0.7.2-0.20180309000617-bc4ae22a39a5/ui/app/serializers/job.js (about)

     1  import { assign } from '@ember/polyfills';
     2  import ApplicationSerializer from './application';
     3  import queryString from 'npm:query-string';
     4  
     5  export default ApplicationSerializer.extend({
     6    attrs: {
     7      parameterized: 'ParameterizedJob',
     8    },
     9  
    10    normalize(typeHash, hash) {
    11      hash.NamespaceID = hash.Namespace;
    12  
    13      // ID is a composite of both the job ID and the namespace the job is in
    14      hash.PlainId = hash.ID;
    15      hash.ID = JSON.stringify([hash.ID, hash.NamespaceID || 'default']);
    16  
    17      // ParentID comes in as "" instead of null
    18      if (!hash.ParentID) {
    19        hash.ParentID = null;
    20      } else {
    21        hash.ParentID = JSON.stringify([hash.ParentID, hash.NamespaceID || 'default']);
    22      }
    23  
    24      // Periodic is a boolean on list and an object on single
    25      if (hash.Periodic instanceof Object) {
    26        hash.PeriodicDetails = hash.Periodic;
    27        hash.Periodic = true;
    28      }
    29  
    30      // Parameterized behaves like Periodic
    31      if (hash.ParameterizedJob instanceof Object) {
    32        hash.ParameterizedDetails = hash.ParameterizedJob;
    33        hash.ParameterizedJob = true;
    34      }
    35  
    36      return this._super(typeHash, hash);
    37    },
    38  
    39    extractRelationships(modelClass, hash) {
    40      const namespace =
    41        !hash.NamespaceID || hash.NamespaceID === 'default' ? undefined : hash.NamespaceID;
    42      const { modelName } = modelClass;
    43  
    44      const [jobURL] = this.store
    45        .adapterFor(modelName)
    46        .buildURL(modelName, hash.ID, hash, 'findRecord')
    47        .split('?');
    48  
    49      return assign(this._super(...arguments), {
    50        summary: {
    51          links: {
    52            related: buildURL(`${jobURL}/summary`, { namespace: namespace }),
    53          },
    54        },
    55        allocations: {
    56          links: {
    57            related: buildURL(`${jobURL}/allocations`, { namespace: namespace }),
    58          },
    59        },
    60        versions: {
    61          links: {
    62            related: buildURL(`${jobURL}/versions`, { namespace: namespace, diffs: true }),
    63          },
    64        },
    65        deployments: {
    66          links: {
    67            related: buildURL(`${jobURL}/deployments`, { namespace: namespace }),
    68          },
    69        },
    70        evaluations: {
    71          links: {
    72            related: buildURL(`${jobURL}/evaluations`, { namespace: namespace }),
    73          },
    74        },
    75      });
    76    },
    77  });
    78  
    79  function buildURL(path, queryParams) {
    80    const qpString = queryString.stringify(queryParams);
    81    if (qpString) {
    82      return `${path}?${qpString}`;
    83    }
    84    return path;
    85  }