Now select the current month if exists.
This commit is contained in:
parent
a7c63c270e
commit
8062cb4c59
@ -39,13 +39,13 @@ def get_months(account_id):
|
|||||||
session = db.session
|
session = db.session
|
||||||
|
|
||||||
query = session.query(
|
query = session.query(
|
||||||
distinct(extract("year", Entry.operation_date)).label("year"),
|
distinct(cast(extract("year", Entry.operation_date), db.String)).label("year"),
|
||||||
extract("month", Entry.operation_date).label("month")
|
cast(extract("month", Entry.operation_date), db.String).label("month")
|
||||||
).filter(Entry.account_id == account_id).order_by("year", "month")
|
).filter(Entry.account_id == account_id).order_by("year", "month")
|
||||||
|
|
||||||
return json.dumps([{
|
return json.dumps([{
|
||||||
"year": i.year,
|
"year": i.year,
|
||||||
"month": i.month
|
"month": i.month.rjust(2, '0')
|
||||||
} for i in query.all()])
|
} for i in query.all()])
|
||||||
|
|
||||||
@app.route("/api/accounts", methods=["PUT"])
|
@app.route("/api/accounts", methods=["PUT"])
|
||||||
|
@ -285,15 +285,23 @@ var ListViewModel = function() {
|
|||||||
|
|
||||||
var monthToSelect = null;
|
var monthToSelect = null;
|
||||||
|
|
||||||
// Reset selected month to the new instance corresponding to the old one
|
var today = new Date();
|
||||||
if(self.month()) {
|
var currentYear = today.getFullYear().toString();
|
||||||
|
var currentMonth = (today.getMonth() + 1 < 10 ? "0" : "") + (today.getMonth() + 1);
|
||||||
|
|
||||||
// Find the new instance of the previously selected month.
|
// Find the new instance of the previously selected month.
|
||||||
$.each(self.months(), function(index, month) {
|
$.each(self.months(), function(index, month) {
|
||||||
|
// Reset selected month to the new instance corresponding to the old one
|
||||||
|
if(self.month()) {
|
||||||
if(month.year() === self.month().year() && month.month() === self.month().month()) {
|
if(month.year() === self.month().year() && month.month() === self.month().month()) {
|
||||||
monthToSelect = month;
|
monthToSelect = month;
|
||||||
}
|
}
|
||||||
});
|
} else {
|
||||||
|
if(month.year() === currentYear && month.month() === currentMonth) {
|
||||||
|
monthToSelect = month;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Set selected month to the last one if not yet selected.
|
// Set selected month to the last one if not yet selected.
|
||||||
if(!monthToSelect && self.months().length > 0) {
|
if(!monthToSelect && self.months().length > 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user