2020-06-01 13:15:59 +00:00
|
|
|
import Route from '@ember/routing/route';
|
|
|
|
import RSVP from 'rsvp';
|
|
|
|
import notifyError from 'nomad-ui/utils/notify-error';
|
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
export default class FsRoute extends Route {
|
2020-06-01 13:15:59 +00:00
|
|
|
model({ path = '/' }) {
|
|
|
|
const decodedPath = decodeURIComponent(path);
|
|
|
|
const allocation = this.modelFor('allocations.allocation');
|
|
|
|
|
|
|
|
if (!allocation.isRunning) {
|
|
|
|
return {
|
|
|
|
path: decodedPath,
|
|
|
|
allocation,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2020-06-01 13:15:59 +00:00
|
|
|
|
|
|
|
setupController(controller, { path, allocation, directoryEntries, isFile, stat } = {}) {
|
2020-06-10 13:49:16 +00:00
|
|
|
super.setupController(...arguments);
|
2020-06-01 13:15:59 +00:00
|
|
|
controller.setProperties({ path, allocation, directoryEntries, isFile, stat });
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
|
|
|
}
|