mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-23 04:18:50 +00:00
Account chart can do live update
This commit is contained in:
@@ -53,6 +53,11 @@ export default () => ({
|
||||
eventListeners: {
|
||||
['@convert-to-native.window'](event){
|
||||
console.log('I heard that! it is now ' + event.detail);
|
||||
this.convertToNative = event.detail;
|
||||
this.accountList = [];
|
||||
chartData = null;
|
||||
this.loadChart();
|
||||
this.loadAccounts();
|
||||
}
|
||||
},
|
||||
|
||||
@@ -61,6 +66,7 @@ export default () => ({
|
||||
console.log('doSomeReload');
|
||||
},
|
||||
getFreshData() {
|
||||
console.log('get fresh data');
|
||||
const start = new Date(window.store.get('start'));
|
||||
const end = new Date(window.store.get('end'));
|
||||
const chartCacheKey = getCacheKey(this.localCacheKey('chart'), {start: start, end: end})
|
||||
@@ -101,18 +107,20 @@ export default () => ({
|
||||
dataset.label = current.label;
|
||||
|
||||
// use the "native" currency code and use the "native_entries" as array
|
||||
// if (this.convertToNative) {
|
||||
// currencies.push(current.native_currency_code);
|
||||
// dataset.currency_code = current.native_currency_code;
|
||||
// collection = Object.values(current.native_entries);
|
||||
// yAxis = 'y' + current.native_currency_code;
|
||||
// }
|
||||
// if (!this.convertToNative) {
|
||||
if (this.convertToNative) {
|
||||
console.log('Convert to native!');
|
||||
currencies.push(current.native_currency_code);
|
||||
dataset.currency_code = current.native_currency_code;
|
||||
collection = Object.values(current.native_entries);
|
||||
yAxis = 'y' + current.native_currency_code;
|
||||
}
|
||||
if (!this.convertToNative) {
|
||||
console.log('NO convert to native!', this.convertToNative);
|
||||
yAxis = 'y' + current.currency_code;
|
||||
dataset.currency_code = current.currency_code;
|
||||
currencies.push(current.currency_code);
|
||||
collection = Object.values(current.entries);
|
||||
// }
|
||||
}
|
||||
dataset.yAxisID = yAxis;
|
||||
dataset.data = collection;
|
||||
|
||||
@@ -147,7 +155,9 @@ export default () => ({
|
||||
return options;
|
||||
},
|
||||
loadChart() {
|
||||
console.log('loadChart');
|
||||
if (true === this.loading) {
|
||||
console.log('already loading chart');
|
||||
return;
|
||||
}
|
||||
this.loading = true;
|
||||
@@ -165,6 +175,7 @@ export default () => ({
|
||||
chart.options = options.options;
|
||||
chart.data = options.data;
|
||||
chart.update();
|
||||
console.log('refresh chart');
|
||||
return;
|
||||
}
|
||||
chart = new Chart(document.querySelector("#account-chart"), options);
|
||||
@@ -294,6 +305,7 @@ export default () => ({
|
||||
this.convertToNative = values[1] && values[3];
|
||||
this.convertToNativeAvailable = values[3];
|
||||
afterPromises = true;
|
||||
console.log('convertToNative in accounts.js: ', values);
|
||||
|
||||
// main dashboard chart:
|
||||
this.loadChart();
|
||||
|
@@ -78,7 +78,6 @@ let index = function () {
|
||||
init() {
|
||||
Promise.all([getVariable('convert_to_native', false)]).then((values) => {
|
||||
this.convertToNative = values[0];
|
||||
console.log('convert_to_native: ' + this.convertToNative);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -27,19 +27,29 @@ export function getConfiguration(name, defaultValue = null) {
|
||||
// to make things available quicker than if the store has to grab it through the API.
|
||||
// then again, it's not that slow.
|
||||
if (validCache && window.hasOwnProperty(name)) {
|
||||
// console.log('Get from window');
|
||||
console.log('Return configuration "' + name + '" from window: ' + window[name]);
|
||||
return Promise.resolve(window[name]);
|
||||
}
|
||||
// load from store2, if it's present.
|
||||
const fromStore = window.store.get(name);
|
||||
if (validCache && typeof fromStore !== 'undefined') {
|
||||
console.log('Return configuration "' + name + '" from store: ' + fromStore);
|
||||
return Promise.resolve(fromStore);
|
||||
}
|
||||
let getter = (new Get);
|
||||
return getter.getByName(name).then((response) => {
|
||||
// console.log('Get "' + name + '" from API');
|
||||
return Promise.resolve(parseResponse(name, response));
|
||||
}).catch(() => {
|
||||
console.log('Return configuration "' + name + '" from API: ' + parseConfigurationResponse(name, response));
|
||||
return Promise.resolve(parseConfigurationResponse(name, response));
|
||||
}).catch((error) => {
|
||||
console.log('Returning "'+name+'" from DEFAULT: ' + defaultValue);
|
||||
console.warn(error);
|
||||
return defaultValue;
|
||||
});
|
||||
}
|
||||
export function parseConfigurationResponse(name, response) {
|
||||
let value = response.data.data.value;
|
||||
window.store.set(name, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
|
@@ -27,16 +27,19 @@ export function getVariable(name, defaultValue = null) {
|
||||
// to make things available quicker than if the store has to grab it through the API.
|
||||
// then again, it's not that slow.
|
||||
if (validCache && window.hasOwnProperty(name)) {
|
||||
console.log('Returning "'+name+'" from window: ' + window[name]);
|
||||
return Promise.resolve(window[name]);
|
||||
}
|
||||
// load from store2, if it's present.
|
||||
const fromStore = window.store.get(name);
|
||||
if (validCache && typeof fromStore !== 'undefined') {
|
||||
console.log('Returning "'+name+'" from store: ' + fromStore);
|
||||
return Promise.resolve(fromStore);
|
||||
}
|
||||
let getter = (new Get);
|
||||
|
||||
return getter.getByName(name).then((response) => {
|
||||
console.log('Returning "'+name+'" from server: ' + parseResponse(name, response));
|
||||
return Promise.resolve(parseResponse(name, response));
|
||||
}).catch((error) => {
|
||||
if('' === defaultValue) {
|
||||
@@ -47,6 +50,7 @@ export function getVariable(name, defaultValue = null) {
|
||||
// POST it and then return it anyway.
|
||||
let poster = (new Post);
|
||||
return poster.post(name, defaultValue).then((response) => {
|
||||
console.log('Returning "'+name+'" from POST: ' + parseResponse(name, response));
|
||||
return Promise.resolve(parseResponse(name, response));
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user