mirror of
https://shylinux.com/x/operation
synced 2025-04-25 01:08:04 +08:00
63 lines
1.9 KiB
Go
63 lines
1.9 KiB
Go
package dashboard
|
|
|
|
import (
|
|
"shylinux.com/x/ice"
|
|
kit "shylinux.com/x/toolkits"
|
|
|
|
"shylinux.com/x/operation/src/dashboard/model"
|
|
)
|
|
|
|
type summary struct {
|
|
Table
|
|
dashboard dashboard
|
|
order string `data:"2"`
|
|
create string `name:"create space* index* query field title score" role:"leader"`
|
|
modify string `name:"modify space* index* query field title score" role:"leader"`
|
|
remove string `name:"remove" role:"leader"`
|
|
scan string `name:"scan" role:"leader"`
|
|
}
|
|
|
|
func (s summary) Scan(m *ice.Message, arg ...string) {
|
|
dashboard_uid := kit.Select(m.Option(model.DASHBOARD_UID), arg, 0)
|
|
s.dashboard.Scan(s.List(m, dashboard_uid), dashboard_uid, func(msg *ice.Message, value ice.Maps) {
|
|
s.Update(m, kit.Dict(model.VALUE, msg.Append(msg.Append(ice.MSG_APPEND))), model.UID, value[model.UID])
|
|
})
|
|
}
|
|
func (s summary) List(m *ice.Message, arg ...string) *ice.Message {
|
|
if len(arg) == 0 {
|
|
return m
|
|
}
|
|
s.Orders(m, model.SCORE, s.Desc(model.CREATED_AT))
|
|
s.Select(m, model.DASHBOARD_UID, arg[0])
|
|
if s.IsLeader(m) {
|
|
m.PushAction(s.Modify, s.Remove).Action(s.Create, s.Scan, s.Schema)
|
|
} else {
|
|
m.Action()
|
|
}
|
|
return s.Button(m, "").Display("").DisplayCSS("")
|
|
}
|
|
func (s summary) Schema(m *ice.Message, arg ...string) {
|
|
databases := map[string]bool{}
|
|
tables := map[string]bool{}
|
|
stats := map[string]int{}
|
|
m.Cmd(s.dashboard, s.Schema).Table(func(value ice.Maps) {
|
|
if !databases[value["TABLE_SCHEMA"]] {
|
|
databases[value["TABLE_SCHEMA"]] = true
|
|
stats["TABLE_SCHEMA"]++
|
|
}
|
|
if !tables[value["TABLE_NAME"]] {
|
|
tables[value["TABLE_NAME"]] = true
|
|
stats["TABLE_NAME"]++
|
|
}
|
|
stats["TABLE_ROWS"] += kit.Int(value["TABLE_ROWS"])
|
|
stats["DATA_LENGTH"] += kit.Int(value["DATA_LENGTH"])
|
|
stats["INDEX_LENGTH"] += kit.Int(value["INDEX_LENGTH"])
|
|
})
|
|
for k, v := range stats {
|
|
m.Push(model.TITLE, k).Push(model.VALUE, kit.TrimSuffix(kit.FmtSize(v), "B"))
|
|
}
|
|
m.Display("").DisplayCSS("")
|
|
}
|
|
|
|
func init() { ice.TeamCtxCmd(summary{}) }
|