|
@@ -7,6 +7,7 @@ import (
|
|
|
"bytes"
|
|
|
"fmt"
|
|
|
"log"
|
|
|
+ "math"
|
|
|
"os"
|
|
|
"strconv"
|
|
|
"text/template"
|
|
@@ -36,7 +37,7 @@ const HEADER_TEMPLATE = `
|
|
|
const TASK_ITEM = `
|
|
|
Title: {{.Title}}
|
|
|
-------------------------
|
|
|
- {{.Desc}}
|
|
|
+{{.Desc}}
|
|
|
|
|
|
Due: {{.Due}}
|
|
|
Priority: {{.Priority}}
|
|
@@ -46,6 +47,10 @@ Done?: {{.Priority}}
|
|
|
|
|
|
const TIME_TO_TEMPLATE = `{{.Hours}}H, {{.Minutes}}M`
|
|
|
|
|
|
+const HOME_TEMPLATE = ``
|
|
|
+
|
|
|
+// TODO: put all templates in their own file
|
|
|
+
|
|
|
type HeaderData struct {
|
|
|
Date string
|
|
|
Season string
|
|
@@ -145,8 +150,11 @@ func (u UserImplementation) getTimeToEod(ts time.Time) TimeToSunShift {
|
|
|
}
|
|
|
out := time.Date(ts.Year(), ts.Month(), ts.Day(), 17, 0, ts.Second(), ts.Nanosecond(), ts.Location())
|
|
|
dur := time.Until(out)
|
|
|
+ hours := dur.Minutes() / 60
|
|
|
+ hours = math.Floor(hours)
|
|
|
+ minutes := (hours * 60) - dur.Minutes()
|
|
|
|
|
|
- return TimeToSunShift{Hours: int(dur.Hours()), Minutes: int(dur.Minutes())}
|
|
|
+ return TimeToSunShift{Hours: int(hours), Minutes: int(minutes)}
|
|
|
}
|
|
|
|
|
|
func (u UserImplementation) getTimeToSunShift(ts time.Time) TimeToSunShift {
|
|
@@ -195,15 +203,8 @@ type model struct {
|
|
|
|
|
|
func InitialModel() model {
|
|
|
shelf := NewFilesystemShelf(FS_SAVE_LOCATION)
|
|
|
- // shelf.AddTask(Task{Id: 1, Title: "This is a sample task", Desc: "Quick sample task that im testing the storage with",
|
|
|
- // Due: time.Now().AddDate(0, 0, 2), Done: false, Priority: 1})
|
|
|
return model{
|
|
|
- // Our to-do list is a grocery list
|
|
|
- choices: GetTaskNames(shelf.GetAll()),
|
|
|
-
|
|
|
- // A map which indicates which choices are selected. We're using
|
|
|
- // the map like a mathematical set. The keys refer to the indexes
|
|
|
- // of the `choices` slice, above.
|
|
|
+ choices: GetTaskNames(shelf.GetAll()),
|
|
|
selected: make(map[int]struct{}),
|
|
|
}
|
|
|
}
|
|
@@ -247,6 +248,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|
|
} else {
|
|
|
m.selected[m.cursor] = struct{}{}
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -261,6 +263,8 @@ func (m model) View() string {
|
|
|
if err != nil {
|
|
|
log.Fatal("Couldnt parse the header template.. sorry. ", err)
|
|
|
}
|
|
|
+ shelf := NewFilesystemShelf(FS_SAVE_LOCATION)
|
|
|
+
|
|
|
s := getHeader(UserImplementation{}, tmpl)
|
|
|
|
|
|
// Iterate over our choices
|
|
@@ -275,7 +279,13 @@ func (m model) View() string {
|
|
|
// Is this choice selected?
|
|
|
checked := " " // not selected
|
|
|
if _, ok := m.selected[i]; ok {
|
|
|
+ for x := range shelf.Tasks {
|
|
|
+ if shelf.Tasks[x].Title == choice {
|
|
|
+ return shelf.RenderTask(shelf.Tasks[x])
|
|
|
+ }
|
|
|
+ }
|
|
|
checked = "x" // selected!
|
|
|
+
|
|
|
}
|
|
|
|
|
|
// Render the row
|