Skip to content

Commit c7e6a9b

Browse files
committed
Add following pages
1 parent a018ea3 commit c7e6a9b

File tree

4 files changed

+109
-1
lines changed

4 files changed

+109
-1
lines changed

app/controllers/me/following.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import Ember from 'ember';
2+
import PaginationMixin from 'cargo/mixins/pagination';
3+
4+
// TODO: reduce duplicatoin with controllers/me/crates
5+
6+
export default Ember.ArrayController.extend(PaginationMixin, {
7+
needs: ['application'],
8+
queryParams: ['page', 'per_page', 'sort'],
9+
page: '1',
10+
per_page: 10,
11+
sort: 'alpha',
12+
showSortBy: false,
13+
14+
totalItems: function() {
15+
return this.store.metadataFor('crate').total;
16+
}.property('model'),
17+
18+
currentSortBy: function() {
19+
if (this.get('sort') === 'downloads') {
20+
return 'Downloads';
21+
} else {
22+
return 'Alphabetical';
23+
}
24+
}.property('sort'),
25+
26+
actions: {
27+
toggleShowSortBy: function() {
28+
var opt = 'showSortBy';
29+
this.get('controllers.application').resetDropdownOption(this, opt);
30+
31+
},
32+
},
33+
});
34+
35+

app/routes/me/crates.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import Ember from 'ember';
2-
import ajax from 'ic-ajax';
32
import AuthenticatedRoute from 'cargo/mixins/authenticated-route';
43

54
export default Ember.Route.extend(AuthenticatedRoute, {

app/routes/me/following.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import Ember from 'ember';
2+
import AuthenticatedRoute from 'cargo/mixins/authenticated-route';
3+
4+
export default Ember.Route.extend(AuthenticatedRoute, {
5+
queryParams: {
6+
page: { refreshModel: true },
7+
sort: { refreshModel: true },
8+
},
9+
10+
model: function(params) {
11+
params.following = 1;
12+
return this.store.find('crate', params);
13+
},
14+
});
15+

app/templates/me/following.hbs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<div id='crates-heading'>
2+
<img class='logo' src="/assets/crate.png"/>
3+
<h1>My Crates</h1>
4+
</div>
5+
6+
{{! TODO: reduce duplication with templates/me/crates.hbs }}
7+
8+
<div id='results'>
9+
<div class='nav'>
10+
<span class='amt small'>
11+
Displaying
12+
<span class='cur'>{{ currentPageStart }}-{{ currentPageEnd }}</span>
13+
of <span class='total'>{{ totalItems }}</span> total results
14+
</span>
15+
</div>
16+
17+
<div class='sort'>
18+
<span class='small'>Sort by</span>
19+
<div class='dropdown-container'>
20+
<a {{action 'toggleShowSortBy'}}
21+
{{bind-attr class='showSortBy:active :dropdown'}}>
22+
<img src="/assets/sort.png"/>
23+
{{ currentSortBy }}
24+
<span class='arrow'></span>
25+
</a>
26+
<ul {{bind-attr class='showSortBy:open :dropdown'}}>
27+
<li>
28+
{{#link-to 'me.following' (query-params sort="alpha")}}
29+
Alphabetical
30+
{{/link-to}}
31+
</li>
32+
<li>
33+
{{#link-to 'me.following' (query-params sort="downloads")}}
34+
Downloads
35+
{{/link-to}}
36+
</li>
37+
</ul>
38+
</div>
39+
</div>
40+
</div>
41+
42+
<div id='crates' class='white-rows'>
43+
{{#each}}
44+
{{render "crate-row" this}}
45+
{{/each}}
46+
</div>
47+
48+
<div class='pagination'>
49+
{{#link-to 'me.following' (query-params page=prevPage) class="prev"}}
50+
<img src="/assets/left-pag.png"/>
51+
{{/link-to}}
52+
{{#each pages}}
53+
{{#link-to 'me.following' (query-params page=this)}}{{ this }}{{/link-to}}
54+
{{/each}}
55+
{{#link-to 'me.following' (query-params page=nextPage) class="next"}}
56+
<img src="/assets/right-pag.png"/>
57+
{{/link-to}}
58+
</div>
59+

0 commit comments

Comments
 (0)