inspektor/app/routes/index.js
Sebastian Kippe e865ffe073 Improve connection handling
* Clear directory data on disconnect
* Clear path URL param on disconnect
* Don't try to fetch dir listing when starting app disconnected
2017-12-22 12:54:29 +01:00

45 lines
997 B
JavaScript

import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import { isEmpty, isPresent } from '@ember/utils';
import { hash } from 'rsvp';
export default Route.extend({
storage: service(),
queryParams: {
path: {
refreshModel: true
}
},
model(params) {
if (this.get('storage.disconnected')) { return {}; }
let path = params.path;
if (isEmpty(params.path)) { return null; }
if (path.substr(-1) !== '/') { path += '/'; }
return hash({
currentListing: this.get('storage').fetchListing(path),
currentDirPath: path
});
},
setupController(controller, model) {
this._super(controller, model);
if (this.get('storage.disconnected')) { return true; }
if (isEmpty(this.get('storage.categories')) && this.get('storage.connected')) {
this.get('storage').fetchRootListing();
}
if (isPresent(model)) {
controller.set('currentDirPath', model.currentDirPath);
}
}
});