|
|
@@ -32,6 +32,8 @@ const MODE_CAL tuiMode = "MODE_CAL"
|
|
|
|
const MODE_TIMEENTRIES tuiMode = "MODE_TIMEENTRIES"
|
|
|
|
const MODE_TIMEENTRIES tuiMode = "MODE_TIMEENTRIES"
|
|
|
|
const MODE_FORMENTRY tuiMode = "MODE_FORMENTRY"
|
|
|
|
const MODE_FORMENTRY tuiMode = "MODE_FORMENTRY"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var version = "dev"
|
|
|
|
|
|
|
|
|
|
|
|
type model struct {
|
|
|
|
type model struct {
|
|
|
|
miteAPI mite.APIClient
|
|
|
|
miteAPI mite.APIClient
|
|
|
|
start calendarTime
|
|
|
|
start calendarTime
|
|
|
@@ -74,10 +76,10 @@ func initialModel(miteDomain, miteApiKey string) model {
|
|
|
|
tab.SetStyles(s)
|
|
|
|
tab.SetStyles(s)
|
|
|
|
|
|
|
|
|
|
|
|
tab.SetColumns([]table.Column{
|
|
|
|
tab.SetColumns([]table.Column{
|
|
|
|
table.Column{Title: "min", Width: 5},
|
|
|
|
{Title: " min", Width: 4},
|
|
|
|
table.Column{Title: "lck", Width: 4},
|
|
|
|
{Title: "🔐", Width: 2},
|
|
|
|
table.Column{Title: "customer", Width: 10},
|
|
|
|
{Title: "customer", Width: 10},
|
|
|
|
table.Column{Title: "description", Width: 40},
|
|
|
|
{Title: "description", Width: 40},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
m.start = calendarTime{time.Now()}
|
|
|
|
m.start = calendarTime{time.Now()}
|
|
|
@@ -109,7 +111,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|
|
|
m.fetchedData = false
|
|
|
|
m.fetchedData = false
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
m.statusBarMessage = fmt.Sprintf("Fetched %d time entries", len(msg.TimeEntries))
|
|
|
|
m.statusBarMessage = fmt.Sprintf("Fetched %d time entries in %s", len(msg.TimeEntries), time.Since(msg.start).Truncate(time.Millisecond))
|
|
|
|
m.timeData.entries = msg.TimeEntries
|
|
|
|
m.timeData.entries = msg.TimeEntries
|
|
|
|
m.formData.customers = msg.Customers
|
|
|
|
m.formData.customers = msg.Customers
|
|
|
|
m.formData.services = msg.Services
|
|
|
|
m.formData.services = msg.Services
|
|
|
@@ -302,12 +304,13 @@ func (m model) tableDataForDate(t time.Time) []table.Row {
|
|
|
|
if entry.Locked {
|
|
|
|
if entry.Locked {
|
|
|
|
lock = "🔐"
|
|
|
|
lock = "🔐"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rows = append(rows, table.Row{fmt.Sprint(entry.Minutes), lock, entry.CustomerName, entry.Note})
|
|
|
|
rows = append(rows, table.Row{fmt.Sprintf("%4d", entry.Minutes), lock, entry.CustomerName, entry.Note})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rows
|
|
|
|
return rows
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type miteDataFetchedMsg struct {
|
|
|
|
type miteDataFetchedMsg struct {
|
|
|
|
|
|
|
|
start time.Time
|
|
|
|
TimeEntries mite.TimeEntries
|
|
|
|
TimeEntries mite.TimeEntries
|
|
|
|
Customers mite.Customers
|
|
|
|
Customers mite.Customers
|
|
|
|
Services mite.Services
|
|
|
|
Services mite.Services
|
|
|
@@ -317,6 +320,7 @@ type miteDataFetchedMsg struct {
|
|
|
|
|
|
|
|
|
|
|
|
func (m model) fetchMiteData() tea.Cmd {
|
|
|
|
func (m model) fetchMiteData() tea.Cmd {
|
|
|
|
return func() tea.Msg {
|
|
|
|
return func() tea.Msg {
|
|
|
|
|
|
|
|
t0 := time.Now()
|
|
|
|
from := time.Now().Add(-time.Hour * 24 * 30 * 6) // about 6 months
|
|
|
|
from := time.Now().Add(-time.Hour * 24 * 30 * 6) // about 6 months
|
|
|
|
to := time.Now().Add(time.Hour * 20 * 30) // about 1 month
|
|
|
|
to := time.Now().Add(time.Hour * 20 * 30) // about 1 month
|
|
|
|
te, err1 := m.miteAPI.GetTimeEntries(from, to)
|
|
|
|
te, err1 := m.miteAPI.GetTimeEntries(from, to)
|
|
|
@@ -330,6 +334,7 @@ func (m model) fetchMiteData() tea.Cmd {
|
|
|
|
Services: svc,
|
|
|
|
Services: svc,
|
|
|
|
Projects: pjt,
|
|
|
|
Projects: pjt,
|
|
|
|
Error: errors.Join(err1, err2, err3, err4),
|
|
|
|
Error: errors.Join(err1, err2, err3, err4),
|
|
|
|
|
|
|
|
start: t0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -341,6 +346,12 @@ func (m model) View() string {
|
|
|
|
lhs := strings.Builder{}
|
|
|
|
lhs := strings.Builder{}
|
|
|
|
rhs := strings.Builder{}
|
|
|
|
rhs := strings.Builder{}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nb := lipgloss.NewStyle().Border(lipgloss.NormalBorder())
|
|
|
|
|
|
|
|
db := lipgloss.NewStyle().Border(lipgloss.DoubleBorder())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lhsS := nb
|
|
|
|
|
|
|
|
rhsS := nb
|
|
|
|
|
|
|
|
|
|
|
|
// if any entries are not "locked", we always use that
|
|
|
|
// if any entries are not "locked", we always use that
|
|
|
|
// regular colour in preference
|
|
|
|
// regular colour in preference
|
|
|
|
styles := map[string]lipgloss.Style{}
|
|
|
|
styles := map[string]lipgloss.Style{}
|
|
|
@@ -362,6 +373,7 @@ func (m model) View() string {
|
|
|
|
|
|
|
|
|
|
|
|
if m.tuiMode == MODE_CAL {
|
|
|
|
if m.tuiMode == MODE_CAL {
|
|
|
|
lhs.WriteString("(f)etch time data\n")
|
|
|
|
lhs.WriteString("(f)etch time data\n")
|
|
|
|
|
|
|
|
lhsS = db
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
lhs.WriteString("\n")
|
|
|
|
lhs.WriteString("\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -373,18 +385,24 @@ func (m model) View() string {
|
|
|
|
if m.tuiMode == MODE_FORMENTRY {
|
|
|
|
if m.tuiMode == MODE_FORMENTRY {
|
|
|
|
lhs.WriteString("(esc) abort form\n")
|
|
|
|
lhs.WriteString("(esc) abort form\n")
|
|
|
|
lhs.WriteString("\n")
|
|
|
|
lhs.WriteString("\n")
|
|
|
|
|
|
|
|
rhsS = db
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
lhs.WriteString("(tab) switch panes\n")
|
|
|
|
lhs.WriteString("(tab) switch panes\n")
|
|
|
|
lhs.WriteString("(q)uit\n")
|
|
|
|
lhs.WriteString("(q)uit\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if m.tuiMode == MODE_TIMEENTRIES {
|
|
|
|
|
|
|
|
rhsS = db
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
calendarWidth := 25
|
|
|
|
lhsWidth := 25
|
|
|
|
tableWidth := m.windowWidth - calendarWidth
|
|
|
|
rhsWidth := m.windowWidth - lhsWidth - 4
|
|
|
|
|
|
|
|
|
|
|
|
if m.tuiMode == MODE_FORMENTRY {
|
|
|
|
if m.tuiMode == MODE_FORMENTRY {
|
|
|
|
rhs.WriteString(m.formData.form.View())
|
|
|
|
rhs.WriteString(m.formData.form.View())
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if m.fetchedData {
|
|
|
|
if m.fetchedData {
|
|
|
|
|
|
|
|
m.timeData.table.Columns()[3].Width = rhsWidth - 30
|
|
|
|
|
|
|
|
m.timeData.table.SetHeight(14)
|
|
|
|
rhs.WriteString(m.timeData.table.View())
|
|
|
|
rhs.WriteString(m.timeData.table.View())
|
|
|
|
rhs.WriteString("\n")
|
|
|
|
rhs.WriteString("\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -392,14 +410,23 @@ func (m model) View() string {
|
|
|
|
|
|
|
|
|
|
|
|
out := lipgloss.JoinHorizontal(
|
|
|
|
out := lipgloss.JoinHorizontal(
|
|
|
|
lipgloss.Top,
|
|
|
|
lipgloss.Top,
|
|
|
|
lipgloss.NewStyle().Width(calendarWidth).Render(lhs.String()),
|
|
|
|
lhsS.Render(lipgloss.NewStyle().Width(lhsWidth).Render(lhs.String())),
|
|
|
|
lipgloss.NewStyle().Width(tableWidth).Render(rhs.String()),
|
|
|
|
rhsS.Render(lipgloss.NewStyle().Width(rhsWidth).Render(rhs.String())),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
sofar := lipgloss.Height(out)
|
|
|
|
sofar := lipgloss.Height(out)
|
|
|
|
|
|
|
|
|
|
|
|
statusMsg := strings.ReplaceAll(m.statusBarMessage, "\n", " ")
|
|
|
|
statusMsg := strings.ReplaceAll(m.statusBarMessage, "\n", " ")
|
|
|
|
out += styleStatusBar.MarginTop(m.windowHeight - sofar).Width(m.windowWidth).Render(statusMsg)
|
|
|
|
|
|
|
|
|
|
|
|
mainMsg := styleStatusBar.Width(m.windowWidth - len(version)).MarginTop(m.windowHeight - sofar).Render(statusMsg)
|
|
|
|
|
|
|
|
versionMsg := styleStatusBar.MarginTop(m.windowHeight - sofar).Render(version)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bar := lipgloss.JoinHorizontal(lipgloss.Top,
|
|
|
|
|
|
|
|
mainMsg,
|
|
|
|
|
|
|
|
versionMsg,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
out += bar
|
|
|
|
|
|
|
|
|
|
|
|
return out
|
|
|
|
return out
|
|
|
|
}
|
|
|
|
}
|
|
|
|