1
0
forked from x/icebergs
This commit is contained in:
harveyshao 2022-11-25 21:05:10 +08:00
parent aacb485deb
commit 244dab2e4b
9 changed files with 105 additions and 124 deletions

View File

@ -6,6 +6,4 @@ import (
const ENGINE = "engine" const ENGINE = "engine"
func init() { func init() { Index.MergeCommands(ice.Commands{ENGINE: {Help: "引擎", Actions: RenderAction()}}) }
Index.MergeCommands(ice.Commands{ENGINE: {Help: "引擎", Actions: RenderAction()}})
}

View File

@ -34,9 +34,6 @@ func _hash_insert(m *ice.Message, prefix, chain string, arg ...string) string {
if expire := m.Conf(prefix, kit.Keys(chain, kit.Keym(EXPIRE))); expire != "" { if expire := m.Conf(prefix, kit.Keys(chain, kit.Keym(EXPIRE))); expire != "" {
arg = kit.Simple(TIME, m.Time(expire), arg) arg = kit.Simple(TIME, m.Time(expire), arg)
} }
m.Debug("what %v %v", m.Conf(prefix, chain))
m.Debug("what %v %v", kit.Data())
m.Debug("what %v %v", m.Conf(prefix, chain))
return m.Echo(Rich(m, prefix, chain, kit.Data(arg, TARGET, m.Optionv(TARGET)))).Result() return m.Echo(Rich(m, prefix, chain, kit.Data(arg, TARGET, m.Optionv(TARGET)))).Result()
} }
func _hash_delete(m *ice.Message, prefix, chain, field, value string) { func _hash_delete(m *ice.Message, prefix, chain, field, value string) {
@ -75,8 +72,8 @@ func _hash_select_field(m *ice.Message, prefix, chain string, key string, field
return return
} }
func _hash_prunes(m *ice.Message, prefix, chain string, arg ...string) { func _hash_prunes(m *ice.Message, prefix, chain string, arg ...string) {
defer RLock(m, prefix, chain)()
fields := _hash_fields(m) fields := _hash_fields(m)
defer RLock(m, prefix, chain)()
Richs(m, prefix, chain, FOREACH, func(key string, value Map) { Richs(m, prefix, chain, FOREACH, func(key string, value Map) {
switch value = kit.GetMeta(value); cb := m.OptionCB(PRUNES).(type) { switch value = kit.GetMeta(value); cb := m.OptionCB(PRUNES).(type) {
case func(string, Map) bool: case func(string, Map) bool:
@ -93,18 +90,19 @@ func _hash_prunes(m *ice.Message, prefix, chain string, arg ...string) {
}) })
} }
func _hash_export(m *ice.Message, prefix, chain, file string) { func _hash_export(m *ice.Message, prefix, chain, file string) {
defer Lock(m, prefix, chain)()
f, p, e := miss.CreateFile(kit.Keys(file, JSON)) f, p, e := miss.CreateFile(kit.Keys(file, JSON))
m.Assert(e) m.Assert(e)
defer f.Close() defer f.Close()
defer m.Echo(p) defer m.Echo(p)
m.Logs(EXPORT, KEY, path.Join(prefix, chain), FILE, p) m.Logs(EXPORT, KEY, path.Join(prefix, chain), FILE, p, COUNT, len(m.Confm(prefix, kit.Keys(chain, HASH))))
en := json.NewEncoder(f) en := json.NewEncoder(f)
defer Lock(m, prefix, chain)()
if en.SetIndent("", " "); !m.Warn(en.Encode(m.Confv(prefix, kit.Keys(chain, HASH))), EXPORT, prefix) { if en.SetIndent("", " "); !m.Warn(en.Encode(m.Confv(prefix, kit.Keys(chain, HASH))), EXPORT, prefix) {
m.Conf(prefix, kit.Keys(chain, HASH), "") m.Conf(prefix, kit.Keys(chain, HASH), "")
} }
} }
func _hash_import(m *ice.Message, prefix, chain, file string) { func _hash_import(m *ice.Message, prefix, chain, file string) {
defer Lock(m, prefix, chain)()
f, e := miss.OpenFile(kit.Keys(file, JSON)) f, e := miss.OpenFile(kit.Keys(file, JSON))
if m.Warn(e) { if m.Warn(e) {
return return
@ -114,7 +112,6 @@ func _hash_import(m *ice.Message, prefix, chain, file string) {
m.Assert(json.NewDecoder(f).Decode(&list)) m.Assert(json.NewDecoder(f).Decode(&list))
m.Logs(IMPORT, KEY, path.Join(prefix, chain), FILE, kit.Keys(file, JSON), COUNT, len(list)) m.Logs(IMPORT, KEY, path.Join(prefix, chain), FILE, kit.Keys(file, JSON), COUNT, len(list))
defer m.Echo("%d", len(list)) defer m.Echo("%d", len(list))
defer Lock(m, prefix, chain)()
for k, data := range list { for k, data := range list {
if m.Confv(prefix, kit.Keys(chain, HASH, k)) == nil { if m.Confv(prefix, kit.Keys(chain, HASH, k)) == nil {
m.Confv(prefix, kit.Keys(chain, HASH, k), data) m.Confv(prefix, kit.Keys(chain, HASH, k), data)
@ -155,9 +152,7 @@ func HashKey(m *ice.Message) string {
} }
return HashShort(m) return HashShort(m)
} }
func HashShort(m *ice.Message) string { func HashShort(m *ice.Message) string { return kit.Select(HASH, m.Config(SHORT), m.Config(SHORT) != UNIQ) }
return kit.Select(HASH, m.Config(SHORT), m.Config(SHORT) != UNIQ)
}
func HashField(m *ice.Message) string { return kit.Select(HASH_FIELD, m.Config(FIELD)) } func HashField(m *ice.Message) string { return kit.Select(HASH_FIELD, m.Config(FIELD)) }
func HashInputs(m *ice.Message, arg ...Any) *ice.Message { func HashInputs(m *ice.Message, arg ...Any) *ice.Message {
return m.Cmdy(INPUTS, m.PrefixKey(), "", HASH, arg) return m.Cmdy(INPUTS, m.PrefixKey(), "", HASH, arg)
@ -184,7 +179,7 @@ func HashModify(m *ice.Message, arg ...Any) *ice.Message {
} }
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 {
m.Fields(0, HashField(m)) m.OptionFields(HashField(m))
} else { } else {
m.Fields(len(kit.Slice(arg, 0, 1)), HashField(m)) m.Fields(len(kit.Slice(arg, 0, 1)), HashField(m))
} }
@ -200,10 +195,7 @@ func HashPrunes(m *ice.Message, cb func(Map) bool) *ice.Message {
if kit.Format(value[TIME]) > expire { if kit.Format(value[TIME]) > expire {
return false return false
} }
if cb != nil && !cb(value) { return cb == nil || cb(value)
return false
}
return true
}) })
return m.Cmdy(PRUNES, m.PrefixKey(), "", HASH).StatusTimeCount() return m.Cmdy(PRUNES, m.PrefixKey(), "", HASH).StatusTimeCount()
} }
@ -241,33 +233,34 @@ func HashSelectDetail(m *ice.Message, key string, cb Any) (has bool) {
return return
} }
func HashSelectField(m *ice.Message, key string, field string) (value string) { func HashSelectField(m *ice.Message, key string, field string) (value string) {
HashSelectDetail(m, key, func(h string, val ice.Map) { HashSelectDetail(m, key, func(key string, val ice.Map) {
if field == HASH { if field == HASH {
value = h value = key
} else { } else {
value = kit.Format(val[field]) value = kit.Format(val[field])
} }
}) })
return return
} }
func HashTarget(m *ice.Message, h string, add Any) (p Any) { func HashSelectTarget(m *ice.Message, key string, create Any) (target Any) {
HashSelectUpdate(m, h, func(value ice.Map) { HashSelectUpdate(m, key, func(value ice.Map) {
p = value[TARGET] target = value[TARGET]
if pp, ok := p.(Map); ok && len(pp) == 0 { if _target, ok := target.(Map); ok && len(_target) == 0 {
p = nil target = nil
} }
if p == nil && add != nil { if target != nil || create == nil {
switch add := add.(type) { return
case func(ice.Map) ice.Any:
p = add(value)
case func() ice.Any:
p = add()
default:
m.ErrorNotImplement(p)
return
}
value[TARGET] = p
} }
switch create := create.(type) {
case func(ice.Map) ice.Any:
target = create(value)
case func() ice.Any:
target = create()
default:
m.ErrorNotImplement(create)
return
}
value[TARGET] = target
}) })
return return
} }

View File

@ -23,14 +23,13 @@ func _list_inputs(m *ice.Message, prefix, chain string, field, value string) {
m.SortIntR(COUNT) m.SortIntR(COUNT)
}() }()
defer RLock(m, prefix, chain)() defer RLock(m, prefix, chain)()
m.Debug("what %v %v", prefix, chain)
Grows(m, prefix, chain, "", "", func(value ice.Map) { Grows(m, prefix, chain, "", "", func(value ice.Map) {
value = kit.GetMeta(value) value = kit.GetMeta(value)
list[kit.Format(value[field])] += kit.Int(kit.Select("1", value[COUNT])) list[kit.Format(value[field])] += kit.Int(kit.Select("1", value[COUNT]))
}) })
} }
func _list_insert(m *ice.Message, prefix, chain string, arg ...string) { func _list_insert(m *ice.Message, prefix, chain string, arg ...string) {
m.Logs(INSERT, KEY, path.Join(prefix, chain), arg[0], arg[1]) m.Logs(INSERT, KEY, path.Join(prefix, chain), arg)
defer Lock(m, prefix, chain)() defer Lock(m, prefix, chain)()
m.Echo("%d", Grow(m, prefix, chain, kit.Dict(arg, TARGET, m.Optionv(TARGET)))) m.Echo("%d", Grow(m, prefix, chain, kit.Dict(arg, TARGET, m.Optionv(TARGET))))
} }
@ -47,13 +46,13 @@ func _list_select(m *ice.Message, prefix, chain, field, value string) {
}) })
} }
func _list_export(m *ice.Message, prefix, chain, file string) { func _list_export(m *ice.Message, prefix, chain, file string) {
defer Lock(m, prefix, chain)()
f, p, e := miss.CreateFile(kit.Keys(file, CSV)) f, p, e := miss.CreateFile(kit.Keys(file, CSV))
m.Assert(e) m.Assert(e)
defer f.Close() defer f.Close()
defer m.Echo(p) defer m.Echo(p)
w := csv.NewWriter(f) w := csv.NewWriter(f)
defer w.Flush() defer w.Flush()
defer RLock(m, prefix, chain)()
count, head := 0, kit.Split(ListField(m)) count, head := 0, kit.Split(ListField(m))
Grows(m, prefix, chain, "", "", func(index int, value ice.Map) { Grows(m, prefix, chain, "", "", func(index int, value ice.Map) {
if value = kit.GetMeta(value); index == 0 { if value = kit.GetMeta(value); index == 0 {
@ -62,11 +61,7 @@ func _list_export(m *ice.Message, prefix, chain, file string) {
} }
w.Write(head) w.Write(head)
} }
data := []string{} w.Write(kit.Simple(head, func(k string) string { return kit.Format(value[k]) }))
for _, k := range head {
data = append(data, kit.Format(value[k]))
}
w.Write(data)
count++ count++
}) })
m.Logs(EXPORT, KEY, path.Join(prefix, chain), FILE, p, COUNT, count) m.Logs(EXPORT, KEY, path.Join(prefix, chain), FILE, p, COUNT, count)
@ -74,13 +69,13 @@ func _list_export(m *ice.Message, prefix, chain, file string) {
m.Conf(prefix, kit.Keys(chain, LIST), "") m.Conf(prefix, kit.Keys(chain, LIST), "")
} }
func _list_import(m *ice.Message, prefix, chain, file string) { func _list_import(m *ice.Message, prefix, chain, file string) {
defer Lock(m, prefix, chain)()
f, e := miss.OpenFile(kit.Keys(file, CSV)) f, e := miss.OpenFile(kit.Keys(file, CSV))
m.Assert(e) m.Assert(e)
defer f.Close() defer f.Close()
r := csv.NewReader(f) r := csv.NewReader(f)
head, _ := r.Read() head, _ := r.Read()
count := 0 count := 0
defer RLock(m, prefix, chain)()
for { for {
line, e := r.Read() line, e := r.Read()
if e != nil { if e != nil {
@ -97,7 +92,7 @@ func _list_import(m *ice.Message, prefix, chain, file string) {
Grow(m, prefix, chain, data) Grow(m, prefix, chain, data)
count++ count++
} }
m.Logs(IMPORT, KEY, kit.Keys(prefix, chain), COUNT, count) m.Logs(IMPORT, KEY, kit.Keys(prefix, chain), FILE, kit.Keys(file, CSV), COUNT, count)
m.Echo("%d", count) m.Echo("%d", count)
} }
@ -120,30 +115,44 @@ func ListAction(arg ...ice.Any) ice.Actions {
} }
func PageListAction(arg ...ice.Any) ice.Actions { func PageListAction(arg ...ice.Any) ice.Actions {
return ice.MergeActions(ice.Actions{ return ice.MergeActions(ice.Actions{
SELECT: {Name: "select id auto insert page", Hand: func(m *ice.Message, arg ...string) { ListSelect(m, arg...) }}, SELECT: {Name: "select id auto insert page", Hand: func(m *ice.Message, arg ...string) { PageListSelect(m, arg...) }},
NEXT: {Hand: func(m *ice.Message, arg ...string) { NextPageLimit(m, m.Config(COUNT), kit.Slice(arg, 1)...) }}, NEXT: {Hand: func(m *ice.Message, arg ...string) { NextPage(m, m.Config(COUNT), kit.Slice(arg, 1)...) }},
PREV: {Hand: func(m *ice.Message, arg ...string) { PrevPage(m, m.Config(COUNT), kit.Slice(arg, 1)...) }}, PREV: {Hand: func(m *ice.Message, arg ...string) { PrevPageLimit(m, m.Config(COUNT), kit.Slice(arg, 1)...) }},
}, ListAction(arg...)) }, ListAction(arg...))
} }
func ListField(m *ice.Message) string { return kit.Select(LIST_FIELD, m.Config(FIELD)) } func ListField(m *ice.Message) string { return kit.Select(LIST_FIELD, m.Config(FIELD)) }
func ListSelect(m *ice.Message, arg ...string) *ice.Message { func ListSelect(m *ice.Message, arg ...string) *ice.Message {
OptionPage(m, kit.Slice(arg, 1)...)
m.Fields(len(kit.Slice(arg, 0, 1)), ListField(m)) m.Fields(len(kit.Slice(arg, 0, 1)), ListField(m))
if m.Cmdy(SELECT, m.PrefixKey(), "", LIST, ID, arg); !m.FieldsIsDetail() { if m.Cmdy(SELECT, m.PrefixKey(), "", LIST, ID, arg); !m.FieldsIsDetail() {
m.SortIntR(ID)
return m.StatusTimeCountTotal(m.Config(COUNT)) return m.StatusTimeCountTotal(m.Config(COUNT))
} }
return m.StatusTime() return m.StatusTime()
} }
func PrevPageLimit(m *ice.Message, total string, arg ...string) { func PageListSelect(m *ice.Message, arg ...string) *ice.Message {
OptionPage(m, kit.Slice(arg, 1)...)
return ListSelect(m, arg...)
}
func NextPageLimit(m *ice.Message, total string, arg ...string) {
if kit.Int(kit.Select("0", arg, 1)) > 0 { if kit.Int(kit.Select("0", arg, 1)) > 0 {
PrevPage(m, total, arg...) NextPage(m, total, arg...)
} else { } else {
m.ProcessHold("已经最前一页啦!") m.ProcessHold("已经是最后一页啦!")
}
}
func NextPage(m *ice.Message, total string, arg ...string) {
limit, offend := kit.Select("10", arg, 0), kit.Select("0", arg, 1)
if offends := kit.Int(offend) - kit.Int(limit); total != "0" && (offends <= -kit.Int(total) || offends >= kit.Int(total)) {
m.ProcessHold("已经是最后一页啦!")
} else if offends == 0 {
m.ProcessRewrite("offend", "")
} else {
m.ProcessRewrite("offend", offends)
} }
} }
func PrevPage(m *ice.Message, total string, arg ...string) { func PrevPage(m *ice.Message, total string, arg ...string) {
limit, offend := kit.Select("10", arg, 0), kit.Select("0", arg, 1) limit, offend := kit.Select("10", arg, 0), kit.Select("0", arg, 1)
if offends := kit.Int(offend) - kit.Int(limit); total != "0" && (offends <= -kit.Int(total) || offends >= kit.Int(total)) { if offends := kit.Int(offend) + kit.Int(limit); total != "0" && (offends <= -kit.Int(total) || offends >= kit.Int(total)) {
m.ProcessHold("已经是最前一页啦!") m.ProcessHold("已经是最前一页啦!")
} else if offends == 0 { } else if offends == 0 {
m.ProcessRewrite("offend", "") m.ProcessRewrite("offend", "")
@ -151,21 +160,11 @@ func PrevPage(m *ice.Message, total string, arg ...string) {
m.ProcessRewrite("offend", offends) m.ProcessRewrite("offend", offends)
} }
} }
func NextPage(m *ice.Message, total string, arg ...string) { func PrevPageLimit(m *ice.Message, total string, arg ...string) {
limit, offend := kit.Select("10", arg, 0), kit.Select("0", arg, 1)
if offends := kit.Int(offend) + kit.Int(limit); total != "0" && (offends <= -kit.Int(total) || offends >= kit.Int(total)) {
m.ProcessHold("已经是最后一页啦!")
} else if offends == 0 {
m.ProcessRewrite("offend", "")
} else {
m.ProcessRewrite("offend", offends)
}
}
func NextPageLimit(m *ice.Message, total string, arg ...string) {
if kit.Int(kit.Select("0", arg, 1)) < 0 { if kit.Int(kit.Select("0", arg, 1)) < 0 {
NextPage(m, total, arg...) PrevPage(m, total, arg...)
} else { } else {
m.ProcessHold("已经是最一页啦!") m.ProcessHold("已经是最前一页啦!")
} }
} }
@ -194,14 +193,6 @@ const (
CACHE_FIELD = "cache.field" CACHE_FIELD = "cache.field"
) )
func Grow(m *ice.Message, prefix string, chain Any, data Any) int {
cache := m.Confm(prefix, chain)
if cache == nil {
cache = kit.Data()
m.Confv(prefix, chain, cache)
}
return miss.Grow(path.Join(prefix, kit.Keys(chain)), cache, data)
}
func Grows(m *ice.Message, prefix string, chain Any, match string, value string, cb Any) Map { func Grows(m *ice.Message, prefix string, chain Any, match string, value string, cb Any) Map {
cache := m.Confm(prefix, chain) cache := m.Confm(prefix, chain)
if cache == nil { if cache == nil {
@ -221,3 +212,11 @@ func Grows(m *ice.Message, prefix string, chain Any, match string, value string,
kit.Int(kit.Select("10", m.Option(CACHE_LIMIT))), kit.Int(kit.Select("10", m.Option(CACHE_LIMIT))),
match, value, cb) match, value, cb)
} }
func Grow(m *ice.Message, prefix string, chain Any, data Any) int {
cache := m.Confm(prefix, chain)
if cache == nil {
cache = kit.Data()
m.Confv(prefix, chain, cache)
}
return miss.Grow(path.Join(prefix, kit.Keys(chain)), cache, data)
}

View File

@ -6,6 +6,7 @@ import (
ice "shylinux.com/x/icebergs" ice "shylinux.com/x/icebergs"
kit "shylinux.com/x/toolkits" kit "shylinux.com/x/toolkits"
"shylinux.com/x/toolkits/logs"
"shylinux.com/x/toolkits/task" "shylinux.com/x/toolkits/task"
) )
@ -248,7 +249,7 @@ var Index = &ice.Context{Name: MDB, Help: "数据模块", Commands: ice.Commands
}} }}
func init() { func init() {
ice.Index.Register(Index, nil, INSERT, DELETE, MODIFY, SELECT, INPUTS, PRUNES, EXPORT, IMPORT, PLUGIN, ENGINE, RENDER, SEARCH) ice.Index.Register(Index, nil, INSERT, DELETE, MODIFY, SELECT, INPUTS, PRUNES, EXPORT, IMPORT, PLUGIN, RENDER, ENGINE, SEARCH)
} }
func AutoConfig(args ...ice.Any) *ice.Action { func AutoConfig(args ...ice.Any) *ice.Action {
return &ice.Action{Hand: func(m *ice.Message, arg ...string) { return &ice.Action{Hand: func(m *ice.Message, arg ...string) {

View File

@ -19,7 +19,6 @@ func _zone_inputs(m *ice.Message, prefix, chain, zone string, field, value strin
return return
} }
h := _hash_select_field(m, prefix, chain, zone, HASH) h := _hash_select_field(m, prefix, chain, zone, HASH)
defer Lock(m, prefix, chain)()
_list_inputs(m, prefix, kit.Keys(chain, HASH, h), field, value) _list_inputs(m, prefix, kit.Keys(chain, HASH, h), field, value)
} }
func _zone_insert(m *ice.Message, prefix, chain, zone string, arg ...string) { func _zone_insert(m *ice.Message, prefix, chain, zone string, arg ...string) {
@ -28,21 +27,18 @@ func _zone_insert(m *ice.Message, prefix, chain, zone string, arg ...string) {
h = _hash_insert(m, prefix, chain, _mdb_getmeta(m, prefix, chain, SHORT), zone) h = _hash_insert(m, prefix, chain, _mdb_getmeta(m, prefix, chain, SHORT), zone)
} }
m.Assert(h != "") m.Assert(h != "")
defer Lock(m, prefix, chain)()
_list_insert(m, prefix, kit.Keys(chain, HASH, h), arg...) _list_insert(m, prefix, kit.Keys(chain, HASH, h), arg...)
} }
func _zone_modify(m *ice.Message, prefix, chain, zone, id string, arg ...string) { func _zone_modify(m *ice.Message, prefix, chain, zone, id string, arg ...string) {
h := _hash_select_field(m, prefix, chain, zone, HASH) h := _hash_select_field(m, prefix, chain, zone, HASH)
m.Assert(h != "") m.Assert(h != "")
defer RLock(m, prefix, chain)()
_list_modify(m, prefix, kit.Keys(chain, HASH, h), ID, id, arg...) _list_modify(m, prefix, kit.Keys(chain, HASH, h), ID, id, arg...)
} }
func _zone_select(m *ice.Message, prefix, chain, zone string, id string) { func _zone_select(m *ice.Message, prefix, chain, zone string, id string) {
if zone == "" { if zone == "" {
_hash_select(m, prefix, chain, HASH, FOREACH) _hash_select(m, prefix, chain, HASH, FOREACH)
return return
} } else if zone == RANDOM {
if zone == RANDOM {
zone = RANDOMS zone = RANDOMS
} }
fields := _zone_fields(m) fields := _zone_fields(m)
@ -56,34 +52,24 @@ func _zone_select(m *ice.Message, prefix, chain, zone string, id string) {
}) })
} }
func _zone_export(m *ice.Message, prefix, chain, file string) { func _zone_export(m *ice.Message, prefix, chain, file string) {
defer Lock(m, prefix, chain)()
f, p, e := miss.CreateFile(kit.Keys(file, CSV)) f, p, e := miss.CreateFile(kit.Keys(file, CSV))
m.Assert(e) m.Assert(e)
defer f.Close() defer f.Close()
m.Echo(p) defer m.Echo(p)
w := csv.NewWriter(f) w := csv.NewWriter(f)
defer w.Flush() defer w.Flush()
fields := _zone_fields(m) head := kit.AddUniq(_zone_fields(m), EXTRA)
if kit.IndexOf(fields, EXTRA) == -1 { w.Write(head)
fields = append(fields, EXTRA)
}
w.Write(fields)
defer Lock(m, prefix, chain)()
keys := []string{}
Richs(m, prefix, chain, FOREACH, func(key string, val ice.Map) { keys = append(keys, key) })
kit.Sort(keys)
count := 0 count := 0
for _, key := range keys { for _, key := range kit.SortedKey(m.Confv(prefix, kit.Keys(chain, HASH))) {
Richs(m, prefix, chain, key, func(key string, val ice.Map) { Richs(m, prefix, chain, key, func(key string, val ice.Map) {
val = kit.GetMeta(val) val = kit.GetMeta(val)
chain := kit.Keys(chain, HASH, key) chain := kit.Keys(chain, HASH, key)
defer RLock(m, prefix, chain)() defer Lock(m, prefix, chain)()
Grows(m, prefix, chain, "", "", func(value ice.Map) { Grows(m, prefix, chain, "", "", func(value ice.Map) {
value = kit.GetMeta(value) value = kit.GetMeta(value)
list := []string{} w.Write(kit.Simple(head, func(k string) string { return kit.Select(kit.Format(kit.Value(val, k)), kit.Format(kit.Value(value, k))) }))
for _, k := range fields {
list = append(list, kit.Select(kit.Format(kit.Value(val, k)), kit.Format(kit.Value(value, k))))
}
w.Write(list)
count++ count++
}) })
}) })
@ -92,13 +78,13 @@ func _zone_export(m *ice.Message, prefix, chain, file string) {
m.Conf(prefix, kit.Keys(chain, HASH), "") m.Conf(prefix, kit.Keys(chain, HASH), "")
} }
func _zone_import(m *ice.Message, prefix, chain, file string) { func _zone_import(m *ice.Message, prefix, chain, file string) {
defer Lock(m, prefix, chain)()
f, e := miss.OpenFile(kit.Keys(file, CSV)) f, e := miss.OpenFile(kit.Keys(file, CSV))
m.Assert(e) m.Assert(e)
defer f.Close() defer f.Close()
r := csv.NewReader(f) r := csv.NewReader(f)
head, _ := r.Read() head, _ := r.Read()
zkey := kit.Select(head[0], m.OptionFields()) zkey := kit.Select(head[0], m.OptionFields())
defer Lock(m, prefix, chain)()
list := ice.Maps{} list := ice.Maps{}
count := 0 count := 0
for { for {
@ -106,8 +92,7 @@ func _zone_import(m *ice.Message, prefix, chain, file string) {
if e != nil { if e != nil {
break break
} }
zone := "" zone, data := "", kit.Dict()
data := kit.Dict()
for i, k := range head { for i, k := range head {
switch k { switch k {
case zkey: case zkey:
@ -156,49 +141,54 @@ func ZoneAction(arg ...ice.Any) ice.Actions {
func PageZoneAction(arg ...ice.Any) ice.Actions { func PageZoneAction(arg ...ice.Any) ice.Actions {
return ice.MergeActions(ice.Actions{ return ice.MergeActions(ice.Actions{
SELECT: {Name: "select zone id auto insert page", Hand: func(m *ice.Message, arg ...string) { PageZoneSelect(m, arg...) }}, SELECT: {Name: "select zone id auto insert page", Hand: func(m *ice.Message, arg ...string) { PageZoneSelect(m, arg...) }},
NEXT: {Hand: func(m *ice.Message, arg ...string) { NextPageLimit(m, arg[0], arg[1:]...) }}, NEXT: {Hand: func(m *ice.Message, arg ...string) { NextPage(m, arg[0], arg[1:]...) }},
PREV: {Hand: func(m *ice.Message, arg ...string) { PrevPage(m, arg[0], arg[1:]...) }}, PREV: {Hand: func(m *ice.Message, arg ...string) { PrevPageLimit(m, arg[0], arg[1:]...) }},
}, ZoneAction(arg...)) }, ZoneAction(arg...))
} }
func ZoneShort(m *ice.Message) string { func ZoneKey(m *ice.Message) string {
return kit.Select(ZONE, m.Config(SHORT), m.Config(SHORT) != UNIQ) if m.Option(HASH) != "" {
return HASH
}
return ZoneShort(m)
} }
func ZoneShort(m *ice.Message) string { return kit.Select(ZONE, m.Config(SHORT), m.Config(SHORT) != UNIQ) }
func ZoneField(m *ice.Message) string { return kit.Select(ZONE_FIELD, m.Config(FIELD)) } func ZoneField(m *ice.Message) string { return kit.Select(ZONE_FIELD, m.Config(FIELD)) }
func ZoneInputs(m *ice.Message, arg ...Any) { func ZoneInputs(m *ice.Message, arg ...Any) {
m.Cmdy(INPUTS, m.PrefixKey(), "", ZONE, m.Option(ZoneShort(m)), arg) m.Cmdy(INPUTS, m.PrefixKey(), "", ZONE, m.Option(ZoneKey(m)), arg)
} }
func ZoneCreate(m *ice.Message, arg ...Any) { func ZoneCreate(m *ice.Message, arg ...Any) {
m.Cmdy(INSERT, m.PrefixKey(), "", HASH, arg) m.Cmdy(INSERT, m.PrefixKey(), "", HASH, arg)
} }
func ZoneRemove(m *ice.Message, arg ...Any) { func ZoneRemove(m *ice.Message, arg ...Any) {
if args := kit.Simple(arg...); len(args) == 0 { if args := kit.Simple(arg...); len(args) == 0 {
arg = append(arg, m.OptionSimple(ZoneShort(m), HASH)) arg = append(arg, m.OptionSimple(ZoneKey(m)))
} else if len(args) == 1 { } else if len(args) == 1 {
arg = kit.List(ZoneShort(m), args[0]) arg = kit.List(ZoneKey(m), args[0])
} }
m.Cmdy(DELETE, m.PrefixKey(), "", HASH, arg) m.Cmdy(DELETE, m.PrefixKey(), "", HASH, arg)
} }
func ZoneInsert(m *ice.Message, arg ...Any) { func ZoneInsert(m *ice.Message, arg ...Any) {
if args := kit.Simple(arg...); args[0] == ZoneShort(m) { if args := kit.Simple(arg...); args[0] == ZoneKey(m) {
m.Cmdy(INSERT, m.PrefixKey(), "", ZONE, args[1:]) m.Cmdy(INSERT, m.PrefixKey(), "", ZONE, args[1:])
} else { } else {
m.Cmdy(INSERT, m.PrefixKey(), "", ZONE, arg) m.Cmdy(INSERT, m.PrefixKey(), "", ZONE, arg)
} }
} }
func ZoneModify(m *ice.Message, arg ...Any) { func ZoneModify(m *ice.Message, arg ...Any) {
m.Cmdy(MODIFY, m.PrefixKey(), "", ZONE, m.Option(ZoneShort(m)), m.Option(ID), arg) if args := kit.Simple(arg...); args[0] == HASH || args[0] == ZoneShort(m) {
m.Cmdy(MODIFY, m.PrefixKey(), "", ZONE, args[1], args[3], arg[4:])
} else {
m.Cmdy(MODIFY, m.PrefixKey(), "", ZONE, m.Option(ZoneKey(m)), m.Option(ID), arg)
}
} }
func ZoneSelect(m *ice.Message, arg ...string) *ice.Message { func ZoneSelect(m *ice.Message, arg ...string) *ice.Message {
arg = kit.Slice(arg, 0, 2) arg = kit.Slice(arg, 0, 2)
m.Fields(len(arg), kit.Fields(TIME, m.Config(SHORT), COUNT), ZoneField(m)) m.Fields(len(arg), kit.Fields(TIME, m.Config(SHORT), COUNT), ZoneField(m))
if m.Cmdy(SELECT, m.PrefixKey(), "", ZONE, arg, logs.FileLineMeta(logs.FileLine(-1))); len(arg) == 0 { if m.Cmdy(SELECT, m.PrefixKey(), "", ZONE, arg, logs.FileLineMeta(logs.FileLine(-1))); len(arg) == 0 {
if m.Config(SHORT) != "" { m.Sort(ZoneShort(m)).StatusTimeCount().PushAction(m.Config(ACTION), REMOVE)
m.Sort(m.Config(SHORT))
}
m.PushAction(m.Config(ACTION), REMOVE)
m.StatusTimeCount()
} else if len(arg) == 1 { } else if len(arg) == 1 {
m.StatusTimeCountTotal(m.Conf("", kit.Keys(HASH, HashSelectField(m, arg[0], HASH), kit.Keym(COUNT)))) m.SortIntR(ID)
m.StatusTimeCountTotal(_mdb_getmeta(m, "", kit.Keys(HASH, HashSelectField(m, arg[0], HASH)), COUNT))
} }
return m return m
} }
@ -211,10 +201,6 @@ func ZoneExport(m *ice.Message, arg ...Any) {
func ZoneImport(m *ice.Message, arg ...Any) { func ZoneImport(m *ice.Message, arg ...Any) {
m.Cmdy(IMPORT, m.PrefixKey(), "", ZONE, arg) m.Cmdy(IMPORT, m.PrefixKey(), "", ZONE, arg)
} }
func PageZoneSelect(m *ice.Message, arg ...string) *ice.Message {
OptionPages(m, kit.Slice(arg, 2)...)
return ZoneSelect(m, arg...)
}
func ZoneSelects(m *ice.Message, arg ...string) *ice.Message { func ZoneSelects(m *ice.Message, arg ...string) *ice.Message {
m.OptionFields(ZoneField(m)) m.OptionFields(ZoneField(m))
return ZoneSelect(m, arg...) return ZoneSelect(m, arg...)
@ -228,3 +214,7 @@ func ZoneSelectCB(m *ice.Message, zone string, cb Any) *ice.Message {
m.Option(CACHE_LIMIT, "-1") m.Option(CACHE_LIMIT, "-1")
return ZoneSelect(m, zone) return ZoneSelect(m, zone)
} }
func PageZoneSelect(m *ice.Message, arg ...string) *ice.Message {
OptionPages(m, kit.Slice(arg, 2)...)
return ZoneSelect(m, arg...)
}

View File

@ -236,7 +236,7 @@ func _spide_head(m *ice.Message, req *http.Request, head ice.Maps, value ice.Map
} }
} }
func _spide_send(m *ice.Message, name string, req *http.Request, timeout string) (*http.Response, error) { func _spide_send(m *ice.Message, name string, req *http.Request, timeout string) (*http.Response, error) {
client := mdb.HashTarget(m, name, func() ice.Any { return &http.Client{Timeout: kit.Duration(timeout)} }).(*http.Client) client := mdb.HashSelectTarget(m, name, func() ice.Any { return &http.Client{Timeout: kit.Duration(timeout)} }).(*http.Client)
return client.Do(req) return client.Do(req)
} }
func _spide_save(m *ice.Message, cache, save, uri string, res *http.Response) { func _spide_save(m *ice.Message, cache, save, uri string, res *http.Response) {

View File

@ -98,7 +98,7 @@ func (frame *Frame) Start(m *ice.Message, arg ...string) bool {
mdb.HashCreate(m, mdb.NAME, WEB, arg, m.OptionSimple(tcp.PROTO, ice.DEV), cli.STATUS, tcp.START) mdb.HashCreate(m, mdb.NAME, WEB, arg, m.OptionSimple(tcp.PROTO, ice.DEV), cli.STATUS, tcp.START)
m.Cmd(tcp.SERVER, tcp.LISTEN, mdb.TYPE, WEB, m.OptionSimple(mdb.NAME, tcp.HOST, tcp.PORT), func(l net.Listener) { m.Cmd(tcp.SERVER, tcp.LISTEN, mdb.TYPE, WEB, m.OptionSimple(mdb.NAME, tcp.HOST, tcp.PORT), func(l net.Listener) {
defer mdb.HashModify(m, m.OptionSimple(mdb.NAME), cli.STATUS, tcp.STOP) defer mdb.HashModify(m, m.OptionSimple(mdb.NAME), cli.STATUS, tcp.STOP)
mdb.HashTarget(m, m.Option(mdb.NAME), func() ice.Any { return l }) mdb.HashSelectTarget(m, m.Option(mdb.NAME), func() ice.Any { return l })
m.Warn(frame.Server.Serve(l)) // 启动服务 m.Warn(frame.Server.Serve(l)) // 启动服务
}) })
} }

View File

@ -38,7 +38,7 @@ func _xterm_get(m *ice.Message, h string) _xterm {
t := mdb.HashSelectField(m, m.Option(mdb.HASH, h), mdb.TYPE) t := mdb.HashSelectField(m, m.Option(mdb.HASH, h), mdb.TYPE)
mdb.HashModify(m, "view", m.Option(ice.MSG_DAEMON)) mdb.HashModify(m, "view", m.Option(ice.MSG_DAEMON))
return mdb.HashTarget(m, h, func() ice.Any { return mdb.HashSelectTarget(m, h, func() ice.Any {
ls := kit.Split(kit.Select(nfs.SH, t)) ls := kit.Split(kit.Select(nfs.SH, t))
cmd := exec.Command(cli.SystemFind(m, ls[0]), ls[1:]...) cmd := exec.Command(cli.SystemFind(m, ls[0]), ls[1:]...)

View File

@ -386,8 +386,8 @@ func SplitCmd(name string, actions Actions) (list []Any) {
case PAGE: case PAGE:
push(TEXT, "limit") push(TEXT, "limit")
push(TEXT, "offend") push(TEXT, "offend")
push(BUTTON, "prev")
push(BUTTON, "next") push(BUTTON, "next")
push(BUTTON, "prev")
case ARGS, TEXT, TEXTAREA, CONTENT: case ARGS, TEXT, TEXTAREA, CONTENT:
push(TEXTAREA, ls[i]) push(TEXTAREA, ls[i])
case PASSWORD: case PASSWORD: