Skip to content

Commit

Permalink
Merge pull request #27 from SumOfUs/development
Browse files Browse the repository at this point in the history
Toggleable funding table
  • Loading branch information
Tuuleh authored Feb 19, 2018
2 parents b9bb32f + e538e30 commit 1bef1ff
Show file tree
Hide file tree
Showing 18 changed files with 277 additions and 203 deletions.
17 changes: 0 additions & 17 deletions circle.yml

This file was deleted.

32 changes: 0 additions & 32 deletions locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,46 +75,14 @@ de:
grants: Stiftungsgelder
donations: Online Spende
total: Gesamteinnahmen
total_amount:
:2016: 4,359,546€
:2015: 4,551,345€
:2014: 3,469,988€
individuals: Spenden von Mitgliedern
individuals_amount:
:2016: 3,637,777€
:2015: 3,823,131€
:2014: 2,865,892€
foundations: Stiftungen
foundations_amount:
:2016: 575,964€
:2015: 713,291€
:2014: 586,990€
other: Andere Einnahmen
other_amount:
:2016: 145,804€
:2015: 14,924€
:2014: 17,106€
expenses:
total: Gesamtausgaben
total_amount:
:2016: 4,679,121€
:2015: 4,465,348€
:2014: 2,533,006€
campaigns: Kampagnen
campaigns_amount:
:2016: 4,081,064€
:2015: 4,033,033€
:2014: 2,238,463€
ops: Organisation & Infrastruktur
ops_amount:
:2016: 439,768€
:2015: 307,463€
:2014: 219,790€
fundraising: Fundraising
fundraising_amount:
:2016: 158,717€
:2015: 124,852€
:2014: 74,753€
branding:
tagline: Menschen vor Profit
license: Creative Commons Namensnennung 3.0 Unported Lizenz.
Expand Down
32 changes: 0 additions & 32 deletions locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,46 +75,14 @@ en:
grants: Foundation grants
donations: Online donations
total: Total income
total_amount:
:2016: $4,637,815
:2015: $4,857,359
:2014: $4,426,005
individuals: Individuals
individuals_amount:
:2016: $3,869,976
:2015: $4,080,182
:2014: $3,655,474
foundations: Foundations
foundations_amount:
:2016: $612,728
:2015: $761,250
:2014: $748,712
other: Other sources
other_amount:
:2016: $155,111
:2015: $15,927
:2014: $21,819
expenses:
total: Total expenses
total_amount:
:2016: $4,977,788
:2015: $4,765,579
:2014: $3,230,875
campaigns: Campaigns
campaigns_amount:
:2015: $4,304,197
:2016: $4,341,557
:2014: $2,855,182
ops: Management & Operations
ops_amount:
:2016: $467,838
:2015: $328,136
:2014: $280,345
fundraising: Fundraising
fundraising_amount:
:2016: $168,848
:2015: $133,246
:2014: $95,348

branding:
tagline: Fighting for people over profits
Expand Down
32 changes: 0 additions & 32 deletions locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,46 +75,14 @@ fr:
grants: Mécénat, subventions provenant de fondations indépendantes
donations: Dons en ligne (provenants de nos membres)
total: Revenu total
total_amount:
:2016: 4,030,214€
:2015: 3,972,348€
:2014: 3,637,428€
individuals: Dons individuels de membres de SumOfUs
individuals_amount:
:2016: 3,383,798€
:2015: 3,336,773€
:2014: 3,004,256€
foundations: Subventions de fondations
foundations_amount:
:2016: 620,791€
:2015: 622,550€
:2014: 615,329€
other: Autre provenance
other_amount:
:2016: 25,625€
:2015: 13,025€
:2014: 17,843€
expenses:
total: Dépenses totales
total_amount:
:2016: 4,071,725€
:2015: 3,896,474€
:2014: 2,642,209€
campaigns: Campagnes
campaigns_amount:
:2016: 3,571,548€
:2015: 3,519,155€
:2014: 2,334,968€
ops: Management & gestion
ops_amount:
:2016: 370,062€
:2015: 268,350€
:2014: 229,266€
fundraising: Levée de fonds
fundraising_amount:
:2016: 128,645€
:2015: 108,969€
:2014: 77,975€
branding:
tagline: L’humain avant les profits
license: Creative Commons Attribution 3.0 Unported License.
Expand Down
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"uglify": "^0.1.5",
"uglify-js": "^3.1.0",
"underscore": "^1.8.3",
"watchify": "^3.7.0"
"watchify": "^3.7.0",
"accounting-js": "^1.1.1"
},
"license": "MIT",
"engines": {
Expand Down
2 changes: 2 additions & 0 deletions source/javascripts/homepage.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ window.SignupForm = require('./sumofus/backbone/signup_form');
window.Campaigns = require('./sumofus/backbone/campaigns');
window.UnsubscribeForm = require('./sumofus/backbone/unsubscribe_form');
window.SweetPlaceholder = require('./sumofus/backbone/sweet_placeholder');
window.FundingTable = require('./sumofus/backbone/funding/funding_table');
window.ExpensesTable = require('./sumofus/backbone/funding/expenses_table')
29 changes: 29 additions & 0 deletions source/javascripts/sumofus/backbone/funding/conversion_rates.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const conversionRates = {
AUD: {
_2014: 0.8666,
_2015: 0.7435,
_2016: 0.7143,
},
CAD: {
_2014: 0.8703,
_2015: 0.7524,
_2016: 0.7252,
},
EUR: {
_2014: 1.2755,
_2015: 1.0672,
_2016: 1.0638,
},
GBP: {
_2014: 1.5823,
_2015: 1.4684,
_2016: 1.2987,
},
USD: {
_2014: 1,
_2015: 1,
_2016: 1,
}
};

module.exports = conversionRates;
62 changes: 62 additions & 0 deletions source/javascripts/sumofus/backbone/funding/expenses_table.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
const conversionRates = require('./conversion_rates.js');

const TableTemplate = require('./table_template.js');
const Expenses = Backbone.Model.extend({
defaults: {
_2014: {
total: 3230875,
campaigns: 2855182,
ops: 280345,
fundraising: 95348,
},
_2015: {
total: 4765579,
campaigns: 4304197,
ops: 328136,
fundraising: 133246,
},
_2016: {
total: 4977788,
campaigns: 4341557,
ops: 467838,
fundraising: 168848,
}
}
});

const ExpensesTable = Backbone.View.extend({
events: {
'change #expenses-currency-select': 'changeCurrency',
},
el: '.expenses-table-container',
model: new Expenses(),

categories: ['total', 'campaigns', 'ops', 'fundraising'],

initialize: function() {
// render initial format - default to USD
this.$el.html(this.template('expenses', this.categories, this.model.attributes, 'USD'));
return this;
},

conversionRates: conversionRates,

changeCurrency(e) {
const currency = $('#expenses-currency-select option:selected').val()
const rates = this.conversionRates[currency];
var newAttributes = {};
_.each(this.model.attributes, function(sources, year){
newAttributes[year] = {};
_.each(sources, function(amount, source){
newAttributes[year][source] = Math.round(amount / rates[year])
});
});
const convertedModel = new Expenses(newAttributes);
this.$el.html(this.template('expenses', this.categories, convertedModel.attributes, currency));
return this;
},

template: TableTemplate,
});

module.exports = ExpensesTable;
15 changes: 15 additions & 0 deletions source/javascripts/sumofus/backbone/funding/format_currency.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const AccountingJs = require('accounting-js');

const formatCurrency = function(money, currency) {
// make money a string and format it appropriately to the currency
switch (currency) {
case 'EUR':
return AccountingJs.formatMoney(money, { symbol: "€", precision: 0 });
case 'GBP':
return AccountingJs.formatMoney(money, { symbol: "£", precision: 0 });
default:
return AccountingJs.formatMoney(money, { precision: 0});
}
}

module.exports = formatCurrency;
62 changes: 62 additions & 0 deletions source/javascripts/sumofus/backbone/funding/funding_table.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
const conversionRates = require('./conversion_rates.js');
const TableTemplate = require('./table_template.js');

const Funding = Backbone.Model.extend({
defaults: {
_2014: {
total: 4426005,
individuals: 3655474,
foundations: 748712,
other: 21819,
},
_2015: {
total: 4857359,
individuals: 4080182,
foundations: 761250,
other: 15927,
},
_2016: {
total: 4637815,
individuals: 3869976,
foundations: 612728,
other: 155111,
}
}
});

const FundingTable = Backbone.View.extend({
events: {
'change #funding-currency-select': 'changeCurrency',
},
el: '.funding-table-container',
model: new Funding(),

categories: ['total', 'individuals', 'foundations', 'other'],

conversionRates: conversionRates,

initialize: function() {
// render initial format - default to USD
this.$el.html(this.template('funding', this.categories, this.model.attributes, 'USD'));
return this;
},

changeCurrency(e) {
const currency = $('#funding-currency-select option:selected').val()
const rates = this.conversionRates[currency];
var newAttributes = {};
_.each(this.model.attributes, function(sources, year){
newAttributes[year] = {};
_.each(sources, function(amount, source){
newAttributes[year][source] = Math.round(amount / rates[year])
});
});
const convertedModel = new Funding(newAttributes);
this.$el.html(this.template('funding', this.categories, convertedModel.attributes, currency));
return this;
},

template: TableTemplate,
});

module.exports = FundingTable;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const roundPercentile = function(x, y, decimals) {
const value = 100 * (x / y);
return Number(Math.round(value+'e'+decimals)+'e-'+decimals);
}

module.exports = roundPercentile;
12 changes: 12 additions & 0 deletions source/javascripts/sumofus/backbone/funding/select_template.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const conversionRates = require('./conversion_rates.js');

const selectTemplate = function(type, selectCurrency){
var openTag = `<select id="${type}-currency-select" class="currency-select" name="currency">`;
_.each(Object.keys(conversionRates), function(currency){
const selected = currency === selectCurrency ? " selected" : "";
openTag = openTag.concat(`<option${selected}>${currency}</option>`);
})
return openTag.concat(`</select>`);
}

module.exports = selectTemplate;
Loading

0 comments on commit 1bef1ff

Please sign in to comment.