-
Notifications
You must be signed in to change notification settings - Fork 34
/
index.go
58 lines (50 loc) · 1.54 KB
/
index.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 apps
import (
"github.com/TeaWeb/code/teaconfigs/agents"
"github.com/TeaWeb/code/teaconfigs/notices"
"github.com/TeaWeb/code/teadb"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/lists"
"github.com/iwind/TeaGo/maps"
)
type IndexAction actions.Action
// 看板首页
func (this *IndexAction) Run(params struct {
AgentId string
}) {
this.Data["agentId"] = params.AgentId
agent := agents.NewAgentConfigFromId(params.AgentId)
if agent == nil {
this.Fail("找不到要修改的Agent")
}
// 用户自定义App
this.Data["apps"] = lists.Map(agent.Apps, func(k int, v interface{}) interface{} {
app := v.(*agents.AppConfig)
// 最新一条数据
level := notices.NoticeLevelNone
for _, item := range app.Items {
if !item.On {
continue
}
value, err := teadb.AgentValueDAO().FindLatestItemValue(agent.Id, app.Id, item.Id)
if err == nil && value != nil {
if value.NoticeLevel == notices.NoticeLevelWarning || value.NoticeLevel == notices.NoticeLevelError && value.NoticeLevel > level {
level = value.NoticeLevel
}
}
}
return maps.Map{
"on": app.On,
"id": app.Id,
"name": app.Name,
"items": app.Items,
"bootingTasks": app.FindBootingTasks(),
"manualTasks": app.FindManualTasks(),
"schedulingTasks": app.FindSchedulingTasks(),
"isSharedWithGroup": app.IsSharedWithGroup,
"isWarning": level == notices.NoticeLevelWarning,
"isError": level == notices.NoticeLevelError,
}
})
this.Show()
}