From ba96c6fae2ca3ea3399934ffd010cecfbaec273c Mon Sep 17 00:00:00 2001 From: Nikolaus Gotsche Date: Tue, 2 Oct 2018 01:48:53 +0200 Subject: New Input method --- interact.go | 48 ++++++++++++++++++++++++++++++++++++++---------- sqlite.go | 53 +++++++++++++++++++++++++++++++---------------------- utils.go | 8 ++++++++ 3 files changed, 77 insertions(+), 32 deletions(-) diff --git a/interact.go b/interact.go index 0c9f73b..932ce1d 100644 --- a/interact.go +++ b/interact.go @@ -128,7 +128,7 @@ func interact() { c.Println(boldRed(arg,"is not a valid id!")) } }else{ - c.Println(boldRed("deletetask - Please enter an id")) + c.Println(boldRed("deletebill - Please enter an id")) showLastBills(0) } c.Println(promptcol("______________________")) @@ -152,8 +152,14 @@ func interact() { c.Println(boldRed(arg,"is not a valid id!")) } }else{ - c.Println(boldRed("deletetask - Please enter an id")) - allProjects() + tids := getTaskIds() + selids,lids := getTaskList(tids,false) + choice := c.MultiChoice(lids,"Select a Task to Edit") + if choice > -1 { + deleteTask(selids[choice]) + } + //c.Println(boldRed("deletetask - Please enter an id")) + //allProjects() } c.Println(promptcol("______________________")) }, @@ -177,8 +183,15 @@ func interact() { c.Println(boldRed(arg,"is not a valid id!")) } }else{ - c.Println(boldRed("project - Please enter an id")) - allProjects() + pids := getProjectIds() + selids,lids := getProjectList(pids) + choice := c.MultiChoice(lids,"Select a Project to Edit") + if choice > -1 { + setProject(selids[choice]) + } + //c.Println(boldRed("editproject - Please enter an id")) + //c.Println(boldRed("project - Please enter an id")) + //allProjects() } c.Println(promptcol("______________________")) }, @@ -204,8 +217,8 @@ func interact() { tids := getTaskIds() selids,lids := getTaskList(tids,false) choice := c.MultiChoice(lids,"Select a Task to Edit") - c.Println(tids) - c.Println(selids) + //c.Println(tids) + //c.Println(selids) if choice > -1 { editTask(selids[choice]) //c.Println(choice,selids[choice]) @@ -229,7 +242,7 @@ func interact() { argi,err := strconv.Atoi(arg) if err == nil{ editProject(argi) - allProjects() + //allProjects() //stdOut() }else{ c.Println(boldRed(arg,"is not a valid id!")) @@ -238,8 +251,8 @@ func interact() { pids := getProjectIds() selids,lids := getProjectList(pids) choice := c.MultiChoice(lids,"Select a Project to Edit") - c.Println(pids) - c.Println(selids) + //c.Println(pids) + //c.Println(selids) if choice > -1 { editProject(selids[choice]) //c.Println(choice,selids[choice]) @@ -631,6 +644,21 @@ func interact() { //fmt.Println("Laboravi emeritus...") } + + +func getInterInput(question string) (out string) { + shell := ishell.New() + //shell.SetMultiChoicePrompt(" ->"," - ") + //shell.SetChecklistOptions("[ ] ","[X] ") + shell.ShowPrompt(false) + defer shell.ShowPrompt(true) + + shell.Print(question) + out = shell.ReadLine() + + return +} + func multichoice(about string) { shell := ishell.New() diff --git a/sqlite.go b/sqlite.go index 6ab652e..c090c0a 100644 --- a/sqlite.go +++ b/sqlite.go @@ -143,7 +143,7 @@ func newTaskTime(proj int, tim string) { } stmt, err := db.Prepare("INSERT INTO timetable(project, start, task, checkout) values(?, datetime(?,'utc'), ?, ?)") fmt.Println(timstr) - task := getInput("Specify Task: ") + task := getInterInput("Specify Task: ") checkErr(err) if (proj == 0) { _, err = stmt.Exec(currproject.id,timstr,task,0) @@ -167,7 +167,7 @@ func newTask(proj int) { boldRed := color.New(color.FgRed, color.Bold).SprintFunc() fmt.Println(boldGreen("Starting new Task")) if (opentask.id == 0) { - task := getInput("Specify Task: ") + task := getInterInput("Specify Task: ") stmt, err := db.Prepare("INSERT INTO timetable(project, task, checkout) values(?, ?, ?)") checkErr(err) if (proj == 0) { @@ -191,7 +191,7 @@ func newBill(proj int) (int,string) { fmt.Println(boldGreen("Creating New Bill")) //Show 5 recent bills showLastBills(5) - invno := getInput("Invoice Number: ") + invno := getInterInput("Invoice Number: ") stmt, err := db.Prepare("INSERT INTO bills (identity, project, date) values(?, ?, datetime('now'))") checkErr(err) answ, err := stmt.Exec(invno,proj) @@ -521,6 +521,8 @@ func getSelectedTasks(in []int) (outtask []task) { } return } + +//Return sum of Hours and Dateranges func analyzeTasks(in []task) (count int, hours float64, duration string) { var lstart,hstop time.Time for i,t := range in { @@ -684,14 +686,21 @@ func showLastProject() { } func addCustomer() { + boldRed := color.New(color.FgRed, color.Bold).SprintFunc() boldGreen := color.New(color.FgGreen, color.Bold).SprintFunc() fmt.Println(boldGreen("Adding new Customer")) - com := getInput("Enter Customer Company: ") - nam := getInput("Enter Customer Name: ") - add := getInput("Enter Address (separate lines by ; [Street;Zip;City;Country]): ") - satstr := getInput("Hourly Rate: ") - sat,err := strconv.ParseFloat(satstr,64) - checkErr(err) + com := getInterInput("Enter Customer Company: ") + nam := getInterInput("Enter Customer Name: ") + add := getInterInput("Enter Address (separate lines by ; [Street;Zip;City;Country]): ") + sat := 0.0 + for { + satstr := getInterInput("Hourly Rate: ") + sat,err = strconv.ParseFloat(satstr,64) + //checkErr(err) + if err != nil { + fmt.Println(satstr,boldRed("can not be Parsed as a Float."), "Try a shape of X.X") + }else{break} + } stmt, err := db.Prepare("INSERT INTO customers(company, name, address, satz) values(?, ?, ?, ?)") checkErr(err) @@ -705,11 +714,11 @@ func newProject() { boldGreen := color.New(color.FgGreen, color.Bold).SprintFunc() fmt.Println(boldGreen("Creating new Project")) if (opentask.id == 0) { - nam := getInput("Enter Project Name: ") + nam := getInterInput("Enter Project Name: ") icust := 0 allCustomers() for{ - cust := getInput("Enter Customer id (0 for none): ") + cust := getInterInput("Enter Customer id: ") icust,err = strconv.Atoi(cust) if (err == nil && (isCustomer(icust) || icust == 0)) { break @@ -1035,23 +1044,23 @@ func editCustomer(id int) { //fmt.Println(boldGreen("Edit Customer",id)) fmt.Println("Old Company Name:",comp) - in := getInput("Enter New:") + in := getInterInput("Enter New:") if in!=""{ comp=in } fmt.Println("Old Name:",name) - in = getInput("Enter New:") + in = getInterInput("Enter New:") if in!=""{ name=in } fmt.Println("Old Adress:",addr) - in = getInput("Enter New:") + in = getInterInput("Enter New:") if in!=""{ addr=in } fmt.Println("Old Hourly Rate:",satz) for{ - satzstr := getInput("Enter New:") + satzstr := getInterInput("Enter New:") if satzstr!=""{ satz,err = strconv.ParseFloat(satzstr,64) if err != nil { @@ -1087,7 +1096,7 @@ func editTask(id int) { rows.Close() //good habit to close fmt.Println("Old Name:",task) - in := getInput("Enter New:") + in := getInterInput("Enter New:") if in!=""{ task=in } @@ -1095,7 +1104,7 @@ func editTask(id int) { stopstr=stop.Local().Format("2006-01-02 15:04") for{ fmt.Println("Old Start:",startstr) - newstart := getInput("Enter New:") + newstart := getInterInput("Enter New:") if newstart!=""{ if isDate(newstart) { startstr=newstart @@ -1108,7 +1117,7 @@ func editTask(id int) { } fmt.Println("Old End:",stopstr) for{ - newend := getInput("Enter New:") + newend := getInterInput("Enter New:") if newend!=""{ if isDate(newend) { stopstr=newend @@ -1121,7 +1130,7 @@ func editTask(id int) { } fmt.Println("Old Project:",prj) for{ - newprj := getInput("Enter New:") + newprj := getInterInput("Enter New:") if newprj!=""{ prj,err = strconv.Atoi(newprj) if err != nil { @@ -1155,14 +1164,14 @@ func editProject(id int) { err = rows.Scan(&name, &first, &fin, &cust) checkErr(err) fmt.Println("Old Name:",name) - in := getInput("Enter New:") + in := getInterInput("Enter New:") if in!=""{ name=in } nfirst=first.Local().Format("2006-01-02 15:04") fmt.Println("Old Begin:",nfirst) for{ - newfirst := getInput("Enter New:") + newfirst := getInterInput("Enter New:") if newfirst!=""{ if isDate(newfirst) { nfirst=newfirst @@ -1175,7 +1184,7 @@ func editProject(id int) { } fmt.Println("Old Customer:",cust) for{ - custs := getInput("Enter Customer id (0 for none): ") + custs := getInterInput("Enter Customer id (0 for none): ") icust,err := strconv.Atoi(custs) if (err == nil && (isCustomer(icust) || icust == 0)) { cust = icust diff --git a/utils.go b/utils.go index c559b2e..312bc1f 100644 --- a/utils.go +++ b/utils.go @@ -70,6 +70,14 @@ func checkErr(err error) { } } +func strLines(in []string) (out string){ + out = "" + for _,s := range in { + out = fmt.Sprintf("%s%s\n",out,s) + } + return +} + func getInput(quest string) string { fmt.Print(quest) in := bufio.NewReader(os.Stdin) -- cgit v1.2.3