summaryrefslogtreecommitdiff
path: root/sqlite.go
diff options
context:
space:
mode:
authorNikolaus Gotsche <n@softwarefools.com>2018-10-25 03:54:43 +0200
committerNikolaus Gotsche <n@softwarefools.com>2018-10-25 03:54:43 +0200
commit25e12980c0448cb58e545fffa137905fd861dea3 (patch)
treef93ee9c04f5a627283f5c75555dd4a6dd0c68f9c /sqlite.go
parent261d250f50b17117e99ab8b4b6ac7dfd35371386 (diff)
Resume now fully functional0.3.3
Diffstat (limited to 'sqlite.go')
-rw-r--r--sqlite.go61
1 files changed, 53 insertions, 8 deletions
diff --git a/sqlite.go b/sqlite.go
index e8e6ebc..dcb76b9 100644
--- a/sqlite.go
+++ b/sqlite.go
@@ -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) {