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

     1  import { inject as service } from '@ember/service';
     2  import { assign } from '@ember/polyfills';
     3  import Watchable from './watchable';
     4  
     5  export default Watchable.extend({
     6    system: service(),
     7  
     8    buildQuery() {
     9      const namespace = this.get('system.activeNamespace.id');
    10  
    11      if (namespace && namespace !== 'default') {
    12        return { namespace };
    13      }
    14      return {};
    15    },
    16  
    17    findAll() {
    18      const namespace = this.get('system.activeNamespace');
    19      return this._super(...arguments).then(data => {
    20        data.forEach(job => {
    21          job.Namespace = namespace ? namespace.get('id') : 'default';
    22        });
    23        return data;
    24      });
    25    },
    26  
    27    findRecordSummary(modelName, name, snapshot, namespaceQuery) {
    28      return this.ajax(`${this.buildURL(modelName, name, snapshot, 'findRecord')}/summary`, 'GET', {
    29        data: assign(this.buildQuery() || {}, namespaceQuery),
    30      });
    31    },
    32  
    33    findRecord(store, type, id, snapshot) {
    34      const [, namespace] = JSON.parse(id);
    35      const namespaceQuery = namespace && namespace !== 'default' ? { namespace } : {};
    36  
    37      return this._super(store, type, id, snapshot, namespaceQuery);
    38    },
    39  
    40    urlForFindRecord(id, type, hash) {
    41      const [name, namespace] = JSON.parse(id);
    42      let url = this._super(name, type, hash);
    43      if (namespace && namespace !== 'default') {
    44        url += `?namespace=${namespace}`;
    45      }
    46      return url;
    47    },
    48  
    49    findAllocations(job) {
    50      const url = `${this.buildURL('job', job.get('id'), job, 'findRecord')}/allocations`;
    51      return this.ajax(url, 'GET', { data: this.buildQuery() }).then(allocs => {
    52        return this.store.pushPayload('allocation', {
    53          allocations: allocs,
    54        });
    55      });
    56    },
    57  
    58    fetchRawDefinition(job) {
    59      const url = this.buildURL('job', job.get('id'), job, 'findRecord');
    60      return this.ajax(url, 'GET', { data: this.buildQuery() });
    61    },
    62  
    63    forcePeriodic(job) {
    64      if (job.get('periodic')) {
    65        const [path, params] = this.buildURL('job', job.get('id'), job, 'findRecord').split('?');
    66        let url = `${path}/periodic/force`;
    67  
    68        if (params) {
    69          url += `?${params}`;
    70        }
    71  
    72        return this.ajax(url, 'POST');
    73      }
    74    },
    75  });