Render directory items in index
This commit is contained in:
parent
bf84e70527
commit
939dce2b1f
10
app/components/directory-listing/component.js
Normal file
10
app/components/directory-listing/component.js
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import Component from '@ember/component';
|
||||||
|
|
||||||
|
export default Component.extend({
|
||||||
|
|
||||||
|
classNames: ['directory-listing'],
|
||||||
|
|
||||||
|
items: null
|
||||||
|
|
||||||
|
|
||||||
|
});
|
16
app/components/directory-listing/template.hbs
Normal file
16
app/components/directory-listing/template.hbs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<td>Name</td>
|
||||||
|
<td>Type</td>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{{#each items as |item|}}
|
||||||
|
<tr>
|
||||||
|
<td class="name">{{item.name}}</td>
|
||||||
|
<td class="type">{{item.type}}</td>
|
||||||
|
</tr>
|
||||||
|
{{/each}}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
@ -9,21 +9,10 @@ export default Controller.extend({
|
|||||||
|
|
||||||
connecting: alias('storage.connecting'),
|
connecting: alias('storage.connecting'),
|
||||||
connected: alias('storage.connected'),
|
connected: alias('storage.connected'),
|
||||||
|
categories: alias('storage.categories'),
|
||||||
categories: null,
|
|
||||||
|
|
||||||
handleConnected: observer('connected', function() {
|
handleConnected: observer('connected', function() {
|
||||||
this.fetchCategories();
|
this.get('storage').fetchCategories();
|
||||||
}),
|
})
|
||||||
|
|
||||||
fetchCategories() {
|
|
||||||
const client = this.get('storage.client');
|
|
||||||
|
|
||||||
client.getListing('').then(listing => {
|
|
||||||
let dirnames = Object.keys(listing);
|
|
||||||
let categories = dirnames.map(i => i.replace('/', '')).sort();
|
|
||||||
this.set('categories', categories);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import Controller from '@ember/controller';
|
import Controller from '@ember/controller';
|
||||||
|
import EmberObject from '@ember/object';
|
||||||
import { inject as service } from '@ember/service';
|
import { inject as service } from '@ember/service';
|
||||||
import { alias } from '@ember/object/computed';
|
import { alias } from '@ember/object/computed';
|
||||||
|
|
||||||
@ -7,6 +8,21 @@ export default Controller.extend({
|
|||||||
storage: service(),
|
storage: service(),
|
||||||
|
|
||||||
connecting: alias('storage.connecting'),
|
connecting: alias('storage.connecting'),
|
||||||
connected: alias('storage.connected')
|
connected: alias('storage.connected'),
|
||||||
|
categories: alias('storage.categories'),
|
||||||
|
|
||||||
|
currentListing: function() {
|
||||||
|
if (!this.get('categories')) { return null; }
|
||||||
|
const listing = [];
|
||||||
|
|
||||||
|
this.get('categories').forEach(categoryName => {
|
||||||
|
listing.pushObject(EmberObject.create({
|
||||||
|
name: categoryName,
|
||||||
|
type: 'folder'
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
return listing;
|
||||||
|
}.property('categories.[]')
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -9,6 +9,7 @@ export default Service.extend({
|
|||||||
connecting: true,
|
connecting: true,
|
||||||
connected: false,
|
connected: false,
|
||||||
client: null,
|
client: null,
|
||||||
|
categories: null,
|
||||||
|
|
||||||
setup: function() {
|
setup: function() {
|
||||||
const rs = new RemoteStorage({
|
const rs = new RemoteStorage({
|
||||||
@ -67,6 +68,16 @@ export default Service.extend({
|
|||||||
this.set('rs', rs);
|
this.set('rs', rs);
|
||||||
this.set('widget', widget);
|
this.set('widget', widget);
|
||||||
this.set('client', rs.scope('/'));
|
this.set('client', rs.scope('/'));
|
||||||
}.on('init')
|
}.on('init'),
|
||||||
|
|
||||||
|
fetchCategories() {
|
||||||
|
const client = this.get('client');
|
||||||
|
|
||||||
|
client.getListing('').then(listing => {
|
||||||
|
let dirnames = Object.keys(listing);
|
||||||
|
let categories = dirnames.map(i => i.replace('/', '')).sort();
|
||||||
|
this.set('categories', categories);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -26,6 +26,9 @@
|
|||||||
padding: 2rem;
|
padding: 2rem;
|
||||||
|
|
||||||
nav {
|
nav {
|
||||||
|
margin-top: 6rem;
|
||||||
|
margin-bottom: 6rem;
|
||||||
|
|
||||||
ul {
|
ul {
|
||||||
list-style: none;
|
list-style: none;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
@ -42,5 +45,9 @@
|
|||||||
flex: 1;
|
flex: 1;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
padding: 2rem;
|
padding: 2rem;
|
||||||
|
|
||||||
|
> header {
|
||||||
|
height: 6em;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,3 +10,5 @@ body {
|
|||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@import "components/directory_listing";
|
||||||
|
28
app/styles/components/_directory_listing.scss
Normal file
28
app/styles/components/_directory_listing.scss
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
.directory-listing {
|
||||||
|
|
||||||
|
table {
|
||||||
|
width: 100%;
|
||||||
|
margin-bottom: 6rem;
|
||||||
|
border-collapse: collapse;
|
||||||
|
|
||||||
|
thead {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
tbody {
|
||||||
|
tr {
|
||||||
|
border-bottom: 1px solid #ececec;
|
||||||
|
}
|
||||||
|
tr:first-of-type {
|
||||||
|
border-top: 1px solid #ececec;
|
||||||
|
}
|
||||||
|
td {
|
||||||
|
padding: 1rem 1.5rem;
|
||||||
|
|
||||||
|
&.type {
|
||||||
|
color: #aaa;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,9 +1,13 @@
|
|||||||
|
<header>
|
||||||
{{#if connecting}}
|
{{#if connecting}}
|
||||||
Connecting...
|
<!-- Connecting... -->
|
||||||
{{else}}
|
|
||||||
{{#if connected}}
|
|
||||||
Connected.
|
|
||||||
{{else}}
|
{{else}}
|
||||||
|
{{#unless connected}}
|
||||||
Not connected.
|
Not connected.
|
||||||
|
{{/unless}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
</header>
|
||||||
|
|
||||||
|
{{#if currentListing}}
|
||||||
|
{{directory-listing items=currentListing}}
|
||||||
{{/if}}
|
{{/if}}
|
@ -5,7 +5,7 @@ moduleForComponent('categories-nav', 'Integration | Component | categories nav',
|
|||||||
integration: true
|
integration: true
|
||||||
});
|
});
|
||||||
|
|
||||||
test('it renders', function(assert) {
|
test('it renders categories', function(assert) {
|
||||||
this.set('categories', [ 'documents', 'notes' ]);
|
this.set('categories', [ 'documents', 'notes' ]);
|
||||||
|
|
||||||
this.render(hbs`{{categories-nav categories=categories}}`);
|
this.render(hbs`{{categories-nav categories=categories}}`);
|
||||||
|
@ -0,0 +1,18 @@
|
|||||||
|
import { moduleForComponent, test } from 'ember-qunit';
|
||||||
|
import hbs from 'htmlbars-inline-precompile';
|
||||||
|
|
||||||
|
moduleForComponent('directory-listing', 'Integration | Component | directory listing', {
|
||||||
|
integration: true
|
||||||
|
});
|
||||||
|
|
||||||
|
test('it renders directory items', function(assert) {
|
||||||
|
this.set('items', [
|
||||||
|
{ name: 'documents', type: 'folder' },
|
||||||
|
{ name: 'public', type: 'folder' }
|
||||||
|
]);
|
||||||
|
|
||||||
|
this.render(hbs`{{directory-listing items=items}}`);
|
||||||
|
|
||||||
|
assert.equal(this.$('table tbody tr:first td:first').text(), 'documents');
|
||||||
|
assert.equal(this.$('table tbody tr:first td:last').text(), 'folder');
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user