github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/ui/app/routes/allocations/allocation/task/fs.js (about)

     1  import Route from '@ember/routing/route';
     2  import RSVP from 'rsvp';
     3  import notifyError from 'nomad-ui/utils/notify-error';
     4  
     5  export default class FsRoute extends Route {
     6    model({ path = '/' }) {
     7      const decodedPath = decodeURIComponent(path);
     8      const taskState = this.modelFor('allocations.allocation.task');
     9  
    10      if (!taskState || !taskState.allocation) return;
    11  
    12      const allocation = taskState.allocation;
    13      const pathWithTaskName = `${taskState.name}${
    14        decodedPath.startsWith('/') ? '' : '/'
    15      }${decodedPath}`;
    16  
    17      return RSVP.all([allocation.stat(pathWithTaskName), taskState.get('allocation.node')])
    18        .then(([statJson]) => {
    19          if (statJson.IsDir) {
    20            return RSVP.hash({
    21              path: decodedPath,
    22              taskState,
    23              directoryEntries: allocation.ls(pathWithTaskName).catch(notifyError(this)),
    24              isFile: false,
    25            });
    26          } else {
    27            return {
    28              path: decodedPath,
    29              taskState,
    30              isFile: true,
    31              stat: statJson,
    32            };
    33          }
    34        })
    35        .catch(notifyError(this));
    36    }
    37  
    38    setupController(controller, { path, taskState, directoryEntries, isFile, stat } = {}) {
    39      super.setupController(...arguments);
    40      controller.setProperties({ path, taskState, directoryEntries, isFile, stat });
    41    }
    42  }