diff options
Diffstat (limited to 'zeitgeist.go')
-rw-r--r-- | zeitgeist.go | 51 |
1 files changed, 35 insertions, 16 deletions
diff --git a/zeitgeist.go b/zeitgeist.go index 3abf395..66ef520 100644 --- a/zeitgeist.go +++ b/zeitgeist.go @@ -27,7 +27,7 @@ var ( fl_timelogs = flag.String("lt", "", "directory to search for timelogs") fl_plandir = flag.String("pl", "", "directory to search for plans") fl_templates = flag.String("tm", "", "directory to search for the templates") - fl_report = flag.String("rp", "report.t", "default report template") + fl_report = flag.String("rp", "report.md", "default report template") fl_today = flag.String("today", time.Now().Format(time.DateOnly), "what is the date today") ) @@ -348,6 +348,11 @@ func (p *Project) readPlans(dir string) error { } for _, name := range matches { + user := strings.Split(filepath.Base(name), ".")[0] + if _, ok := p.Users[user]; !ok { + return fmt.Errorf("file %q doesn't belong to a user name", name) + } + f, e := os.Open(name) if e != nil { return fmt.Errorf("os.Open(%q) failed: %w", name, e) @@ -481,7 +486,7 @@ func (p *Project) readPlans(dir string) error { if a > 0 { entry := Entry{ - User: parts[1], + User: user, WP: wps[0], Task: wps[1], Amount: a, @@ -597,7 +602,7 @@ func (p *Project) readTimelogs(dir string) error { } entry := Entry{ - User: parts[1], + User: user, WP: wps[0], Task: wps[1], Amount: amount} @@ -611,7 +616,7 @@ func (p *Project) readTimelogs(dir string) error { return nil } -//go:embed templates/*.t +//go:embed templates/*.md var embedFS embed.FS var once sync.Once var templates *template.Template @@ -621,9 +626,9 @@ func (p *Project) printReport(name string) { once.Do(func() { if *fl_templates != "" { - templates, e = template.ParseGlob(*fl_templates + "/*.t") + templates, e = template.ParseGlob(*fl_templates + "/*.md") } else { - templates, e = template.ParseFS(embedFS, "templates/*.t") + templates, e = template.ParseFS(embedFS, "templates/*.md") } if e != nil { log.Fatalf("Couldn't parse templates: %v\n", e) @@ -764,7 +769,7 @@ func (f *FullDates) FilterUser(user string) *FullDates { return f } -func (p *Project) monthCal(year, month int) []string { +func (p *Project) monthCal(year, month int, user ...string) []string { /* 2 9 16 23 30 3 10 17 24 31 @@ -779,6 +784,20 @@ func (p *Project) monthCal(year, month int) []string { const wd = 6 * cw const sp = " " + userOK := func(en Entries) bool { + if len(user) == 0 { + return true + } + for _, u := range user { + for _, e := range en { + if e.User == u { + return true + } + } + } + return false + } + lines := [7]string{} m := time.Month(month) date := time.Date(year, m, 1, 0, 0, 0, 0, time.UTC) @@ -803,9 +822,9 @@ func (p *Project) monthCal(year, month int) []string { str = fmt.Sprintf("%[1]*s", l, "☺") } else if _, ok := p.Blocked[Date(date)]; ok { suf = "¬" - } else if _, ok := p.Timeline[Date(date)]; ok { + } else if ev, ok := p.Timeline[Date(date)]; ok && userOK(ev) { suf = "•" - } else if _, ok := p.Planned[Date(date)]; ok { + } else if ev, ok := p.Planned[Date(date)]; ok && userOK(ev) { suf = "¤" //"¶" } lines[d] += str + suf @@ -826,14 +845,14 @@ func (p *Project) MonthCalendar(year, month int) string { return h + strings.Join(lines, "\n") } -func (p *Project) QuaterYearCalendar(year, quarter int) string { +func (p *Project) QuaterYearCalendar(year, quarter int, user ...string) string { return "not implemented" } -func (p *Project) YearCalendar(year int) string { +func (p *Project) YearCalendar(year int, user ...string) string { t := [12][]string{} for i := range 12 { - t[i] = p.monthCal(year, i+1) + t[i] = p.monthCal(year, i+1, user...) } wd := len(bytes.Runes([]byte(t[0][0]))) lines := []string{} @@ -857,13 +876,13 @@ func (p *Project) YearCalendar(year int) string { s := fmt.Sprintf("%[1]*d\n", 3*wd/2+2, year) - return s + strings.Join(lines, "\n") + "\n\n" + return s + strings.Join(lines, "\n") } -func (p *Project) Calendars() map[int]string { +func (p *Project) Calendars(user ...string) map[int]string { r := make(map[int]string) for y := p.Start.Year(); y <= p.End.Year(); y++ { - r[y] = p.YearCalendar(y) + r[y] = p.YearCalendar(y, user...) } return r } @@ -1001,7 +1020,7 @@ func renderParallel(content ...[]string) []string { } func (p *Project) ParallelWPTotals(tmpl ...string) ([]string, error) { - tm := "wp-total.t" + tm := "wp-total.md" if len(tmpl) > 0 { tm = tmpl[0] } |