From 35bbd18bf8943a20784d676cb6153c6a826f2d93 Mon Sep 17 00:00:00 2001 From: Nikolaus Gotsche Date: Fri, 28 Sep 2018 12:25:28 +0200 Subject: List Projects and Tasks if no id is given to editproject/edittask --- interact.go | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- main.go | 3 ++- sqlite.go | 34 ++++++++++++++++++++++++++++++++-- 3 files changed, 92 insertions(+), 6 deletions(-) diff --git a/interact.go b/interact.go index f4a8b4b..0c9f73b 100644 --- a/interact.go +++ b/interact.go @@ -201,7 +201,16 @@ func interact() { c.Println(boldRed(arg,"is not a valid id!")) } }else{ - c.Println(boldRed("edittask - Please enter an id")) + tids := getTaskIds() + selids,lids := getTaskList(tids,false) + choice := c.MultiChoice(lids,"Select a Task to Edit") + c.Println(tids) + c.Println(selids) + if choice > -1 { + editTask(selids[choice]) + //c.Println(choice,selids[choice]) + } + //c.Println(boldRed("edittask - Please enter an id")) } c.Println(promptcol("______________________")) }, @@ -226,8 +235,17 @@ func interact() { c.Println(boldRed(arg,"is not a valid id!")) } }else{ - c.Println(boldRed("editproject - Please enter an id")) - allProjects() + pids := getProjectIds() + selids,lids := getProjectList(pids) + choice := c.MultiChoice(lids,"Select a Project to Edit") + c.Println(pids) + c.Println(selids) + if choice > -1 { + editProject(selids[choice]) + //c.Println(choice,selids[choice]) + } + //c.Println(boldRed("editproject - Please enter an id")) + //allProjects() } c.Println(promptcol("______________________")) }, @@ -385,6 +403,17 @@ func interact() { }, }) */ + //Test stuff in shell + shell.AddCmd(&ishell.Cmd{ + Name: "test", + Help: "Test some functions in interactive mode", + LongHelp: ` Usage: test + Test functions in interactive mode`, + Func: func(c *ishell.Context) { + multichoice("Geh scheissn") + + }, + }) // Prompt Color shell.AddCmd(&ishell.Cmd{ @@ -602,4 +631,30 @@ func interact() { //fmt.Println("Laboravi emeritus...") } +func multichoice(about string) { + shell := ishell.New() + shell.SetMultiChoicePrompt(" ->"," - ") + shell.SetChecklistOptions("[ ] ","[X] ") + + shell.AddCmd(&ishell.Cmd{ + Name: "choice", + Help: "multiple choice prompt", + Func: func(c *ishell.Context) { + choice := c.MultiChoice([]string{ + "Golangers", + "Go programmers", + "Gophers", + "Goers", + }, "What are Go programmers called ?") + if choice == 2 { + c.Println("You got it!") + } else { + c.Println("Sorry, you're wrong.") + } + }, + }) + str := "choice" + shell.Process(str) + shell.Println(about) +} diff --git a/main.go b/main.go index 9160c58..9b28697 100644 --- a/main.go +++ b/main.go @@ -117,7 +117,8 @@ func main() { }else if test { //fmt.Println(Round(12.55,0.5),Round(12.55,0.1),Round(12.55,1),Round(12.55,5)) //fmt.Println(getGitTag()) - fmt.Println("Nothing to test") + multichoice("Fuckoff") + fmt.Println("Nothing to test") //tmpltest() //newBill(1) //c := []int{2,3} diff --git a/sqlite.go b/sqlite.go index 6ce6c3c..6ab652e 100644 --- a/sqlite.go +++ b/sqlite.go @@ -102,8 +102,8 @@ func initDB(filename string) { times VARCHAR(240), hours VARCHAR(240), moneys VARCHAR(240), - paid TIMESTAMP DEFAULT '1791-09-30 19:07', - date TIMESTAMP DEFAULT '1791-09-30 19:07'); + paid TIMESTAMP DEFAULT datetime('1791-09-30 19:07','utc'), + date TIMESTAMP DEFAULT datetime('1791-09-30 19:07','utc') ); ` _, err = db.Exec(sqlstmt) checkErr(err) @@ -613,6 +613,36 @@ func getTaskList(in []int,showcust bool) ([]int, []string) { } return outids,outstr } +func getProjectIds() ([]int) { + var ids []int + rows,err := db.Query("SELECT id FROM projects WHERE id != 0")// ORDER BY id DESC") + checkErr(err) + var id int + + defer rows.Close() + for rows.Next() { + err = rows.Scan(&id) + checkErr(err) + ids = append(ids,id) + } + return ids +} + + +func getTaskIds() ([]int) { + var ids []int + rows,err := db.Query("SELECT id FROM timetable WHERE stop != '1791-09-30 19:07'")// ORDER BY id DESC") + checkErr(err) + var id int + + defer rows.Close() + for rows.Next() { + err = rows.Scan(&id) + checkErr(err) + ids = append(ids,id) + } + return ids +} func getOpenTask() { rows,err := db.Query("SELECT id, project, start, task, checkout FROM timetable WHERE stop = '1791-09-30 19:07'") -- cgit v1.2.3