Skip to content

Commit a72846f

Browse files
committed
Auto merge of #2214 - RobbieClarken:sort-by-newly-added, r=jtgeibel
Enable sorting crates by most recently added This change adds the option to sort crates by "Newly Added" on the following pages: - `/crates` - `/search` - `/users/:user_id` - `/teams/:team_id` - `/keywords/:keyword_id` - `/categories/:category_id` - `/me/crates` Sorting is performed using the `crates.created_at` column. I've put "Newly Added" as the last option in the dropdown: <img width="258" alt="sort-by-newly-added" src="https://user-images.githubusercontent.com/663161/75087201-2a7ff500-558d-11ea-896b-2e82de37811d.png"> Let me know if you would like a different label or for the order to be different. I couldn't find any existing frontend tests of changing sort order. I'd be happy to add some as part of this PR if they would be valuable. Closes #1919.
2 parents 5202619 + 975de2a commit a72846f

File tree

17 files changed

+106
-3
lines changed

17 files changed

+106
-3
lines changed

app/controllers/category/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export default Controller.extend(PaginationMixin, {
1919
return 'All-Time Downloads';
2020
} else if (this.sort === 'alpha') {
2121
return 'Alphabetical';
22+
} else if (this.sort === 'new') {
23+
return 'Newly Added';
2224
} else if (this.get('sort') === 'recent-updates') {
2325
return 'Recent Updates';
2426
} else {

app/controllers/crates.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ export default Controller.extend(PaginationMixin, {
2121
return 'Recent Downloads';
2222
} else if (this.get('sort') === 'recent-updates') {
2323
return 'Recent Updates';
24+
} else if (this.sort === 'new') {
25+
return 'Newly Added';
2426
} else {
2527
return 'Alphabetical';
2628
}

app/controllers/keyword/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export default Controller.extend(PaginationMixin, {
1717
return 'All-Time Downloads';
1818
} else if (this.sort === 'alpha') {
1919
return 'Alphabetical';
20+
} else if (this.sort === 'new') {
21+
return 'Newly Added';
2022
} else if (this.get('sort') === 'recent-updates') {
2123
return 'Recent Updates';
2224
} else {

app/controllers/me/crates.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ export default Controller.extend(PaginationMixin, {
2121
return 'Recent Downloads';
2222
} else if (this.get('sort') === 'recent-updates') {
2323
return 'Recent Updates';
24+
} else if (this.sort === 'new') {
25+
return 'Newly Added';
2426
} else {
2527
return 'Alphabetical';
2628
}

app/controllers/search.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ export default Controller.extend(PaginationMixin, {
3333
return 'Recent Downloads';
3434
} else if (this.get('sort') === 'recent-updates') {
3535
return 'Recent Updates';
36+
} else if (this.sort === 'new') {
37+
return 'Newly Added';
3638
} else {
3739
return 'Relevance';
3840
}

app/controllers/team.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export default Controller.extend(PaginationMixin, {
1919
return 'Recent Downloads';
2020
} else if (this.get('sort') === 'recent-updates') {
2121
return 'Recent Updates';
22+
} else if (this.sort === 'new') {
23+
return 'Newly Added';
2224
} else {
2325
return 'Alphabetical';
2426
}

app/controllers/user.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export default Controller.extend(PaginationMixin, {
2020
return 'Recent Downloads';
2121
} else if (this.get('sort') === 'recent-updates') {
2222
return 'Recent Updates';
23+
} else if (this.sort === 'new') {
24+
return 'Newly Added';
2325
} else {
2426
return 'Alphabetical';
2527
}

app/templates/category/index.hbs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@
7777
Recent Updates
7878
</LinkTo>
7979
</li>
80+
<li>
81+
<LinkTo @query={{hash sort="new"}}>
82+
Newly Added
83+
</LinkTo>
84+
</li>
8085
</dd.Content>
8186
</Dropdown>
8287
</div>
@@ -88,4 +93,4 @@
8893
{{/each}}
8994
</div>
9095

91-
<Pagination @pages={{this.pages}} @prevPage={{this.prevPage}} @nextPage={{this.nextPage}} />
96+
<Pagination @pages={{this.pages}} @prevPage={{this.prevPage}} @nextPage={{this.nextPage}} />

app/templates/crates.hbs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@
6565
Recent Updates
6666
</LinkTo>
6767
</li>
68+
<li>
69+
<LinkTo @query={{hash page=1 sort="new"}}>
70+
Newly Added
71+
</LinkTo>
72+
</li>
6873
</dd.Content>
6974
</Dropdown>
7075
</div>

app/templates/keyword/index.hbs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@
4545
Recent Updates
4646
</LinkTo>
4747
</li>
48+
<li>
49+
<LinkTo @query={{hash sort="new"}}>
50+
Newly Added
51+
</LinkTo>
52+
</li>
4853
</dd.Content>
4954
</Dropdown>
5055
</div>

0 commit comments

Comments
 (0)