diff --git a/base/web/web.go b/base/web/web.go index 19440325..75d061e3 100644 --- a/base/web/web.go +++ b/base/web/web.go @@ -847,7 +847,7 @@ var Index = &ice.Context{Name: "web", Help: "网络模块", target := strings.Split(arg[0], ".") m.Warn(m.Richs(ice.WEB_SPACE, nil, target[0], func(key string, value map[string]interface{}) { - if channel, ok := value["channel"].(chan *ice.Message); !m.Warn(!ok, "socket err") { + if socket, ok := value["socket"].(*websocket.Conn); !m.Warn(!ok, "socket err") { // 复制选项 for _, k := range kit.Simple(m.Optionv("_option")) { switch k { @@ -866,8 +866,7 @@ var Index = &ice.Context{Name: "web", Help: "网络模块", // 下发命令 m.Target().Server().(*Frame).send[id] = m - - channel <- m + socket.WriteMessage(MSG_MAPS, []byte(m.Format("meta"))) t := time.AfterFunc(kit.Duration(m.Conf(ice.WEB_SPACE, "meta.timeout.c")), func() { m.Log(ice.LOG_WARN, "timeout") }) @@ -1951,26 +1950,15 @@ var Index = &ice.Context{Name: "web", Help: "网络模块", } // m.Cmd(ice.WEB_GROUP, m.Option("group"), "add", m.Option("name")) - c := make(chan *ice.Message, ice.ICE_CHAN) // 添加节点 h := m.Rich(ice.WEB_SPACE, nil, kit.Dict( kit.MDB_TYPE, m.Option("node"), kit.MDB_NAME, m.Option("name"), kit.MDB_TEXT, m.Option("user"), "share", share, "socket", s, - "channel", c, )) m.Log(ice.LOG_CREATE, "space: %s share: %s", m.Option(kit.MDB_NAME), share) - m.Gos(m, func(m *ice.Message) { - for { - select { - case msg := <-c: - s.WriteMessage(MSG_MAPS, []byte(msg.Format("meta"))) - } - } - }) - m.Gos(m, func(m *ice.Message) { // 监听消息 m.Event(ice.SPACE_START, m.Option("node"), m.Option("name")) diff --git a/core/code/code.go b/core/code/code.go index 483d754f..2cdb1715 100644 --- a/core/code/code.go +++ b/core/code/code.go @@ -27,17 +27,6 @@ var Index = &ice.Context{Name: "code", Help: "编程中心", Commands: map[string]*ice.Command{ ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Load() - - // m.Watch(ice.SYSTEM_INIT, "compile", "linux") - // m.Watch(ice.SYSTEM_INIT, "publish", "bin/ice.sh") - // - // if m.Richs(ice.WEB_FAVOR, nil, "auto.init", nil) == nil { - // m.Cmd(ice.WEB_FAVOR, "auto.init", ice.TYPE_SHELL, "下载脚本", `curl -s "$ctx_dev/publish/auto.sh" -o auto.sh`) - // m.Cmd(ice.WEB_FAVOR, "auto.init", ice.TYPE_SHELL, "加载脚本", `source auto.sh`) - // } - // if m.Richs(ice.WEB_FAVOR, nil, "ice.init", nil) == nil { - // m.Cmd(ice.WEB_FAVOR, "ice.init", ice.TYPE_SHELL, "一键启动", `curl -s "$ctx_dev/publish/ice.sh" |sh`) - // } }}, ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Save("login") @@ -46,12 +35,12 @@ var Index = &ice.Context{Name: "code", Help: "编程中心", "login": {Name: "login", Help: "登录", List: ice.ListLook("key"), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) > 0 && arg[0] == "action" { switch arg[1] { - case "modify": + case "modify", "编辑": m.Richs("login", nil, m.Option("key"), func(key string, value map[string]interface{}) { m.Log(ice.LOG_MODIFY, "%s %s %v->%s", key, arg[2], value[arg[2]], arg[3]) value[arg[2]] = arg[3] }) - case "delete": + case "delete", "删除": m.Log(ice.LOG_DELETE, "%s %s", m.Option("key"), m.Conf("login", kit.Keys("hash", m.Option("key")))) m.Conf("login", kit.Keys("hash", m.Option("key")), "") } @@ -96,17 +85,7 @@ var Index = &ice.Context{Name: "code", Help: "编程中心", m.Push(key, value, []string{"pid", "pane", "hostname", "username"}) }) - case "check": - m.Richs("login", nil, m.Option("sid"), func(key string, value map[string]interface{}) { - - }) - case "prune": - if len(arg) > 1 && arg[1] == "all" { - m.Conf("login", "hash", "") - break - } - list := []string{} m.Richs("login", nil, "*", func(key string, value map[string]interface{}) { if len(arg) > 1 && arg[1] == "all" || value["status"] == "logout" { @@ -114,6 +93,7 @@ var Index = &ice.Context{Name: "code", Help: "编程中心", } }) + // 清理会话 kit.Fetch(list, func(index int, value string) { m.Log(ice.LOG_DELETE, "%s: %s", value, m.Conf("login", kit.Keys("hash", value))) m.Conf("login", kit.Keys("hash", value), "") diff --git a/misc/git/git.go b/misc/git/git.go index 00618a22..07395cde 100644 --- a/misc/git/git.go +++ b/misc/git/git.go @@ -27,10 +27,10 @@ var Index = &ice.Context{Name: "git", Help: "代码库", Caches: map[string]*ice.Cache{}, Configs: map[string]*ice.Config{ "repos": {Name: "repos", Help: "仓库", Value: kit.Data(kit.MDB_SHORT, "name", "owner", "https://github.com/shylinux")}, - "total": {Name: "repos", Help: "仓库", Value: kit.Data(kit.MDB_SHORT, "name", "skip", kit.Dict("wubi-dict", "true", "word-dict", "true"))}, + "total": {Name: "total", Help: "统计", Value: kit.Data(kit.MDB_SHORT, "name", "skip", kit.Dict("wubi-dict", "true", "word-dict", "true"))}, }, Commands: map[string]*ice.Command{ - "init": {Name: "init", Help: "init", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + "init": {Name: "init", Help: "初始化", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { // 系统项目 wd, _ := os.Getwd() add(m, path.Base(wd), wd) diff --git a/misc/idc/idc.go b/misc/idc/idc.go new file mode 100644 index 00000000..83dd0f8a --- /dev/null +++ b/misc/idc/idc.go @@ -0,0 +1,52 @@ +package idc + +import ( + "github.com/shylinux/icebergs" + "github.com/shylinux/icebergs/base/web" + "github.com/shylinux/icebergs/core/code" + "github.com/shylinux/toolkits" +) + +var Index = &ice.Context{Name: "idc", Help: "idc", + Caches: map[string]*ice.Cache{}, + Configs: map[string]*ice.Config{ + "conf": {Name: "conf", Help: "conf", Value: kit.Data(kit.MDB_SHORT, "name")}, + "show": {Name: "show", Help: "show", Value: kit.Data(kit.MDB_SHORT, "show")}, + }, + Commands: map[string]*ice.Command{ + ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + m.Load() + }}, + ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + m.Save("conf", "show") + }}, + + "show": {Name: "show key type name text", Help: "show", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + if m.Show(cmd, arg...) { + return + } + + m.Optionv("header", "Content-Type", "application/json") + m.Cmdy(ice.WEB_SPIDE, "dev", "msg", "POST", "/code/idc/show", "data", kit.Format(kit.Dict("cmds", append([]string{}, arg...)))) + }}, + + "/show": {Name: "/show key type name text", Help: "show", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + if m.Richs("show", nil, arg[0], nil) == nil { + m.Rich("show", nil, kit.Data("show", arg[0])) + } + + m.Richs("show", nil, arg[0], func(key string, val map[string]interface{}) { + m.Grow("show", kit.Keys(kit.MDB_HASH, key), kit.Dict( + kit.MDB_TYPE, arg[1], kit.MDB_NAME, arg[2], kit.MDB_TEXT, arg[3], + kit.MDB_EXTRA, kit.Dict(arg[4:]), + )) + }) + m.Echo("hello world") + }}, + "/conf": {Name: "conf key field", Help: "conf", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + m.Echo(m.Conf("conf", arg[0], arg[1])) + }}, + }, +} + +func init() { code.Index.Register(Index, &web.Frame{}) } diff --git a/misc/idc/idc.js b/misc/idc/idc.js new file mode 100644 index 00000000..957bfb22 --- /dev/null +++ b/misc/idc/idc.js @@ -0,0 +1,9 @@ +Volcanos("onimport", {help: "导入数据", list: [], + "init": function(can, msg, cb, output, action, option) {}, +}) +Volcanos("onaction", {help: "控件菜单", list: []}) +Volcanos("onchoice", {help: "控件交互", list: ["刷新"] + "刷新": function(event, can, value, cmd, target) {}, +}) +Volcanos("ondetail", {help: "控件详情", list: []}) +Volcanos("onexport", {help: "导出数据", list: []}) diff --git a/misc/idc/idc.shy b/misc/idc/idc.shy new file mode 100644 index 00000000..a936c3f1 --- /dev/null +++ b/misc/idc/idc.shy @@ -0,0 +1 @@ +title "idc" diff --git a/misc/shy.go b/misc/shy.go index 6cd3c993..be9ac41e 100644 --- a/misc/shy.go +++ b/misc/shy.go @@ -3,7 +3,6 @@ package misc import ( _ "github.com/shylinux/icebergs/misc/docker" _ "github.com/shylinux/icebergs/misc/git" - _ "github.com/shylinux/icebergs/misc/input" _ "github.com/shylinux/icebergs/misc/tmux" _ "github.com/shylinux/icebergs/misc/vim" _ "github.com/shylinux/icebergs/misc/zsh" diff --git a/type.go b/type.go index f6d4a7f1..1737932c 100644 --- a/type.go +++ b/type.go @@ -1523,6 +1523,32 @@ func (m *Message) Grows(key string, chain interface{}, match string, value strin } return meta } +func (m *Message) Show(cmd string, arg ...string) bool { + if len(arg) == 0 { + // 日志分类 + m.Richs(cmd, nil, "*", func(key string, value map[string]interface{}) { + m.Push(key, value["meta"]) + }) + return true + } + if len(arg) < 3 { + m.Richs(cmd, nil, arg[0], func(key string, val map[string]interface{}) { + if len(arg) == 1 { + // 日志列表 + m.Grows(cmd, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) { + m.Push(key, value) + }) + return + } + // 日志详情 + m.Grows(cmd, kit.Keys(kit.MDB_HASH, key), "id", arg[1], func(index int, value map[string]interface{}) { + m.Push("detail", value) + }) + }) + return true + } + return false +} func (m *Message) Cmdy(arg ...interface{}) *Message { msg := m.Cmd(arg...)