github.com/hernad/nomad@v1.6.112/ui/app/routes/csi/volumes/volume.js (about)

     1  /**
     2   * Copyright (c) HashiCorp, Inc.
     3   * SPDX-License-Identifier: MPL-2.0
     4   */
     5  
     6  import { inject as service } from '@ember/service';
     7  import Route from '@ember/routing/route';
     8  import { collect } from '@ember/object/computed';
     9  import RSVP from 'rsvp';
    10  import notifyError from 'nomad-ui/utils/notify-error';
    11  import { watchRecord } from 'nomad-ui/utils/properties/watch';
    12  import WithWatchers from 'nomad-ui/mixins/with-watchers';
    13  import classic from 'ember-classic-decorator';
    14  
    15  @classic
    16  export default class VolumeRoute extends Route.extend(WithWatchers) {
    17    @service store;
    18    @service system;
    19  
    20    startWatchers(controller, model) {
    21      if (!model) return;
    22  
    23      controller.set('watchers', {
    24        model: this.watch.perform(model),
    25      });
    26    }
    27  
    28    serialize(model) {
    29      return { volume_name: JSON.parse(model.get('id')).join('@') };
    30    }
    31  
    32    model(params) {
    33      // Issue with naming collissions
    34      const url = params.volume_name.split('@');
    35      const namespace = url.pop();
    36      const name = url.join('');
    37  
    38      const fullId = JSON.stringify([`csi/${name}`, namespace || 'default']);
    39  
    40      return RSVP.hash({
    41        volume: this.store.findRecord('volume', fullId, { reload: true }),
    42        namespaces: this.store.findAll('namespace'),
    43      })
    44        .then((hash) => hash.volume)
    45        .catch(notifyError(this));
    46    }
    47  
    48    // Since volume includes embedded records for allocations,
    49    // it's possible that allocations that are server-side deleted may
    50    // not be removed from the UI while sitting on the volume detail page.
    51    @watchRecord('volume') watch;
    52    @collect('watch') watchers;
    53  }