Expand layout

This commit is contained in:
James Cole
2023-08-06 07:02:55 +02:00
parent ff737ae05e
commit d73c3476c8
9 changed files with 131 additions and 651 deletions

View File

@@ -43,9 +43,12 @@ export default () => ({
this.loadChart();
},
loadChart() {
if (this.loading) {
console.log('loadChart.');
if (true === this.loading) {
console.log('loadChart CANCELLED');
return;
}
console.log('loadChart continues');
// load chart data
this.loading = true;
const dashboard = new Dashboard();
@@ -62,7 +65,8 @@ export default () => ({
}, series: [],
settings: [],
xaxis: {
categories: [], labels: {
categories: [],
labels: {
formatter: function (value) {
if (undefined === value) {
return '';
@@ -127,15 +131,24 @@ export default () => ({
this.loading = false;
});
}, loadAccounts() {
if (this.loadingAccounts) {
console.log('loadAccounts');
if (true === this.loadingAccounts) {
console.log('loadAccounts CANCELLED');
return;
}
console.log('loadAccounts continues');
this.loadingAccounts = true;
const max = 10;
let totalAccounts = 0;
let count = 0;
let accounts = [];
Promise.all([getVariable('frontpageAccounts'),]).then((values) => {
for (let i = 0; i < values[0].length; i++) {
if (values[0].hasOwnProperty(i)) {
let accountId = values[0][i];
totalAccounts = values[0].length;
console.log('total accounts is ' + totalAccounts);
for (let i in values[0]) {
let account = values[0];
if (account.hasOwnProperty(i)) {
let accountId = account[i];
// grab account info for box:
(new Get).get(accountId, new Date(window.store.get('end'))).then((response) => {
let parent = response.data.data;
@@ -163,29 +176,36 @@ export default () => ({
}
groups.push(group);
}
this.accountList[i] = {
accounts.push({
name: parent.attributes.name,
id: parent.id,
balance: formatMoney(parent.attributes.current_balance, parent.attributes.currency_code),
groups: groups,
};
});
count++;
if (count === totalAccounts) {
this.accountList = accounts;
}
console.log('Count is now ' + count);
});
});
}
}
this.loadingAccounts = false;
//this.loadingAccounts = false;
});
},
init() {
// console.log('init');
console.log('init accounts');
Promise.all([getVariable('viewRange', '1M'), getVariable('autoConversion', false),]).then((values) => {
console.log('from promise');
this.autoConversion = values[1];
// console.log(values[1]);
this.loadChart();
this.loadAccounts();
});
window.store.observe('end', () => {
console.log('from observe end');
this.loadChart();
this.loadAccounts();
});

View File

@@ -18,7 +18,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import Summary from "../../api/v1/summary/index.js";
import Summary from "../../api/v2/summary/index.js";
import {format} from "date-fns";
import {getVariable} from "../../store/get-variable.js";

View File

@@ -20,7 +20,9 @@
import {getVariable} from "../../store/get-variable.js";
import Dashboard from "../../api/v2/chart/budget/dashboard.js";
import ApexCharts from "apexcharts";
import formatMoney from "../../util/format-money.js";
window.budgetCurrencies = [];
export default () => ({
loadingChart: false,
chart: null,
@@ -31,10 +33,9 @@ export default () => ({
}
// load chart data
this.loadingChart = true;
window.budgetCurrencies = [];
const dashboard = new Dashboard();
dashboard.dashboard(new Date(window.store.get('start')), new Date(window.store.get('end')), null).then((response) => {
console.log(response.data);
let options = {
legend: {show: false},
series: [{
@@ -76,16 +77,52 @@ export default () => ({
style: {
fontSize: '13px',
fontWeight: 900
},
formatter: function (val, opt) {
let index = 0;
if (typeof opt === 'object') {
index = opt.dataPointIndex; // this is the "category name + currency" index
}
let currencyCode = window.budgetCurrencies[index] ?? 'EUR';
return formatMoney(val, currencyCode);
}
}
}
},
},
yaxis: {
labels: {
formatter: function (value, index) {
if (undefined === value) {
return value;
}
if (undefined === index) {
return value;
}
if (typeof index === 'object') {
index = index.dataPointIndex; // this is the "category name + currency" index
}
let currencyCode = window.budgetCurrencies[index] ?? 'EUR';
return formatMoney(value, currencyCode);
}
}
},
xaxis: {
categories: []
},
fill: {
opacity: 0.8
},
dataLabels: {
formatter: function (val, opt) {
let index = 0;
if (typeof opt === 'object') {
index = opt.dataPointIndex; // this is the "category name + currency" index
}
let currencyCode = window.budgetCurrencies[index] ?? 'EUR';
return formatMoney(val, currencyCode);
},
}
};
@@ -96,8 +133,9 @@ export default () => ({
// convert to EUR yes no?
let label = current.label + ' (' + current.currency_code + ')';
options.xaxis.categories.push(label);
console.log(current);
if (this.autoConversion) {
window.budgetCurrencies.push(current.native_code);
// series 0: spent
options.series[0].data.push(parseFloat(current.native_entries.spent) * -1);
// series 1: left
@@ -106,6 +144,7 @@ export default () => ({
options.series[2].data.push(parseFloat(current.native_entries.overspent));
}
if (!this.autoConversion) {
window.budgetCurrencies.push(current.currency_code);
// series 0: spent
options.series[0].data.push(parseFloat(current.entries.spent) * -1);
// series 1: left
@@ -132,15 +171,17 @@ export default () => ({
},
init() {
console.log('init budgets');
Promise.all([getVariable('autoConversion', false),]).then((values) => {
this.autoConversion = values[0];
console.log('here we are, budgets.');
this.loadChart();
});
window.store.observe('end', () => {
this.loadChart();
});
window.store.observe('autoConversion', (newValue) => {
this.autoConversion = newValue;
this.loadChart();
});
},
});