From e29ffdc3193e4e994bec973050b35f0fc4d985f8 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Tue, 31 Jan 2017 17:28:33 +0800 Subject: [PATCH] Add contributor and kredits count to page --- app/controllers/index.js | 20 ++++++++++++++++++++ app/styles/app.scss | 15 +++++++++++++++ app/templates/index.hbs | 5 +++++ tests/unit/controllers/index-test.js | 25 +++++++++++++++++++++++++ 4 files changed, 65 insertions(+) create mode 100644 app/controllers/index.js create mode 100644 tests/unit/controllers/index-test.js diff --git a/app/controllers/index.js b/app/controllers/index.js new file mode 100644 index 0000000..fddb970 --- /dev/null +++ b/app/controllers/index.js @@ -0,0 +1,20 @@ +import Ember from 'ember'; + +const { + computed +} = Ember; + +export default Ember.Controller.extend({ + + contributorsCount: computed('model.contributors.[]', function() { + return this.get('model.contributors').length; + }), + + kreditsSum: computed('model.contributors.[]', function() { + let kredits = this.get('model.contributors').mapBy('kredits'); + return kredits.reduce(function(previousValue, currentValue) { + return currentValue + previousValue; + }); + }) + +}); diff --git a/app/styles/app.scss b/app/styles/app.scss index 8bf9237..4ef2134 100644 --- a/app/styles/app.scss +++ b/app/styles/app.scss @@ -21,6 +21,7 @@ $font-family-sans: 'Open Sans', sans-serif; body { background-image: url('/img/bg.jpg'); background-repeat: none; + background-attachment: fixed; font-family: $font-family-sans; font-size: 16px; font-weight: 300; @@ -47,6 +48,20 @@ section { font-size: 2rem; } } + + &#contributors { + .content { + p.stats { + padding-top: 2rem; + font-size: 1rem; + color: lightblue; + text-align: center; + span.number { + font-weight: 600; + } + } + } + } } @import "components/contributor-list"; diff --git a/app/templates/index.hbs b/app/templates/index.hbs index c47d9b2..b7f14f2 100644 --- a/app/templates/index.hbs +++ b/app/templates/index.hbs @@ -6,6 +6,11 @@
{{contributor-list contributors=model.contributors}} + +

+ {{kreditsSum}} kredits issued and distributed among + {{contributorsCount}} contributors. +

diff --git a/tests/unit/controllers/index-test.js b/tests/unit/controllers/index-test.js new file mode 100644 index 0000000..0a51409 --- /dev/null +++ b/tests/unit/controllers/index-test.js @@ -0,0 +1,25 @@ +import { moduleFor, test } from 'ember-qunit'; + +moduleFor('controller:index', 'Unit | Controller | index'); + +let addFixtures = function(controller) { + controller.set('model', { contributors: [ + { github_username: "neo", github_uid: "318", kredits: 10000 }, + { github_username: "morpheus", github_uid: "843", kredits: 15000 }, + { github_username: "mouse", github_uid: "842", kredits: 5000 }, + ]}); +}; + +test('#contributorsCount returns number of contributors', function(assert) { + let controller = this.subject(); + addFixtures(controller); + + assert.equal(controller.get('contributorsCount'), 3); +}); + +test('#kreditsSum returns the sum of all kredits', function(assert) { + let controller = this.subject(); + addFixtures(controller); + + assert.equal(controller.get('kreditsSum'), 30000); +});