Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collections #159

Merged
merged 1 commit into from
Jul 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions addon/components/md-collection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Ember from 'ember';
import DefaultCollectionHeaderView from 'ember-cli-materialize/views/default-collection-header';
import layout from '../templates/components/md-collection';

const { computed: { bool } } = Ember;

export default Ember.Component.extend({
classNames: ['collection'],
classNameBindings: ['_hasHeader:with-header'],
headerView: DefaultCollectionHeaderView,
header: null,
layout: layout,
_hasHeader: bool('header')
});
6 changes: 6 additions & 0 deletions addon/templates/components/md-collection.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{{#if _hasHeader}}
{{view headerView}}
{{/if}}
{{#each content as |item|}}
{{yield item}}
{{/each}}
1 change: 1 addition & 0 deletions addon/templates/default-collection-header.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h4>{{header}}</h4>
7 changes: 7 additions & 0 deletions addon/views/default-collection-header.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Ember from 'ember';
import layout from '../templates/default-collection-header';

export default Ember.View.extend({
layout: layout,
classNames: ['collection-header']
});
1 change: 1 addition & 0 deletions app/components/md-collection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from 'ember-cli-materialize/components/md-collection';
1 change: 1 addition & 0 deletions app/views/default-collection-header.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from 'ember-cli-materialize/views/default-collection-header';
1 change: 1 addition & 0 deletions tests/dummy/app/controllers/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default Ember.Controller.extend({
{name: 'Buttons', route: 'buttons'},
{name: 'Cards', route: 'cards'},
{name: 'Collapsible', route: 'collapsible'},
{name: 'Collection', route: 'collection'},
{name: 'Copyright', route: 'copyright'},
{name: 'Forms', route: 'forms'},
{name: 'Loader', route: 'loader'},
Expand Down
5 changes: 5 additions & 0 deletions tests/dummy/app/controllers/collection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Ember from 'ember';

export default Ember.Controller.extend({

});
1 change: 1 addition & 0 deletions tests/dummy/app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Router.map(function() {
this.route("pagination");
this.route("parallax");
this.route("tabs");
this.route("collection");
});

export default Router;
15 changes: 15 additions & 0 deletions tests/dummy/app/routes/collection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Ember from 'ember';

export default Ember.Route.extend({
model() {
// BEGIN-SNIPPET collection-route
let content = Ember.A([
{id: 'white', name: 'Walter White', route: 'tabs'},
{id: 'pinkman', name: 'Jesse Pinkman', route: 'modal'},
{id: 'freng', name: 'Gustavo Freng', route: 'collection'}
]);
// END-SNIPPET
return content;
}
});

42 changes: 42 additions & 0 deletions tests/dummy/app/templates/collection.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{{example-header title="Collection"}}

<div class='container'>
{{#options-panel}}
{{component-option optionId="content" required=true description="Iterable collection"}}
{{component-option optionId="header" description="Header text"}}
{{component-option optionId="headerView" description="Header view (string or view class)"}}
{{/options-panel}}

<p>For the following examples, let's say we have an array like this</p>
{{code-snippet name='collection-route.js'}}

<div class="section">
<h4 class="col s12 header">Basic Collection</h4>
{{example-snippet snippet='collection-basic' class='basic-collection-example' content=content}}
</div>
<div class="section">
<h4 class="col s12 header">Links</h4>
{{example-snippet snippet='collection-links' class='links-collection-example' content=content}}
</div>
<div class="section">
<h4 class="col s12 header">Simple Collection Header</h4>
{{example-snippet snippet='collection-header' class='simple-header-collection-example' content=content}}
</div>
<div class="section">
<h4 class="col s12 header">Custom Collection Header</h4>
<p>First you need to create a view</p>
{{code-snippet name='custom-collection-header.js'}}
<p>And a template for the header view</p>
{{code-snippet name='my-custom-header.hbs'}}
<p>You can then pass this view to the collection</p>
{{example-snippet snippet='collection-header-custom' class='custom-header-collection-example' content=content}}
</div>
<div class="section">
<h4 class="col s12 header">Secondary Content</h4>
{{example-snippet snippet='collection-secondary-content' class='secondary-content-collection-example' content=content}}
</div>
<div class="section">
<h4 class="col s12 header">Avatars</h4>
{{example-snippet snippet='collection-avatars' class='avatars-collection-example' content=content}}
</div>
</div>
10 changes: 10 additions & 0 deletions tests/dummy/app/templates/snippets/collection-avatars.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{{#md-collection content=content as |item|}}
<div class='collection-item avatar'>
<i class="circle green mdi-action-favorite"></i>
<span class="title">{{item.name}}</span>
<p>A character from the TV series "Breaking Bad"</p>
{{#link-to item.route class='secondary-content'}}
<i class="mdi-action-favorite"></i>
{{/link-to}}
</div>
{{/md-collection}}
5 changes: 5 additions & 0 deletions tests/dummy/app/templates/snippets/collection-basic.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{{#md-collection content=content as |item|}}
<div class='collection-item'>
{{item.name}}
</div>
{{/md-collection}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{#md-collection content=content
headerView='my-custom-header'
header='People to Watch' as |item|}}
<div class='collection-item'>
{{item.name}}
</div>
{{/md-collection}}
5 changes: 5 additions & 0 deletions tests/dummy/app/templates/snippets/collection-header.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{{#md-collection content=content header='People to Watch' as |item|}}
<div class='collection-item'>
{{item.name}}
</div>
{{/md-collection}}
3 changes: 3 additions & 0 deletions tests/dummy/app/templates/snippets/collection-links.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{#md-collection content=content as |item|}}
{{link-to item.name item.route class='collection-item'}}
{{/md-collection}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{{#md-collection content=content as |item|}}
<div class='collection-item'>
{{item.name}}
{{#link-to item.route class='secondary-content'}}
<i class="mdi-action-favorite"></i>
{{/link-to}}
</div>
{{/md-collection}}
1 change: 1 addition & 0 deletions tests/dummy/app/templates/snippets/my-custom-header.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h4 class='white-text'>{{header}}</h4>
10 changes: 10 additions & 0 deletions tests/dummy/app/views/my-custom-header.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// BEGIN-SNIPPET custom-collection-header
import Ember from 'ember';
import DefaultCollectionHeader from 'ember-cli-materialize/views/default-collection-header';
import layout from '../templates/snippets/my-custom-header';

export default DefaultCollectionHeader.extend({
classNames: ['deep-purple'],
layout: layout
});
// END-SNIPPET
41 changes: 41 additions & 0 deletions tests/integration/collection-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import Ember from 'ember';

import startApp from '../../tests/helpers/start-app';
import { module, test } from 'qunit';

var App;

module('Acceptance - Collection', {
setup: function() {
App = startApp();
},
teardown: function() {
Ember.run(App, 'destroy');
}
});

test('Load the demo page', function(assert) {
visit('/collection');

andThen(function () {
// Basic collection
assert.equal(find('.basic-collection-example .collection-item').length, 3, '3 items in basic collection example');

// Links example
assert.equal(find('.links-collection-example a.collection-item').length, 3, 'links items in links collection example');
// "active" link
assert.equal(find('.links-collection-example a.collection-item.active').text(), 'Gustavo Freng', 'Gus should be active');

// Simple header on collection
assert.equal(find('.simple-header-collection-example .collection-item').length, 3, '3 items in basic collection example');
assert.equal(find('.simple-header-collection-example .collection-header').text(), 'People to Watch', 'Header content is correct');
assert.equal(find('.simple-header-collection-example .with-header').length, 1, 'with-header class is present');

// Custom header on collection
assert.equal(find('.custom-header-collection-example .collection-item').length, 3, '3 items in basic collection example');
assert.equal(find('.custom-header-collection-example .collection-header').text(), 'People to Watch', 'Header content is correct');
assert.equal(find('.custom-header-collection-example .with-header').length, 1, 'with-header class is present');
assert.equal(find('.custom-header-collection-example .collection-header.deep-purple').length, 1, 'Header is customized (deep-purple)');

});
});
19 changes: 19 additions & 0 deletions tests/unit/components/md-collection-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { moduleForComponent, test } from 'ember-qunit';

moduleForComponent('md-collection', 'Unit | Component | md collection', {
// Specify the other units that are required for this test
// needs: ['component:foo', 'helper:bar'],
unit: true
});

test('it renders', function(assert) {
assert.expect(2);

// Creates the component instance
var component = this.subject();
assert.equal(component._state, 'preRender');

// Renders the component to the page
this.render();
assert.equal(component._state, 'inDOM');
});
9 changes: 9 additions & 0 deletions tests/unit/views/default-collection-header-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { moduleFor, test } from 'ember-qunit';

moduleFor('view:default-collection-header', 'Unit | View | default collection header');

// Replace this with your real tests.
test('it exists', function(assert) {
var view = this.subject();
assert.ok(view);
});