-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
101 lines (91 loc) · 2.57 KB
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package main
import (
"fmt"
"time"
"github.com/dominikbraun/timetrace/core"
"github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"
)
var version = "v0.3"
type Report struct {
Project string
Records []core.Record
Total time.Duration
Sum string
}
type Users struct {
Username string
Password string
IsAdmin bool
}
type ProjectTime struct {
Project string
Time string
}
type PageData struct {
Page string
Version string
Message string
Tracking bool
CurrentProject string
CurrentSession string
CurrentProjectTime string
Today string
Breaks string
Projects []*core.Project
Summary map[string]string
DefaultDate string
}
func (data *PageData) Init(page string, c *gin.Context) {
session := sessions.Default(c)
data.Message = session.Get("message").(string)
data.Page = page
data.Version = version
data.CurrentProject = "---"
data.CurrentSession = "---"
data.CurrentProjectTime = "---"
data.Tracking = false
data.DefaultDate = time.Now().Local().Format("2006-01-02")
status, err := timetrace.Status()
fmt.Println("error: ", err)
if err == nil {
fmt.Println("populating data", status.Current, status.TrackedTimeCurrent)
if status.Current != nil {
data.CurrentProject = status.Current.Project.Key
data.Tracking = true
}
if status.TrackedTimeCurrent != nil {
data.CurrentSession = timetrace.Formatter().FormatDuration(*status.TrackedTimeCurrent)
}
//Get Time worked today on Current Project
records, err := timetrace.ListRecords(time.Now())
var elapsed time.Duration
m := make(map[string]time.Duration)
s := make(map[string]string)
data.Summary = s
if err == nil {
for _, record := range records {
//Get Time worked today on Current Project
if record.Project.Key == data.CurrentProject {
elapsed = elapsed + record.Duration()
fmt.Println(elapsed, record.Duration())
}
m[record.Project.Key] = m[record.Project.Key] + record.Duration()
}
fmt.Println(m)
for key, value := range m {
fmt.Println("key:value ", key, value)
data.Summary[key] = timetrace.Formatter().FormatDuration(value)
}
data.CurrentProjectTime = timetrace.Formatter().FormatDuration(elapsed)
}
data.Today = timetrace.Formatter().FormatDuration(status.TrackedTimeToday)
data.Breaks = timetrace.Formatter().FormatDuration(status.BreakTimeToday)
}
//get all projects
data.Projects, err = timetrace.ListProjects()
if err != nil {
fmt.Println("error retrieving projects", err)
data.Projects = []*core.Project{}
}
}