From 2f6b3e193cca69b20e4861aca3b403fc3d7fce2f Mon Sep 17 00:00:00 2001 From: Gwenhael Le Moine Date: Thu, 21 Nov 2019 11:23:20 +0100 Subject: [PATCH 01/10] add donut --- public/pure.html | 114 ++++++++++++++++++++++++++++++----------------- 1 file changed, 74 insertions(+), 40 deletions(-) diff --git a/public/pure.html b/public/pure.html index ed10f8a..4020609 100644 --- a/public/pure.html +++ b/public/pure.html @@ -1,55 +1,89 @@ - From 5cde92fea3a7f2ef100e3ced866338cb4754c4a0 Mon Sep 17 00:00:00 2001 From: Gwenhael Le Moine Date: Thu, 21 Nov 2019 12:38:35 +0100 Subject: [PATCH 02/10] utf-8 --- public/pure.html | 1 + 1 file changed, 1 insertion(+) diff --git a/public/pure.html b/public/pure.html index 4020609..5abdd76 100644 --- a/public/pure.html +++ b/public/pure.html @@ -1,5 +1,6 @@ + -
+
+ + +

+
+
+
+
From 5151b2fc790a00addcde8d8bad1facc7a4aa86aa Mon Sep 17 00:00:00 2001 From: Gwenhael Le Moine Date: Thu, 21 Nov 2019 15:37:07 +0100 Subject: [PATCH 04/10] granularity --- public/pure.html | 93 +++++++++++++++++++++++++++++------------------- 1 file changed, 56 insertions(+), 37 deletions(-) diff --git a/public/pure.html b/public/pure.html index a57c96f..e5c9986 100644 --- a/public/pure.html +++ b/public/pure.html @@ -12,20 +12,9 @@ }; const API = { - balance: (period, categories, depth) => fetch_from_API( "/api/ledger/balance", - { period: period, - categories: categories, - depth: depth } ), - - register: (period, categories) => fetch_from_API( "/api/ledger/register", - { period: period, - categories: categories } ), - - graph_values: (period, categories, granularity) => fetch_from_API( "/api/ledger/graph_values", - { period: period, - categories: categories, - granularity: granularity } ), - + balance: (period, categories, depth) => fetch_from_API( "/api/ledger/balance", { period: period, categories: categories, depth: depth } ), + register: (period, categories) => fetch_from_API( "/api/ledger/register", { period: period, categories: categories } ), + graph_values: (period, categories, granularity) => fetch_from_API( "/api/ledger/graph_values", { period: period, categories: categories, granularity: granularity } ), accounts: () => fetch_from_API( "/api/ledger/accounts" ) } @@ -68,35 +57,60 @@ ${dataset.map( line => data_to_donut_segment( line ) ).join("")} -
${JSON.stringify( dataset )}
`; + `; } }; let current_period; - const Period = { - set: ( period ) => { - current_period = period; - document.querySelector( "#period #display" ).innerHTML = current_period.toISOString(); + let granularity = 3; - monthly( current_period.toISOString().split("T")[0].slice( 0, -3 ), "#month" ); - }, - get: () => current_period, - prev: () => { - current_period.setMonth( current_period.getMonth() - 1 ); - Period.set( current_period ); - }, - next: () => { - current_period.setMonth( current_period.getMonth() + 1 ); - Period.set( current_period ); + const Controls = { + 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' }; + document.querySelector( "#period #display" ).innerHTML = `${months[ current_period.getMonth() ]} ${current_period.getFullYear()}`; + + monthly(); + }, + get: () => current_period, + prev: () => { + current_period.setMonth( current_period.getMonth() - 1 ); + Controls.period.set( current_period ); + }, + next: () => { + current_period.setMonth( current_period.getMonth() + 1 ); + Controls.period.set( current_period ); + }, }, + granularity: { + set: ( value ) => { + if ( !isNaN( parseInt( value ) ) ) { + granularity = parseInt( value ); + + monthly(); + } + } + } }; - const monthly = ( month, element_selector ) => { - API.balance( month, ["Expenses"].join(" "), 3 ) + const monthly = () => { + API.balance( current_period.toISOString().split("T")[0].slice( 0, -3 ), ["Expenses"].join(" "), granularity ) .then( balance => { const total = balance.reduce( (memo, line) => memo + line.amount, 0 ); - UI.donut( document.querySelector( `${element_selector} #donut` ), + UI.donut( document.querySelector( `#month #donut` ), balance.sort( (a, b) => b.amount - a.amount ) .map( line => { line.color = Utils.text_to_color( line.account ); @@ -110,17 +124,22 @@ -
- - -

+
+
+ + +

+
+
+ +
From 53bc76aeab3faa66fe868f4fff266a3e51ed0ef3 Mon Sep 17 00:00:00 2001 From: Gwenhael Le Moine Date: Thu, 21 Nov 2019 15:47:09 +0100 Subject: [PATCH 05/10] granularity isn't what you think it is --- public/pure.html | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/public/pure.html b/public/pure.html index e5c9986..8afbb17 100644 --- a/public/pure.html +++ b/public/pure.html @@ -94,19 +94,19 @@ Controls.period.set( current_period ); }, }, - granularity: { - set: ( value ) => { - if ( !isNaN( parseInt( value ) ) ) { - granularity = parseInt( value ); + /* granularity: { + * set: ( value ) => { + * if ( !isNaN( parseInt( value ) ) ) { + * granularity = parseInt( value ); - monthly(); - } - } - } + * monthly(); + * } + * } + * } */ }; const monthly = () => { - API.balance( current_period.toISOString().split("T")[0].slice( 0, -3 ), ["Expenses"].join(" "), granularity ) + API.balance( current_period.toISOString().split("T")[0].slice( 0, -3 ), ["Expenses"].join(" "), 999 ) .then( balance => { const total = balance.reduce( (memo, line) => memo + line.amount, 0 ); @@ -130,9 +130,9 @@

-
- -
+
From 0efc88e71d4881779ee42cf50792e0bab67eb5ed Mon Sep 17 00:00:00 2001 From: Gwenhael Le Moine Date: Mon, 25 Nov 2019 11:51:02 +0100 Subject: [PATCH 06/10] select accounts --- public/pure.html | 71 ++++++++++++++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 27 deletions(-) diff --git a/public/pure.html b/public/pure.html index 8afbb17..3e2e8af 100644 --- a/public/pure.html +++ b/public/pure.html @@ -58,42 +58,52 @@ ${dataset.map( line => data_to_donut_segment( line ) ).join("")} `; - } - }; + } + }; - let current_period; - let granularity = 3; + let current_period; + let granularity = 3; - const Controls = { - period: { + const Controls = { + 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' }; - document.querySelector( "#period #display" ).innerHTML = `${months[ current_period.getMonth() ]} ${current_period.getFullYear()}`; + 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' }; + document.querySelector( "#period #display" ).innerHTML = `${months[ current_period.getMonth() ]} ${current_period.getFullYear()}`; - monthly(); + monthly(); }, get: () => current_period, prev: () => { - current_period.setMonth( current_period.getMonth() - 1 ); - Controls.period.set( current_period ); + current_period.setMonth( current_period.getMonth() - 1 ); + Controls.period.set( current_period ); }, next: () => { - current_period.setMonth( current_period.getMonth() + 1 ); - Controls.period.set( current_period ); + current_period.setMonth( current_period.getMonth() + 1 ); + Controls.period.set( current_period ); }, - }, + }, + accounts: { + init: async () => { + let accounts = await API.accounts(); + + let account_to_option = ( account ) => ``; + document.querySelector("#accounts").innerHTML = ``; + } + } /* granularity: { * set: ( value ) => { * if ( !isNaN( parseInt( value ) ) ) { @@ -134,12 +144,19 @@
--> +
+
From d52d58eb15182673afcf50e23e951d7969b52dda Mon Sep 17 00:00:00 2001 From: Gwenhael Le Moine Date: Mon, 25 Nov 2019 15:48:35 +0100 Subject: [PATCH 07/10] active accounts list --- public/pure.html | 80 ++++++++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 36 deletions(-) diff --git a/public/pure.html b/public/pure.html index 3e2e8af..eb7ebc7 100644 --- a/public/pure.html +++ b/public/pure.html @@ -58,50 +58,57 @@ ${dataset.map( line => data_to_donut_segment( line ) ).join("")} `; - } - }; + } + }; - let current_period; - let granularity = 3; + let current_period; + let granularity = 3; - const Controls = { - period: { + const Controls = { + period: { + init: () => Controls.period.set( new Date() ), 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' }; - document.querySelector( "#period #display" ).innerHTML = `${months[ current_period.getMonth() ]} ${current_period.getFullYear()}`; + 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' }; + document.querySelector( "#period #display" ).innerHTML = `${months[ current_period.getMonth() ]} ${current_period.getFullYear()}`; - monthly(); + monthly(); }, get: () => current_period, prev: () => { - current_period.setMonth( current_period.getMonth() - 1 ); - Controls.period.set( current_period ); + current_period.setMonth( current_period.getMonth() - 1 ); + Controls.period.set( current_period ); }, next: () => { - current_period.setMonth( current_period.getMonth() + 1 ); - Controls.period.set( current_period ); + current_period.setMonth( current_period.getMonth() + 1 ); + Controls.period.set( current_period ); }, - }, - accounts: { + }, + accounts: { init: async () => { - let accounts = await API.accounts(); + let account_to_option = account => ``; + let accounts = await API.accounts(); + let select = document.querySelector("select#accounts"); + select.innerHTML = ''; - let account_to_option = ( account ) => ``; - document.querySelector("#accounts").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('')}`; + } + }, + onchange: ( accounts_selected ) => { + /* TODO */ + console.log( accounts_selected ); } } /* granularity: { @@ -144,8 +151,9 @@ --> -
-
+ + +
@@ -153,9 +161,9 @@ From 49be4d3db33bf03553d13fd55e8315e005835437 Mon Sep 17 00:00:00 2001 From: Gwenhael Le Moine Date: Mon, 25 Nov 2019 16:02:09 +0100 Subject: [PATCH 08/10] reacting --- public/pure.html | 46 ++++++++++++---------------------------------- 1 file changed, 12 insertions(+), 34 deletions(-) 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 @@

- From 282608bbebe63eb53224d81e0a9659feeade8fc0 Mon Sep 17 00:00:00 2001 From: Gwenhael Le Moine Date: Mon, 25 Nov 2019 16:40:14 +0100 Subject: [PATCH 09/10] changes --- public/pure.html | 67 ++++++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/public/pure.html b/public/pure.html index baad025..31dc9bc 100644 --- a/public/pure.html +++ b/public/pure.html @@ -2,24 +2,25 @@ @@ -140,8 +147,6 @@ (async () => { await Controls.accounts.init(); await Controls.period.init(); - - console.log( await API.graph_values( "", ["Expenses", "Income"].join(" "), "monthly" ) ) })(); From 67751cebeddc9ea25f90f0381d839dd85648a0fb Mon Sep 17 00:00:00 2001 From: Gwenhael Le Moine Date: Wed, 27 Nov 2019 12:18:14 +0100 Subject: [PATCH 10/10] ameba --- .gitignore | 1 + shard.lock | 4 ++++ shard.yml | 4 ++++ 3 files changed, 9 insertions(+) diff --git a/.gitignore b/.gitignore index 6d8fbb9..3aaf0be 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ /credger /public/js /.shards +/bin/ diff --git a/shard.lock b/shard.lock index 14613c2..7eef175 100644 --- a/shard.lock +++ b/shard.lock @@ -1,5 +1,9 @@ version: 1.0 shards: + ameba: + github: crystal-ameba/ameba + version: 0.10.1 + exception_page: github: crystal-loot/exception_page version: 0.1.2 diff --git a/shard.yml b/shard.yml index 52807ed..398cb94 100644 --- a/shard.yml +++ b/shard.yml @@ -1,6 +1,10 @@ name: credger version: 1.99 +development_dependencies: + ameba: + github: crystal-ameba/ameba + dependencies: kemal: github: kemalcr/kemal