diff --git a/public/pure.html b/public/pure.html index eb7ebc7..baad025 100644 --- a/public/pure.html +++ b/public/pure.html @@ -61,29 +61,18 @@ } }; + let selected_accounts = []; let current_period; - let granularity = 3; const Controls = { period: { init: () => Controls.period.set( new Date() ), - set: ( period ) => { + set: period => { current_period = period; - 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' }; + 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' }; document.querySelector( "#period #display" ).innerHTML = `${months[ current_period.getMonth() ]} ${current_period.getFullYear()}`; - monthly(); + monthly( current_period, selected_accounts ); }, get: () => current_period, prev: () => { @@ -97,33 +86,25 @@ }, accounts: { init: async () => { - let account_to_option = account => ``; + let account_to_option = ( account, selected ) => ``; let accounts = await API.accounts(); let select = document.querySelector("select#accounts"); select.innerHTML = ''; for ( let i = 1 ; i < accounts.reduce( (memo, a) => a.length > memo ? a.length : memo, 0 ) ; i++ ) { - select.innerHTML += `${accounts.filter( a => a.length == i ).map( account => account_to_option( account )).join('')}`; + select.innerHTML += `${accounts.filter( a => a.length == i ).map( account => account_to_option( account, i == 1 )).join('')}`; } }, - onchange: ( accounts_selected ) => { - /* TODO */ - console.log( accounts_selected ); + onchange: accounts_selected => { + selected_accounts = accounts_selected; + + monthly( current_period, selected_accounts ); } } - /* granularity: { - * set: ( value ) => { - * if ( !isNaN( parseInt( value ) ) ) { - * granularity = parseInt( value ); - - * monthly(); - * } - * } - * } */ }; - const monthly = () => { - API.balance( current_period.toISOString().split("T")[0].slice( 0, -3 ), ["Expenses"].join(" "), 999 ) + const monthly = ( period, categories ) => { + API.balance( period.toISOString().split("T")[0].slice( 0, -3 ), categories.join(" "), 999 ) .then( balance => { const total = balance.reduce( (memo, line) => memo + line.amount, 0 ); @@ -147,9 +128,6 @@

-