Skip to content

Add dropdown box to allow selecting more results per page #1762

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

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 12 additions & 0 deletions app/controllers/crates.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,16 @@ export default Controller.extend(PaginationMixin, {
return 'Alphabetical';
}
}),

resultCount: computed('per_page', function() {
if (this.per_page === 10) {
return 10;
} else if (this.per_page === 20) {
return 20;
} else if (this.per_page === 50) {
return 50;
} else {
return 100;
}
}),
});
1 change: 1 addition & 0 deletions app/routes/crates.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default Route.extend({
letter: { refreshModel: true },
page: { refreshModel: true },
sort: { refreshModel: true },
per_page: { refreshModel: true },
},

model(params) {
Expand Down
22 changes: 16 additions & 6 deletions app/styles/crate.scss
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,26 @@
width: 100%;
@include display-flex;
@include justify-content(space-between);
align-items: center;
margin-bottom: 25px;

.cur, .total { color: $main-color; font-weight: bold; }

.dropdown-container { font-size: 85%; }
a.dropdown {
background-color: $main-bg-dark;
padding: 10px;
display: inline-block;
@include border-radius(5px);
.dropdown-section {
@include display-flex;
@include justify-content(space-between);

.dropdown-container { font-size: 85%; }
a.dropdown {
background-color: $main-bg-dark;
padding: 10px;
display: inline-block;
@include border-radius(5px);
}

.per_page {
margin-left: 10px;
}
}
}

Expand Down
97 changes: 66 additions & 31 deletions app/templates/crates.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -34,39 +34,74 @@
</span>
</div>

<div class='sort' data-test-crates-sort>
<span class='small'>Sort by</span>
<div class='dropdown-section'>
<div class='sort' data-test-crates-sort>
<span class='small'>Sort by</span>

{{#rl-dropdown-container class="dropdown-container"}}
{{#rl-dropdown-toggle tagName="a" class="dropdown" data-test-current-order=true}}
{{svg-jar "sort"}}
{{ currentSortBy }}
<span class='arrow'></span>
{{/rl-dropdown-toggle}}
{{#rl-dropdown-container class="dropdown-container"}}
{{#rl-dropdown-toggle tagName="a" class="dropdown" data-test-current-order=true}}
{{svg-jar "sort"}}
{{ currentSortBy }}
<span class='arrow'></span>
{{/rl-dropdown-toggle}}

{{#rl-dropdown tagName="ul" class="dropdown" closeOnChildClick="a:link"}}
<li>
{{#link-to (query-params page=1 sort="alpha")}}
Alphabetical
{{/link-to}}
</li>
<li>
{{#link-to (query-params page=1 sort="downloads")}}
All-Time Downloads
{{/link-to}}
</li>
<li>
{{#link-to (query-params page=1 sort="recent-downloads")}}
Recent Downloads
{{/link-to}}
</li>
<li>
{{#link-to (query-params page=1 sort="recent-updates")}}
Recent Updates
{{/link-to}}
</li>
{{/rl-dropdown}}
{{/rl-dropdown-container}}
{{#rl-dropdown tagName="ul" class="dropdown" closeOnChildClick="a:link"}}
<li>
{{#link-to (query-params page=1 sort="alpha")}}
Alphabetical
{{/link-to}}
</li>
<li>
{{#link-to (query-params page=1 sort="downloads")}}
All-Time Downloads
{{/link-to}}
</li>
<li>
{{#link-to (query-params page=1 sort="recent-downloads")}}
Recent Downloads
{{/link-to}}
</li>
<li>
{{#link-to (query-params page=1 sort="recent-updates")}}
Recent Updates
{{/link-to}}
</li>
{{/rl-dropdown}}
{{/rl-dropdown-container}}
</div>
<div class='per_page' data-test-crates-count>
<span class='small'>Display results</span>

{{#rl-dropdown-container class="dropdown-container"}}
{{#rl-dropdown-toggle tagName="a" class="dropdown" data-test-current-count=true}}
{{ resultCount }}
<span class='arrow'></span>
{{/rl-dropdown-toggle}}

{{#rl-dropdown tagName="ul" class="dropdown" closeOnChildClick="a:link"}}
<li>
{{#link-to (query-params page=1 per_page=10)}}
10
{{/link-to}}
</li>
<li>
{{#link-to (query-params page=1 per_page=20)}}
20
{{/link-to}}
</li>
<li>
{{#link-to (query-params page=1 per_page=50)}}
50
{{/link-to}}
</li>
<li>
{{#link-to (query-params page=1 per_page=100)}}
100
{{/link-to}}
</li>
{{/rl-dropdown}}
{{/rl-dropdown-container}}
</div>
</div>
</div>

Expand Down
7 changes: 7 additions & 0 deletions tests/acceptance/crates-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ module('Acceptance | crates page', function(hooks) {
assert.dom('[data-test-crates-sort] [data-test-current-order]').hasText('Alphabetical');
});

test('crates default count is 10', async function(assert) {
this.server.loadFixtures();

await visit('/crates');
assert.dom('[data-test-crates-count] [data-test-current-count]').hasText('10');
});

test('downloads appears for each crate on crate list', async function(assert) {
this.server.loadFixtures();

Expand Down