-
Notifications
You must be signed in to change notification settings - Fork 0
/
dashboard.go
58 lines (52 loc) · 1.34 KB
/
dashboard.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
package webui
import (
_ "embed" // used for dashboard.html
"github.com/phntom/nixeepass/orm"
"html/template"
"io"
"net/http"
"time"
)
//go:embed dashboard.html
var dashboardContent string
var dashboardTemplate *template.Template
func dashboardHandler(writer io.Writer, request *http.Request) error {
userID := "abc123"
userName := "phantom@kix.co.il"
var devices []orm.Device
db := orm.GetDB()
result := db.Find(&devices, orm.Device{UserID: userID}, 100)
err := result.Error
if err != nil {
return err
}
var backups []orm.Backup
result = db.Find(&backups, orm.Backup{UserID: userID}, 20)
err = result.Error
if err != nil {
return err
}
backupActiveModified := time.Unix(0, 0)
if len(backups) > 0 {
backupActiveModified = backups[0].CreatedAt
}
data := DashboardPage{
NeedsLogin: false,
AppName: cfgDashboard.AppName,
BrandName: cfgDashboard.BrandName,
UserID: userID,
UserName: userName,
Devices: devices,
BackupActiveModified: backupActiveModified,
Backups: backups,
CSRF: "abc123",
HTTPConfig: cfgHttp,
}
return dashboardTemplate.Execute(writer, data)
}
func GetIconMap(key string) string {
if val, ok := cfgDashboard.IconMap[key]; ok {
return val
}
return "fa-regular fa-circle-question"
}