forked from x/icebergs
add web.count
This commit is contained in:
parent
afdebbdc67
commit
32e5ea4067
@ -8,6 +8,7 @@ import (
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/web/html"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
"shylinux.com/x/toolkits/logs"
|
||||
"shylinux.com/x/toolkits/miss"
|
||||
@ -235,9 +236,9 @@ func HashSelect(m *ice.Message, arg ...string) *ice.Message {
|
||||
m.Cmdy(SELECT, m.PrefixKey(), m.Option(SUBKEY), HASH, HashShort(m), arg, logs.FileLineMeta(-1))
|
||||
kit.If(kit.Select(Config(m, SHORT), Config(m, SORT)), func(sort string) { kit.If(sort != UNIQ, func() { m.Sort(sort) }) })
|
||||
if m.PushAction(Config(m, ACTION), REMOVE); !m.FieldsIsDetail() {
|
||||
m.Options(ice.TABLE_CHECKBOX, Config(m, html.CHECKBOX))
|
||||
return m.Action(CREATE, PRUNES)
|
||||
}
|
||||
if m.FieldsIsDetail() {
|
||||
m.Table(func(value ice.Maps) {
|
||||
m.SetAppend().OptionFields(ice.FIELDS_DETAIL)
|
||||
kit.For(kit.Split(HashField(m)), func(key string) {
|
||||
@ -250,7 +251,6 @@ func HashSelect(m *ice.Message, arg ...string) *ice.Message {
|
||||
})
|
||||
kit.For(kit.SortedKey(value), func(k string) { m.Push(k, value[k]) })
|
||||
})
|
||||
}
|
||||
return m
|
||||
}
|
||||
func HashPrunes(m *ice.Message, cb func(Map) bool) *ice.Message {
|
||||
|
@ -10,10 +10,22 @@ const COUNT = "count"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
COUNT: &ice.Command{Help: "计数", Actions: ice.MergeActions(ice.Actions{
|
||||
COUNT: &ice.Command{Name: "count hash auto location", Help: "计数", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.CREATE: {Name: "create type name text", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashSelectUpdate(m, mdb.HashCreate(m), func(value ice.Map) { value[mdb.COUNT] = kit.Int(value[mdb.COUNT]) + 1 })
|
||||
}},
|
||||
}, mdb.HashAction(mdb.LIMIT, 1000, mdb.LEAST, 500, mdb.SHORT, "type,name", mdb.FIELD, "time,hash,count,type,name,text", mdb.SORT, "type,name,text"))},
|
||||
"location": {Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashSelects(m).Sort(mdb.COUNT, ice.INT_R)
|
||||
GoToast(m, "", func(toast func(string, int, int)) []string {
|
||||
m.Table(func(index int, value ice.Maps) {
|
||||
location := kit.Format(kit.Value(SpideGet(m, "http://opendata.baidu.com/api.php?query=%s&co=&resource_id=6006&oe=utf8", value["name"]), "data.0.location"))
|
||||
toast(location, index, m.Length())
|
||||
mdb.HashModify(m, mdb.HASH, value[mdb.HASH], "location", location)
|
||||
m.Sleep("500ms")
|
||||
})
|
||||
return nil
|
||||
})
|
||||
}},
|
||||
}, mdb.HashAction(mdb.LIMIT, 1000, mdb.LEAST, 500, mdb.SHORT, "type,name", mdb.FIELD, "time,hash,count,type,name,text", mdb.SORT, "type,name,text,location"))},
|
||||
})
|
||||
}
|
||||
|
@ -80,4 +80,5 @@ func FormatDanger(value string) string {
|
||||
|
||||
const (
|
||||
AcceptLanguage = "Accept-Language"
|
||||
CHECKBOX = "checkbox"
|
||||
)
|
||||
|
@ -11,6 +11,7 @@ import (
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/tcp"
|
||||
"shylinux.com/x/icebergs/base/web/html"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
@ -25,18 +26,21 @@ func _route_match(m *ice.Message, space string, cb func(ice.Maps, int, []ice.Map
|
||||
if m.Warn(err) {
|
||||
return
|
||||
}
|
||||
list := []ice.Maps{}
|
||||
res := []ice.Maps{}
|
||||
list := kit.Split(space)
|
||||
m.Cmd("").Table(func(value ice.Maps) {
|
||||
if value[mdb.STATUS] == OFFLINE {
|
||||
|
||||
} else if value[SPACE] == space {
|
||||
list = append(list, value)
|
||||
res = append(res, value)
|
||||
} else if kit.IsIn(value[SPACE], list...) {
|
||||
res = append(res, value)
|
||||
} else if reg.MatchString(kit.Format("%s:%s=%s@%s", value[SPACE], value[mdb.TYPE], value[nfs.MODULE], value[nfs.VERSION])) {
|
||||
list = append(list, value)
|
||||
res = append(res, value)
|
||||
}
|
||||
})
|
||||
for i, item := range list {
|
||||
cb(item, i, list)
|
||||
for i, item := range res {
|
||||
cb(item, i, res)
|
||||
}
|
||||
}
|
||||
func _route_toast(m *ice.Message, space string, args ...string) {
|
||||
@ -133,7 +137,7 @@ func init() {
|
||||
kit.If(value[mdb.STATUS] == OFFLINE, func() { mdb.HashRemove(m, SPACE, value[SPACE]) })
|
||||
})
|
||||
}},
|
||||
}, mdb.HashAction(mdb.SHORT, SPACE, mdb.FIELD, "time,space,type,module,version,md5,size,path,hostname", mdb.SORT, "type,space", mdb.ACTION, ice.MAIN)), Hand: func(m *ice.Message, arg ...string) {
|
||||
}, mdb.HashAction(mdb.SHORT, SPACE, mdb.FIELD, "time,space,type,module,version,md5,size,path,hostname", mdb.SORT, "type,space", html.CHECKBOX, ice.TRUE, mdb.ACTION, ice.MAIN)), Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) > 1 {
|
||||
_route_match(m, arg[0], func(value ice.Maps, i int, list []ice.Maps) {
|
||||
_route_push(m, value[SPACE], m.Cmd(SPACE, value[SPACE], arg[1:]))
|
||||
|
@ -203,7 +203,7 @@ func init() {
|
||||
m.Cmdy(nfs.DIR, ice.USR_ICONS, nfs.PATH).CutTo(nfs.PATH, arg[0])
|
||||
case aaa.PASSWORD:
|
||||
m.SetAppend()
|
||||
case ctx.INDEX:
|
||||
case ctx.INDEX, ice.CMD:
|
||||
if space := m.Option(SPACE); space != "" {
|
||||
m.Options(SPACE, []string{}).Cmdy(SPACE, space, ctx.COMMAND)
|
||||
} else {
|
||||
|
@ -57,6 +57,7 @@ const (
|
||||
type relay struct {
|
||||
ice.Hash
|
||||
ice.Code
|
||||
checkbox string `data:"true"`
|
||||
short string `data:"machine"`
|
||||
field string `data:"time,machine,username,password,host,port,portal,module,version,commit,compile,boot,package,shell,kernel,arch,ncpu,vcpu,mhz,mem,disk,network,listen,socket,proc,vendor"`
|
||||
statsTables string `name:"statsTables" event:"stats.tables"`
|
||||
@ -68,6 +69,7 @@ type relay struct {
|
||||
forFlow string `name:"forFlow machine cmd*:textarea=pwd" help:"流程"`
|
||||
list string `name:"list machine auto" help:"代理"`
|
||||
pushbin string `name:"pushbin" help:"部署"`
|
||||
adminCmd string `name:"adminCmd cmd" help:"命令"`
|
||||
}
|
||||
|
||||
func (s relay) Init(m *ice.Message, arg ...string) {
|
||||
@ -203,10 +205,10 @@ func (s relay) List(m *ice.Message, arg ...string) *ice.Message {
|
||||
stats[DISK_TOTAL] += kit.Int(ls[1])
|
||||
}
|
||||
if value[web.PORTAL] == "" {
|
||||
m.Push(web.LINK, "").PushButton(s.Xterm, s.Pushbin, s.Install, s.Remove)
|
||||
m.Push(web.LINK, "").PushButton(s.Xterm, s.AdminCmd, s.Pushbin, s.Install, s.Remove)
|
||||
return
|
||||
}
|
||||
m.PushButton(s.Admin, s.Vimer, s.Repos, s.Xterm, s.Pushbin, s.Upgrade, s.Remove)
|
||||
m.PushButton(s.Admin, s.Vimer, s.Repos, s.Xterm, s.AdminCmd, s.Pushbin, s.Upgrade, s.Remove)
|
||||
switch value[web.PORTAL] {
|
||||
case tcp.PORT_443:
|
||||
m.Push(web.LINK, kit.Format("https://%s", value[tcp.HOST]))
|
||||
@ -219,7 +221,6 @@ func (s relay) List(m *ice.Message, arg ...string) *ice.Message {
|
||||
})
|
||||
_stats := kit.Dict(MEM, kit.FmtSize(stats[MEM_FREE], stats[MEM_TOTAL]), DISK, kit.FmtSize(stats[DISK_USED], stats[DISK_TOTAL]))
|
||||
m.StatusTimeCount(m.Spawn().Options(stats, _stats).OptionSimple(VCPU, MEM, DISK, SOCKET, PROC))
|
||||
m.Options(ice.TABLE_CHECKBOX, ice.TRUE)
|
||||
m.RewriteAppend(func(value, key string, index int) string {
|
||||
if key == MEM {
|
||||
if ls := kit.Split(value, " /"); len(ls) > 0 && kit.Int(ls[0]) < 256*1024*1024 {
|
||||
@ -257,6 +258,9 @@ func (s relay) Pushbin(m *ice.Message, arg ...string) {
|
||||
}
|
||||
s.shell(m, m.Template(PUSHBIN_SH), arg...)
|
||||
}
|
||||
func (s relay) AdminCmd(m *ice.Message, arg ...string) {
|
||||
s.shell(m, kit.JoinWord("contexts/"+ice.BIN_ICE_BIN, web.ADMIN, m.Option(ice.CMD)), arg...)
|
||||
}
|
||||
|
||||
func (s relay) Xterm(m *ice.Message, arg ...string) { s.Code.Xterm(m, m.Option(MACHINE), arg...) }
|
||||
func (s relay) Repos(m *ice.Message, arg ...string) { s.iframeCmd(m, web.CODE_GIT_STATUS, arg...) }
|
||||
|
Loading…
x
Reference in New Issue
Block a user