Refactor categories into rootListing
This uses proper paths with slashes everywhere, and lists documents instead of just folders for root.
This commit is contained in:
4
app/components/breadcrumb-nav.js
Normal file
4
app/components/breadcrumb-nav.js
Normal file
@@ -0,0 +1,4 @@
|
||||
import Component from '@ember/component';
|
||||
|
||||
export default Component.extend({
|
||||
});
|
||||
@@ -2,7 +2,7 @@
|
||||
<nav>
|
||||
<ul>
|
||||
{{#each categories as |category|}}
|
||||
<li>{{#link-to "index" (query-params path=category)}}{{category}}{{/link-to}}</li>
|
||||
<li>{{#link-to "index" (query-params path=category.path)}}{{category.name}}{{/link-to}}</li>
|
||||
{{/each}}
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import Controller from '@ember/controller';
|
||||
import EmberObject from '@ember/object';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { alias } from '@ember/object/computed';
|
||||
import { observer } from '@ember/object';
|
||||
import { isEmpty } from '@ember/utils';
|
||||
|
||||
export default Controller.extend({
|
||||
|
||||
@@ -9,10 +11,30 @@ export default Controller.extend({
|
||||
|
||||
connecting: alias('storage.connecting'),
|
||||
connected: alias('storage.connected'),
|
||||
categories: alias('storage.categories'),
|
||||
rootListing: alias('storage.rootListing'),
|
||||
|
||||
handleConnected: observer('connected', function() {
|
||||
this.get('storage').fetchCategories();
|
||||
})
|
||||
this.get('storage').fetchRootListing();
|
||||
}),
|
||||
|
||||
categories: function() {
|
||||
let categories = [];
|
||||
let rootListing = this.get('rootListing');
|
||||
if (isEmpty(rootListing)) { return categories; }
|
||||
|
||||
rootListing.forEach(item => {
|
||||
if (!item.isFolder) { return; }
|
||||
|
||||
categories.push(EmberObject.create({
|
||||
name: item.name.replace('/', ''),
|
||||
type: item.type,
|
||||
path: item.name
|
||||
}));
|
||||
});
|
||||
|
||||
return categories;
|
||||
}.property('rootListing')
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import Controller from '@ember/controller';
|
||||
import EmberObject from '@ember/object';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { alias } from '@ember/object/computed';
|
||||
import { isPresent } from '@ember/utils';
|
||||
@@ -10,7 +9,7 @@ export default Controller.extend({
|
||||
|
||||
connecting: alias('storage.connecting'),
|
||||
connected: alias('storage.connected'),
|
||||
categories: alias('storage.categories'),
|
||||
rootListing: alias('storage.rootListing'),
|
||||
|
||||
queryParams: ['path'],
|
||||
|
||||
@@ -18,18 +17,7 @@ export default Controller.extend({
|
||||
if (isPresent(this.get('model'))) {
|
||||
return this.get('model').sortBy('name');
|
||||
}
|
||||
|
||||
if (!this.get('categories')) { return null; }
|
||||
const listing = [];
|
||||
|
||||
this.get('categories').forEach(categoryName => {
|
||||
listing.push(EmberObject.create({
|
||||
name: categoryName,
|
||||
type: 'folder'
|
||||
}));
|
||||
});
|
||||
|
||||
return listing;
|
||||
}.property('categories.[]', 'model.[]')
|
||||
return this.get('rootListing');
|
||||
}.property('rootListing.[]', 'model.[]')
|
||||
|
||||
});
|
||||
|
||||
@@ -26,7 +26,7 @@ export default Route.extend({
|
||||
this._super(controller, model);
|
||||
|
||||
if (isEmpty(this.get('storage.categories')) && this.get('storage.connected')) {
|
||||
this.get('storage').fetchCategories();
|
||||
this.get('storage').fetchRootListing();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ export default Service.extend({
|
||||
connecting: true,
|
||||
connected: false,
|
||||
client: null,
|
||||
categories: null,
|
||||
rootListing: null,
|
||||
|
||||
setup: function() {
|
||||
const rs = new RemoteStorage({
|
||||
@@ -72,16 +72,9 @@ export default Service.extend({
|
||||
this.set('client', rs.scope('/'));
|
||||
}.on('init'),
|
||||
|
||||
fetchCategories() {
|
||||
const client = this.get('client');
|
||||
|
||||
client.getListing('').then(listing => {
|
||||
let dirnames = Object.keys(listing);
|
||||
let categories = dirnames.reject(i => i.substr(-1) !== '/')
|
||||
.map(i => i.replace('/', ''))
|
||||
.sort();
|
||||
|
||||
this.set('categories', categories);
|
||||
fetchRootListing() {
|
||||
this.fetchListing('').then(items => {
|
||||
this.set('rootListing', items.sortBy('name'));
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
1
app/templates/components/breadcrumb-nav.hbs
Normal file
1
app/templates/components/breadcrumb-nav.hbs
Normal file
@@ -0,0 +1 @@
|
||||
{{yield}}
|
||||
Reference in New Issue
Block a user