1
0
forked from x/ContextOS

tce add componet.ctx

This commit is contained in:
shaoying 2018-11-11 22:56:30 +08:00
parent 1b86db71df
commit dbe0234629
9 changed files with 125 additions and 53 deletions

View File

@ -150,8 +150,9 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
"shy": "source",
}, Help: "系统命令超时"},
"cmd_timeout": &ctx.Config{Name: "cmd_timeout", Value: "60s", Help: "系统命令超时"},
"source_list": &ctx.Config{Name: "source_list", Value: []interface{}{}, Help: "系统命令超时"},
"system_env": &ctx.Config{Name: "system_env", Value: map[string]interface{}{}, Help: "系统命令超时"},
"cmd_timeout": &ctx.Config{Name: "cmd_timeout", Value: "60s", Help: "系统命令超时"},
"cmd_combine": &ctx.Config{Name: "cmd_combine", Value: map[string]interface{}{
"vi": map[string]interface{}{"active": true},
"top": map[string]interface{}{"active": true},
@ -614,8 +615,9 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
}
m.Confv("source_list", -1, map[string]interface{}{
"source_word": strings.Join(arg, " "),
"source_time": m.Time(),
"source_ctx": m.Option("current_ctx"),
"source_cmd": strings.Join(arg, " "),
})
if m.Options("current_ctx") {
@ -638,7 +640,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
}},
"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)
msg := m.Spawn(c).Cmd("cmd", name, arg[1:])
m.Copy(msg, "append").Copy(msg, "result")
}},
@ -751,7 +753,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
}},
"system": &ctx.Command{Name: "system word...", Help: []string{"调用系统命令, word: 命令",
"cmd_active(true/false): 是否交互", "cmd_timeout: 命令超时", "cmd_env: 环境变量", "cmd_dir: 工作目录"},
Form: map[string]int{"cmd_active": 1, "cmd_timeout": 1, "cmd_env": 2, "cmd_dir": 1},
Form: map[string]int{"cmd_active": 1, "cmd_timeout": 1, "cmd_env": 2, "cmd_dir": 1, "cmd_error": 0},
Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
conf := map[string]interface{}{}
if m.Confv("cmd_combine", arg[0]) != nil {
@ -778,6 +780,10 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
if conf["path"] != nil {
cmd.Path = m.Parse(conf["path"])
}
for k, v := range m.Confv("system_env").(map[string]interface{}) {
cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", k, m.Parse(v)))
}
if conf["env"] != nil {
for k, v := range conf["env"].(map[string]interface{}) {
cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", k, m.Parse(v)))
@ -786,6 +792,11 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
for i := 0; i < len(m.Meta["cmd_env"])-1; i += 2 {
cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", m.Meta["cmd_env"][i], m.Parse(m.Meta["cmd_env"][i+1])))
}
m.Log("info", "cmd.env %v", cmd.Env)
for _, v := range os.Environ() {
cmd.Env = append(cmd.Env, v)
}
if conf["dir"] != nil {
cmd.Dir = m.Parse(conf["dir"])
}
@ -803,11 +814,20 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
} else {
wait := make(chan bool, 1)
go func() {
if out, e := cmd.CombinedOutput(); e != nil {
m.Echo("error: ").Echo("%s\n", e)
m.Echo("%s\n", string(out))
if m.Has("cmd_error") {
if out, e := cmd.CombinedOutput(); e != nil {
m.Echo("error: ").Echo("%s\n", e)
m.Echo("%s\n", string(out))
} else {
m.Echo(string(out))
}
} else {
m.Echo(string(out))
if out, e := cmd.Output(); e != nil {
m.Echo("error: ").Echo("%s\n", e)
m.Echo("%s\n", string(out))
} else {
m.Echo(string(out))
}
}
wait <- true
}()

View File

@ -861,7 +861,6 @@ func (m *Message) Sess(key string, arg ...interface{}) *Message {
return nil
}
func (m *Message) Call(cb func(msg *Message) (sub *Message), arg ...interface{}) *Message {
m.Log("fuck", "arg --- %v", arg)
if m.callback = cb; len(arg) > 0 || len(m.Meta["detail"]) > 0 {
m.Cmd(arg...)
}
@ -2867,6 +2866,9 @@ var Index = &Context{Name: "ctx", Help: "模块中心",
})
m.Table()
case "list":
if m.Cap("list_count") == "" {
break
}
begin, end := 0, m.Capi("list_count")
if len(arg) > 0 {
if n, e := strconv.Atoi(arg[0]); e == nil {
@ -3051,7 +3053,7 @@ var Index = &Context{Name: "ctx", Help: "模块中心",
// f, e := os.Create(which)
// m.Assert(e)
// defer f.Close()
//
//
buf, e := json.MarshalIndent(save, "", " ")
m.Assert(e)
m.Sess("nfs").Add("option", "data", string(buf)).Cmd("save", which)

View File

@ -195,7 +195,7 @@ var Index = &ctx.Context{Name: "mdb", Help: "数据中心",
}},
"show": &ctx.Command{Name: "show table fields...",
Help: "查询数据库, table: 表名, fields: 字段, where: 查询条件, group: 聚合字段, order: 排序字段",
Form: map[string]int{"where": 1, "group": 1, "order": 1, "limit": 1, "offset": 1, "other": -1,
Form: map[string]int{"where": 1, "group": 1, "desc": 0, "order": 1, "limit": 1, "offset": 1, "other": -1,
"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) {
if _, ok := m.Target().Server.(*MDB); m.Assert(ok) {
@ -224,6 +224,9 @@ var Index = &ctx.Context{Name: "mdb", Help: "数据中心",
where := m.Confx("where", m.Option("where"), "where %s")
group := m.Confx("group", m.Option("group"), "group by %s")
order := m.Confx("order", m.Option("order"), "order by %s")
if m.Has("desc") {
order = order + " desc"
}
limit := m.Confx("limit", m.Option("limit"), "limit %s")
offset := m.Confx("offset", m.Option("offset"), "offset %s")

View File

@ -1039,8 +1039,6 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
_, f, e := open(m, name, os.O_WRONLY|os.O_CREATE|os.O_TRUNC)
m.Assert(e)
defer f.Close()
m.Log("fuck", "what %v", name)
m.Log("fuck", "what %v", m.Meta)
switch {
case strings.HasSuffix(arg[0], ".json"):
@ -1081,8 +1079,6 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
f.WriteString(v)
}
}
m.Log("fuck", "what %v", name)
m.Log("fuck", "what %v", m.Meta)
m.Set("append").Set("result").Echo(name)
}},

View File

@ -286,7 +286,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
map[string]interface{}{"componet_name": "head", "template": "head"},
map[string]interface{}{"componet_name": "clipbaord", "componet_help": "clipbaord", "template": "clipboard"},
map[string]interface{}{"componet_name": "time", "componet_help": "time", "template": "componet",
"context": "cli", "command": "time", "arguments": []interface{}{"@string"},
"context": "cli", "componet_cmd": "time", "arguments": []interface{}{"@string"},
"inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "time_format",
"label": "format", "value": "2006-01-02 15:04:05",
@ -620,7 +620,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
m.Add("append", "componet_name", value["componet_name"])
m.Add("append", "componet_help", value["componet_help"])
m.Add("append", "context", value["context"])
m.Add("append", "command", value["command"])
m.Add("append", "componet_cmd", value["componet_cmd"])
}
}
m.Sort("group").Table()
@ -631,7 +631,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
m.Add("append", "componet_name", value["componet_name"])
m.Add("append", "componet_help", value["componet_help"])
m.Add("append", "context", value["context"])
m.Add("append", "command", value["command"])
m.Add("append", "componet_cmd", value["componet_cmd"])
}
m.Table()
case 2:
@ -648,8 +648,8 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
} else {
m.Confv("componet", []interface{}{arg[0], arg[1]}, map[string]interface{}{
"componet_name": arg[2], "componet_help": arg[3],
"context": m.Confx("componet_context", arg, 4),
"command": m.Confx("componet_command", arg, 5),
"context": m.Confx("componet_context", arg, 4),
"componet_cmd": m.Confx("componet_command", arg, 5),
})
break
}
@ -806,8 +806,8 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
}
if order != "" || (val["pre_run"] != nil && val["pre_run"].(bool)) {
if val["command"] != nil {
msg.Cmd(val["command"], args)
if val["componet_cmd"] != nil {
msg.Cmd(val["componet_cmd"], args)
if msg.Options("file_name") {
m.Append("page_redirect", fmt.Sprintf("/download/%s",
msg.Sess("nfs").Copy(msg, "append").Copy(msg, "result").Cmd("export", msg.Option("file_name")).Result(0)))

View File

@ -24,10 +24,10 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
"login": []interface{}{
map[string]interface{}{"componet_name": "head", "template": "head"},
map[string]interface{}{"componet_name": "userinfo", "componet_help": "userinfo",
"context": "aaa", "command": "userinfo", "arguments": []interface{}{"@sessid"},
"context": "aaa", "componet_cmd": "userinfo", "arguments": []interface{}{"@sessid"},
},
map[string]interface{}{"componet_name": "login", "componet_help": "login", "template": "componet",
"context": "aaa", "command": "login", "arguments": []interface{}{"@username", "@password"},
"context": "aaa", "componet_cmd": "login", "arguments": []interface{}{"@username", "@password"},
"inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "username", "label": "username"},
map[string]interface{}{"type": "password", "name": "password", "label": "password"},
@ -41,7 +41,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
map[string]interface{}{"componet_name": "head", "template": "head"},
map[string]interface{}{"componet_name": "clipbaord", "componet_help": "clipbaord", "template": "clipboard"},
map[string]interface{}{"componet_name": "buffer", "componet_help": "buffer", "template": "componet",
"context": "cli", "command": "tmux", "arguments": []interface{}{"buffer"}, "inputs": []interface{}{
"context": "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"},
map[string]interface{}{"type": "button", "label": "refresh"},
@ -49,7 +49,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
"pre_run": true,
},
map[string]interface{}{"componet_name": "time", "componet_help": "time", "template": "componet",
"context": "cli", "command": "time", "arguments": []interface{}{"@string"},
"context": "cli", "componet_cmd": "time", "arguments": []interface{}{"@string"},
"inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "time_format",
"label": "format", "value": "2006-01-02 15:04:05",
@ -59,14 +59,14 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
},
},
map[string]interface{}{"componet_name": "json", "componet_help": "json", "template": "componet",
"context": "nfs", "command": "json", "arguments": []interface{}{"@string"},
"context": "nfs", "componet_cmd": "json", "arguments": []interface{}{"@string"},
"inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "string", "label": "string"},
map[string]interface{}{"type": "button", "label": "refresh"},
},
},
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", "componet_cmd": "dir", "arguments": []interface{}{"@dir", "dir_sort", "@sort_order", "@sort_field"},
"pre_run": true, "display_result": "",
"inputs": []interface{}{
map[string]interface{}{"type": "choice", "name": "dir_type",
@ -99,7 +99,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
},
},
map[string]interface{}{"componet_name": "upload", "componet_help": "upload", "template": "componet",
"context": "web", "command": "upload", "form_type": "upload",
"context": "web", "componet_cmd": "upload", "form_type": "upload",
"inputs": []interface{}{
map[string]interface{}{"type": "file", "name": "upload"},
map[string]interface{}{"type": "submit", "value": "submit"},
@ -107,7 +107,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
"display_result": "",
},
map[string]interface{}{"componet_name": "download", "componet_help": "download", "template": "componet",
"context": "cli.shy", "command": "source", "arguments": []interface{}{"@cmd"},
"context": "cli.shy", "componet_cmd": "source", "arguments": []interface{}{"@cmd"},
"display_result": "", "file_name": "",
"inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "file_name", "value": "data_2006_0102_1504.txt", "class": "file_name"},
@ -116,16 +116,8 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
},
},
},
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"},
"context": "cli.shy", "componet_cmd": "source", "arguments": []interface{}{"@cmd"},
"inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "cmd", "value": "",
"class": "cmd", "clipstack": "clistack",
@ -133,7 +125,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
},
},
map[string]interface{}{"componet_name": "command1", "componet_help": "command1", "template": "componet",
"context": "cli.shy", "command": "source", "arguments": []interface{}{"@cmd"},
"context": "cli.shy", "componet_cmd": "source", "arguments": []interface{}{"@cmd"},
"inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "cmd", "value": "",
"class": "cmd", "clipstack": "clistack",
@ -141,22 +133,37 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
},
},
map[string]interface{}{"componet_name": "command2", "componet_help": "command2", "template": "componet",
"context": "cli.shy", "command": "source", "arguments": []interface{}{"@cmd"},
"context": "cli.shy", "componet_cmd": "source", "arguments": []interface{}{"@cmd"},
"inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "cmd", "value": "",
"class": "cmd", "clipstack": "clistack",
},
},
},
map[string]interface{}{"componet_name": "ctx", "componet_help": "ctx", "template": "componet",
"context": "cli.shy", "componet_cmd": "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": "cmd", "componet_help": "cmd", "template": "componet",
"context": "cli.shy", "componet_cmd": "context", "arguments": []interface{}{"@current_ctx", "command", "list"},
"pre_run": true, "display_result": "",
"inputs": []interface{}{
map[string]interface{}{"type": "button", "label": "refresh"},
},
},
map[string]interface{}{"componet_name": "command_list", "componet_help": "command_list", "template": "componet",
"context": "cli", "command": "config", "arguments": []interface{}{"source_list"},
"context": "cli", "componet_cmd": "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", "componet_cmd": "config", "arguments": []interface{}{"counter"},
"inputs": []interface{}{
map[string]interface{}{"type": "button", "label": "refresh"},
},
@ -164,7 +171,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
"display_result": "",
},
map[string]interface{}{"componet_name": "windows", "componet_help": "windows", "template": "componet",
"context": "cli", "command": "windows",
"context": "cli", "componet_cmd": "windows",
"inputs": []interface{}{
map[string]interface{}{"type": "button", "label": "refresh"},
},
@ -172,7 +179,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
"display_result": "",
},
map[string]interface{}{"componet_name": "runtime", "componet_help": "runtime", "template": "componet",
"context": "cli", "command": "runtime",
"context": "cli", "componet_cmd": "runtime",
"inputs": []interface{}{
map[string]interface{}{"type": "button", "label": "refresh"},
},
@ -180,7 +187,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
"display_result": "",
},
map[string]interface{}{"componet_name": "sysinfo", "componet_help": "sysinfo", "template": "componet",
"context": "cli", "command": "sysinfo",
"context": "cli", "componet_cmd": "sysinfo",
"inputs": []interface{}{
map[string]interface{}{"type": "button", "label": "refresh"},
},

View File

@ -213,7 +213,6 @@ var Index = &ctx.Context{Name: "wiki", Help: "文档中心",
"modify_time": m.Option("modify_time"),
})
default:
m.Log("fuck", "5")
}
ls = markdown.ToHTML(ls, nil, nil)

View File

@ -156,11 +156,17 @@ function onaction(event, action) {
default:
console.log(event)
if (event.target.dataset["last_char"] == "j" && event.key == "k") {
if (event.target.value) {
event.target.value = ""
} else {
event.target.blur()
}
event.target.value = event.target.value.substr(0, event.target.value.length-2)
check_argument(event.target.form, event.target)
event.target.dataset["history"] = JSON.stringify(history)
event.target.dataset["history_last"] = history.length-1
console.log(history.length)
break
// if (event.target.value) {
// event.target.value = ""
// } else {
// event.target.blur()
// }
}
event.target.dataset["last_char"] = event.key
}
@ -296,6 +302,14 @@ function init_download(event) {
} else {
option["dir"].value += name
}
if (name.endsWith(".py")) {
var cmd = document.querySelector("form.option.command input[name=cmd]")
cmd.value = "run "+ name
cmd.focus()
if (!event.altKey) {
return
}
}
if (name.endsWith("/")) {
context.Cookie("download_dir", option["dir"].value)
}
@ -373,6 +387,36 @@ function init_context() {
send_command(option)
}
}
function init_context() {
var append = document.querySelector("table.append.command")
var option = document.querySelector("form.option.command")
insert_before(append, "input", {
"type": "button",
"value": "clear",
"onclick": function(event) {
option["cmd"].value = ""
return true
}
})
insert_before(append, "input", {
"type": "button",
"value": "exec",
"onclick": function(event) {
send_command(option)
return true
}
})
insert_before(append, "input", {
"type": "button",
"value": "online",
"onclick": function(event) {
option["cmd"].value += " cmd_env IS_PROD_RUNTIME 1"
send_command(option)
option["cmd"].focus()
return true
}
})
}
window.onload = function() {
init_option()
@ -380,4 +424,5 @@ window.onload = function() {
init_result()
init_download()
init_context()
init_command()
}

View File

@ -118,7 +118,7 @@
{{end}}
{{define "componet"}}
<fieldset><legend title="{{option .Meta "componet_help"}}">{{option .Meta "componet_help"}}({{option .Meta "context"}}.{{option .Meta "command"}})</legend>
<fieldset><legend title="{{option .Meta "componet_help"}}">{{option .Meta "componet_help"}}({{option .Meta "context"}}.{{option .Meta "componet_cmd"}})</legend>
{{$form_type := option . "form_type"|meta}}
{{if eq $form_type "upload"}}