1
0
forked from x/icebergs

add m.show

This commit is contained in:
shaoying 2020-03-28 12:41:38 +08:00
parent 4749dab18d
commit b70843b780
8 changed files with 95 additions and 40 deletions

View File

@ -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"))

View File

@ -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), "")

View File

@ -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)

52
misc/idc/idc.go Normal file
View File

@ -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{}) }

9
misc/idc/idc.js Normal file
View File

@ -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: []})

1
misc/idc/idc.shy Normal file
View File

@ -0,0 +1 @@
title "idc"

View File

@ -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"

26
type.go
View File

@ -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...)