Now select the current month if exists.

This commit is contained in:
Alexis Lahouze 2013-01-26 12:47:04 +01:00
parent a7c63c270e
commit 8062cb4c59
2 changed files with 17 additions and 9 deletions

View File

@ -39,13 +39,13 @@ def get_months(account_id):
session = db.session
query = session.query(
distinct(extract("year", Entry.operation_date)).label("year"),
extract("month", Entry.operation_date).label("month")
distinct(cast(extract("year", Entry.operation_date), db.String)).label("year"),
cast(extract("month", Entry.operation_date), db.String).label("month")
).filter(Entry.account_id == account_id).order_by("year", "month")
return json.dumps([{
"year": i.year,
"month": i.month
"month": i.month.rjust(2, '0')
} for i in query.all()])
@app.route("/api/accounts", methods=["PUT"])

View File

@ -285,15 +285,23 @@ var ListViewModel = function() {
var monthToSelect = null;
// Reset selected month to the new instance corresponding to the old one
if(self.month()) {
var today = new Date();
var currentYear = today.getFullYear().toString();
var currentMonth = (today.getMonth() + 1 < 10 ? "0" : "") + (today.getMonth() + 1);
// Find the new instance of the previously selected 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()) {
monthToSelect = month;
}
});
} else {
if(month.year() === currentYear && month.month() === currentMonth) {
monthToSelect = month;
}
}
});
// Set selected month to the last one if not yet selected.
if(!monthToSelect && self.months().length > 0) {