now remembers ui values for which tab we are on and whether we clicked show estimated or not
This commit is contained in:
2
TODO
2
TODO
@@ -1,6 +1,4 @@
|
|||||||
UI:
|
UI:
|
||||||
* remember which tab
|
|
||||||
* remember show estimates
|
|
||||||
|
|
||||||
For bills:
|
For bills:
|
||||||
* using frequency and known bills fill in missing gaps
|
* using frequency and known bills fill in missing gaps
|
||||||
|
|||||||
28
db.py
28
db.py
@@ -109,6 +109,12 @@ def init_db():
|
|||||||
FOREIGN KEY(bill_type) REFERENCES bill_type(id)
|
FOREIGN KEY(bill_type) REFERENCES bill_type(id)
|
||||||
)''')
|
)''')
|
||||||
|
|
||||||
|
cur.execute('''CREATE TABLE IF NOT EXISTS bill_ui (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
last_tab INTEGER,
|
||||||
|
show_estimated INTEGER
|
||||||
|
)''')
|
||||||
|
|
||||||
# Check if table is empty, if so insert default values
|
# Check if table is empty, if so insert default values
|
||||||
cur.execute('SELECT COUNT(*) FROM finance')
|
cur.execute('SELECT COUNT(*) FROM finance')
|
||||||
if cur.fetchone()[0] == 0:
|
if cur.fetchone()[0] == 0:
|
||||||
@@ -128,6 +134,8 @@ def init_db():
|
|||||||
cur.execute( "INSERT INTO bill_freq values ( 1, 'Annual', 1 )" )
|
cur.execute( "INSERT INTO bill_freq values ( 1, 'Annual', 1 )" )
|
||||||
cur.execute( "INSERT INTO bill_freq values ( 2, 'Quarterly', 4 )" )
|
cur.execute( "INSERT INTO bill_freq values ( 2, 'Quarterly', 4 )" )
|
||||||
cur.execute( "INSERT INTO bill_freq values ( 3, 'Monthly', 12 )" )
|
cur.execute( "INSERT INTO bill_freq values ( 3, 'Monthly', 12 )" )
|
||||||
|
# start with no specific Tab/bill_type to show, and dont show_estimated
|
||||||
|
cur.execute( "INSERT INTO bill_ui values ( 1, null, 0 )" )
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
@@ -353,3 +361,23 @@ def set_bill_type_growth( id, min_g, avg_g, max_g ):
|
|||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def get_bill_ui():
|
||||||
|
conn = connect_db(True)
|
||||||
|
cur = conn.cursor()
|
||||||
|
# only ever be 1
|
||||||
|
cur.execute('SELECT * FROM bill_ui')
|
||||||
|
ui = cur.fetchone()
|
||||||
|
conn.close()
|
||||||
|
return ui
|
||||||
|
|
||||||
|
def save_ui(data):
|
||||||
|
conn = connect_db(False)
|
||||||
|
cur = conn.cursor()
|
||||||
|
if 'last_tab' in data:
|
||||||
|
cur.execute( f"update bill_ui set last_tab='{data['last_tab']}'" )
|
||||||
|
if 'show_estimated' in data:
|
||||||
|
cur.execute( f"update bill_ui set show_estimated='{data['show_estimated']}'" )
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
return
|
||||||
|
|||||||
12
main.py
12
main.py
@@ -3,6 +3,7 @@ from flask import Flask, render_template, request, redirect, url_for, Response,
|
|||||||
from calc import calculate_savings_depletion
|
from calc import calculate_savings_depletion
|
||||||
from db import init_db, get_finance_data, update_finance, get_budget_data, insert_cset, get_comp_set_data, get_comp_set_options, get_bill_freqs
|
from db import init_db, get_finance_data, update_finance, get_budget_data, insert_cset, get_comp_set_data, get_comp_set_options, get_bill_freqs
|
||||||
from db import get_bill_data, new_bill, update_bill_data, delete_bill
|
from db import get_bill_data, new_bill, update_bill_data, delete_bill
|
||||||
|
from db import get_bill_ui, save_ui
|
||||||
from db import get_bill_types, insert_bill_type, update_bill_type, delete_bill_type, use_growth
|
from db import get_bill_types, insert_bill_type, update_bill_type, delete_bill_type, use_growth
|
||||||
from bills import process_bill_data
|
from bills import process_bill_data
|
||||||
from collections import defaultdict, Counter
|
from collections import defaultdict, Counter
|
||||||
@@ -144,9 +145,11 @@ def DisplayBillData():
|
|||||||
bill_data = get_bill_data()
|
bill_data = get_bill_data()
|
||||||
bill_types = get_bill_types()
|
bill_types = get_bill_types()
|
||||||
bill_freqs = get_bill_freqs()
|
bill_freqs = get_bill_freqs()
|
||||||
|
bill_ui = get_bill_ui()
|
||||||
|
print( f"bu={bill_ui}" )
|
||||||
process_bill_data(bill_data, bill_types, bill_freqs)
|
process_bill_data(bill_data, bill_types, bill_freqs)
|
||||||
bill_data = get_bill_data()
|
bill_data = get_bill_data()
|
||||||
return render_template('bills.html', bill_data=bill_data, bill_types=bill_types, bill_freqs=bill_freqs )
|
return render_template('bills.html', bill_data=bill_data, bill_types=bill_types, bill_freqs=bill_freqs, bill_ui=bill_ui )
|
||||||
|
|
||||||
@app.route('/newbilltype', methods=['POST'])
|
@app.route('/newbilltype', methods=['POST'])
|
||||||
def InsertBillType():
|
def InsertBillType():
|
||||||
@@ -191,6 +194,13 @@ def UseGrowth():
|
|||||||
use_growth( data['bill_type'], data['which_growth'] )
|
use_growth( data['bill_type'], data['which_growth'] )
|
||||||
return "200"
|
return "200"
|
||||||
|
|
||||||
|
@app.route('/saveui', methods=['POST'])
|
||||||
|
def SaveUI():
|
||||||
|
data = request.get_json()
|
||||||
|
save_ui( data )
|
||||||
|
return "200"
|
||||||
|
|
||||||
|
|
||||||
# Main program
|
# Main program
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(debug=True)
|
app.run(debug=True)
|
||||||
|
|||||||
@@ -103,7 +103,7 @@
|
|||||||
<!-- create tabbed view for each bill type -->
|
<!-- create tabbed view for each bill type -->
|
||||||
<nav id="bills-nav" class="nav nav-tabs">
|
<nav id="bills-nav" class="nav nav-tabs">
|
||||||
{% for bt in bill_types %}
|
{% for bt in bill_types %}
|
||||||
<button class="nav-link" id="tab-{{bt.name}}" data-bs-toggle="tab" data-bs-target="#tab-{{bt.id}}" type="button" role="tab" aria-controls="tab1" aria-selected="true">{{bt.name}}</button>
|
<button class="nav-link" id="tab-but-{{bt.id}}" data-bs-toggle="tab" data-bs-target="#tab-{{bt.id}}" type="button" role="tab" aria-controls="tab1" aria-selected="true" onClick="SaveTab('{{bt.id}}')">{{bt.name}}</button>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
@@ -157,10 +157,17 @@
|
|||||||
function ToggleEstimated()
|
function ToggleEstimated()
|
||||||
{
|
{
|
||||||
if( $("#showEstimated").is(":checked") )
|
if( $("#showEstimated").is(":checked") )
|
||||||
|
{
|
||||||
|
val=1
|
||||||
$('.est').removeClass('d-none')
|
$('.est').removeClass('d-none')
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
val=0
|
||||||
$('.est').addClass('d-none')
|
$('.est').addClass('d-none')
|
||||||
}
|
}
|
||||||
|
$.ajax( { type: 'POST', url: '/saveui', contentType: 'application/json', data: JSON.stringify( { 'show_estimated': val } ), success: function() { } } )
|
||||||
|
}
|
||||||
|
|
||||||
function StartNewBillData()
|
function StartNewBillData()
|
||||||
{
|
{
|
||||||
@@ -319,6 +326,11 @@
|
|||||||
data: JSON.stringify( { 'bill_type': bt, 'which_growth': which } ), success: function() { window.location='bills' } } )
|
data: JSON.stringify( { 'bill_type': bt, 'which_growth': which } ), success: function() { window.location='bills' } } )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function SaveTab( last_tab )
|
||||||
|
{
|
||||||
|
$.ajax( { type: 'POST', url: '/saveui', contentType: 'application/json', data: JSON.stringify( { 'last_tab': last_tab } ), success: function() { } } )
|
||||||
|
}
|
||||||
|
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
// if amount has enter key in it then save, but dont do this for other fields in new bill
|
// if amount has enter key in it then save, but dont do this for other fields in new bill
|
||||||
$("#new-bill-data-amount").keyup(function(event){ if(event.which == 13){ $("#save-bill").click(); } event.preventDefault(); });
|
$("#new-bill-data-amount").keyup(function(event){ if(event.which == 13){ $("#save-bill").click(); } event.preventDefault(); });
|
||||||
@@ -329,8 +341,15 @@
|
|||||||
|
|
||||||
// force something to be active
|
// force something to be active
|
||||||
$('#bills-nav .nav-link').first().addClass('active');
|
$('#bills-nav .nav-link').first().addClass('active');
|
||||||
// now go back to last tab, as per something I dont know yet :)
|
{% if bill_ui %}
|
||||||
$('#tab-Water').tab('show');
|
// if we have data on it - go back to last tab
|
||||||
|
$('#tab-but-{{bill_ui.last_tab}}').tab('show');
|
||||||
|
{% if bill_ui.show_estimated %}
|
||||||
|
$('#showEstimated').click()
|
||||||
|
{% endif %}
|
||||||
|
{% else %}
|
||||||
|
$('#tab-but-1').tab('show');
|
||||||
|
{% endif %}
|
||||||
} )
|
} )
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in New Issue
Block a user