diff --git a/app/components/contributor-list/component.js b/app/components/contributor-list/component.js index 3f72fb3..925647e 100644 --- a/app/components/contributor-list/component.js +++ b/app/components/contributor-list/component.js @@ -1,18 +1,43 @@ -import Component from '@ember/component'; +import Component from '@glimmer/component'; +import { action } from '@ember/object'; import { inject as service } from '@ember/service'; +import { tracked } from '@glimmer/tracking'; -export default Component.extend({ - tagName: '', +export default class ContributorComponent extends Component { + @service router; - router: service(), - - selectedContributorId: null, - - actions: { - - openContributorDetails(contributor) { - this.router.transitionTo('dashboard.contributors.show', contributor); - } + @tracked selectedContributorId = null; + @tracked showToplistOnly = true; + get contributorList () { + return this.args.contributorList; } -}); + + get contributorTop10 () { + return this.contributorList ? + this.contributorList.slice(0, 10) : []; + } + + get contributors () { + return this.showToplistOnly ? + this.contributorTop10 : this.contributorList; + } + + get hiddenContributorsAmount () { + return this.contributorList.length - 10; + } + + get showAllButtonText () { + return `Show ${this.hiddenContributorsAmount} more contributors`; + } + + @action + openContributorDetails (contributor) { + this.router.transitionTo('dashboard.contributors.show', contributor); + } + + @action + showAllContributors () { + this.showToplistOnly = false; + } +} diff --git a/app/components/contributor-list/template.hbs b/app/components/contributor-list/template.hbs index 0f105d9..e51aee0 100644 --- a/app/components/contributor-list/template.hbs +++ b/app/components/contributor-list/template.hbs @@ -2,7 +2,7 @@ - {{#each @contributorList as |c|}} + {{#each this.contributors as |c|}} @@ -21,5 +21,12 @@ {{/each}} + {{#if this.showToplistOnly}} + + + {{this.showAllButtonText}} + + + {{/if}} diff --git a/app/controllers/dashboard.js b/app/controllers/dashboard.js index 0de990e..45e07a4 100644 --- a/app/controllers/dashboard.js +++ b/app/controllers/dashboard.js @@ -25,7 +25,10 @@ export default Controller.extend({ kreditsToplistSorting: computed('showUnconfirmedKredits', function(){ return this.showUnconfirmedKredits ? ['amountTotal:desc'] : ['amountConfirmed:desc']; }), - kreditsToplist: sort('kreditsByContributor', 'kreditsToplistSorting'), + kreditsToplist: computed('kreditsByContributor', function(){ + return this.kreditsByContributor.filter(c => c.amountTotal > 0); + }), + kreditsToplistSorted: sort('kreditsToplist', 'kreditsToplistSorting'), showUnconfirmedKredits: true, hideUnconfirmedKredits: not('showUnconfirmedKredits'), diff --git a/app/templates/dashboard.hbs b/app/templates/dashboard.hbs index 4f050af..6d10ddf 100644 --- a/app/templates/dashboard.hbs +++ b/app/templates/dashboard.hbs @@ -11,7 +11,7 @@ {{/if}}
- diff --git a/tests/unit/controllers/dashboard-test.js b/tests/unit/controllers/dashboard-test.js index fde691a..050a998 100644 --- a/tests/unit/controllers/dashboard-test.js +++ b/tests/unit/controllers/dashboard-test.js @@ -1,29 +1,31 @@ -// import { isEmpty, isPresent } from '@ember/utils'; -// import { module, test } from 'qunit'; -// import { setupTest } from 'ember-qunit'; -// import Contributor from 'kredits-web/models/contributor'; -// -// module('Unit | Controller | index', function(hooks) { -// setupTest(hooks); -// -// let addFixtures = function(controller) { -// [ -// { github_username: "neo", github_uid: "318", totalKreditsEarned: 10000 }, -// { github_username: "morpheus", github_uid: "843", totalKreditsEarned: 15000 }, -// { github_username: "trinity", github_uid: "123", totalKreditsEarned: 5000 }, -// { github_username: "mouse", github_uid: "696", totalKreditsEarned: 0 } -// ].forEach(fixture => { -// controller.get('kredits.contributors').push(Contributor.create(fixture)); -// }); -// }; -// -// test('doesn\'t contain people with 0 balance', function(assert) { -// let controller = this.owner.lookup('controller:index'); -// addFixtures(controller); -// -// let contributorsSorted = controller.get('contributorsSorted'); -// -// assert.ok(isPresent(contributorsSorted.findBy('github_username', 'neo'))); -// assert.ok(isEmpty(contributorsSorted.findBy('github_username', 'mouse'))); -// }); -// }); +import { isEmpty } from '@ember/utils'; +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; +import Contributor from 'kredits-web/models/contributor'; + +module('Unit | Controller | Dashboard', function(hooks) { + setupTest(hooks); + + let addFixtures = function(controller) { + [ + { github_username: "neo", github_uid: "318", totalKreditsEarned: 10000 }, + { github_username: "morpheus", github_uid: "843", totalKreditsEarned: 15000 }, + { github_username: "trinity", github_uid: "123", totalKreditsEarned: 5000 }, + { github_username: "mouse", github_uid: "696", totalKreditsEarned: 0 } + ].forEach(fixture => { + controller.get('kredits.contributors').push(Contributor.create(fixture)); + }); + }; + + test('kreditsToplistSorted()', function(assert) { + const controller = this.owner.lookup('controller:dashboard'); + addFixtures(controller); + + const kreditsToplistSorted = controller.get('kreditsToplistSorted'); + + assert.equal(kreditsToplistSorted.length, 3, + 'contains all contributors with kredits'); + assert.ok(isEmpty(kreditsToplistSorted.findBy('github_username', 'mouse')), + 'does not contain contributors with 0 kredits'); + }); +});