mirror of
https://github.com/gwenhael-le-moine/credger.git
synced 2024-12-26 09:58:36 +01:00
reacting
This commit is contained in:
parent
d52d58eb15
commit
49be4d3db3
1 changed files with 12 additions and 34 deletions
|
@ -61,29 +61,18 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let selected_accounts = [];
|
||||||
let current_period;
|
let current_period;
|
||||||
let granularity = 3;
|
|
||||||
|
|
||||||
const Controls = {
|
const Controls = {
|
||||||
period: {
|
period: {
|
||||||
init: () => Controls.period.set( new Date() ),
|
init: () => Controls.period.set( new Date() ),
|
||||||
set: ( period ) => {
|
set: period => {
|
||||||
current_period = period;
|
current_period = period;
|
||||||
const months = { 0: 'Janvier',
|
const months = { 0: 'Janvier', 1: 'Février', 2: 'Mars', 3: 'Avril', 4: 'Mai', 5: 'Juin', 6: 'Juillet', 7: 'Août', 8: 'Septembre', 9: 'Octobre', 10: 'Novembre', 11: 'Décembre' };
|
||||||
1: 'Février',
|
|
||||||
2: 'Mars',
|
|
||||||
3: 'Avril',
|
|
||||||
4: 'Mai',
|
|
||||||
5: 'Juin',
|
|
||||||
6: 'Juillet',
|
|
||||||
7: 'Août',
|
|
||||||
8: 'Septembre',
|
|
||||||
9: 'Octobre',
|
|
||||||
10: 'Novembre',
|
|
||||||
11: 'Décembre' };
|
|
||||||
document.querySelector( "#period #display" ).innerHTML = `${months[ current_period.getMonth() ]} ${current_period.getFullYear()}`;
|
document.querySelector( "#period #display" ).innerHTML = `${months[ current_period.getMonth() ]} ${current_period.getFullYear()}`;
|
||||||
|
|
||||||
monthly();
|
monthly( current_period, selected_accounts );
|
||||||
},
|
},
|
||||||
get: () => current_period,
|
get: () => current_period,
|
||||||
prev: () => {
|
prev: () => {
|
||||||
|
@ -97,33 +86,25 @@
|
||||||
},
|
},
|
||||||
accounts: {
|
accounts: {
|
||||||
init: async () => {
|
init: async () => {
|
||||||
let account_to_option = account => `<option value="${account.join(':')}">${account.join(':')}</option>`;
|
let account_to_option = ( account, selected ) => `<option value="${account.join(':')}" ${selected ? "selected" : ""}>${account.join(':')}</option>`;
|
||||||
let accounts = await API.accounts();
|
let accounts = await API.accounts();
|
||||||
let select = document.querySelector("select#accounts");
|
let select = document.querySelector("select#accounts");
|
||||||
select.innerHTML = '';
|
select.innerHTML = '';
|
||||||
|
|
||||||
for ( let i = 1 ; i < accounts.reduce( (memo, a) => a.length > memo ? a.length : memo, 0 ) ; i++ ) {
|
for ( let i = 1 ; i < accounts.reduce( (memo, a) => a.length > memo ? a.length : memo, 0 ) ; i++ ) {
|
||||||
select.innerHTML += `<optgroup label="Depth: ${i}">${accounts.filter( a => a.length == i ).map( account => account_to_option( account )).join('')}</optgroup>`;
|
select.innerHTML += `<optgroup label="Depth: ${i}">${accounts.filter( a => a.length == i ).map( account => account_to_option( account, i == 1 )).join('')}</optgroup>`;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onchange: ( accounts_selected ) => {
|
onchange: accounts_selected => {
|
||||||
/* TODO */
|
selected_accounts = accounts_selected;
|
||||||
console.log( accounts_selected );
|
|
||||||
|
monthly( current_period, selected_accounts );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* granularity: {
|
|
||||||
* set: ( value ) => {
|
|
||||||
* if ( !isNaN( parseInt( value ) ) ) {
|
|
||||||
* granularity = parseInt( value );
|
|
||||||
|
|
||||||
* monthly();
|
|
||||||
* }
|
|
||||||
* }
|
|
||||||
* } */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const monthly = () => {
|
const monthly = ( period, categories ) => {
|
||||||
API.balance( current_period.toISOString().split("T")[0].slice( 0, -3 ), ["Expenses"].join(" "), 999 )
|
API.balance( period.toISOString().split("T")[0].slice( 0, -3 ), categories.join(" "), 999 )
|
||||||
.then( balance => {
|
.then( balance => {
|
||||||
const total = balance.reduce( (memo, line) => memo + line.amount, 0 );
|
const total = balance.reduce( (memo, line) => memo + line.amount, 0 );
|
||||||
|
|
||||||
|
@ -147,9 +128,6 @@
|
||||||
<button onclick="Controls.period.next()">+</button>
|
<button onclick="Controls.period.next()">+</button>
|
||||||
<h3 id="display"></h3>
|
<h3 id="display"></h3>
|
||||||
</div>
|
</div>
|
||||||
<!-- <div id="granularity">
|
|
||||||
<input oninput="Controls.granularity.set( this.value );">
|
|
||||||
</div> -->
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<select id="accounts" name="accounts" multiple size="20" onchange="Controls.accounts.onchange( Array.from( this.options ).filter( o => o.selected ).map( o => o.value ) )"></select>
|
<select id="accounts" name="accounts" multiple size="20" onchange="Controls.accounts.onchange( Array.from( this.options ).filter( o => o.selected ).map( o => o.value ) )"></select>
|
||||||
|
|
Loading…
Reference in a new issue