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

     1  import { inject as service } from '@ember/service';
     2  import Route from '@ember/routing/route';
     3  import { run } from '@ember/runloop';
     4  import WithForbiddenState from 'nomad-ui/mixins/with-forbidden-state';
     5  import notifyForbidden from 'nomad-ui/utils/notify-forbidden';
     6  
     7  export default Route.extend(WithForbiddenState, {
     8    system: service(),
     9    store: service(),
    10  
    11    beforeModel() {
    12      return this.get('system.namespaces');
    13    },
    14  
    15    model() {
    16      return this.get('store')
    17        .findAll('job')
    18        .catch(notifyForbidden(this));
    19    },
    20  
    21    syncToController(controller) {
    22      const namespace = this.get('system.activeNamespace.id');
    23  
    24      // The run next is necessary to let the controller figure
    25      // itself out before updating QPs.
    26      // See: https://github.com/emberjs/ember.js/issues/5465
    27      run.next(() => {
    28        if (namespace && namespace !== 'default') {
    29          controller.set('jobNamespace', namespace);
    30        } else {
    31          controller.set('jobNamespace', 'default');
    32        }
    33      });
    34    },
    35  
    36    setupController(controller) {
    37      this.syncToController(controller);
    38      return this._super(...arguments);
    39    },
    40  
    41    actions: {
    42      refreshRoute() {
    43        this.refresh();
    44      },
    45    },
    46  });