From fdfa8d72b5cb487ebe9ed2e18a795380dc6da541 Mon Sep 17 00:00:00 2001 From: Olavi Haapala Date: Sun, 28 Jan 2018 22:13:58 +0200 Subject: [PATCH] Fix stopping from command line fixes and closes #57 --- qml/pages/FirstPage.qml | 52 ++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/qml/pages/FirstPage.qml b/qml/pages/FirstPage.qml index 844e6c0..aa3fbb2 100644 --- a/qml/pages/FirstPage.qml +++ b/qml/pages/FirstPage.qml @@ -137,31 +137,31 @@ Page { } if (appState.arguments.stopFromCommandLine) { - // var description = "Automatically saved from command line" - // var project = settings.getDefaultProjectId() - // var taskId = "0" - - // TODO: Change the format - // var dateString = helpers.dateToDbDateString(new Date()) - - // Log.info("AutoSaving: " + uid + "," + dateString + "," + startTime.format("H:mm") + "," + endTime.format("H:mm") + "," + duration + "," + project + "," + description + "," + breakDuration + "," + taskId) - - // var values = { - // "dateString": dateString, - // "startTime": startTime.format("H:mm"), - // "endTime": endTime.format("H:mm"), - // "duration": duration, - // "project": project, - // "description": description, - // "breakDuration": breakDuration, - // "taskId": taskId - // } - - // if(db.saveHourRow(values)) { - // refreshState() - // } else { - // banner.notify("Error when saving!") - // } + var startMoment = moment(appState.timerStartTime) + var endMoment = moment() + + var values = { + "date": startMoment.format("YYYY-MM-DD"), + "startTime": startMoment.format("HH:mm"), + "endTime": endMoment.format("HH:mm"), + // For legacy reasons + "duration": helpers.millisecondsToHours(appState.timerDuration), + "project": settings.getDefaultProjectId(), + "description": "Automatically saved from command line", + // For legacy reasons + "breakDuration": helpers.millisecondsToHours(appState.breakTimerDuration), + "taskId": "0" + }; + + Log.info("Trying to save automatically: " + JSON.stringify(values)); + + if(db.saveHourRow(values)) { + // Try to avoid saving multiple times etc. + stopFromCommandLine = false + firstPage.refreshState() + } else { + banner.notify("Error when saving!") + } } else { if (fromCover && pageStack.depth > 1) { pageStack.replaceAbove(appWindow.firstPage,Qt.resolvedUrl("../pages/Add.qml"), { fromTimer: true, fromCover: fromCover }) @@ -523,7 +523,7 @@ Page { // TODO: Why is this here? if(appState.timerRunning && appState.arguments.stopFromCommandLine) { banner.notify(qsTr("Timer stopped by command line argument")) - stop() + stopTimer() pageStack.push(Qt.resolvedUrl("All.qml"), {dataContainer: root, section: qsTr("Today")}) } }