diff --git a/TODO b/TODO index 48c6ada..5c07ed2 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,4 @@ UI: - * when we choose a tab of bill_data -> set new bill select based on tab - & vice-versa, add a bill of type, reload page to show the tab of those bills For bills: * gas bills are a mess and more than 4 per year... *SIGH* try this: diff --git a/db.py b/db.py index 8489728..dfb3c01 100644 --- a/db.py +++ b/db.py @@ -309,9 +309,12 @@ def get_bill_freqs(): def new_bill( bill_type, amount, bill_date, estimated ): conn = connect_db(False) cur = conn.cursor() - # force delete estimates as new bill will potentially change them/growth, etc. + # if we are a real bill added by UI if not estimated: + # delete old estimates as new bill will potentially change them/growth, etc. cur.execute( f"delete from bill_data where estimated=1" ) + # force the next /bills load to show the tab for the bill we are adding + cur.execute( f"update bill_ui set last_tab='{bill_type}'" ) cur.execute( f"insert into bill_data ( 'bill_type', 'amount', 'bill_date', 'estimated' ) values ( '{bill_type}', '{float(amount):.2f}', '{bill_date}', {estimated} )" ) conn.commit() conn.close() diff --git a/templates/bills.html b/templates/bills.html index b883c60..eceb695 100644 --- a/templates/bills.html +++ b/templates/bills.html @@ -345,6 +345,8 @@ function SaveTab( last_tab ) { + // set the drop-down for new bill to be this tab now... + $("#new-bill-data-type").val( $('.nav-tabs .nav-link.active').prop('id').replace("tab-but-", "") ) $.ajax( { type: 'POST', url: '/saveui', contentType: 'application/json', data: JSON.stringify( { 'last_tab': last_tab } ), success: function() { } } ) } @@ -367,6 +369,8 @@ {% else %} $('#tab-but-1').tab('show'); {% endif %} + // make the new bill drop-down default to the same as the current tab + $("#new-bill-data-type").val( {{bill_ui.last_tab}} ) } )