1
0
forked from x/icebergs
This commit is contained in:
harveyshao 2022-11-25 14:38:46 +08:00
parent 97cc535496
commit aacb485deb
5 changed files with 32 additions and 16 deletions

View File

@ -34,6 +34,9 @@ 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) {

View File

@ -23,6 +23,7 @@ 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]))
@ -120,8 +121,8 @@ 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) { ListSelect(m, arg...) }},
PREV: {Hand: func(m *ice.Message, arg ...string) { PrevPage(m, m.Config(COUNT), kit.Slice(arg, 1)...) }},
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) { NextPageLimit(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)...) }},
}, 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)) }

View File

@ -19,7 +19,7 @@ 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 RLock(m, prefix, chain)() 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) {
@ -115,7 +115,9 @@ func _zone_import(m *ice.Message, prefix, chain, file string) {
case ID: case ID:
continue continue
case EXTRA: case EXTRA:
if line[i] != "" {
kit.Value(data, k, kit.UnMarshal(line[i])) kit.Value(data, k, kit.UnMarshal(line[i]))
}
default: default:
kit.Value(data, k, line[i]) kit.Value(data, k, line[i])
} }
@ -130,17 +132,17 @@ func _zone_import(m *ice.Message, prefix, chain, file string) {
}() }()
count++ count++
} }
m.Logs(IMPORT, KEY, path.Join(prefix, chain), FILE, p, COUNT, count) m.Logs(IMPORT, KEY, path.Join(prefix, chain), FILE, kit.Keys(file, CSV), COUNT, count)
m.Echo("%d", count) m.Echo("%d", count)
} }
const ( const (
ZONE_FIELD = "zone,id,time,type,name,text" ZONE_FIELD = "time,id,type,name,text"
) )
const ZONE = "zone" const ZONE = "zone"
func ZoneAction(args ...ice.Any) ice.Actions { func ZoneAction(arg ...ice.Any) ice.Actions {
return ice.Actions{ice.CTX_INIT: AutoConfig(append([]ice.Any{SHORT, ZONE}, args)...), return ice.Actions{ice.CTX_INIT: AutoConfig(append(kit.List(SHORT, ZONE, FIELD, ZONE_FIELD), arg...)...),
INPUTS: {Hand: func(m *ice.Message, arg ...string) { ZoneInputs(m, arg) }}, INPUTS: {Hand: func(m *ice.Message, arg ...string) { ZoneInputs(m, arg) }},
CREATE: {Hand: func(m *ice.Message, arg ...string) { ZoneCreate(m, arg) }}, CREATE: {Hand: func(m *ice.Message, arg ...string) { ZoneCreate(m, arg) }},
REMOVE: {Hand: func(m *ice.Message, arg ...string) { ZoneRemove(m, arg) }}, REMOVE: {Hand: func(m *ice.Message, arg ...string) { ZoneRemove(m, arg) }},
@ -149,10 +151,15 @@ func ZoneAction(args ...ice.Any) ice.Actions {
SELECT: {Name: "select zone id auto insert", Hand: func(m *ice.Message, arg ...string) { ZoneSelect(m, arg...) }}, SELECT: {Name: "select zone id auto insert", Hand: func(m *ice.Message, arg ...string) { ZoneSelect(m, arg...) }},
EXPORT: {Hand: func(m *ice.Message, arg ...string) { ZoneExport(m, arg) }}, EXPORT: {Hand: func(m *ice.Message, arg ...string) { ZoneExport(m, arg) }},
IMPORT: {Hand: func(m *ice.Message, arg ...string) { ZoneImport(m, arg) }}, IMPORT: {Hand: func(m *ice.Message, arg ...string) { ZoneImport(m, arg) }},
PREV: {Hand: func(m *ice.Message, arg ...string) { PrevPage(m, arg[0], arg[1:]...) }},
NEXT: {Hand: func(m *ice.Message, arg ...string) { NextPageLimit(m, arg[0], arg[1:]...) }},
} }
} }
func PageZoneAction(arg ...ice.Any) 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...) }},
NEXT: {Hand: func(m *ice.Message, arg ...string) { NextPageLimit(m, arg[0], arg[1:]...) }},
PREV: {Hand: func(m *ice.Message, arg ...string) { PrevPage(m, arg[0], arg[1:]...) }},
}, ZoneAction(arg...))
}
func ZoneShort(m *ice.Message) string { func ZoneShort(m *ice.Message) string {
return kit.Select(ZONE, m.Config(SHORT), m.Config(SHORT) != UNIQ) return kit.Select(ZONE, m.Config(SHORT), m.Config(SHORT) != UNIQ)
} }
@ -172,8 +179,12 @@ func ZoneRemove(m *ice.Message, arg ...Any) {
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) {
m.Cmdy(INSERT, m.PrefixKey(), "", ZONE, args[1:])
} 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) m.Cmdy(MODIFY, m.PrefixKey(), "", ZONE, m.Option(ZoneShort(m)), m.Option(ID), arg)
} }
@ -200,7 +211,7 @@ 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 ZoneSelectPage(m *ice.Message, arg ...string) *ice.Message { func PageZoneSelect(m *ice.Message, arg ...string) *ice.Message {
OptionPages(m, kit.Slice(arg, 2)...) OptionPages(m, kit.Slice(arg, 2)...)
return ZoneSelect(m, arg...) return ZoneSelect(m, arg...)
} }

View File

@ -13,5 +13,6 @@ func init() {
"demo-list": {Actions: ice.MergeActions(mdb.ListAction(), ctx.CmdAction())}, "demo-list": {Actions: ice.MergeActions(mdb.ListAction(), ctx.CmdAction())},
"demo-page-list": {Actions: ice.MergeActions(mdb.PageListAction(), ctx.CmdAction())}, "demo-page-list": {Actions: ice.MergeActions(mdb.PageListAction(), ctx.CmdAction())},
"demo-zone": {Actions: ice.MergeActions(mdb.ZoneAction(), ctx.CmdAction())}, "demo-zone": {Actions: ice.MergeActions(mdb.ZoneAction(), ctx.CmdAction())},
"demo-page-zone": {Actions: ice.MergeActions(mdb.PageZoneAction(), ctx.CmdAction())},
}) })
} }

View File

@ -26,7 +26,7 @@ func init() {
}}, }},
}, mdb.ZoneAction(mdb.SHORT, mdb.ZONE, mdb.FIELD, "time,id,type,name,text,path,file,line")), Hand: func(m *ice.Message, arg ...string) { }, mdb.ZoneAction(mdb.SHORT, mdb.ZONE, mdb.FIELD, "time,id,type,name,text,path,file,line")), Hand: func(m *ice.Message, arg ...string) {
m.Option(mdb.CACHE_LIMIT, "30") m.Option(mdb.CACHE_LIMIT, "30")
if mdb.ZoneSelectPage(m, arg...); len(arg) > 0 && arg[0] != "" { if mdb.PageZoneSelect(m, arg...); len(arg) > 0 && arg[0] != "" {
if arg[0] == "_recent_file" { if arg[0] == "_recent_file" {
m.Sort(nfs.FILE) m.Sort(nfs.FILE)
} }