1
0
forked from x/icebergs

add checkbox

This commit is contained in:
IT 老营长 @云轩领航-创始人 2023-12-11 15:38:23 +08:00
parent 93a9591cf7
commit e18395626a
3 changed files with 12 additions and 4 deletions

View File

@ -76,6 +76,12 @@ func _hash_select(m *ice.Message, prefix, chain, field, value string) {
defer m.SortStrR(TIME) defer m.SortStrR(TIME)
fields := _hash_fields(m) fields := _hash_fields(m)
defer RLock(m, prefix)() defer RLock(m, prefix)()
if strings.Contains(value, ",") {
kit.For(kit.Split(value), func(value string) {
Richs(m, prefix, chain, value, func(key string, value Map) { _mdb_select(m, m.OptionCB(""), key, value, fields, nil) })
})
return
}
Richs(m, prefix, chain, value, func(key string, value Map) { _mdb_select(m, m.OptionCB(""), key, value, fields, nil) }) Richs(m, prefix, chain, value, func(key string, value Map) { _mdb_select(m, m.OptionCB(""), key, value, fields, nil) })
} }
func _hash_select_field(m *ice.Message, prefix, chain string, key string, field string) (value string) { func _hash_select_field(m *ice.Message, prefix, chain string, key string, field string) (value string) {
@ -221,7 +227,7 @@ func HashModify(m *ice.Message, arg ...Any) *ice.Message {
return m.Cmd(MODIFY, m.PrefixKey(), m.Option(SUBKEY), HASH, arg) return m.Cmd(MODIFY, m.PrefixKey(), m.Option(SUBKEY), HASH, arg)
} }
func HashSelect(m *ice.Message, arg ...string) *ice.Message { func HashSelect(m *ice.Message, arg ...string) *ice.Message {
if len(arg) > 0 && arg[0] == FOREACH { if len(arg) > 0 && (arg[0] == FOREACH || strings.Contains(arg[0], ",")) {
m.Fields(0, HashField(m)) m.Fields(0, HashField(m))
} else { } else {
m.Fields(len(kit.Slice(arg, 0, 1)), HashField(m)) m.Fields(len(kit.Slice(arg, 0, 1)), HashField(m))

View File

@ -247,6 +247,7 @@ const ( // MSG
LOG_TRACEID = "log.id" LOG_TRACEID = "log.id"
TOAST_DURATION = "toast.duration" TOAST_DURATION = "toast.duration"
TABLE_CHECKBOX = "table.checkbox"
) )
const ( // RENDER const ( // RENDER
RENDER_BUTTON = "_button" RENDER_BUTTON = "_button"

View File

@ -158,7 +158,7 @@ func (s relay) Stats(m *ice.Message) {
} }
return nil return nil
}).ProcessInner() }).ProcessInner()
s.ForEach(m.Spawn(ice.Maps{MACHINE: "", ice.CMD: "contexts/bin/ice.bin web.admin runtime"})).Table(func(value ice.Maps) { s.ForEach(m.Spawn(ice.Maps{MACHINE: m.Option(MACHINE), ice.CMD: "contexts/bin/ice.bin web.admin runtime"})).Table(func(value ice.Maps) {
res := kit.UnMarshal(value[ice.RES]) res := kit.UnMarshal(value[ice.RES])
data := kit.Value(res, cli.MAKE) data := kit.Value(res, cli.MAKE)
s.Modify(m, kit.Simple(MACHINE, value[MACHINE], kit.Dict( s.Modify(m, kit.Simple(MACHINE, value[MACHINE], kit.Dict(
@ -227,6 +227,7 @@ 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])) _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.StatusTimeCount(m.Spawn().Options(stats, _stats).OptionSimple(VCPU, MEM, DISK, SOCKET, PROC))
m.Option(ice.TABLE_CHECKBOX, ice.TRUE)
m.RewriteAppend(func(value, key string, index int) string { m.RewriteAppend(func(value, key string, index int) string {
if key == MEM { if key == MEM {
if ls := kit.Split(value, " /"); len(ls) > 0 && kit.Int(ls[0]) < 256*1024*1024 { if ls := kit.Split(value, " /"); len(ls) > 0 && kit.Int(ls[0]) < 256*1024*1024 {
@ -241,7 +242,7 @@ func (s relay) Install(m *ice.Message, arg ...string) {
s.shell(m, m.Template(INSTALL_SH), arg...) s.shell(m, m.Template(INSTALL_SH), arg...)
} }
func (s relay) Upgrade(m *ice.Message, arg ...string) { func (s relay) Upgrade(m *ice.Message, arg ...string) {
if len(arg) == 0 && m.Option(MACHINE) == "" { if len(arg) == 0 && (m.Option(MACHINE) == "" || strings.Contains(m.Option(MACHINE), ",")) {
m.Options(ice.CMD, m.Template(UPGRADE_SH), cli.DELAY, "0", "interval", "3s") m.Options(ice.CMD, m.Template(UPGRADE_SH), cli.DELAY, "0", "interval", "3s")
s.ForFlow(m) s.ForFlow(m)
} else { } else {
@ -294,7 +295,7 @@ func (s relay) shell(m *ice.Message, init string, arg ...string) {
} }
func (s relay) foreach(m *ice.Message, cb func(*ice.Message, []string)) { func (s relay) foreach(m *ice.Message, cb func(*ice.Message, []string)) {
cmd := kit.Filters(strings.Split(m.Option(ice.CMD), lex.NL), "") cmd := kit.Filters(strings.Split(m.Option(ice.CMD), lex.NL), "")
s.Hash.ForEach(m, "", func(msg *ice.Message) { cb(msg, cmd) }) s.Hash.ForEach(m, MACHINE, func(msg *ice.Message) { cb(msg, cmd) })
} }
func (s relay) foreachModify(m *ice.Message, key, cmd string, cb func([]string) string) { func (s relay) foreachModify(m *ice.Message, key, cmd string, cb func([]string) string) {
kit.If(cb == nil, func() { cb = func(ls []string) string { return kit.Join(ls) } }) kit.If(cb == nil, func() { cb = func(ls []string) string { return kit.Join(ls) } })