summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikolaus Gotsche <n@softwarefools.com>2018-10-14 23:40:18 +0200
committerNikolaus Gotsche <n@softwarefools.com>2018-10-14 23:40:18 +0200
commitae396b0399a9ee4ec8aee4879f0eb36bc7aeb7e8 (patch)
tree97ef6e5616ce8b25ff82603853e8e1ad1237d236
parent35f3d2dbaa37778e78dde4416d90d1f779e00b8c (diff)
Pause Resume and more bugfixing0.3.1
-rw-r--r--interact.go34
-rw-r--r--main.go1
-rw-r--r--sqlite.go129
3 files changed, 122 insertions, 42 deletions
diff --git a/interact.go b/interact.go
index 3c458e4..136e1d2 100644
--- a/interact.go
+++ b/interact.go
@@ -65,6 +65,36 @@ func interact() {
})
shell.AddCmd(&ishell.Cmd{
+ Name: "resume",
+ Help: "Resume the Paused Task",
+ LongHelp: ` Usage: resume
+ Resume the Task that was paused 'now'.`,
+ Func: func(c *ishell.Context) {
+ newTask(true)
+ stdOut()
+ setPauseTask(0)
+ c.Println(promptcol("______________________"))
+ },
+ })
+
+ shell.AddCmd(&ishell.Cmd{
+ Name: "pause",
+ Help: "Close the Current Task and remember it",
+ LongHelp: ` Usage: pause
+ Closes the current task 'now' and remember it to continue later.
+ The User is not asked to enter a comment.`,
+ Func: func(c *ishell.Context) {
+ if opentask.id>0 {
+ setPauseTask(opentask.id)
+ c.Println("Pausing Task",pausetask)
+ }
+ closeTask(false)
+ stdOut()
+ c.Println(promptcol("______________________"))
+ },
+ })
+
+ shell.AddCmd(&ishell.Cmd{
Name: "status",
Help: "Show Current Project and Tasks",
LongHelp: ` Usage: status
@@ -92,7 +122,7 @@ func interact() {
LongHelp: ` Usage: startnow
Start a new Task in the currently open Project with current local time`,
Func: func(c *ishell.Context) {
- newTask(currproject.id)
+ newTask(false)
stdOut()
c.Println(promptcol("______________________"))
},
@@ -105,7 +135,7 @@ func interact() {
Stop the open Task at the current local time.
If no task is open the user will be notified.`,
Func: func(c *ishell.Context) {
- closeTask()
+ closeTask(true)
stdOut()
c.Println(promptcol("______________________"))
},
diff --git a/main.go b/main.go
index 9b28697..fdc84e7 100644
--- a/main.go
+++ b/main.go
@@ -147,6 +147,7 @@ func main() {
if !help {
initDB(dbname)
+ pausetask = getPauseTask()
getLastProject()
getOpenTask()
}
diff --git a/sqlite.go b/sqlite.go
index 666e2ca..f59d5c5 100644
--- a/sqlite.go
+++ b/sqlite.go
@@ -66,7 +66,7 @@ var db *sql.DB
var err error
var currproject project
var opentask task
-
+var pausetask int
func initDB(filename string) {
if _, err := os.Stat(filename); os.IsNotExist(err) {
@@ -138,7 +138,7 @@ func initDB(filename string) {
}else{
db, err = sql.Open("sqlite3", filename)
checkErr(err)
- fmt.Println("Opening DB", filename ," - Last Usage:",lastUsage())
+ fmt.Println("Opening DB", filename ," - Last Usage:",lastUsage())
}
}
@@ -154,6 +154,24 @@ func lastUsage() (out string) {
return
}
+func getPauseTask() (id int) {
+ rows,err := db.Query("SELECT pauseid FROM vars WHERE id = 1")
+ checkErr(err)
+ for rows.Next() {
+ err = rows.Scan(&id)
+ checkErr(err)
+ }
+ return
+}
+
+func setPauseTask(id int) {
+ stmt, err := db.Prepare("UPDATE vars SET pauseid = ? WHERE id = 1 ")
+ checkErr(err)
+ _, err = stmt.Exec(id)
+ checkErr(err)
+ pausetask = id
+}
+
func newTaskTime(proj int, tim string) {
boldGreen := color.New(color.FgGreen, color.Bold).SprintFunc()
boldRed := color.New(color.FgRed, color.Bold).SprintFunc()
@@ -194,27 +212,40 @@ func newTaskTime(proj int, tim string) {
}
-func newTask(proj int) {
+func newTask(resume bool) {
boldGreen := color.New(color.FgGreen, color.Bold).SprintFunc()
boldRed := color.New(color.FgRed, color.Bold).SprintFunc()
- fmt.Println(boldGreen("Starting new Task"))
- if (opentask.id == 0) {
- task := getInterInput("Specify Task: ")
- stmt, err := db.Prepare("INSERT INTO timetable(project, task, checkout) values(?, ?, ?)")
- checkErr(err)
- if (proj == 0) {
- _, err = stmt.Exec(currproject.id,task,0)
- }else{
- _, err = stmt.Exec(proj,task,0)
- }
- checkErr(err)
- fmt.Println("...New Task inserted into",currproject.name,": ",task)
- getOpenTask()
- updateProject(currproject.id)
- } else {
+ task := ""
+ if (opentask.id > 0) {
fmt.Println(boldRed("Another Task is already Open"))
showOpenTask()
+ return
}
+ if resume {
+ if pausetask == 0 {
+ fmt.Println(boldRed("No Task was Paused"))
+ return
+ }else{
+ idx := []int{pausetask}
+ tsks := getSelectedTasks(idx)
+ fulltask := tsks[0]
+ fmt.Println(boldGreen("Resuming Task ",pausetask," - ",fulltask.taskname))
+ //fmt.Println()
+ task = fulltask.taskname
+ }
+ }else{
+ fmt.Println(boldGreen("Starting new Task"))
+ task = getInterInput("Specify Task: ")
+ }
+ stmt, err := db.Prepare("INSERT INTO timetable(project, task, checkout) values(?, ?, ?)")
+ checkErr(err)
+ _, err = stmt.Exec(currproject.id,task,0)
+ checkErr(err)
+ if !resume{
+ fmt.Println("...New Task inserted into",currproject.name,": ",task)
+ }
+ getOpenTask()
+ updateProject(currproject.id)
}
func newBill(proj int) (int,string) {
@@ -387,21 +418,25 @@ func closeTaskTime(tim string) {
//fmt.Println(tim,timt)
}
-func closeTask() {
+func closeTask(loud bool) {
boldGreen := color.New(color.FgGreen, color.Bold).SprintFunc()
boldRed := color.New(color.FgRed, color.Bold).SprintFunc()
- fmt.Println(boldGreen("Stoping Task ",opentask.id,":",opentask.taskname))
+ if loud {
+ fmt.Println(boldGreen("Stoping Task ",opentask.id,":",opentask.taskname))
+ }
if opentask.id==0 {
fmt.Println(boldRed("There is no Open Task"))
return
}
if (time.Now().After(opentask.start.Local())) {
com := ""
- if isInterSure("Do You Want to enter a Comment?"){
- com = getInterMultiInput("Comment:")
- }
- fmt.Println("...Closing Task",opentask.id)
- stmt, err := db.Prepare("UPDATE timetable SET stop = datetime('now'), comment = ? WHERE id = ?")
+ if loud {
+ if isInterSure("Do You Want to enter a Comment?"){
+ com = getInterMultiInput("Comment:")
+ }
+ fmt.Println("...Closing Task",opentask.id)
+ }
+ stmt, err := db.Prepare("UPDATE timetable SET stop = datetime('now'), comment = ? WHERE id = ?")
checkErr(err)
_, err = stmt.Exec(com,opentask.id)
checkErr(err)
@@ -774,7 +809,11 @@ func getOpenTask() {
func showOpenTask() {
if (opentask.id==0) {
- fmt.Println("___No Open Tasks____________")
+ if pausetask > 0 {
+ fmt.Printf ("___Task %v Paused___________\n",pausetask)
+ }else{
+ fmt.Println("___No Open Tasks____________")
+ }
} else {
fmt.Println("___Open Task________________")
dur := float64(time.Now().Sub(opentask.start))/(1000000000*60*60)
@@ -816,8 +855,16 @@ func addCustomer() {
func newProject() {
boldRed := color.New(color.FgRed, color.Bold).SprintFunc()
boldGreen := color.New(color.FgGreen, color.Bold).SprintFunc()
+ if (opentask.id > 0) {
+ fmt.Println(boldRed("There is an Open Task"))
+ showOpenTask()
+ return
+ }
+ if pausetask > 0 {
+ fmt.Println(boldRed("Task ",pausetask," pause status removed"))
+ setPauseTask(0)
+ }
fmt.Println(boldGreen("Creating new Project"))
- if (opentask.id == 0) {
nam := getInterInput("Enter Project Name: ")
icust := 0
allCustomers()
@@ -840,10 +887,6 @@ func newProject() {
checkErr(err)
fmt.Println(" Project Created:",nam)
getLastProject()
- } else {
- fmt.Println(boldRed("There is an Open Task"))
- showOpenTask()
- }
}
func getClosedTasks(num int) {
@@ -954,13 +997,23 @@ func getLastProject() {
func setProject (nid int) {
boldGreen := color.New(color.FgGreen, color.Bold).SprintFunc()
boldRed := color.New(color.FgRed, color.Bold).SprintFunc()
- fmt.Println(boldGreen("Opening Project ",nid))
- if !isProject(nid){
- fmt.Println(boldRed("There is no Project"),nid)
+ if (opentask.id > 0) {
+ fmt.Println(boldRed("There is an Open Task"))
+ showOpenTask()
+ return
+ }
+ if pausetask > 0 {
+ fmt.Println(boldRed("Task ",pausetask," pause status removed"))
+ setPauseTask(0)
+ }
+ if isProject(nid){
+ fmt.Println(boldGreen("Opening Project ",nid))
+ }else{
+ fmt.Println(boldRed("There is no Project"),nid)
return
}
- if (opentask.id == 0) {
- rows,err := db.Query("SELECT * FROM projects WHERE id = $1",nid)
+
+ rows,err := db.Query("SELECT * FROM projects WHERE id = $1",nid)
checkErr(err)
var uid int
@@ -984,10 +1037,6 @@ func setProject (nid int) {
//currproject.finish = finish != 0
currproject.customer = custo
updateProject(uid)
- } else {
- fmt.Println(boldRed("There is an Open Task"))
- showOpenTask()
- }
}
func getCustomerList() (outint []int, outstr []string) {