diff options
| -rw-r--r-- | interact.go | 30 | ||||
| -rw-r--r-- | sqlite.go | 61 | ||||
| -rw-r--r-- | utils.go | 29 |
3 files changed, 101 insertions, 19 deletions
diff --git a/interact.go b/interact.go index 4b54315..7336550 100644 --- a/interact.go +++ b/interact.go @@ -494,7 +494,11 @@ func interact() { LongHelp: ` Usage: test Test functions in interactive mode`, Func: func(c *ishell.Context) { - multichoice("Geh scheissn") + //multichoice("Geh scheissn") + + nm,st := GetTaskSums(currproject.id) + i := Multichoice("Sicha?",st) + fmt.Println(nm[i]) }, }) @@ -590,8 +594,8 @@ func interact() { billprojid = projids[0] } - seltasks := getSelectedTasks(selids) - count, hours, dur := analyzeTasks(seltasks) + seltasks := GetSelectedTasks(selids) + count, hours, dur := AnalyzeTasks(seltasks) //c.Printf("%v Tasks Selected. Totaling %.2f (h) - Dates: %s\n",count,hours,dur) proj, cust := getProject(billprojid) @@ -626,8 +630,8 @@ func interact() { if len(restids) == 0 { break } - resttasks := getSelectedTasks(restids) - rcount, rhours, _ := analyzeTasks(resttasks) + resttasks := GetSelectedTasks(restids) + rcount, rhours, _ := AnalyzeTasks(resttasks) rids, rstr := getTaskList(restids, false) qu := "Select Tasks to Group as Billitem" @@ -647,8 +651,8 @@ func interact() { restids = removeItems(restids, taskids) if len(taskids) > 0 { - ittasks := getSelectedTasks(taskids) - itcount, ithours, itdur := analyzeTasks(ittasks) + ittasks := GetSelectedTasks(taskids) + itcount, ithours, itdur := AnalyzeTasks(ittasks) c.Printf("\n%v Tasks Selected, Total %.2f(h), Date: %s\n", itcount, ithours, itdur) c.ShowPrompt(false) c.Print("Name your Task for the Bill: ") @@ -782,8 +786,8 @@ func getNewInterMultiInput(question, old, border string) (out string) { if old != "" { shell.Println(border,"Current:\n", old) + shell.Println(border,"Should current entry be replaced? A Newline will be added otherwise") } - shell.Println(border,"Should current entry be replaced? A Newline will be added otherwise") if isInterSure(border+" ") { shell.Println(border, question, "(Multiline input, end with ';')") out = shell.ReadMultiLines(";") @@ -806,13 +810,17 @@ func getNewInterMultiInput(question, old, border string) (out string) { }*/ } -func multichoice(about string) { +// Invoke an Multiplechoice Question with a question and +// the list of options and return the selected list id +func Multichoice(question string,list []string) (int) { shell := ishell.New() shell.SetMultiChoicePrompt(" ->", " - ") shell.SetChecklistOptions("[ ] ", "[X] ") - shell.AddCmd(&ishell.Cmd{ + choice := shell.MultiChoice(list,question) + return choice + /*shell.AddCmd(&ishell.Cmd{ Name: "choice", Help: "multiple choice prompt", Func: func(c *ishell.Context) { @@ -831,5 +839,5 @@ func multichoice(about string) { }) str := "choice" shell.Process(str) - shell.Println(about) + shell.Println(about)*/ } @@ -115,7 +115,8 @@ func initDB(filename string) { CREATE TABLE vars( id INTEGER PRIMARY KEY AUTOINCREMENT, pauseid INTEGER DEFAULT NULL, - last TIMESTAMP DEFAULT '1791-09-30 19:07'); + last TIMESTAMP DEFAULT '1791-09-30 19:07', + color INTEGER DEFAULT 1 ); CREATE TRIGGER first AFTER INSERT ON timetable BEGIN update vars SET last = datetime('now') WHERE id = 1; @@ -237,11 +238,17 @@ func newTask(resume bool) { if resume { if pausetask == 0 { fmt.Println(nli+boldRed("No Task was Paused")) - fmt.Println(frame(negR(),false)) - return + if isInterSure(nli+"Resume older task?"){ + nm,st := GetTaskSums(currproject.id) + ch := Multichoice("What Task should be resumed?",st) + task = nm[ch] + }else{ + fmt.Println(frame(negR(),false)) + return + } } else { idx := []int{pausetask} - tsks := getSelectedTasks(idx) + tsks := GetSelectedTasks(idx) fulltask := tsks[0] fmt.Println(nli+"Resuming Task ", pausetask, " - ", fulltask.taskname) //fmt.Println() @@ -690,7 +697,8 @@ func getProject(id int) (outpr project, outcu customer) { return } -func getSelectedTasks(in []int) (outtask []task) { +// Return the []tasks correspintding to an []int of task ids +func GetSelectedTasks(in []int) (outtask []task) { ins := strings.Trim(strings.Replace(fmt.Sprint(in), " ", " , ", -1), "[]") que := fmt.Sprintf("SELECT * FROM timetable WHERE id IN (%s)", ins) rows, err := db.Query(que) @@ -709,7 +717,7 @@ func getSelectedTasks(in []int) (outtask []task) { } //Return sum of Hours and Dateranges -func analyzeTasks(in []task) (count int, hours float64, duration string) { +func AnalyzeTasks(in []task) (count int, hours float64, duration string) { var lstart, hstop time.Time for i, t := range in { if i == 0 { @@ -831,6 +839,43 @@ func getTaskIds() []int { return ids } +// Get All Tasks of Project with prid as a slice of Tasknames and +// a curresponding slice of strings to display +func GetTaskSums(prid int) (names,strings []string ) { + rows, err := db.Query("SELECT task FROM timetable WHERE stop != '1791-09-30 19:07' AND project = $1",prid) + checkErr(err) + var nam string + for rows.Next() { + err = rows.Scan(&nam) + checkErr(err) + if !IsStrElement(nam,names){ + names = append(names, nam) + } + } + for _,na := range names { + var ids []int + var id int + quer := fmt.Sprintf("SELECT id FROM timetable WHERE stop != '1791-09-30 19:07' AND task = '%s' AND project = %v",na,prid) + //rows, err = db.Query("SELECT id FROM timetable WHERE stop != '1791-09-30 19:07' AND task = ' $1 ' AND project = $2",na,prid) + rows, err = db.Query(quer) + checkErr(err) + for rows.Next() { + err = rows.Scan(&id) + checkErr(err) + ids = append(ids,id) + } + tsks := GetSelectedTasks(ids) + //fmt.Println(na,ids) + //fmt.Println(tsks) + count,hours,daterange := AnalyzeTasks(tsks) + full := fmt.Sprintf("%s: %vx (%s) %.2f[h]",na,count,daterange,hours) + strings = append(strings, full) + + } + + return +} + func getOpenTask() { rows, err := db.Query("SELECT id, project, start, task, checkout FROM timetable WHERE stop = '1791-09-30 19:07'") checkErr(err) @@ -1656,7 +1701,7 @@ func isSure() bool { return false } }*/ - +/* func isElement(some int, group []int) bool { for _, e := range group { if e == some { @@ -1674,7 +1719,7 @@ func removeItems(master, rem []int) []int { } } return out -} +}*/ /* func checkErr(err error) { @@ -248,3 +248,32 @@ func sumFloatArray(in []float64) (sum float64) { } return } + +func isElement(some int, group []int) bool { + for _, e := range group { + if e == some { + return true + } + } + return false +} + +func removeItems(master, rem []int) []int { + var out []int + for _, v := range master { + if !isElement(v, rem) { + out = append(out, v) + } + } + return out +} + +func IsStrElement(some string, group []string) bool { + for _, e := range group { + if e == some { + return true + } + } + return false +} + |
