Skip to content

Replace pagination mixin with computed property macro #2802

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

Merged
merged 6 commits into from
Sep 18, 2020
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
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ module.exports = {

'ember/no-empty-attrs': 'off',
'ember/no-get': 'off',
'ember/no-mixins': 'off',
'ember/require-computed-property-dependencies': 'off',

'import-helpers/order-imports': [
Expand Down
6 changes: 3 additions & 3 deletions app/components/pagination.hbs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<nav local-class='pagination' aria-label="Pagination navigation">
<LinkTo @query={{hash page=@prevPage}} local-class="prev" @rel="prev" @title="previous page" data-test-pagination-prev>
<LinkTo @query={{hash page=@pagination.prevPage}} local-class="prev" @rel="prev" @title="previous page" data-test-pagination-prev>
{{svg-jar "left-pag"}}
</LinkTo>
<ol>
{{#each @pages as |page|}}
{{#each @pagination.pages as |page|}}
<li>
<LinkTo @query={{hash page=page}} @title={{concat "Go to page " page}}>
{{ page }}
</LinkTo>
</li>
{{/each}}
</ol>
<LinkTo @query={{hash page=@nextPage}} local-class="next" @rel="next" @title="next page" data-test-pagination-next>
<LinkTo @query={{hash page=@pagination.nextPage}} local-class="next" @rel="next" @title="next page" data-test-pagination-next>
{{svg-jar "right-pag"}}
</LinkTo>
</nav>
5 changes: 3 additions & 2 deletions app/controllers/categories.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ import Controller from '@ember/controller';
import { computed } from '@ember/object';
import { readOnly } from '@ember/object/computed';

import PaginationMixin from '../mixins/pagination';
import { pagination } from '../utils/pagination';

export default Controller.extend(PaginationMixin, {
export default Controller.extend({
queryParams: ['page', 'per_page', 'sort'],
page: '1',
per_page: 100,
sort: 'alpha',

totalItems: readOnly('model.meta.total'),
pagination: pagination(),

currentSortBy: computed('sort', function () {
return this.sort === 'crates' ? '# Crates' : 'Alphabetical';
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/category/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ import Controller from '@ember/controller';
import { computed } from '@ember/object';
import { readOnly } from '@ember/object/computed';

import PaginationMixin from '../../mixins/pagination';
import { pagination } from '../../utils/pagination';

export default Controller.extend(PaginationMixin, {
export default Controller.extend({
queryParams: ['page', 'per_page', 'sort'],
page: '1',
per_page: 10,
sort: 'recent-downloads',

totalItems: readOnly('model.meta.total'),
pagination: pagination(),

category: null,

Expand Down
5 changes: 3 additions & 2 deletions app/controllers/crate/reverse-dependencies.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import Controller from '@ember/controller';
import { readOnly } from '@ember/object/computed';

import PaginationMixin from '../../mixins/pagination';
import { pagination } from '../../utils/pagination';

export default Controller.extend(PaginationMixin, {
export default Controller.extend({
queryParams: ['page', 'per_page'],
page: '1',
per_page: 10,
crate: null,

totalItems: readOnly('model.meta.total'),
pagination: pagination(),
});
5 changes: 3 additions & 2 deletions app/controllers/crates.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import Controller from '@ember/controller';
import { computed } from '@ember/object';
import { readOnly } from '@ember/object/computed';

import PaginationMixin from '../mixins/pagination';
import { pagination } from '../utils/pagination';

export default Controller.extend(PaginationMixin, {
export default Controller.extend({
queryParams: ['letter', 'page', 'per_page', 'sort'],
letter: null,
page: '1',
Expand All @@ -13,6 +13,7 @@ export default Controller.extend(PaginationMixin, {
alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split(''),

totalItems: readOnly('model.meta.total'),
pagination: pagination(),

currentSortBy: computed('sort', function () {
if (this.sort === 'downloads') {
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/keyword/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ import Controller from '@ember/controller';
import { computed } from '@ember/object';
import { readOnly } from '@ember/object/computed';

import PaginationMixin from '../../mixins/pagination';
import { pagination } from '../../utils/pagination';

export default Controller.extend(PaginationMixin, {
export default Controller.extend({
queryParams: ['page', 'per_page', 'sort'],
page: '1',
per_page: 10,
sort: 'recent-downloads',

totalItems: readOnly('model.meta.total'),
pagination: pagination(),

currentSortBy: computed('sort', function () {
if (this.sort === 'downloads') {
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/keywords.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ import Controller from '@ember/controller';
import { computed } from '@ember/object';
import { readOnly } from '@ember/object/computed';

import PaginationMixin from '../mixins/pagination';
import { pagination } from '../utils/pagination';

export default Controller.extend(PaginationMixin, {
export default Controller.extend({
queryParams: ['page', 'per_page', 'sort'],
page: '1',
per_page: 10,
sort: 'crates',

totalItems: readOnly('model.meta.total'),
pagination: pagination(),

currentSortBy: computed('sort', function () {
return this.sort === 'crates' ? '# Crates' : 'Alphabetical';
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/me/crates.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ import Controller from '@ember/controller';
import { computed } from '@ember/object';
import { readOnly } from '@ember/object/computed';

import PaginationMixin from '../../mixins/pagination';
import { pagination } from '../../utils/pagination';

// TODO: reduce duplicatoin with controllers/crates

export default Controller.extend(PaginationMixin, {
export default Controller.extend({
queryParams: ['page', 'per_page', 'sort'],
page: '1',
per_page: 10,
sort: 'alpha',

totalItems: readOnly('model.meta.total'),
pagination: pagination(),

currentSortBy: computed('sort', function () {
if (this.sort === 'downloads') {
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/me/following.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ import Controller from '@ember/controller';
import { computed } from '@ember/object';
import { readOnly } from '@ember/object/computed';

import PaginationMixin from '../../mixins/pagination';
import { pagination } from '../../utils/pagination';

// TODO: reduce duplicatoin with controllers/me/crates

export default Controller.extend(PaginationMixin, {
export default Controller.extend({
queryParams: ['page', 'per_page', 'sort'],
page: '1',
per_page: 10,
sort: 'alpha',

totalItems: readOnly('model.meta.total'),
pagination: pagination(),

currentSortBy: computed('sort', function () {
return this.sort === 'downloads' ? 'Downloads' : 'Alphabetical';
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { bool, readOnly } from '@ember/object/computed';

import { task } from 'ember-concurrency';

import PaginationMixin from '../mixins/pagination';
import { pagination } from '../utils/pagination';

export default Controller.extend(PaginationMixin, {
export default Controller.extend({
queryParams: ['all_keywords', 'page', 'per_page', 'q', 'sort'],
q: null,
page: '1',
Expand All @@ -23,6 +23,7 @@ export default Controller.extend(PaginationMixin, {
}),

totalItems: readOnly('model.meta.total'),
pagination: pagination(),

currentSortBy: computed('sort', function () {
if (this.sort === 'downloads') {
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/team.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ import Controller from '@ember/controller';
import { computed } from '@ember/object';
import { readOnly } from '@ember/object/computed';

import PaginationMixin from '../mixins/pagination';
import { pagination } from '../utils/pagination';

export default Controller.extend(PaginationMixin, {
export default Controller.extend({
queryParams: ['page', 'per_page', 'sort'],
page: '1',
per_page: 10,
sort: 'alpha',

totalItems: readOnly('model.crates.meta.total'),
pagination: pagination(),

currentSortBy: computed('sort', function () {
if (this.sort === 'downloads') {
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ import Controller from '@ember/controller';
import { computed } from '@ember/object';
import { readOnly } from '@ember/object/computed';

import PaginationMixin from '../mixins/pagination';
import { pagination } from '../utils/pagination';

// TODO: reduce duplication with controllers/crates

export default Controller.extend(PaginationMixin, {
export default Controller.extend({
queryParams: ['page', 'per_page', 'sort'],
page: '1',
per_page: 10,
sort: 'alpha',

totalItems: readOnly('model.crates.meta.total'),
pagination: pagination(),

currentSortBy: computed('sort', function () {
if (this.sort === 'downloads') {
Expand Down
76 changes: 0 additions & 76 deletions app/mixins/pagination.js

This file was deleted.

6 changes: 3 additions & 3 deletions app/templates/categories.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

<div local-class="results-meta">
<ResultsCount
@start={{this.currentPageStart}}
@end={{this.currentPageEnd}}
@start={{this.pagination.currentPageStart}}
@end={{this.pagination.currentPageEnd}}
@total={{this.totalItems}}
data-test-categories-nav
/>
Expand Down Expand Up @@ -37,7 +37,7 @@
{{/each}}
</div>

<Pagination @pages={{this.pages}} @prevPage={{this.prevPage}} @nextPage={{this.nextPage}} />
<Pagination @pagination={{this.pagination}} />

<div local-class='categories-footer'>
Want to categorize your crate?
Expand Down
6 changes: 3 additions & 3 deletions app/templates/category/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
<h2>Crates</h2>
<div local-class="results-meta">
<ResultsCount
@start={{this.currentPageStart}}
@end={{this.currentPageEnd}}
@start={{this.pagination.currentPageStart}}
@end={{this.pagination.currentPageEnd}}
@total={{this.totalItems}}
data-test-category-nav
/>
Expand All @@ -60,4 +60,4 @@
{{/each}}
</div>

<Pagination @pages={{this.pages}} @prevPage={{this.prevPage}} @nextPage={{this.nextPage}} />
<Pagination @pagination={{this.pagination}} />
6 changes: 3 additions & 3 deletions app/templates/crate/reverse-dependencies.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

<div local-class="results-meta">
<ResultsCount
@start={{this.currentPageStart}}
@end={{this.currentPageEnd}}
@start={{this.pagination.currentPageStart}}
@end={{this.pagination.currentPageEnd}}
@total={{this.totalItems}}
@name="reverse dependencies of {{this.crate.name}}"
/>
Expand All @@ -25,4 +25,4 @@
{{/each}}
</div>

<Pagination @pages={{this.pages}} @prevPage={{this.prevPage}} @nextPage={{this.nextPage}} />
<Pagination @pagination={{this.pagination}} />
6 changes: 3 additions & 3 deletions app/templates/crates.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

<div local-class="results-meta">
<ResultsCount
@start={{this.currentPageStart}}
@end={{this.currentPageEnd}}
@start={{this.pagination.currentPageStart}}
@end={{this.pagination.currentPageEnd}}
@total={{this.totalItems}}
data-test-crates-nav
/>
Expand All @@ -43,4 +43,4 @@
{{/each}}
</div>

<Pagination @pages={{this.pages}} @prevPage={{this.prevPage}} @nextPage={{this.nextPage}} />
<Pagination @pagination={{this.pagination}} />
Loading