open-nomad/ui/app/routes/allocations/allocation/fs.js
Michael Lange 2072911356 Always show the file browser for allocations and tasks.
Before, we'd show a helpful error message when a task isn't running
instead of erroring in a generic way. Turns out when an alloc is
terminal but reachable, the filesystem is left behind so we were hiding
it.

Now it is always shown and in the event that something errors, it'll
either be generic, or--more commonly--a 404 of the allocation.
2020-10-25 22:24:56 -07:00

38 lines
1.1 KiB
JavaScript

import Route from '@ember/routing/route';
import RSVP from 'rsvp';
import notifyError from 'nomad-ui/utils/notify-error';
export default class FsRoute extends Route {
model({ path = '/' }) {
const decodedPath = decodeURIComponent(path);
const allocation = this.modelFor('allocations.allocation');
if (!allocation) return;
return RSVP.all([allocation.stat(decodedPath), allocation.get('node')])
.then(([statJson]) => {
if (statJson.IsDir) {
return RSVP.hash({
path: decodedPath,
allocation,
directoryEntries: allocation.ls(decodedPath).catch(notifyError(this)),
isFile: false,
});
} else {
return {
path: decodedPath,
allocation,
isFile: true,
stat: statJson,
};
}
})
.catch(notifyError(this));
}
setupController(controller, { path, allocation, directoryEntries, isFile, stat } = {}) {
super.setupController(...arguments);
controller.setProperties({ path, allocation, directoryEntries, isFile, stat });
}
}