Skip to content

Commit 8ed9998

Browse files
committed
Add checkboxes for Inherited, Protected, Private, Deprecated
1 parent f299f0e commit 8ed9998

File tree

4 files changed

+78
-5
lines changed

4 files changed

+78
-5
lines changed
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import Ember from 'ember';
2+
import _ from 'lodash/lodash';
3+
4+
const { computed } = Ember;
5+
6+
7+
export default Ember.Controller.extend({
8+
filteredMethods: computed('model.methods.[]', 'showInherited', 'showProtected', 'showPrivate', 'showDeprecated', function() {
9+
return this.filterItems('methods');
10+
}),
11+
12+
filteredEvents: computed('model.events.[]', 'showInherited', 'showProtected', 'showPrivate', 'showDeprecated', function() {
13+
return this.filterItems('events');
14+
}),
15+
16+
filteredProperties: computed('model.properties.[]', 'showInherited', 'showProtected', 'showPrivate', 'showDeprecated', function() {
17+
return this.filterItems('properties');
18+
}),
19+
20+
filterItems(itemType) {
21+
let items = this.get('model.' + itemType);
22+
if (!this.get('showInherited')) {
23+
items = items.filter(item => item.inherited !== true);
24+
}
25+
if (!this.get('showProtected')) {
26+
items = items.filter(item => item.access !== 'protected');
27+
}
28+
if (!this.get('showPrivate')) {
29+
items = items.filter(item => item.access !== 'private');
30+
}
31+
if (!this.get('showDeprecated')) {
32+
items = items.filter(item => item.deprecated !== true);
33+
}
34+
return _.uniq(_.sortBy(items, 'name'), true, (item => item.name));
35+
}
36+
});

app/styles/_class.scss

+4
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ article.chapter ul {
1111
margin-bottom: 0;
1212
}
1313
}
14+
15+
.access-checkbox {
16+
display: inline;
17+
}

app/templates/project-version/class.hbs

+25-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,34 @@
22
<h1>{{model.name}} {{#if model.access}}<span class="access">{{model.access}}</span>{{/if}}</h1>
33

44
<p>{{{model.description}}}</p>
5+
6+
<section>
7+
Show:
8+
<label class="access-checkbox">
9+
{{input type="checkbox" checked=showInherited}}
10+
Inherited
11+
</label>
12+
<label class="access-checkbox">
13+
{{input type="checkbox" checked=showProtected}}
14+
Protected
15+
</label>
16+
<label class="access-checkbox">
17+
{{input type="checkbox" checked=showPrivate}}
18+
Private
19+
</label>
20+
<label class="access-checkbox">
21+
{{input type="checkbox" checked=showDeprecated}}
22+
Deprecated
23+
</label>
24+
</section>
25+
26+
527
<section>
628
<h2>Methods</h2>
729

830
{{#if model.methods}}
931
<ul class="spec-method-list">
10-
{{#each model.methods as |method|}}
32+
{{#each filteredMethods as |method|}}
1133
<li>
1234
{{#link-to 'methods.method' model.project.id model.projectVersion.version model.name method.name (query-params anchor=method.name)}}
1335
{{method.name}}
@@ -24,7 +46,7 @@
2446
<h2>Properties</h2>
2547
{{#if model.properties}}
2648
<ul class="spec-property-list">
27-
{{#each model.properties as |property|}}
49+
{{#each filteredProperties as |property|}}
2850
<li>
2951
{{#link-to 'properties.property' model.project.id model.projectVersion.version model.name property.name (query-params anchor=property.name)}}
3052
{{property.name}}
@@ -41,7 +63,7 @@
4163
<h2>Events</h2>
4264
{{#if model.events}}
4365
<ul class="spec-event-list">
44-
{{#each model.events as |event|}}
66+
{{#each filteredEvents as |event|}}
4567
<li>
4668
{{#link-to 'events.event' model.project.id model.projectVersion.version model.name event.name (query-params anchor=event.name)}}
4769
{{event.name}}

tests/acceptance/class-test.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,26 @@ import $ from 'jquery';
44

55
moduleForAcceptance('Class', {
66
beforeEach() {
7-
return visit('/ember/1.0.0/classes/Container');
7+
return visit('/ember/1.0.0/classes/Container').then(() => {
8+
click('.access-checkbox:contains(Inherited)');
9+
click('.access-checkbox:contains(Protected)');
10+
click('.access-checkbox:contains(Private)');
11+
click('.access-checkbox:contains(Deprecated)');
12+
});
813
}
914
});
1015

1116
test('lists all the methods on the class page', function (assert) {
1217
const store = this.application.__container__.lookup('service:store');
1318
const container = store.peekRecord('class', 'ember-1.0.0-Container');
1419
assert.equal($(findWithAssert('.spec-method-list li')).length, container.get('methods.length'));
20+
21+
click('.access-checkbox:contains(Private)'); // turn private back off
22+
23+
andThen(() => {
24+
assert.equal($(findWithAssert('.spec-method-list li')).length,
25+
container.get('methods').filter(method => method.access !== 'private').length);
26+
});
1527
});
1628

1729
test('lists all the properties on the class page', function (assert) {
@@ -25,4 +37,3 @@ test('lists all the events on the class page', function (assert) {
2537
const container = store.peekRecord('class', 'ember-1.0.0-Container');
2638
assert.equal($(find('.spec-event-list li')).length, container.get('events.length'));
2739
});
28-

0 commit comments

Comments
 (0)