Skip to content

Commit

Permalink
Fixed bug with Curret[Item]. Added gif to readme.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nanohard committed Jul 8, 2017
1 parent a74eee4 commit 5f05e35
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 11 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Time tracker for projects and tasks written in golang.

**Only supported on Linux**

![gotime](https://user-images.githubusercontent.com/10169206/27987771-f1a5bd9e-63d8-11e7-8d3d-a8abc33bd0e9.gif)

## Overview
I created this in response to my need to record entries for tasks and tasks for projects, and my want to not have to type a whole command in the console for every action I wanted to perform. Thus gotime was born; an ncurses-style console user interface program with an SQlite3 database.

Expand All @@ -14,7 +16,7 @@ The time is stamped in seconds upon starting and stopping an entry; no timer is
Upon starting the program you will be required to type in the name of a project. Navigate to the right and press Ctrl-A to add a task, and do the same to create and start an entry. Press Ctrl-S to save the entry.

## Controls
* **Ctrl-A**: Adds an item to the current view. If in the entries view it will "start" an Entry. This will create a timestamp of the current time and create an entry in the database. At this point you may type notes into the Entry's details. Press Ctrl-S to stop and save the Entry.
* **Ctrl-A**: Add an item to the current view. If in the entries view it will "start" an Entry. This will create a timestamp of the current time and create an entry in the database. At this point you may type notes into the Entry's details. Press Ctrl-S to stop and save the Entry.
* **Ctrl-S**: Save the text you have written in the output box, whether for an Entry's details or a description for a Project or Task. For an Entry this will save the details you have written and stop the timer.
* **Ctrl-D**: Add a description to a Project or Task.
* **Ctrl-R**: Remove an Entry, Task, or Project. Removing a Project or Task will also remove all of its children.
Expand Down
54 changes: 46 additions & 8 deletions funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,24 @@ func cursorDown(g *gocui.Gui, v *gocui.View) error {
n, _ := v.Line(cy)
if v.Name() == P {
nv, _ := g.View(T)
models.CurrentProject = models.GetProject(n)
if n != "" {
models.CurrentProject = models.GetProject(n)
}
// log.Println("cursorDown project.id:", models.CurrentProject.ID)
redrawTasks(g, nv)
} else if v.Name() == T {
nv, _ := g.View(E)
models.CurrentTask = models.GetTask(n)
if n != "" {
models.CurrentTask = models.GetTask(n)
}
// log.Println("cursorDown task.id:", models.CurrentTask.ID)
redrawEntries(g, nv)
} else if v.Name() == E {
nv, _ := g.View(O)
models.CurrentEntry = models.GetEntry(n)
if n != "" {
models.CurrentEntry = models.GetEntry(n)
}
// log.Println("cursorUp entry.id:", models.CurrentEntry.ID)
redrawOutput(g, nv)
}
}
Expand All @@ -44,15 +53,30 @@ func cursorUp(g *gocui.Gui, v *gocui.View) error {
n, _ := v.Line(cy)
if v.Name() == P {
nv, _ := g.View(T)
models.CurrentProject = models.GetProject(n)
if n != "" {
models.CurrentProject = models.GetProject(n)
} else {
models.CurrentProject = models.Project{}
}
// log.Println("cursorUp project.id:", models.CurrentProject.ID)
redrawTasks(g, nv)
} else if v.Name() == T {
nv, _ := g.View(E)
models.CurrentTask = models.GetTask(n)
if n != "" {
models.CurrentTask = models.GetTask(n)
} else {
models.CurrentTask = models.Task{}
}
// log.Println("cursorUp task.id:", models.CurrentTask.ID)
redrawEntries(g, nv)
} else if v.Name() == E {
nv, _ := g.View(O)
models.CurrentEntry = models.GetEntry(n)
if n != "" {
models.CurrentEntry = models.GetEntry(n)
} else {
models.CurrentEntry = models.Entry{}
}
// log.Println("cursorUp entry.id:", models.CurrentEntry.ID)
redrawOutput(g, nv)
}
}
Expand Down Expand Up @@ -165,12 +189,16 @@ func selectItem(g *gocui.Gui, cv *gocui.View) error {
if nv, err = g.SetCurrentView(T); err != nil {
return err
}
models.CurrentEntry = models.Entry{}
// log.Println("selectItem project view CurrentEntry:", models.CurrentEntry.ID)
nv.SetCursor(0, 0)
cursorUp(g, nv)
case T:
if nv, err = g.SetCurrentView(E); err != nil {
return err
}
models.CurrentEntry = models.Entry{}
// log.Println("selectItem task view CurrentEntry:", models.CurrentEntry.ID)
nv.SetCursor(0, 0)
cursorUp(g, nv)
}
Expand All @@ -196,17 +224,20 @@ func deleteItem(g *gocui.Gui, v *gocui.View) error {
switch v.Name() {
case P:
models.CurrentProject.Delete()
models.CurrentProject = models.Project{}
redrawProjects(g, v)
v.SetCursor(0, 0)
cursorUp(g, v)
case T:
models.CurrentTask.Delete()
models.CurrentTask = models.Task{}
redrawTasks(g, v)
v.SetCursor(0, 0)
cursorUp(g, v)

case E:
models.CurrentEntry.Delete()
models.CurrentEntry = models.Entry{}
redrawEntries(g, v)
v.SetCursor(0, 0)
cursorUp(g, v)
Expand All @@ -233,6 +264,7 @@ func goBack(g *gocui.Gui, cv *gocui.View) error {
if nv, err = g.SetCurrentView(T); err != nil {
return err
}
models.CurrentEntry = models.Entry{}
outputView, _ := g.View(O)
redrawOutput(g, outputView)
}
Expand Down Expand Up @@ -268,7 +300,10 @@ func redrawProjects(g *gocui.Gui, v *gocui.View) {
// so we need to refresh the tasks view with the currently highlighted project.
_, cy := v.Cursor()
l, _ := v.Line(cy)
models.CurrentProject = models.GetProject(l)
if l != "" {
models.CurrentProject = models.GetProject(l)
}
// log.Println("redrawProjects project.id:", models.CurrentProject.ID)
tasksView, _ := g.View(T)
// Projects is only redrawn if in the projects view, so it's
// safe to zero the current task and entry.
Expand Down Expand Up @@ -310,6 +345,7 @@ func redrawEntries(g *gocui.Gui, v *gocui.View) {
for _, i := range items {
// We can simply Fprint to a view.
_, err := fmt.Fprintln(v, i.Name)
// log.Println("redrawEntries CurrentTask.ID:", models.CurrentTask.ID)
if err != nil {
log.Println("Error writing to the entries view:", err)
}
Expand All @@ -324,7 +360,9 @@ func redrawEntries(g *gocui.Gui, v *gocui.View) {
// Read the cursor, get the data, print it.
_, cy := v.Cursor()
l, _ := v.Line(cy)
models.CurrentEntry = models.GetEntry(l)
if l != "" {
models.CurrentEntry = models.GetEntry(l)
}
outputView, _ := g.View(O)
redrawOutput(g, outputView)
}
Expand Down
2 changes: 1 addition & 1 deletion models/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func AllEntries(t Task) []Entry {
// after scanning it into the struct.
func GetEntry(n string) Entry {
var e Entry
DB.Where("name = ?", n).First(&e)
DB.Where(&Entry{Name: n}).First(&e)
return e
}

Expand Down
3 changes: 2 additions & 1 deletion models/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ func AllTasks(p Project) []Task {
func GetTask(n string) Task {
var t Task
n = strings.TrimSpace(n)
DB.Where("name = ?", n).First(&t)
// DB.Where(&Task{Name: n}).First(&t)
DB.Model(&CurrentProject).Where(&Task{Name: n}).Related(&t)
return t
}

Expand Down

0 comments on commit 5f05e35

Please sign in to comment.