diff --git a/base/aaa/aaa.go b/base/aaa/aaa.go index 36ec864c..63afe265 100644 --- a/base/aaa/aaa.go +++ b/base/aaa/aaa.go @@ -9,8 +9,8 @@ var Index = &ice.Context{Name: "aaa", Help: "认证模块", Caches: map[string]*ice.Cache{}, Configs: map[string]*ice.Config{ ice.AAA_ROLE: {Name: "role", Help: "角色", Value: kit.Data()}, - ice.AAA_USER: {Name: "user", Help: "用户", Value: kit.Data("short", "username")}, - ice.AAA_SESS: {Name: "sess", Help: "会话", Value: kit.Data("short", "uniq", "expire", "720h")}, + ice.AAA_USER: {Name: "user", Help: "用户", Value: kit.Data(kit.MDB_SHORT, "username")}, + ice.AAA_SESS: {Name: "sess", Help: "会话", Value: kit.Data(kit.MDB_SHORT, "uniq", "expire", "720h")}, }, Commands: map[string]*ice.Command{ ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}}, diff --git a/base/web/web.go b/base/web/web.go index 255a1d88..65d1402c 100644 --- a/base/web/web.go +++ b/base/web/web.go @@ -302,14 +302,14 @@ var Index = &ice.Context{Name: "web", Help: "网页模块", }}, )}, ice.WEB_SPACE: {Name: "space", Help: "空间站", Value: kit.Data("buffer", 4096, "redial", 3000)}, - ice.WEB_STORY: {Name: "story", Help: "故事会", Value: kit.Data("short", "data")}, + ice.WEB_STORY: {Name: "story", Help: "故事会", Value: kit.Data(kit.MDB_SHORT, "data")}, ice.WEB_CACHE: {Name: "cache", Help: "缓存", Value: kit.Data( - "short", "text", "path", "var/file", + kit.MDB_SHORT, "text", "path", "var/file", "store", "var/data", "limit", "30", "least", "10", )}, ice.WEB_ROUTE: {Name: "route", Help: "路由", Value: kit.Data()}, ice.WEB_PROXY: {Name: "proxy", Help: "代理", Value: kit.Data()}, - ice.WEB_FAVOR: {Name: "favor", Help: "收藏", Value: kit.Data()}, + ice.WEB_FAVOR: {Name: "favor", Help: "收藏", Value: kit.Data(kit.MDB_SHORT, kit.MDB_NAME)}, ice.WEB_SHARE: {Name: "share", Help: "共享", Value: kit.Data()}, }, Commands: map[string]*ice.Command{ @@ -321,16 +321,20 @@ var Index = &ice.Context{Name: "web", Help: "网页模块", m.Conf("cli.runtime", "node.name", m.Conf("cli.runtime", "boot.hostname")) m.Conf("cli.runtime", "node.type", "server") - m.Rich(ice.WEB_SPACE, nil, map[string]interface{}{ - "type": "myself", - "node": m.Conf("cli.runtime", "boot.hostname"), - "user": m.Conf("cli.runtime", "boot.username"), - }) + m.Rich(ice.WEB_SPACE, nil, kit.Dict( + "type", "myself", + "node", m.Conf("cli.runtime", "boot.hostname"), + "user", m.Conf("cli.runtime", "boot.username"), + )) m.Target().Start(m, arg...) }}, - ice.WEB_SPACE: {Name: "space", Help: "空间站", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + ice.WEB_SPACE: {Name: "space", Help: "空间站", Meta: kit.Dict("exports", []string{"pod", "node"}), List: kit.List( + kit.MDB_INPUT, "text", "name", "pod", "action", "auto", + kit.MDB_INPUT, "button", "value", "查看", "action", "auto", + kit.MDB_INPUT, "button", "value", "返回", "cb", "Last", + ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) == 0 { - m.Conf(ice.WEB_SPACE, kit.MDB_HASH, func(key string, value map[string]interface{}) { + m.Richs(ice.WEB_SPACE, nil, "", func(key string, value map[string]interface{}) { m.Push(key, value) }) return @@ -523,14 +527,70 @@ var Index = &ice.Context{Name: "web", Help: "网页模块", }}, ice.WEB_PROXY: {Name: "proxy", Help: "代理", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { }}, - ice.WEB_FAVOR: {Name: "favor", Help: "收藏", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + ice.WEB_FAVOR: {Name: "favor", Help: "收藏", Meta: kit.Dict("exports", []string{"hot", "favor"}), List: kit.List( + kit.MDB_INPUT, "text", "name", "hot", "action", "auto", + kit.MDB_INPUT, "text", "name", "id", "action", "auto", + kit.MDB_INPUT, "button", "value", "查看", "action", "auto", + kit.MDB_INPUT, "button", "value", "返回", "cb", "Last", + ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) == 0 { - m.Confm(ice.WEB_SHARE, "hash", func(key string, value map[string]interface{}) { - m.Push(key, value) + // 收藏门类 + m.Richs(ice.WEB_FAVOR, nil, "", func(key string, value map[string]interface{}) { + m.Push("favor", kit.Value(value, "meta.name")) + m.Push("count", kit.Value(value, "meta.count")) + m.Push("time", kit.Value(value, "meta.create_time")) }) return } + if len(arg) > 1 { + switch arg[1] { + case "modify": + // 编辑收藏 + m.Richs(ice.WEB_FAVOR, nil, m.Option("hot"), func(key string, value map[string]interface{}) { + m.Grows(ice.WEB_FAVOR, kit.Keys(kit.MDB_HASH, key), "id", m.Option("id"), func(index int, value map[string]interface{}) { + m.Info("modify favor: %s index: %d value: %v->%v", key, index, value[arg[2]], arg[3]) + kit.Value(value, arg[2], arg[3]) + }) + }) + return + } + } + + // 创建收藏 + favor := "" + if m.Richs(ice.WEB_FAVOR, nil, arg[0], func(key string, value map[string]interface{}) { + favor = key + }) == nil { + favor = m.Rich(ice.WEB_FAVOR, nil, kit.Data(kit.MDB_NAME, arg[0])) + m.Info("create favor: %s name: %s", favor, arg[0]) + } + + if len(arg) == 1 { + // 收藏列表 + m.Grows(ice.WEB_FAVOR, kit.Keys(kit.MDB_HASH, favor), "", "", func(index int, value map[string]interface{}) { + m.Push(kit.Format(index), value, []string{"create_time", "id", "type", "name", "text"}) + }) + return + } + + if len(arg) == 2 { + // 收藏详情 + m.Grows(ice.WEB_FAVOR, kit.Keys(kit.MDB_HASH, favor), "id", arg[1], func(index int, value map[string]interface{}) { + for k, v := range value { + m.Push("key", k).Push("value", v) + } + m.Sort("key") + }) + return + } + + // 添加收藏 + index := m.Grow(ice.WEB_FAVOR, kit.Keys(kit.MDB_HASH, favor), kit.Dict( + kit.MDB_TYPE, arg[1], kit.MDB_NAME, arg[2], kit.MDB_TEXT, arg[3], + )) + m.Info("create favor: %s index: %d name: %s", favor, index, arg[2]) + m.Echo("%d", index) }}, ice.WEB_SHARE: {Name: "share", Help: "共享", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) == 0 { diff --git a/core/chat/chat.go b/core/chat/chat.go index db633fcb..33be32bf 100644 --- a/core/chat/chat.go +++ b/core/chat/chat.go @@ -20,7 +20,7 @@ var Index = &ice.Context{Name: "chat", Help: "聊天模块", }}, ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Cmd(ice.CTX_CONFIG, "save", "chat.json", ice.CHAT_GROUP) - m.Cmd(ice.CTX_CONFIG, "save", "web.json", ice.WEB_STORY, ice.WEB_CACHE, ice.WEB_SHARE) + m.Cmd(ice.CTX_CONFIG, "save", "web.json", ice.WEB_STORY, ice.WEB_CACHE, ice.WEB_FAVOR, ice.WEB_SHARE) m.Cmd(ice.CTX_CONFIG, "save", "aaa.json", ice.AAA_ROLE, ice.AAA_USER, ice.AAA_SESS) }}, @@ -114,6 +114,7 @@ var Index = &ice.Context{Name: "chat", Help: "聊天模块", m.Richs(ice.CHAT_GROUP, prefix, "", func(key string, value map[string]interface{}) { m.Push(key, value["meta"], []string{kit.MDB_KEY, kit.MDB_NAME}) }) + m.Sort(kit.MDB_NAME) return } diff --git a/core/team/team.go b/core/team/team.go index 0bab48da..7829bc68 100644 --- a/core/team/team.go +++ b/core/team/team.go @@ -24,9 +24,9 @@ var Index = &ice.Context{Name: "team", Help: "团队模块", "exports": []interface{}{"you", "name"}, "detail": []interface{}{"启动", "停止"}, }, List: kit.List( - kit.MDB_TYPE, "text", "value", "", "name", "name", - kit.MDB_TYPE, "text", "value", "", "name", "type", - kit.MDB_TYPE, "button", "value", "创建", "action", "auto", + kit.MDB_INPUT, "text", "value", "", "name", "name", + kit.MDB_INPUT, "text", "value", "", "name", "type", + kit.MDB_INPUT, "button", "value", "创建", "action", "auto", ), Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) { if len(arg) > 1 { switch arg[1] { diff --git a/core/wiki/wiki.go b/core/wiki/wiki.go index 6836f131..2e1a34a1 100644 --- a/core/wiki/wiki.go +++ b/core/wiki/wiki.go @@ -38,9 +38,9 @@ var Index = &ice.Context{Name: "wiki", Help: "文档模块", "chart": {Name: "chart block|chain|table name text [fg bg fs ls p m]", Help: "绘图", Meta: map[string]interface{}{ "display": "inner", }, List: kit.List( - kit.MDB_TYPE, "select", "value", "chain", "values", "block chain table", - kit.MDB_TYPE, "text", "value", "", - kit.MDB_TYPE, "button", "value", "生成", + kit.MDB_INPUT, "select", "value", "chain", "values", "block chain table", + kit.MDB_INPUT, "text", "value", "", + kit.MDB_INPUT, "button", "value", "生成", ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { // 创建类型 var chart Chart @@ -165,9 +165,9 @@ var Index = &ice.Context{Name: "wiki", Help: "文档模块", "remote": "true", "display": "inner", "detail": []string{"add", "commit", "history", "share"}, }, List: kit.List( - kit.MDB_TYPE, "text", "value", "miss.md", "name", "path", - kit.MDB_TYPE, "button", "value", "执行", "action", "auto", - kit.MDB_TYPE, "button", "value", "返回", "cb", "Last", + kit.MDB_INPUT, "text", "value", "miss.md", "name", "path", + kit.MDB_INPUT, "button", "value", "执行", "action", "auto", + kit.MDB_INPUT, "button", "value", "返回", "cb", "Last", ), Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) { if len(arg) > 0 { switch arg[0] { diff --git a/misc/tmux/tmux.go b/misc/tmux/tmux.go index 90a8b974..3b1ff52d 100644 --- a/misc/tmux/tmux.go +++ b/misc/tmux/tmux.go @@ -57,10 +57,10 @@ var Index = &ice.Context{Name: "tmux", Help: "终端模块", }}, "buffer": {Name: "buffer", Help: "终端", List: kit.List( - kit.MDB_TYPE, "text", "name", "buffer", "action", "auto", - kit.MDB_TYPE, "text", "name", "value", - kit.MDB_TYPE, "button", "value", "查看", "action", "auto", - kit.MDB_TYPE, "button", "value", "返回", "cb", "Last", + kit.MDB_INPUT, "text", "name", "buffer", "action", "auto", + kit.MDB_INPUT, "text", "name", "value", + kit.MDB_INPUT, "button", "value", "查看", "action", "auto", + kit.MDB_INPUT, "button", "value", "返回", "cb", "Last", ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) == 0 { @@ -87,11 +87,11 @@ var Index = &ice.Context{Name: "tmux", Help: "终端模块", m.Cmdy("cli.system", "tmux", "show-buffer", "-b", arg[0]).Set("append") }}, "session": {Name: "session", Help: "会话", List: kit.List( - kit.MDB_TYPE, "text", "name", "session", "action", "auto", - kit.MDB_TYPE, "text", "name", "window", "action", "auto", - kit.MDB_TYPE, "text", "name", "pane", "action", "auto", - kit.MDB_TYPE, "button", "value", "查看", "action", "auto", - kit.MDB_TYPE, "button", "value", "返回", "cb", "Last", + kit.MDB_INPUT, "text", "name", "session", "action", "auto", + kit.MDB_INPUT, "text", "name", "window", "action", "auto", + kit.MDB_INPUT, "text", "name", "pane", "action", "auto", + kit.MDB_INPUT, "button", "value", "查看", "action", "auto", + kit.MDB_INPUT, "button", "value", "返回", "cb", "Last", ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { prefix := []string{"cli.system", "tmux"} if len(arg) > 3 { diff --git a/type.go b/type.go index a15f764a..be2e274d 100644 --- a/type.go +++ b/type.go @@ -817,7 +817,8 @@ func (m *Message) Richs(key string, chain interface{}, raw interface{}, cb inter return nil } - switch h := kit.Format(raw); h { + h := kit.Format(raw) + switch h { case "*", "": // 全部遍历 switch cb := cb.(type) { @@ -836,7 +837,7 @@ func (m *Message) Richs(key string, chain interface{}, raw interface{}, cb inter res, _ = hash[h].(map[string]interface{}) default: // 单个查询 - switch kit.Format(kit.Value(meta, "short")) { + switch kit.Format(kit.Value(meta, kit.MDB_SHORT)) { case "", "uniq": default: h = kit.Hashs(h) @@ -849,6 +850,8 @@ func (m *Message) Richs(key string, chain interface{}, raw interface{}, cb inter switch cb := cb.(type) { case func(map[string]interface{}): cb(res) + case func(string, map[string]interface{}): + cb(h, res) } } return res @@ -880,7 +883,7 @@ func (m *Message) Rich(key string, chain interface{}, data interface{}) string { // 生成键值 h := "" - switch short := kit.Format(kit.Value(meta, "short")); short { + switch short := kit.Format(kit.Value(meta, kit.MDB_SHORT)); short { case "": h = kit.ShortKey(hash, 6) case "uniq": @@ -888,7 +891,11 @@ func (m *Message) Rich(key string, chain interface{}, data interface{}) string { case "data": h = kit.Hashs(kit.Format(data)) default: - h = kit.Hashs(kit.Format(kit.Value(data, short))) + if kit.Value(data, "meta") != nil { + h = kit.Hashs(kit.Format(kit.Value(data, "meta."+short))) + } else { + h = kit.Hashs(kit.Format(kit.Value(data, short))) + } } // 添加数据 @@ -913,8 +920,10 @@ func (m *Message) Grow(key string, chain interface{}, data interface{}) int { id := kit.Int(meta["count"]) + 1 if kit.Value(data, "meta") != nil { kit.Value(data, "meta.id", id) + kit.Value(data, "meta.create_time", m.Time()) } else { kit.Value(data, "id", id) + kit.Value(data, "create_time", m.Time()) } // 添加数据