mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Sort expenses and revenue by percentage.
This commit is contained in:
parent
b6109ca93e
commit
0756054690
@ -71,6 +71,7 @@ import {createNamespacedHelpers} from "vuex";
|
|||||||
|
|
||||||
const {mapState, mapGetters, mapActions, mapMutations} = createNamespacedHelpers('dashboard/index')
|
const {mapState, mapGetters, mapActions, mapMutations} = createNamespacedHelpers('dashboard/index')
|
||||||
|
|
||||||
|
// TODO same as credit list but reversed
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "MainCreditList",
|
name: "MainCreditList",
|
||||||
@ -131,21 +132,27 @@ export default {
|
|||||||
},
|
},
|
||||||
parseIncome(data) {
|
parseIncome(data) {
|
||||||
for (let mainKey in data) {
|
for (let mainKey in data) {
|
||||||
if (data.hasOwnProperty(mainKey) ) {
|
if (data.hasOwnProperty(mainKey)) {
|
||||||
mainKey = parseInt(mainKey);
|
mainKey = parseInt(mainKey);
|
||||||
// contains currency info and entries.
|
// contains currency info and entries.
|
||||||
let current = data[mainKey];
|
let current = data[mainKey];
|
||||||
if (0 === mainKey) {
|
current.pct = 0;
|
||||||
this.max = data[mainKey].difference_float;
|
this.max = current.difference_float > this.max ? current.difference_float : this.max;
|
||||||
current.pct = 100;
|
|
||||||
}
|
|
||||||
if (0 !== mainKey) {
|
|
||||||
// calc percentage:
|
|
||||||
current.pct = (data[mainKey].difference_float / this.max) * 100;
|
|
||||||
}
|
|
||||||
this.income.push(current);
|
this.income.push(current);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (0 === this.max) {
|
||||||
|
this.max = 1;
|
||||||
|
}
|
||||||
|
// now sort + pct:
|
||||||
|
for (let i in this.income) {
|
||||||
|
if (this.income.hasOwnProperty(i)) {
|
||||||
|
let current = this.income[i];
|
||||||
|
current.pct = (current.difference_float / this.max) * 100;
|
||||||
|
this.income[i] = current;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.income.sort((a,b) => (a.pct > b.pct) ? -1 : ((b.pct > a.pct) ? 1 : 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,7 @@ export default {
|
|||||||
return {
|
return {
|
||||||
locale: 'en-US',
|
locale: 'en-US',
|
||||||
expenses: [],
|
expenses: [],
|
||||||
max: 0,
|
min: 0,
|
||||||
loading: true,
|
loading: true,
|
||||||
error: false
|
error: false
|
||||||
}
|
}
|
||||||
@ -132,20 +132,27 @@ export default {
|
|||||||
parseExpenses(data) {
|
parseExpenses(data) {
|
||||||
for (let mainKey in data) {
|
for (let mainKey in data) {
|
||||||
if (data.hasOwnProperty(mainKey) && /^0$|^[1-9]\d*$/.test(mainKey) && mainKey <= 4294967294) {
|
if (data.hasOwnProperty(mainKey) && /^0$|^[1-9]\d*$/.test(mainKey) && mainKey <= 4294967294) {
|
||||||
// contains currency info and entries.
|
|
||||||
let current = data[mainKey];
|
let current = data[mainKey];
|
||||||
if (0 === parseInt(mainKey)) {
|
current.pct = 0;
|
||||||
this.max = data[mainKey].difference_float;
|
|
||||||
current.pct = 100;
|
|
||||||
}
|
|
||||||
if (0 !== parseInt(mainKey)) {
|
|
||||||
// calc percentage:
|
|
||||||
current.pct = (data[mainKey].difference_float / this.max) * 100;
|
|
||||||
}
|
|
||||||
this.expenses.push(current);
|
|
||||||
|
|
||||||
|
this.min = current.difference_float < this.min ? current.difference_float : this.min;
|
||||||
|
this.expenses.push(current);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (0 === this.min) {
|
||||||
|
this.min = -1;
|
||||||
|
}
|
||||||
|
// now sort + pct:
|
||||||
|
for (let i in this.expenses) {
|
||||||
|
if (this.expenses.hasOwnProperty(i)) {
|
||||||
|
let current = this.expenses[i];
|
||||||
|
current.pct = (current.difference_float*-1 / this.min*-1) * 100;
|
||||||
|
this.expenses[i] = current;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.expenses.sort((a,b) => (a.pct > b.pct) ? -1 : ((b.pct > a.pct) ? 1 : 0));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2002,9 +2002,9 @@ caniuse-api@^3.0.0:
|
|||||||
lodash.uniq "^4.5.0"
|
lodash.uniq "^4.5.0"
|
||||||
|
|
||||||
caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001109, caniuse-lite@^1.0.30001181:
|
caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001109, caniuse-lite@^1.0.30001181:
|
||||||
version "1.0.30001204"
|
version "1.0.30001205"
|
||||||
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001204.tgz#256c85709a348ec4d175e847a3b515c66e79f2aa"
|
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001205.tgz#d79bf6a6fb13196b4bb46e5143a22ca0242e0ef8"
|
||||||
integrity sha512-JUdjWpcxfJ9IPamy2f5JaRDCaqJOxDzOSKtbdx4rH9VivMd1vIzoPumsJa9LoMIi4Fx2BV2KZOxWhNkBjaYivQ==
|
integrity sha512-TL1GrS5V6LElbitPazidkBMD9sa448bQDDLrumDqaggmKFcuU2JW1wTOHJPukAcOMtEmLcmDJEzfRrf+GjM0Og==
|
||||||
|
|
||||||
chalk@^1.1.3:
|
chalk@^1.1.3:
|
||||||
version "1.1.3"
|
version "1.1.3"
|
||||||
|
2
public/v2/js/dashboard.js
vendored
2
public/v2/js/dashboard.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user