1
0
mirror of https://shylinux.com/x/ContextOS synced 2025-04-25 16:58:06 +08:00
Change-Id: I7379cab80a84eccbe137bcb8b78af965b8b83604
This commit is contained in:
shaoying 2019-01-23 16:55:33 +08:00
parent 9c0331ba25
commit 75a94fddad
12 changed files with 484 additions and 665 deletions

View File

@ -357,7 +357,7 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
has := "false"
m.Confm("auth", []string{p, "ship"}, func(k string, ship map[string]interface{}) {
if ship["meta"] == arg[i+1] {
if ship["expire_time"] == nil || ship["expire_time"].(int64) > time.Now().Unix() {
if ship["expire_time"] == nil || int64(kit.Int(ship["expire_time"])) > time.Now().Unix() {
has = k
}
}

View File

@ -134,20 +134,21 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
Commands: map[string]*ctx.Command{
"source": &ctx.Command{Name: "source [script|stdio|snippet]", Help: "解析脚本, script: 脚本文件, stdio: 命令终端, snippet: 代码片段", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
if len(arg) == 0 {
m.Cmdy("dir", "dir_deep", "dir_reg", ".*\\.(sh|shy|py)$")
m.Cmdy("dir", "", "dir_deep", "dir_reg", ".*\\.(sh|shy|py)$")
return
}
// 解析脚本文件
if m.Cmds("nfs.path", arg[0]) {
switch path.Ext(arg[0]) {
if p := m.Cmdx("nfs.path", arg[0]); p != "" {
arg[0] = p
switch path.Ext(p) {
case "":
case ".shy":
m.Option("scan_end", "false")
m.Start(fmt.Sprintf("shell%d", m.Capi("nshell", 1)), "shell", arg...)
m.Wait()
default:
m.Cmdy("system", m.Conf("cmd_script", strings.TrimPrefix(path.Ext(arg[0]), ".")), arg)
m.Cmdy("system", m.Conf("cmd_script", strings.TrimPrefix(path.Ext(p), ".")), arg)
}
return
}

View File

@ -595,16 +595,16 @@ var Index = &Context{Name: "ctx", Help: "模块中心", Server: &CTX{},
for _, v := range cs {
if msg.target = v; v == nil {
m.Add("append", "name", "")
m.Add("append", "names", "")
m.Add("append", "ctx", "")
m.Add("append", "msg", "")
m.Add("append", "status", "")
m.Add("append", "stream", "")
m.Add("append", "help", "")
m.Add("append", "helps", "")
continue
}
m.Add("append", "name", msg.target.Name)
m.Add("append", "names", msg.target.Name)
if msg.target.context != nil {
m.Add("append", "ctx", msg.target.context.Name)
} else {
@ -613,7 +613,7 @@ var Index = &Context{Name: "ctx", Help: "模块中心", Server: &CTX{},
m.Add("append", "msg", msg.target.message.code)
m.Add("append", "status", msg.Cap("status"))
m.Add("append", "stream", msg.Cap("stream"))
m.Add("append", "help", msg.target.Help)
m.Add("append", "helps", msg.target.Help)
}
case "spawn":
@ -944,6 +944,9 @@ var Index = &Context{Name: "ctx", Help: "模块中心", Server: &CTX{},
"trans": &Command{Name: "trans option [type|data|json] limit 10 [index...]", Help: "数据转换", Hand: func(m *Message, c *Context, key string, arg ...string) (e error) {
value, arg := m.Optionv(arg[0]), arg[1:]
if v, ok := value.(string); ok {
json.Unmarshal([]byte(v), &value)
}
view := "data"
if len(arg) > 0 {
@ -953,10 +956,11 @@ var Index = &Context{Name: "ctx", Help: "模块中心", Server: &CTX{},
}
}
limit := m.Confi("page_limit")
limit := kit.Int(kit.Select(m.Conf("page_limit"), m.Option("limit")))
if len(arg) > 0 && arg[0] == "limit" {
limit, arg = kit.Int(arg[1]), arg[2:]
}
m.Log("fuck", "trans limt %v", limit)
chain := strings.Join(arg, ".")
if chain != "" {
@ -1090,7 +1094,7 @@ var Index = &Context{Name: "ctx", Help: "模块中心", Server: &CTX{},
return
}},
"select": &Command{Name: "select key value field",
Form: map[string]int{"parse": 2, "hide": 1, "fields": -1, "group": 1, "order": 2, "limit": 1, "offset": 1, "format": -1, "trans_map": -1, "vertical": 0},
Form: map[string]int{"eq": 2, "parse": 2, "hide": -1, "fields": -1, "group": 1, "order": 2, "limit": 1, "offset": 1, "format": -1, "trans_map": -1, "vertical": 0},
Help: "选取数据", Hand: func(m *Message, c *Context, key string, arg ...string) (e error) {
msg := m.Set("result").Spawn()
@ -1160,24 +1164,28 @@ var Index = &Context{Name: "ctx", Help: "模块中心", Server: &CTX{},
for _, k := range m.Meta["hide"] {
hides[k] = true
}
if len(arg) == 0 {
arg = append(arg, m.Meta["append"]...)
}
for i := 0; i < nrow; i++ {
if len(arg) == 0 || strings.Contains(m.Meta[arg[0]][i], arg[1]) {
for _, k := range m.Meta["append"] {
if hides[k] {
continue
}
msg.Add("append", k, m.Meta[k][i])
// if len(arg) == 0 || strings.Contains(m.Meta[arg[0]][i], arg[1]) {
if m.Has("eq") {
if m.Meta[m.Meta["eq"][0]][i] != m.Meta["eq"][1] {
continue
}
}
for _, k := range arg {
if hides[k] {
continue
}
msg.Add("append", k, m.Meta[k][i])
}
}
// 选择列
if m.Option("fields") != "" {
msg = m.Spawn()
m.Hand = true
msg.Copy(m, strings.Split(strings.Join(m.Meta["fields"], " "), " ")...)
m.Hand = false
m.Set("append").Copy(msg, "append")
if len(msg.Meta["append"]) == 0 {
return
}
if len(msg.Meta[msg.Meta["append"][0]]) == 0 {
return
}
// 聚合
@ -1235,18 +1243,13 @@ var Index = &Context{Name: "ctx", Help: "模块中心", Server: &CTX{},
// 排序
if m.Has("order") {
m.Sort(m.Meta["order"][1], m.Option("order"))
m.Sort(m.Option("order"), kit.Select("str", m.Meta["order"], 1))
}
// 分页
offset := 0
limit := m.Confi("page_limit")
if m.Has("limit") {
limit = m.Optioni("limit")
}
if m.Has("offset") {
offset = m.Optioni("offset")
}
offset := kit.Int(kit.Select("0", m.Option("offset")))
limit := kit.Int(kit.Select(m.Conf("page_limit"), m.Option("limit")))
nrow = len(m.Meta[m.Meta["append"][0]])
if offset > nrow {
offset = nrow
@ -1295,12 +1298,12 @@ var Index = &Context{Name: "ctx", Help: "模块中心", Server: &CTX{},
}
// 取单值
if len(arg) > 2 {
if len(m.Meta[arg[2]]) > 0 {
m.Echo(m.Meta[arg[2]][0])
}
return
}
// if len(arg) > 2 {
// if len(m.Meta[arg[2]]) > 0 {
// m.Echo(m.Meta[arg[2]][0])
// }
// return
// }
m.Set("result").Table()
return

View File

@ -598,6 +598,9 @@ func (m *Message) Copy(msg *Message, arg ...string) *Message {
m.Add(meta, msg.Meta[meta][0], msg.Meta[meta][1:])
}
case "option", "append":
if msg.Meta[meta] == nil {
break
}
if i == len(arg)-1 {
arg = append(arg, msg.Meta[meta]...)
}
@ -605,9 +608,8 @@ func (m *Message) Copy(msg *Message, arg ...string) *Message {
for i++; i < len(arg); i++ {
if v, ok := msg.Data[arg[i]]; ok {
m.Put(meta, arg[i], v)
}
if v, ok := msg.Meta[arg[i]]; ok {
m.Add(meta, arg[i], v)
} else if v, ok := msg.Meta[arg[i]]; ok {
m.Set(meta, arg[i], v) // TODO fuck Add
}
}
default:
@ -818,6 +820,18 @@ func (m *Message) Table(cbs ...interface{}) *Message {
if len(cbs) > 0 {
switch cb := cbs[0].(type) {
case func(map[string]string) bool:
nrow := len(m.Meta[m.Meta["append"][0]])
line := map[string]string{}
for i := 0; i < nrow; i++ {
for _, k := range m.Meta["append"] {
line[k] = m.Meta[k][i]
}
if !cb(line) {
break
}
}
return m
case func(map[string]string):
nrow := len(m.Meta[m.Meta["append"][0]])
line := map[string]string{}
@ -1331,16 +1345,19 @@ func (m *Message) Cmd(args ...interface{}) *Message {
if args := []string{}; x.Form != nil {
for i := 0; i < len(arg); i++ {
if n, ok := x.Form[arg[i]]; ok {
if n < 0 {
n += len(arg) - i
}
for j := i + 1; j <= i+n; j++ {
for j := i + 1; j <= i+n && j < len(arg); j++ {
if _, ok := x.Form[arg[j]]; ok {
n = j - i - 1
}
}
m.Add("option", arg[i], arg[i+1:i+1+n])
if i+1+n > len(arg) {
m.Add("option", arg[i], arg[i+1:])
} else {
m.Add("option", arg[i], arg[i+1:i+1+n])
}
i += n
} else {
args = append(args, arg[i])
@ -1406,12 +1423,26 @@ func (m *Message) Confm(key string, args ...interface{}) map[string]interface{}
}
switch fun := args[0].(type) {
case func(int, string):
for i, v := range table {
fun(i, kit.Format(v))
}
case func(int, string) bool:
for i, v := range table {
if fun(i, kit.Format(v)) {
break
}
}
case func(string, string):
for k, v := range value {
fun(k, kit.Format(v))
}
case func(string, string) bool:
for k, v := range value {
if fun(k, kit.Format(v)) {
break
}
}
case func(map[string]interface{}):
fun(value)
case func(string, map[string]interface{}):

View File

@ -70,7 +70,7 @@ var Index = &ctx.Context{Name: "mdb", Help: "数据中心",
"temp_view": &ctx.Config{Name: "temp_view", Value: map[string]interface{}{}, Help: "缓存数据"},
},
Commands: map[string]*ctx.Command{
"temp": &ctx.Command{Name: "temp [type [meta [data]]] [tid [node|ship|data] [chain... [select ...]]]", Form: map[string]int{"select": -1}, Help: "缓存数据", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
"temp": &ctx.Command{Name: "temp [type [meta [data]]] [tid [node|ship|data] [chain... [select ...]]]", Form: map[string]int{"select": -1, "limit": 1}, Help: "缓存数据", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
if len(arg) > 2 { // 添加数据
if temp := m.Confm("temp", arg[0]); temp == nil {
h := m.Cmdx("aaa.hash", arg[0], arg[1])
@ -124,6 +124,8 @@ var Index = &ctx.Context{Name: "mdb", Help: "数据中心",
m.Confv("temp", []string{h, "data"}, msg.Meta)
}
temp = view
} else if arg[0] == "hash" { // 添加缓存
m.Echo(hash)
} else if arg[0] == "" { // 添加缓存
b, _ := json.MarshalIndent(temp["data"], "", " ")
m.Echo(string(b))
@ -148,7 +150,7 @@ var Index = &ctx.Context{Name: "mdb", Help: "数据中心",
chain := strings.Join(m.Optionv("select").([]string), " ")
hh := m.Cmdx("aaa.hash", "select", chain, h)
if view := m.Confm("temp", hh); view != nil { // 加载缓存
if view := m.Confm("temp", hh); view != nil && false { // 加载缓存
msg = msg.Spawn()
switch data := view["data"].(type) {
case map[string][]string:

View File

@ -177,6 +177,7 @@ func (nfs *NFS) Read(p []byte) (n int, err error) {
m.TryCatch(m, true, func(m *ctx.Message) {
scroll_count := 0
scroll_lines := m.Confi("term", "scroll_lines")
which := m.Capi("ninput")
what := make([]rune, 0, 1024)
rest := make([]rune, 0, 1024)
@ -315,11 +316,11 @@ func (nfs *NFS) Read(p []byte) (n int, err error) {
case termbox.KeyCtrlT:
m.Option("scroll", true)
nfs.Term(m, "scroll", 1).Term(m, "flush")
nfs.Term(m, "scroll", scroll_lines).Term(m, "flush")
m.Option("scroll", false)
case termbox.KeyCtrlO:
m.Option("scroll", true)
nfs.Term(m, "scroll", -1).Term(m, "flush")
nfs.Term(m, "scroll", -scroll_lines).Term(m, "flush")
m.Option("scroll", false)
case termbox.KeyCtrlJ, termbox.KeyEnter:
@ -1010,6 +1011,9 @@ func (nfs *NFS) Close(m *ctx.Message, arg ...string) bool {
}
case m.Source():
}
if nfs.Name == "stdio" {
return false
}
return true
}
@ -1025,6 +1029,7 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
"cursor_x": 0, "cursor_y": 0, "fgcolor": -1, "bgcolor": -1,
"prompt": "", "wrap": "false",
"scroll_count": "5",
"scroll_lines": "5",
"begin_row": 0, "begin_col": 0,
"shadow": "hello",
@ -1402,6 +1407,14 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
m.Set("result").Echo(p)
return
}},
"json": &ctx.Command{Name: "json str", Help: "导入数据", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
var data interface{}
m.Assert(json.Unmarshal([]byte(arg[0]), &data))
b, e := json.MarshalIndent(data, "", " ")
m.Assert(e)
m.Echo(string(b))
return
}},
"open": &ctx.Command{Name: "open file", Help: "打开文件, file: 文件名", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
if m.Has("io") {

View File

@ -125,6 +125,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
names := strings.SplitN(arg[0], ".", 2)
if names[0] == "" { // 本地执行
host := m.Confm("host", m.Option("hostname"))
m.Option("current_ctx", kit.Format(host["cm_target"]))
msg := m.Find(kit.Format(host["cm_target"])).Cmd(arg[1:])
m.Copy(msg, "append").Copy(msg, "result")
@ -148,19 +149,19 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
if names[0] == "*" {
m.Confm("host", func(name string, host map[string]interface{}) {
m.Find(kit.Format(host["module"]), true).Copy(m, "option").CallBack(sync, func(sub *ctx.Message) *ctx.Message {
return m.Copy(sub)
return m.Copy(sub, "append").Copy(sub, "result")
}, "send", "", arg)
})
} else if m.Confm("host", names[0], func(host map[string]interface{}) {
m.Find(kit.Format(host["module"]), true).Copy(m, "option").CallBack(sync, func(sub *ctx.Message) *ctx.Message {
return m.Copy(sub)
return m.Copy(sub, "append").Copy(sub, "result")
}, "send", rest, arg)
m.Log("fuck", "m %v", m.Meta)
}) == nil {
m.Find(m.Cap("stream"), true).Copy(m, "option").CallBack(sync, func(sub *ctx.Message) *ctx.Message {
return m.Copy(sub)
return m.Copy(sub, "append").Copy(sub, "result")
}, "send", strings.Join(names, "."), arg)
}
}
@ -181,6 +182,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
}
msg := m.Cmd("ssh.remote", m.Conf("current"), arg)
m.Copy(msg, "append")
m.Copy(msg, "result")
return
}},

File diff suppressed because it is too large Load Diff

View File

@ -4,6 +4,7 @@ import (
"contexts/ctx"
"contexts/web"
"fmt"
"net/http"
"strconv"
)
@ -22,8 +23,8 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
"componet_group": &ctx.Config{Name: "component_group", Value: "index", Help: "默认组件"},
"componet": &ctx.Config{Name: "componet", Value: map[string]interface{}{
"login": []interface{}{
map[string]interface{}{"componet_name": "head", "template": "head"},
map[string]interface{}{"componet_name": "login", "componet_help": "login", "template": "componet",
map[string]interface{}{"name": "head", "template": "head"},
map[string]interface{}{"name": "login", "help": "login", "template": "componet",
"componet_ctx": "aaa", "componet_cmd": "auth", "arguments": []interface{}{"@sessid", "ship", "username", "@username", "password", "@password"},
"inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "username", "label": "username"},
@ -32,12 +33,12 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
},
"display_append": "", "display_result": "",
},
map[string]interface{}{"componet_name": "tail", "template": "tail"},
map[string]interface{}{"name": "tail", "template": "tail"},
},
"index": []interface{}{
map[string]interface{}{"componet_name": "head", "template": "head"},
map[string]interface{}{"componet_name": "docker", "componet_help": "docker", "template": "docker"},
// map[string]interface{}{"componet_name": "login", "componet_help": "login", "template": "componet",
map[string]interface{}{"name": "head", "template": "head"},
map[string]interface{}{"name": "toolkit", "help": "toolkit", "template": "toolkit"},
// map[string]interface{}{"name": "login", "help": "login", "template": "componet",
// "componet_ctx": "aaa", "componet_cmd": "login", "arguments": []interface{}{"@username", "@password"},
// "inputs": []interface{}{
// map[string]interface{}{"type": "text", "name": "username", "label": "username"},
@ -46,12 +47,12 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
// },
// "display_append": "", "display_result": "",
// },
// map[string]interface{}{"componet_name": "userinfo", "componet_help": "userinfo", "template": "componet",
// map[string]interface{}{"name": "userinfo", "help": "userinfo", "template": "componet",
// "componet_ctx": "aaa", "componet_cmd": "login", "arguments": []interface{}{"@sessid"},
// "pre_run": true,
// },
map[string]interface{}{"componet_name": "clipboard", "componet_help": "clipboard", "template": "clipboard"},
map[string]interface{}{"componet_name": "buffer", "componet_help": "buffer", "template": "componet",
map[string]interface{}{"name": "clipboard", "help": "clipboard", "template": "clipboard"},
map[string]interface{}{"name": "buffer", "help": "buffer", "template": "componet",
"componet_ctx": "cli", "componet_cmd": "tmux", "arguments": []interface{}{"buffer"}, "inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "limit", "label": "limit", "value": "3"},
map[string]interface{}{"type": "text", "name": "index", "label": "index"},
@ -59,7 +60,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
},
"pre_run": true,
},
// map[string]interface{}{"componet_name": "time", "componet_help": "time", "template": "componet",
// map[string]interface{}{"name": "time", "help": "time", "template": "componet",
// "componet_ctx": "cli", "componet_cmd": "time", "arguments": []interface{}{"@string"},
// "inputs": []interface{}{
// map[string]interface{}{"type": "text", "name": "time_format",
@ -69,14 +70,14 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
// map[string]interface{}{"type": "button", "value": "refresh"},
// },
// },
// map[string]interface{}{"componet_name": "json", "componet_help": "json", "template": "componet",
// map[string]interface{}{"name": "json", "help": "json", "template": "componet",
// "componet_ctx": "nfs", "componet_cmd": "json", "arguments": []interface{}{"@string"},
// "inputs": []interface{}{
// map[string]interface{}{"type": "text", "name": "string", "label": "string"},
// map[string]interface{}{"type": "button", "value": "refresh"},
// },
// },
map[string]interface{}{"componet_name": "dir", "componet_help": "dir", "template": "componet",
map[string]interface{}{"name": "dir", "help": "dir", "template": "componet",
"componet_ctx": "nfs", "componet_cmd": "dir", "arguments": []interface{}{"@dir", "dir_sort", "@sort_order", "@sort_field"},
"pre_run": true, "display_result": "",
"inputs": []interface{}{
@ -109,7 +110,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
map[string]interface{}{"type": "text", "name": "dir", "label": "dir"},
},
},
map[string]interface{}{"componet_name": "upload", "componet_help": "upload", "template": "componet",
map[string]interface{}{"name": "upload", "help": "upload", "template": "componet",
"componet_ctx": "web", "componet_cmd": "upload", "form_type": "upload",
"inputs": []interface{}{
map[string]interface{}{"type": "file", "name": "upload"},
@ -117,7 +118,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
},
"display_result": "",
},
// map[string]interface{}{"componet_name": "download", "componet_help": "download", "template": "componet",
// map[string]interface{}{"name": "download", "help": "download", "template": "componet",
// "componet_ctx": "cli.shy", "componet_cmd": "source", "arguments": []interface{}{"@cmds"},,
// "display_result": "", "download_file": "",
// "inputs": []interface{}{
@ -127,7 +128,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
// },
// },
// },
map[string]interface{}{"componet_name": "cmd", "componet_help": "cmd", "template": "componet",
map[string]interface{}{"name": "cmd", "help": "cmd", "template": "componet",
"componet_ctx": "cli.shy", "componet_cmd": "source", "arguments": []interface{}{"@cmd"},
"inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "cmd", "value": "",
@ -135,7 +136,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
},
},
},
map[string]interface{}{"componet_name": "ctx", "componet_help": "ctx", "template": "componet",
map[string]interface{}{"name": "ctx", "help": "ctx", "template": "componet",
"componet_ctx": "cli.shy", "componet_cmd": "context", "arguments": []interface{}{"@ctx", "list"},
"display_result": "",
"inputs": []interface{}{
@ -143,7 +144,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
map[string]interface{}{"type": "button", "value": "refresh"},
},
},
// map[string]interface{}{"componet_name": "ccc", "componet_help": "ccc", "template": "componet",
// map[string]interface{}{"name": "ccc", "help": "ccc", "template": "componet",
// "componet_ctx": "cli.shy", "componet_cmd": "context", "arguments": []interface{}{"@current_ctx", "@ccc"},
// "display_result": "",
// "inputs": []interface{}{
@ -157,21 +158,21 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
// map[string]interface{}{"type": "button", "value": "refresh"},
// },
// },
// map[string]interface{}{"componet_name": "cmd", "componet_help": "cmd", "template": "componet",
// map[string]interface{}{"name": "cmd", "help": "cmd", "template": "componet",
// "componet_ctx": "cli.shy", "componet_cmd": "context", "arguments": []interface{}{"@current_ctx", "cmd", "list"},
// "pre_run": true, "display_result": "",
// "inputs": []interface{}{
// map[string]interface{}{"type": "button", "value": "refresh"},
// },
// },
// map[string]interface{}{"componet_name": "history", "componet_help": "history", "template": "componet",
// map[string]interface{}{"name": "history", "help": "history", "template": "componet",
// "componet_ctx": "cli", "componet_cmd": "config", "arguments": []interface{}{"source_list"},
// "pre_run": true, "display_result": "",
// "inputs": []interface{}{
// map[string]interface{}{"type": "button", "value": "refresh"},
// },
// },
// map[string]interface{}{"componet_name": "develop", "componet_help": "develop", "template": "componet",
// map[string]interface{}{"name": "develop", "help": "develop", "template": "componet",
// "componet_ctx": "web.code", "componet_cmd": "config", "arguments": []interface{}{"counter"},
// "inputs": []interface{}{
// map[string]interface{}{"type": "button", "value": "refresh"},
@ -179,7 +180,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
// "pre_run": true,
// "display_result": "",
// },
// map[string]interface{}{"componet_name": "windows", "componet_help": "windows", "template": "componet",
// map[string]interface{}{"name": "windows", "help": "windows", "template": "componet",
// "componet_ctx": "cli", "componet_cmd": "windows",
// "inputs": []interface{}{
// map[string]interface{}{"type": "button", "value": "refresh"},
@ -187,7 +188,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
// "pre_run": true,
// "display_result": "",
// },
map[string]interface{}{"componet_name": "runtime", "componet_help": "runtime", "template": "componet",
map[string]interface{}{"name": "runtime", "help": "runtime", "template": "componet",
"componet_ctx": "cli", "componet_cmd": "runtime",
"inputs": []interface{}{
map[string]interface{}{"type": "button", "value": "refresh"},
@ -195,7 +196,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
"pre_run": true,
"display_result": "",
},
// map[string]interface{}{"componet_name": "sysinfo", "componet_help": "sysinfo", "template": "componet",
// map[string]interface{}{"name": "sysinfo", "help": "sysinfo", "template": "componet",
// "componet_ctx": "cli", "componet_cmd": "sysinfo",
// "inputs": []interface{}{
// map[string]interface{}{"type": "button", "value": "refresh"},
@ -203,9 +204,16 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
// "pre_run": true,
// "display_result": "",
// },
map[string]interface{}{"componet_name": "tail", "template": "tail"},
map[string]interface{}{"name": "tail", "template": "tail"},
},
}, Help: "组件列表"},
"upgrade": &ctx.Config{Name: "upgrade", Value: map[string]interface{}{
"file": map[string]interface{}{
"init_shy": "etc/init0.shy",
"exit_shy": "etc/exit.shy",
"bench": "bin/bench",
},
}, Help: "日志地址"},
},
Commands: map[string]*ctx.Command{
"/counter": &ctx.Command{Name: "/counter", Help: "/counter", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
@ -233,6 +241,30 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
}
return
}},
"/upgrade/": &ctx.Command{Name: "/upgrade/", Help: "下载文件", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
r := m.Optionv("request").(*http.Request)
w := m.Optionv("response").(http.ResponseWriter)
p := m.Cmdx("nfs.path", key)
m.Log("info", "upgrade %s %s", p, m.Cmdx("aaa.hash", "file", p))
http.ServeFile(w, r, p)
return
}},
"upgrade": &ctx.Command{Name: "upgrade system|script", Help: "服务升级", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
if len(arg) > 0 && arg[0] == "system" {
m.Cmd("cli.source", m.Conf("exit.shy"))
m.Confm("upgrade", "file", func(key string, value string) {
m.Cmd("web.get", "dev", fmt.Sprintf("code/upgrade/%s", key), "save", value)
})
m.Cmd("cli.system", "chmod", "u+x", "bin/bench")
// os.Exit(1)
return
}
m.Cmdy("web.get", "dev", fmt.Sprintf("code/upgrade/script/%s", arg[0]), "save", fmt.Sprintf("usr/script/%s", arg[0]), arg[1:])
return
}},
},
}

View File

@ -434,6 +434,9 @@ func Chain(root interface{}, args ...interface{}) interface{} {
return root
}
func Link(name string, url string) string {
return fmt.Sprintf("<a href=\"%s\" target=\"_blank\">%s</a>", url, name)
}
func Duration(arg ...string) time.Duration {
d, _ := time.ParseDuration(arg[0])

View File

@ -35,7 +35,7 @@ function save_clipboard(item) {
alert("保存成功")
})
}
function copy_to_clipboard(text, skip_blur, skip_docker) {
function copy_to_clipboard(text, skip_blur, skip_toolkit) {
var clipboard = modify_node(".clipboard", {"value": text})
if (skip_blur) {
document.execCommand("copy")
@ -49,7 +49,7 @@ function copy_to_clipboard(text, skip_blur, skip_docker) {
insert_child(clipstack, "option").value = text
clipstack.childElementCount > 3 && clipstack.removeChild(clipstack.lastElementChild)
if (skip_docker) {
if (skip_toolkit) {
return
}
@ -766,7 +766,7 @@ function init_command() {
}
}
}
function init_docker() {
function init_toolkit() {
text = JSON.parse(bench_data.clipstack || "[]")
for (var i = 0; i < text.length; i++) {
copy_to_clipboard(text[i])
@ -775,8 +775,8 @@ function init_docker() {
document.querySelectorAll("div.workflow").forEach(function(workflow) {
// 移动面板
workflow.style.left = context.Cookie("docker_left")
workflow.style.top = context.Cookie("docker_top")
workflow.style.left = context.Cookie("toolkit_left")
workflow.style.top = context.Cookie("toolkit_top")
var moving = false, left0 = 0, top0 = 0, x0 = 0, y0 = 0
workflow.onclick = function(event) {
if (event.target != workflow) {
@ -794,25 +794,25 @@ function init_docker() {
if (moving) {
workflow.style.left = (left0+(event.clientX-x0))+"px"
workflow.style.top = (top0+(event.clientY-y0))+"px"
context.Cookie("docker_left", workflow.style.left)
context.Cookie("docker_top", workflow.style.top)
context.Cookie("toolkit_left", workflow.style.left)
context.Cookie("toolkit_top", workflow.style.top)
}
}
// 固定面板
if (context.Cookie("docker_class")) {
workflow.className = context.Cookie("docker_class")
if (context.Cookie("toolkit_class")) {
workflow.className = context.Cookie("toolkit_class")
}
var head = workflow.querySelector("div")
head.onclick = function(event) {
head.dataset["show"] = !right(head.dataset["show"])
workflow.className = right(head.dataset["show"])? "workflow max": "workflow"
context.Cookie("docker_class", workflow.className)
context.Cookie("toolkit_class", workflow.className)
}
// 折叠目录
var docker = workflow.querySelector("ul.docker")
docker.querySelectorAll("li>div").forEach(function(menu) {
var toolkit = workflow.querySelector("ul.toolkit")
toolkit.querySelectorAll("li>div").forEach(function(menu) {
menu.onclick = function(event) {
menu.dataset["hide"] = !right(menu.dataset["hide"])
menu.nextElementSibling.style.display = right(menu.dataset["hide"])? "none": ""
@ -820,7 +820,7 @@ function init_docker() {
})
// 事件
docker.querySelectorAll("li>ul>li").forEach(function(item) {
toolkit.querySelectorAll("li>ul>li").forEach(function(item) {
// if (bench_data.board["key"] == item.dataset["key"]) {
// // item.className = "stick"
// }
@ -881,7 +881,7 @@ function init_docker() {
"cmd": "aaa.work "+context.Search("bench")+" delete",
})
var b = ""
document.querySelectorAll("div.workflow>ul.docker>li>ul.fly>li[data-key]").forEach(function(item){
document.querySelectorAll("div.workflow>ul.toolkit>li>ul.fly>li[data-key]").forEach(function(item){
if (!b && item.dataset["key"] != context.Search("bench")) {
b = item.dataset["key"]
}
@ -914,6 +914,6 @@ window.onload = function() {
init_context()
init_command()
init_docker()
init_toolkit()
}

View File

@ -22,6 +22,7 @@
}
</style>
<style>
{{$toolkit_view := conf . "route" "toolkit_view"}}
div.workflow {
color:#e6dd37;
font-size:14px;
@ -32,12 +33,12 @@
height:20px;
overflow:scroll;
position:fixed;
top:{{conf . "docker_view" "top"}}px;
left:{{conf . "docker_view" "left"}}px;
top:{{index $toolkit_view "top"}}px;
left:{{index $toolkit_view "left"}}px;
}
div.workflow:hover, div.workflow.max {
width:{{conf . "docker_view" "width"}}px;
height:{{conf . "docker_view" "height"}}px;
width:{{index $toolkit_view "width"}}px;
height:{{index $toolkit_view "height"}}px;
}
div.workflow div:hover, div.workflow li li:hover {
background-color:red;
@ -121,6 +122,7 @@
cursor:pointer;
}
table.append td {
max-width:1200px;
font-family:monospace;
padding-left: 10px;
padding-right: 20px;
@ -168,13 +170,12 @@
</fieldset>
{{end}}
{{define "docker"}}
{{$key := option . "bench"}}
{{define "toolkit"}}
{{$bench_data := option . "bench_data"}}
{{$username := option . "username"|option}}
{{$bench := conf . "bench" $key}}
<div class="workflow">
<div>&nbsp;bench (Ctrl+B)</div>
<ul class="docker">
<ul class="toolkit">
<li><div>粘贴板</div>
<ul class="txt">
<li data-action="save_txt">+ 保存粘贴板(Ctrl+S)</li>
@ -190,10 +191,8 @@
<li class="stick" data-action="shrink_cmd">+ 折叠命令行(Ctrl+Z)</li>
<li data-action="create_cmd">+ 添加命令行(Ctrl+M)</li>
{{if $bench}}
{{range $index, $cmd := index $bench "commands"}}
<li class="cmd{{$index}}" data-cmd="{{$index}}">{{index $cmd "now"|option}} {{$index}}: {{index $cmd "cmd"|option}}</li>
{{end}}
{{range $index, $cmd := index $bench_data "commands"}}
<li class="cmd{{$index}}" data-cmd="{{$index}}">{{index $cmd "now"|option}} {{$index}}: {{index $cmd "cmd"|option}}</li>
{{end}}
</ul>
</li>
@ -213,7 +212,7 @@
{{end}}
{{define "componet"}}
<fieldset><legend title="{{option .Meta "componet_help"}}">{{option .Meta "componet_help"}}({{option .Meta "componet_ctx"}}.{{option .Meta "componet_cmd"}})</legend>
<fieldset><legend title="{{option .Meta "help"}}">{{option .Meta "name"}}({{option .Meta "help"}})</legend>
{{$form_type := option . "form_type"|meta}}
{{$msg := .}}
@ -302,8 +301,8 @@
{{end}}
{{define "tail"}}
<script src="/librarys/context.js"></script>
<script src="/librarys/code.js"></script>
<script src="/static/librarys/context.js"></script>
<script src="/static/librarys/code.js"></script>
</body>
{{end}}