forked from x/ContextOS
add componet.ctx
This commit is contained in:
parent
e167d1522c
commit
1b86db71df
@ -4,5 +4,4 @@
|
|||||||
config load var/counter.json counter
|
config load var/counter.json counter
|
||||||
|
|
||||||
source etc/local.shy
|
source etc/local.shy
|
||||||
source etc/demo.shy
|
|
||||||
~shy
|
~shy
|
||||||
|
@ -2,6 +2,7 @@ package cli
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"contexts/ctx"
|
"contexts/ctx"
|
||||||
|
"path"
|
||||||
"toolkit"
|
"toolkit"
|
||||||
|
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -84,9 +85,10 @@ func (cli *CLI) Spawn(m *ctx.Message, c *ctx.Context, arg ...string) ctx.Server
|
|||||||
":": []string{"command"},
|
":": []string{"command"},
|
||||||
"::": []string{"command", "list"},
|
"::": []string{"command", "list"},
|
||||||
|
|
||||||
"pwd": []string{"nfs.pwd"},
|
"pwd": []string{"nfs.pwd"},
|
||||||
"dir": []string{"nfs.dir"},
|
"path": []string{"nfs.path"},
|
||||||
"git": []string{"nfs.git"},
|
"dir": []string{"nfs.dir"},
|
||||||
|
"git": []string{"nfs.git"},
|
||||||
}
|
}
|
||||||
|
|
||||||
return s
|
return s
|
||||||
@ -139,8 +141,8 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
|||||||
"init.shy": &ctx.Config{Name: "init.shy", Value: "etc/init.shy", Help: "启动脚本"},
|
"init.shy": &ctx.Config{Name: "init.shy", Value: "etc/init.shy", Help: "启动脚本"},
|
||||||
"exit.shy": &ctx.Config{Name: "exit.shy", Value: "etc/exit.shy", Help: "启动脚本"},
|
"exit.shy": &ctx.Config{Name: "exit.shy", Value: "etc/exit.shy", Help: "启动脚本"},
|
||||||
|
|
||||||
"time_unit": &ctx.Config{Name: "time_unit", Value: "1000", Help: "时间倍数"},
|
"time_unit": &ctx.Config{Name: "time_unit", Value: "1000", Help: "时间倍数"},
|
||||||
"time_close": &ctx.Config{Name: "time_close(open/close)", Value: "open", Help: "时间区间"},
|
"time_close": &ctx.Config{Name: "time_close(open/close)", Value: "open", Help: "时间区间"},
|
||||||
|
|
||||||
"cmd_script": &ctx.Config{Name: "cmd_script", Value: map[string]interface{}{
|
"cmd_script": &ctx.Config{Name: "cmd_script", Value: map[string]interface{}{
|
||||||
"sh": "bash",
|
"sh": "bash",
|
||||||
@ -149,6 +151,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
|||||||
}, Help: "系统命令超时"},
|
}, Help: "系统命令超时"},
|
||||||
|
|
||||||
"cmd_timeout": &ctx.Config{Name: "cmd_timeout", Value: "60s", Help: "系统命令超时"},
|
"cmd_timeout": &ctx.Config{Name: "cmd_timeout", Value: "60s", Help: "系统命令超时"},
|
||||||
|
"source_list": &ctx.Config{Name: "source_list", Value: []interface{}{}, Help: "系统命令超时"},
|
||||||
"cmd_combine": &ctx.Config{Name: "cmd_combine", Value: map[string]interface{}{
|
"cmd_combine": &ctx.Config{Name: "cmd_combine", Value: map[string]interface{}{
|
||||||
"vi": map[string]interface{}{"active": true},
|
"vi": map[string]interface{}{"active": true},
|
||||||
"top": map[string]interface{}{"active": true},
|
"top": map[string]interface{}{"active": true},
|
||||||
@ -610,6 +613,15 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m.Confv("source_list", -1, map[string]interface{}{
|
||||||
|
"source_word": strings.Join(arg, " "),
|
||||||
|
"source_time": m.Time(),
|
||||||
|
})
|
||||||
|
|
||||||
|
if m.Options("current_ctx") {
|
||||||
|
args := []string{"context", m.Option("current_ctx")}
|
||||||
|
arg = append(args, arg...)
|
||||||
|
}
|
||||||
m.Sess("yac").Call(func(msg *ctx.Message) *ctx.Message {
|
m.Sess("yac").Call(func(msg *ctx.Message) *ctx.Message {
|
||||||
switch msg.Cmd().Detail(0) {
|
switch msg.Cmd().Detail(0) {
|
||||||
case "cmd":
|
case "cmd":
|
||||||
@ -624,6 +636,11 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
|||||||
m.Copy(msg, "append").Copy(msg, "result")
|
m.Copy(msg, "append").Copy(msg, "result")
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
|
"run": &ctx.Command{Name: "run", Help: "脚本参数", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
|
name := path.Join(m.Option("dir_root"), m.Option("download_dir"), arg[0])
|
||||||
|
msg := m.Spawn(c).Cmd("cmd", name)
|
||||||
|
m.Copy(msg, "append").Copy(msg, "result")
|
||||||
|
}},
|
||||||
|
|
||||||
"sleep": &ctx.Command{Name: "sleep time", Help: "睡眠, time(ns/us/ms/s/m/h): 时间值(纳秒/微秒/毫秒/秒/分钟/小时)", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
"sleep": &ctx.Command{Name: "sleep time", Help: "睡眠, time(ns/us/ms/s/m/h): 时间值(纳秒/微秒/毫秒/秒/分钟/小时)", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
if d, e := time.ParseDuration(arg[0]); m.Assert(e) {
|
if d, e := time.ParseDuration(arg[0]); m.Assert(e) {
|
||||||
|
@ -2796,6 +2796,9 @@ var Index = &Context{Name: "ctx", Help: "模块中心",
|
|||||||
switch action {
|
switch action {
|
||||||
case "cmd":
|
case "cmd":
|
||||||
msg.Cmd(arg)
|
msg.Cmd(arg)
|
||||||
|
if !msg.Hand {
|
||||||
|
msg = msg.Sess("cli").Cmd("cmd", arg)
|
||||||
|
}
|
||||||
m.Copy(msg, "append").Copy(msg, "result")
|
m.Copy(msg, "append").Copy(msg, "result")
|
||||||
case "switch":
|
case "switch":
|
||||||
m.target = msg.target
|
m.target = msg.target
|
||||||
@ -3045,13 +3048,15 @@ var Index = &Context{Name: "ctx", Help: "模块中心",
|
|||||||
|
|
||||||
switch action {
|
switch action {
|
||||||
case "save":
|
case "save":
|
||||||
f, e := os.Create(which)
|
// f, e := os.Create(which)
|
||||||
m.Assert(e)
|
// m.Assert(e)
|
||||||
defer f.Close()
|
// defer f.Close()
|
||||||
|
//
|
||||||
buf, e := json.MarshalIndent(save, "", " ")
|
buf, e := json.MarshalIndent(save, "", " ")
|
||||||
m.Assert(e)
|
m.Assert(e)
|
||||||
f.Write(buf)
|
m.Sess("nfs").Add("option", "data", string(buf)).Cmd("save", which)
|
||||||
|
|
||||||
|
// f.Write(buf)
|
||||||
case "export":
|
case "export":
|
||||||
buf, e := json.MarshalIndent(save, "", " ")
|
buf, e := json.MarshalIndent(save, "", " ")
|
||||||
m.Assert(e)
|
m.Assert(e)
|
||||||
|
@ -199,6 +199,15 @@ var Index = &ctx.Context{Name: "mdb", Help: "数据中心",
|
|||||||
"extra_field": 2, "extra_fields": 1, "extra_format": 1, "trans_field": 1, "trans_map": 2},
|
"extra_field": 2, "extra_fields": 1, "extra_format": 1, "trans_field": 1, "trans_map": 2},
|
||||||
Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
if _, ok := m.Target().Server.(*MDB); m.Assert(ok) {
|
if _, ok := m.Target().Server.(*MDB); m.Assert(ok) {
|
||||||
|
if len(arg) == 0 {
|
||||||
|
msg := m.Spawn().Cmd("query", "show tables")
|
||||||
|
for _, v := range msg.Meta[msg.Meta["append"][0]] {
|
||||||
|
m.Add("append", "table", v)
|
||||||
|
}
|
||||||
|
m.Table()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
table := m.Confx("table", arg, 0)
|
table := m.Confx("table", arg, 0)
|
||||||
if v := m.Confv("tables", table); v != nil {
|
if v := m.Confv("tables", table); v != nil {
|
||||||
table = v.(string)
|
table = v.(string)
|
||||||
|
@ -84,6 +84,7 @@ func dir(m *ctx.Message, name string, level int, deep bool, trip int, fields []s
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
f, _ := os.Stat(f.Name())
|
||||||
if !(m.Confx("dir_type") == "file" && f.IsDir() ||
|
if !(m.Confx("dir_type") == "file" && f.IsDir() ||
|
||||||
m.Confx("dir_type") == "dir" && !f.IsDir()) {
|
m.Confx("dir_type") == "dir" && !f.IsDir()) {
|
||||||
for _, field := range fields {
|
for _, field := range fields {
|
||||||
@ -1009,6 +1010,9 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
|
|||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
"save": &ctx.Command{Name: "save file string...", Help: "保存文件, file: 保存的文件, string: 保存的内容", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
"save": &ctx.Command{Name: "save file string...", Help: "保存文件, file: 保存的文件, string: 保存的内容", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
|
if len(arg) == 1 && m.Has("data") {
|
||||||
|
arg = append(arg, m.Option("data"))
|
||||||
|
}
|
||||||
if p, f, e := open(m, arg[0], os.O_WRONLY|os.O_CREATE|os.O_TRUNC); m.Assert(e) {
|
if p, f, e := open(m, arg[0], os.O_WRONLY|os.O_CREATE|os.O_TRUNC); m.Assert(e) {
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
|
@ -283,9 +283,9 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
"componet_group": &ctx.Config{Name: "component_group", Value: "index", Help: "默认组件"},
|
"componet_group": &ctx.Config{Name: "component_group", Value: "index", Help: "默认组件"},
|
||||||
"componet": &ctx.Config{Name: "componet", Value: map[string]interface{}{
|
"componet": &ctx.Config{Name: "componet", Value: map[string]interface{}{
|
||||||
"index": []interface{}{
|
"index": []interface{}{
|
||||||
map[string]interface{}{"name": "head", "template": "head"},
|
map[string]interface{}{"componet_name": "head", "template": "head"},
|
||||||
map[string]interface{}{"name": "clipbaord", "help": "clipbaord", "template": "clipboard"},
|
map[string]interface{}{"componet_name": "clipbaord", "componet_help": "clipbaord", "template": "clipboard"},
|
||||||
map[string]interface{}{"name": "time", "help": "time", "template": "componet",
|
map[string]interface{}{"componet_name": "time", "componet_help": "time", "template": "componet",
|
||||||
"context": "cli", "command": "time", "arguments": []interface{}{"@string"},
|
"context": "cli", "command": "time", "arguments": []interface{}{"@string"},
|
||||||
"inputs": []interface{}{
|
"inputs": []interface{}{
|
||||||
map[string]interface{}{"type": "text", "name": "time_format",
|
map[string]interface{}{"type": "text", "name": "time_format",
|
||||||
@ -295,7 +295,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
map[string]interface{}{"type": "button", "label": "refresh"},
|
map[string]interface{}{"type": "button", "label": "refresh"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
map[string]interface{}{"name": "tail", "template": "tail"},
|
map[string]interface{}{"componet_name": "tail", "template": "tail"},
|
||||||
},
|
},
|
||||||
}, Help: "组件列表"},
|
}, Help: "组件列表"},
|
||||||
},
|
},
|
||||||
@ -617,8 +617,8 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
value := val.(map[string]interface{})
|
value := val.(map[string]interface{})
|
||||||
m.Add("append", "group", k)
|
m.Add("append", "group", k)
|
||||||
m.Add("append", "order", i)
|
m.Add("append", "order", i)
|
||||||
m.Add("append", "name", value["name"])
|
m.Add("append", "componet_name", value["componet_name"])
|
||||||
m.Add("append", "help", value["help"])
|
m.Add("append", "componet_help", value["componet_help"])
|
||||||
m.Add("append", "context", value["context"])
|
m.Add("append", "context", value["context"])
|
||||||
m.Add("append", "command", value["command"])
|
m.Add("append", "command", value["command"])
|
||||||
}
|
}
|
||||||
@ -628,8 +628,8 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
for i, val := range m.Confv("componet", arg[0]).([]interface{}) {
|
for i, val := range m.Confv("componet", arg[0]).([]interface{}) {
|
||||||
value := val.(map[string]interface{})
|
value := val.(map[string]interface{})
|
||||||
m.Add("append", "order", i)
|
m.Add("append", "order", i)
|
||||||
m.Add("append", "name", value["name"])
|
m.Add("append", "componet_name", value["componet_name"])
|
||||||
m.Add("append", "help", value["help"])
|
m.Add("append", "componet_help", value["componet_help"])
|
||||||
m.Add("append", "context", value["context"])
|
m.Add("append", "context", value["context"])
|
||||||
m.Add("append", "command", value["command"])
|
m.Add("append", "command", value["command"])
|
||||||
}
|
}
|
||||||
@ -647,7 +647,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
m.Confv("componet", []interface{}{arg[0], arg[1]}, map[string]interface{}{
|
m.Confv("componet", []interface{}{arg[0], arg[1]}, map[string]interface{}{
|
||||||
"name": arg[2], "help": arg[3],
|
"componet_name": arg[2], "componet_help": arg[3],
|
||||||
"context": m.Confx("componet_context", arg, 4),
|
"context": m.Confx("componet_context", arg, 4),
|
||||||
"command": m.Confx("componet_command", arg, 5),
|
"command": m.Confx("componet_command", arg, 5),
|
||||||
})
|
})
|
||||||
@ -742,13 +742,13 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
for count := 0; count == 0; group, order, right = "login", "", true {
|
for count := 0; count == 0; group, order, right = "login", "", true {
|
||||||
for _, v := range m.Confv("componet", group).([]interface{}) {
|
for _, v := range m.Confv("componet", group).([]interface{}) {
|
||||||
val := v.(map[string]interface{})
|
val := v.(map[string]interface{})
|
||||||
if order != "" && val["name"].(string) != order {
|
if order != "" && val["componet_name"].(string) != order {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
order_right := right
|
order_right := right
|
||||||
if !order_right && login != nil {
|
if !order_right && login != nil {
|
||||||
if role := login.Confv("right", []interface{}{group, val["name"], "right", "role"}); role != nil && role.(string) == "share" {
|
if role := login.Confv("right", []interface{}{group, val["componet_name"], "right", "role"}); role != nil && role.(string) == "share" {
|
||||||
order_right = true
|
order_right = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -770,7 +770,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
}
|
}
|
||||||
count++
|
count++
|
||||||
|
|
||||||
msg.Option("componet_order", val["name"].(string))
|
msg.Option("componet_order", val["componet_name"].(string))
|
||||||
|
|
||||||
for k, v := range val {
|
for k, v := range val {
|
||||||
if msg.Option(k) != "" {
|
if msg.Option(k) != "" {
|
||||||
@ -823,7 +823,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
}
|
}
|
||||||
|
|
||||||
if msg.Appends("directory") {
|
if msg.Appends("directory") {
|
||||||
m.Append("page_redirect", fmt.Sprintf("/download?file=%s", msg.Append("directory")))
|
m.Append("page_redirect", fmt.Sprintf("/download/%s", msg.Append("directory")))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,11 +22,11 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
|||||||
"componet_group": &ctx.Config{Name: "component_group", Value: "index", Help: "默认组件"},
|
"componet_group": &ctx.Config{Name: "component_group", Value: "index", Help: "默认组件"},
|
||||||
"componet": &ctx.Config{Name: "componet", Value: map[string]interface{}{
|
"componet": &ctx.Config{Name: "componet", Value: map[string]interface{}{
|
||||||
"login": []interface{}{
|
"login": []interface{}{
|
||||||
map[string]interface{}{"name": "head", "template": "head"},
|
map[string]interface{}{"componet_name": "head", "template": "head"},
|
||||||
map[string]interface{}{"name": "userinfo", "help": "userinfo",
|
map[string]interface{}{"componet_name": "userinfo", "componet_help": "userinfo",
|
||||||
"context": "aaa", "command": "userinfo", "arguments": []interface{}{"@sessid"},
|
"context": "aaa", "command": "userinfo", "arguments": []interface{}{"@sessid"},
|
||||||
},
|
},
|
||||||
map[string]interface{}{"name": "login", "help": "login", "template": "componet",
|
map[string]interface{}{"componet_name": "login", "componet_help": "login", "template": "componet",
|
||||||
"context": "aaa", "command": "login", "arguments": []interface{}{"@username", "@password"},
|
"context": "aaa", "command": "login", "arguments": []interface{}{"@username", "@password"},
|
||||||
"inputs": []interface{}{
|
"inputs": []interface{}{
|
||||||
map[string]interface{}{"type": "text", "name": "username", "label": "username"},
|
map[string]interface{}{"type": "text", "name": "username", "label": "username"},
|
||||||
@ -35,12 +35,12 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
|||||||
},
|
},
|
||||||
"display_append": "", "display_result": "", "result_reload": "10",
|
"display_append": "", "display_result": "", "result_reload": "10",
|
||||||
},
|
},
|
||||||
map[string]interface{}{"name": "tail", "template": "tail"},
|
map[string]interface{}{"componet_name": "tail", "template": "tail"},
|
||||||
},
|
},
|
||||||
"index": []interface{}{
|
"index": []interface{}{
|
||||||
map[string]interface{}{"name": "head", "template": "head"},
|
map[string]interface{}{"componet_name": "head", "template": "head"},
|
||||||
map[string]interface{}{"name": "clipbaord", "help": "clipbaord", "template": "clipboard"},
|
map[string]interface{}{"componet_name": "clipbaord", "componet_help": "clipbaord", "template": "clipboard"},
|
||||||
map[string]interface{}{"name": "buffer", "help": "buffer", "template": "componet",
|
map[string]interface{}{"componet_name": "buffer", "componet_help": "buffer", "template": "componet",
|
||||||
"context": "cli", "command": "tmux", "arguments": []interface{}{"buffer"}, "inputs": []interface{}{
|
"context": "cli", "command": "tmux", "arguments": []interface{}{"buffer"}, "inputs": []interface{}{
|
||||||
map[string]interface{}{"type": "text", "name": "limit", "label": "limit", "value": "3"},
|
map[string]interface{}{"type": "text", "name": "limit", "label": "limit", "value": "3"},
|
||||||
map[string]interface{}{"type": "text", "name": "index", "label": "index"},
|
map[string]interface{}{"type": "text", "name": "index", "label": "index"},
|
||||||
@ -48,7 +48,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
|||||||
},
|
},
|
||||||
"pre_run": true,
|
"pre_run": true,
|
||||||
},
|
},
|
||||||
map[string]interface{}{"name": "time", "help": "time", "template": "componet",
|
map[string]interface{}{"componet_name": "time", "componet_help": "time", "template": "componet",
|
||||||
"context": "cli", "command": "time", "arguments": []interface{}{"@string"},
|
"context": "cli", "command": "time", "arguments": []interface{}{"@string"},
|
||||||
"inputs": []interface{}{
|
"inputs": []interface{}{
|
||||||
map[string]interface{}{"type": "text", "name": "time_format",
|
map[string]interface{}{"type": "text", "name": "time_format",
|
||||||
@ -58,25 +58,14 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
|||||||
map[string]interface{}{"type": "button", "label": "refresh"},
|
map[string]interface{}{"type": "button", "label": "refresh"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
map[string]interface{}{"name": "time", "help": "time", "template": "componet",
|
map[string]interface{}{"componet_name": "json", "componet_help": "json", "template": "componet",
|
||||||
"context": "cli", "command": "time", "arguments": []interface{}{"@string"},
|
|
||||||
"file_name": "nice-2006-01-02_1504.txt",
|
|
||||||
"inputs": []interface{}{
|
|
||||||
map[string]interface{}{"type": "text", "name": "time_format",
|
|
||||||
"label": "format", "value": "2006-01-02 15:04:05",
|
|
||||||
},
|
|
||||||
map[string]interface{}{"type": "text", "name": "string", "label": "string"},
|
|
||||||
map[string]interface{}{"type": "button", "label": "refresh"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
map[string]interface{}{"name": "json", "help": "json", "template": "componet",
|
|
||||||
"context": "nfs", "command": "json", "arguments": []interface{}{"@string"},
|
"context": "nfs", "command": "json", "arguments": []interface{}{"@string"},
|
||||||
"inputs": []interface{}{
|
"inputs": []interface{}{
|
||||||
map[string]interface{}{"type": "text", "name": "string", "label": "string"},
|
map[string]interface{}{"type": "text", "name": "string", "label": "string"},
|
||||||
map[string]interface{}{"type": "button", "label": "refresh"},
|
map[string]interface{}{"type": "button", "label": "refresh"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
map[string]interface{}{"name": "dir", "help": "dir", "template": "componet",
|
map[string]interface{}{"componet_name": "dir", "componet_help": "dir", "template": "componet",
|
||||||
"context": "nfs", "command": "dir", "arguments": []interface{}{"@dir", "dir_sort", "@sort_order", "@sort_field"},
|
"context": "nfs", "command": "dir", "arguments": []interface{}{"@dir", "dir_sort", "@sort_order", "@sort_field"},
|
||||||
"pre_run": true, "display_result": "",
|
"pre_run": true, "display_result": "",
|
||||||
"inputs": []interface{}{
|
"inputs": []interface{}{
|
||||||
@ -109,7 +98,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
|||||||
map[string]interface{}{"type": "text", "name": "dir", "label": "dir"},
|
map[string]interface{}{"type": "text", "name": "dir", "label": "dir"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
map[string]interface{}{"name": "upload", "help": "upload", "template": "componet",
|
map[string]interface{}{"componet_name": "upload", "componet_help": "upload", "template": "componet",
|
||||||
"context": "web", "command": "upload", "form_type": "upload",
|
"context": "web", "command": "upload", "form_type": "upload",
|
||||||
"inputs": []interface{}{
|
"inputs": []interface{}{
|
||||||
map[string]interface{}{"type": "file", "name": "upload"},
|
map[string]interface{}{"type": "file", "name": "upload"},
|
||||||
@ -117,24 +106,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
|||||||
},
|
},
|
||||||
"display_result": "",
|
"display_result": "",
|
||||||
},
|
},
|
||||||
map[string]interface{}{"name": "command", "help": "command", "template": "componet",
|
map[string]interface{}{"componet_name": "download", "componet_help": "download", "template": "componet",
|
||||||
"context": "cli.shy", "command": "source", "arguments": []interface{}{"@cmd"},
|
|
||||||
"inputs": []interface{}{
|
|
||||||
map[string]interface{}{"type": "text", "name": "cmd", "value": "",
|
|
||||||
"class": "cmd", "clipstack": "clistack",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
map[string]interface{}{"name": "command_result", "help": "command_result", "template": "componet",
|
|
||||||
"context": "cli.shy", "command": "source", "arguments": []interface{}{"@cmd"},
|
|
||||||
"display_result": "", "file_name": "result_2006_0102_1504.txt",
|
|
||||||
"inputs": []interface{}{
|
|
||||||
map[string]interface{}{"type": "text", "name": "cmd", "value": "",
|
|
||||||
"class": "cmd", "clipstack": "clistack",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
map[string]interface{}{"name": "command_append", "help": "command_append", "template": "componet",
|
|
||||||
"context": "cli.shy", "command": "source", "arguments": []interface{}{"@cmd"},
|
"context": "cli.shy", "command": "source", "arguments": []interface{}{"@cmd"},
|
||||||
"display_result": "", "file_name": "",
|
"display_result": "", "file_name": "",
|
||||||
"inputs": []interface{}{
|
"inputs": []interface{}{
|
||||||
@ -144,7 +116,46 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
map[string]interface{}{"name": "develop", "help": "develop", "template": "componet",
|
map[string]interface{}{"componet_name": "ctx", "componet_help": "ctx", "template": "componet",
|
||||||
|
"context": "cli.shy", "command": "context", "arguments": []interface{}{"@ctx", "list"},
|
||||||
|
"display_result": "",
|
||||||
|
"inputs": []interface{}{
|
||||||
|
map[string]interface{}{"type": "text", "name": "ctx", "value": "shy"},
|
||||||
|
map[string]interface{}{"type": "button", "label": "refresh"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
map[string]interface{}{"componet_name": "command", "componet_help": "command", "template": "componet",
|
||||||
|
"context": "cli.shy", "command": "source", "arguments": []interface{}{"@cmd"},
|
||||||
|
"inputs": []interface{}{
|
||||||
|
map[string]interface{}{"type": "text", "name": "cmd", "value": "",
|
||||||
|
"class": "cmd", "clipstack": "clistack",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
map[string]interface{}{"componet_name": "command1", "componet_help": "command1", "template": "componet",
|
||||||
|
"context": "cli.shy", "command": "source", "arguments": []interface{}{"@cmd"},
|
||||||
|
"inputs": []interface{}{
|
||||||
|
map[string]interface{}{"type": "text", "name": "cmd", "value": "",
|
||||||
|
"class": "cmd", "clipstack": "clistack",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
map[string]interface{}{"componet_name": "command2", "componet_help": "command2", "template": "componet",
|
||||||
|
"context": "cli.shy", "command": "source", "arguments": []interface{}{"@cmd"},
|
||||||
|
"inputs": []interface{}{
|
||||||
|
map[string]interface{}{"type": "text", "name": "cmd", "value": "",
|
||||||
|
"class": "cmd", "clipstack": "clistack",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
map[string]interface{}{"componet_name": "command_list", "componet_help": "command_list", "template": "componet",
|
||||||
|
"context": "cli", "command": "config", "arguments": []interface{}{"source_list"},
|
||||||
|
"pre_run": true, "display_result": "",
|
||||||
|
"inputs": []interface{}{
|
||||||
|
map[string]interface{}{"type": "button", "label": "refresh"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
map[string]interface{}{"componet_name": "develop", "componet_help": "develop", "template": "componet",
|
||||||
"context": "web.code", "command": "config", "arguments": []interface{}{"counter"},
|
"context": "web.code", "command": "config", "arguments": []interface{}{"counter"},
|
||||||
"inputs": []interface{}{
|
"inputs": []interface{}{
|
||||||
map[string]interface{}{"type": "button", "label": "refresh"},
|
map[string]interface{}{"type": "button", "label": "refresh"},
|
||||||
@ -152,7 +163,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
|||||||
"pre_run": true,
|
"pre_run": true,
|
||||||
"display_result": "",
|
"display_result": "",
|
||||||
},
|
},
|
||||||
map[string]interface{}{"name": "windows", "help": "windows", "template": "componet",
|
map[string]interface{}{"componet_name": "windows", "componet_help": "windows", "template": "componet",
|
||||||
"context": "cli", "command": "windows",
|
"context": "cli", "command": "windows",
|
||||||
"inputs": []interface{}{
|
"inputs": []interface{}{
|
||||||
map[string]interface{}{"type": "button", "label": "refresh"},
|
map[string]interface{}{"type": "button", "label": "refresh"},
|
||||||
@ -160,7 +171,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
|||||||
"pre_run": true,
|
"pre_run": true,
|
||||||
"display_result": "",
|
"display_result": "",
|
||||||
},
|
},
|
||||||
map[string]interface{}{"name": "runtime", "help": "runtime", "template": "componet",
|
map[string]interface{}{"componet_name": "runtime", "componet_help": "runtime", "template": "componet",
|
||||||
"context": "cli", "command": "runtime",
|
"context": "cli", "command": "runtime",
|
||||||
"inputs": []interface{}{
|
"inputs": []interface{}{
|
||||||
map[string]interface{}{"type": "button", "label": "refresh"},
|
map[string]interface{}{"type": "button", "label": "refresh"},
|
||||||
@ -168,7 +179,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
|||||||
"pre_run": true,
|
"pre_run": true,
|
||||||
"display_result": "",
|
"display_result": "",
|
||||||
},
|
},
|
||||||
map[string]interface{}{"name": "sysinfo", "help": "sysinfo", "template": "componet",
|
map[string]interface{}{"componet_name": "sysinfo", "componet_help": "sysinfo", "template": "componet",
|
||||||
"context": "cli", "command": "sysinfo",
|
"context": "cli", "command": "sysinfo",
|
||||||
"inputs": []interface{}{
|
"inputs": []interface{}{
|
||||||
map[string]interface{}{"type": "button", "label": "refresh"},
|
map[string]interface{}{"type": "button", "label": "refresh"},
|
||||||
@ -176,7 +187,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
|||||||
"pre_run": true,
|
"pre_run": true,
|
||||||
"display_result": "",
|
"display_result": "",
|
||||||
},
|
},
|
||||||
map[string]interface{}{"name": "tail", "template": "tail"},
|
map[string]interface{}{"componet_name": "tail", "template": "tail"},
|
||||||
},
|
},
|
||||||
}, Help: "组件列表"},
|
}, Help: "组件列表"},
|
||||||
},
|
},
|
||||||
|
@ -22,12 +22,13 @@ function send_command(form, cb) {
|
|||||||
msg = msg[0]
|
msg = msg[0]
|
||||||
|
|
||||||
var result = document.querySelector("code.result."+data["componet_name"]+" pre")
|
var result = document.querySelector("code.result."+data["componet_name"]+" pre")
|
||||||
result && (result.innerHTML = (msg.result || []).join(""))
|
|
||||||
|
|
||||||
var append = document.querySelector("table.append."+data["componet_name"])
|
var append = document.querySelector("table.append."+data["componet_name"])
|
||||||
append && (append.innerHTML = "")
|
if (msg && (msg.append || msg.result)) {
|
||||||
|
result && (result.innerHTML = (msg.result || []).join(""))
|
||||||
|
append && (append.innerHTML = "")
|
||||||
|
}
|
||||||
|
|
||||||
if (append && msg.append) {
|
if (append && msg && msg.append) {
|
||||||
var tr = append_child(append, "tr")
|
var tr = append_child(append, "tr")
|
||||||
for (var i in msg.append) {
|
for (var i in msg.append) {
|
||||||
append_child(tr, "th", msg.append[i])
|
append_child(tr, "th", msg.append[i])
|
||||||
@ -218,7 +219,13 @@ function init_append(event) {
|
|||||||
}
|
}
|
||||||
function init_result(event) {
|
function init_result(event) {
|
||||||
var result = document.querySelectorAll("code.result pre").forEach(function(item) {
|
var result = document.querySelectorAll("code.result pre").forEach(function(item) {
|
||||||
|
item.onselect = function(event) {
|
||||||
|
console.log(event)
|
||||||
|
|
||||||
|
}
|
||||||
item.onclick = function(event) {
|
item.onclick = function(event) {
|
||||||
|
console.log(event)
|
||||||
|
return
|
||||||
copy_to_clipboard(event.target.innerText)
|
copy_to_clipboard(event.target.innerText)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -284,7 +291,11 @@ function init_download(event) {
|
|||||||
if (event.target.tagName == "TD") {
|
if (event.target.tagName == "TD") {
|
||||||
copy_to_clipboard(event.target.innerText.trim())
|
copy_to_clipboard(event.target.innerText.trim())
|
||||||
var name = event.target.innerText.trim()
|
var name = event.target.innerText.trim()
|
||||||
option["dir"].value += name
|
if (option["dir"].value && !option["dir"].value.endsWith("/")) {
|
||||||
|
option["dir"].value += "/"+name
|
||||||
|
} else {
|
||||||
|
option["dir"].value += name
|
||||||
|
}
|
||||||
if (name.endsWith("/")) {
|
if (name.endsWith("/")) {
|
||||||
context.Cookie("download_dir", option["dir"].value)
|
context.Cookie("download_dir", option["dir"].value)
|
||||||
}
|
}
|
||||||
@ -306,6 +317,59 @@ function init_download(event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
send_command(option, function(){
|
||||||
|
option["dir"].value = context.Cookie("download_dir")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function init_context() {
|
||||||
|
var append = document.querySelector("table.append.ctx")
|
||||||
|
var option = document.querySelector("form.option.ctx")
|
||||||
|
insert_before(append, "input", {
|
||||||
|
"type": "button",
|
||||||
|
"value": "ctx",
|
||||||
|
"onclick": function(event) {
|
||||||
|
option["ctx"].value = "ctx"
|
||||||
|
send_command(option)
|
||||||
|
context.Cookie("current_ctx", option["ctx"].value)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
insert_before(append, "input", {
|
||||||
|
"type": "button",
|
||||||
|
"value": "shy",
|
||||||
|
"onclick": function(event) {
|
||||||
|
option["ctx"].value = "shy"
|
||||||
|
send_command(option)
|
||||||
|
context.Cookie("current_ctx", option["ctx"].value)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
insert_before(append, "input", {
|
||||||
|
"type": "button",
|
||||||
|
"value": "mdb",
|
||||||
|
"onclick": function(event) {
|
||||||
|
option["ctx"].value = "mdb"
|
||||||
|
send_command(option)
|
||||||
|
context.Cookie("current_ctx", option["ctx"].value)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
option["ctx"].value = context.Cookie("current_ctx")
|
||||||
|
send_command(option)
|
||||||
|
|
||||||
|
append.onchange = append.onclick = function(event) {
|
||||||
|
console.log(event)
|
||||||
|
if (event.target.tagName == "TD") {
|
||||||
|
var name = event.target.innerText.trim()
|
||||||
|
copy_to_clipboard(name)
|
||||||
|
option["ctx"].value = name
|
||||||
|
context.Cookie("current_ctx", option["ctx"].value)
|
||||||
|
} else if (event.target.tagName == "TH") {
|
||||||
|
}
|
||||||
|
|
||||||
send_command(option)
|
send_command(option)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -315,4 +379,5 @@ window.onload = function() {
|
|||||||
init_append()
|
init_append()
|
||||||
init_result()
|
init_result()
|
||||||
init_download()
|
init_download()
|
||||||
|
init_context()
|
||||||
}
|
}
|
||||||
|
@ -118,18 +118,18 @@
|
|||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{define "componet"}}
|
{{define "componet"}}
|
||||||
<fieldset><legend title="{{option .Meta "help"}}">{{option .Meta "help"}}({{option .Meta "context"}}.{{option .Meta "command"}})</legend>
|
<fieldset><legend title="{{option .Meta "componet_help"}}">{{option .Meta "componet_help"}}({{option .Meta "context"}}.{{option .Meta "command"}})</legend>
|
||||||
{{$form_type := option . "form_type"|meta}}
|
{{$form_type := option . "form_type"|meta}}
|
||||||
|
|
||||||
{{if eq $form_type "upload"}}
|
{{if eq $form_type "upload"}}
|
||||||
{{end}}
|
{{end}}
|
||||||
<form class="option {{option .Meta "name"}}"
|
<form class="option {{option .Meta "componet_name"}}"
|
||||||
data-last_componet_group="{{option . "last_componet_group"|meta}}"
|
data-last_componet_group="{{option . "last_componet_group"|meta}}"
|
||||||
data-last_componet_order="{{option . "last_componet_order"|meta}}"
|
data-last_componet_order="{{option . "last_componet_order"|meta}}"
|
||||||
data-componet_group="{{option . "componet_group"|meta}}"
|
data-componet_group="{{option . "componet_group"|meta}}"
|
||||||
data-componet_order="{{option . "componet_order"|meta}}"
|
data-componet_order="{{option . "componet_order"|meta}}"
|
||||||
data-componet_name="{{option . "name"|meta}}"
|
data-componet_name="{{option . "componet_name"|meta}}"
|
||||||
data-componet_help="{{option . "help"|meta}}"
|
data-componet_help="{{option . "componet_help"|meta}}"
|
||||||
{{if eq $form_type "upload"}}
|
{{if eq $form_type "upload"}}
|
||||||
method="POST" action="/upload" enctype="multipart/form-data"
|
method="POST" action="/upload" enctype="multipart/form-data"
|
||||||
onsubmit="onaction(event,'upload')"
|
onsubmit="onaction(event,'upload')"
|
||||||
@ -183,7 +183,7 @@
|
|||||||
{{if index .Meta "display_append"}}
|
{{if index .Meta "display_append"}}
|
||||||
{{option .Meta "display_append"}}
|
{{option .Meta "display_append"}}
|
||||||
{{else}}
|
{{else}}
|
||||||
<table class="append {{option .Meta "name"}}">
|
<table class="append {{option .Meta "componet_name"}}">
|
||||||
{{$msg := .}}
|
{{$msg := .}}
|
||||||
<tr>{{range $field := append .}}<th>{{$field}}</th>{{end}}</tr>
|
<tr>{{range $field := append .}}<th>{{$field}}</th>{{end}}</tr>
|
||||||
{{range $line := table .}}
|
{{range $line := table .}}
|
||||||
@ -195,7 +195,7 @@
|
|||||||
{{if index .Meta "display_result"}}
|
{{if index .Meta "display_result"}}
|
||||||
{{option .Meta "display_result"}}
|
{{option .Meta "display_result"}}
|
||||||
{{else}}
|
{{else}}
|
||||||
<code class="result {{option .Meta "name"}}"><pre>{{result .Meta}}</pre></code>
|
<code class="result {{option .Meta "componet_name"}}"><pre>{{result .Meta}}</pre></code>
|
||||||
{{end}}
|
{{end}}
|
||||||
</fieldset>
|
</fieldset>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user