mirror of
https://shylinux.com/x/ContextOS
synced 2025-06-26 18:07:30 +08:00
add page.sync
This commit is contained in:
parent
9c887c773e
commit
af591d88a1
@ -99,6 +99,9 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
||||
"nshell": &ctx.Cache{Name: "nshell", Value: "0", Help: "终端数量"},
|
||||
},
|
||||
Configs: map[string]*ctx.Config{
|
||||
"compile": &ctx.Config{Name: "compile", Value: map[string]interface{}{
|
||||
"bench": "src/examples/app/bench.go",
|
||||
}, Help: "运行环境"},
|
||||
"runtime": &ctx.Config{Name: "runtime", Value: map[string]interface{}{
|
||||
"init_env": []interface{}{"ctx_cas", "ctx_dev", "ctx_box", "ctx_root", "ctx_home", "web_port", "ssh_port", "USER"},
|
||||
"boot": map[string]interface{}{"web_port": ":9094", "ssh_port": ":9090"},
|
||||
@ -172,6 +175,12 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
||||
})
|
||||
return
|
||||
}},
|
||||
"compile": &ctx.Command{Name: "compile", Help: "解析脚本, script: 脚本文件, stdio: 命令终端, snippet: 代码片段", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
if m.Cmdy("cli.system", "go", "install", m.Cmdx("nfs.path", m.Conf("compile", "bench"))); m.Result(0) == "" {
|
||||
m.Cmdy("cli.quit", 1)
|
||||
}
|
||||
return
|
||||
}},
|
||||
"runtime": &ctx.Command{Name: "runtime", Help: "runtime", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
if len(arg) == 0 {
|
||||
m.Cmdy("ctx.config", "runtime")
|
||||
@ -218,10 +227,12 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
||||
}},
|
||||
"quit": &ctx.Command{Name: "quit code", Help: "停止服务", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
m.Cmd("cli.source", m.Conf("system", "script.exit"))
|
||||
m.Append("directory", "")
|
||||
m.Echo("1s restarting...")
|
||||
|
||||
m.GoFunc(m, func(m *ctx.Message) {
|
||||
time.Sleep(time.Second * 3)
|
||||
os.Exit(kit.Int(arg[0]))
|
||||
time.Sleep(time.Second * 1)
|
||||
os.Exit(kit.Int(kit.Select("0", arg, 0)))
|
||||
})
|
||||
return
|
||||
}},
|
||||
|
@ -1234,9 +1234,14 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
|
||||
return
|
||||
}
|
||||
|
||||
if p := m.Cmdx("nfs.path", arg[0]); p != "" {
|
||||
m.Option("git_dir", p)
|
||||
arg = arg[1:]
|
||||
} else {
|
||||
wd, e := os.Getwd()
|
||||
m.Assert(e)
|
||||
m.Option("git_dir", wd)
|
||||
}
|
||||
|
||||
cmds := []string{}
|
||||
if v := m.Confv("git", []string{arg[0], "cmds"}); v != nil {
|
||||
|
@ -80,6 +80,84 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
||||
"display_result": "", "display_append": "",
|
||||
},
|
||||
},
|
||||
"project": []interface{}{
|
||||
map[string]interface{}{"componet_name": "compile", "componet_help": "compile",
|
||||
"componet_tmpl": "componet", "componet_view": "Compile", "componet_init": "",
|
||||
"componet_type": "private", "componet_ctx": "cli", "componet_cmd": "compile",
|
||||
"componet_args": []interface{}{}, "inputs": []interface{}{
|
||||
map[string]interface{}{"type": "button", "value": "编译"},
|
||||
},
|
||||
},
|
||||
map[string]interface{}{"componet_name": "runtime", "componet_help": "runtime",
|
||||
"componet_tmpl": "componet", "componet_view": "Runtime", "componet_init": "",
|
||||
"componet_type": "private", "componet_ctx": "cli", "componet_cmd": "runtime",
|
||||
"componet_args": []interface{}{"system"}, "inputs": []interface{}{
|
||||
map[string]interface{}{"type": "button", "value": "运行"},
|
||||
},
|
||||
},
|
||||
map[string]interface{}{"componet_name": "ifconfig", "componet_help": "ifconfig",
|
||||
"componet_tmpl": "componet", "componet_view": "Runtime", "componet_init": "",
|
||||
"componet_type": "private", "componet_ctx": "tcp", "componet_cmd": "ifconfig",
|
||||
"componet_args": []interface{}{}, "inputs": []interface{}{
|
||||
map[string]interface{}{"type": "button", "value": "网卡"},
|
||||
},
|
||||
},
|
||||
map[string]interface{}{"componet_name": "context", "componet_help": "context",
|
||||
"componet_tmpl": "componet", "componet_view": "Runtime", "componet_init": "",
|
||||
"componet_type": "private", "componet_ctx": "ctx", "componet_cmd": "context",
|
||||
"componet_args": []interface{}{}, "inputs": []interface{}{
|
||||
map[string]interface{}{"type": "button", "value": "模块"},
|
||||
},
|
||||
},
|
||||
map[string]interface{}{"componet_name": "dir", "componet_help": "dir",
|
||||
"componet_tmpl": "componet", "componet_view": "Runtime", "componet_init": "",
|
||||
"componet_type": "private", "componet_ctx": "nfs", "componet_cmd": "dir",
|
||||
"componet_args": []interface{}{}, "inputs": []interface{}{
|
||||
map[string]interface{}{"type": "text", "name": "pod"},
|
||||
map[string]interface{}{"type": "button", "value": "执行"},
|
||||
},
|
||||
"exports": []interface{}{"dir", "filename"},
|
||||
},
|
||||
map[string]interface{}{"componet_name": "git", "componet_help": "git",
|
||||
"componet_tmpl": "componet", "componet_view": "Runtime", "componet_init": "",
|
||||
"componet_type": "private", "componet_ctx": "cli", "componet_cmd": "git",
|
||||
"componet_args": []interface{}{}, "inputs": []interface{}{
|
||||
map[string]interface{}{"type": "text", "name": "dir", "imports": "dir"},
|
||||
map[string]interface{}{"type": "select", "name": "cmd", "values": []interface{}{"status", "diff"}},
|
||||
map[string]interface{}{"type": "button", "value": "执行"},
|
||||
},
|
||||
},
|
||||
map[string]interface{}{"componet_name": "pod", "componet_help": "pod",
|
||||
"componet_tmpl": "componet", "componet_view": "Runtime", "componet_init": "",
|
||||
"componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "remote",
|
||||
"componet_args": []interface{}{}, "inputs": []interface{}{
|
||||
map[string]interface{}{"type": "button", "value": "执行"},
|
||||
},
|
||||
"exports": []interface{}{"pod", "key"},
|
||||
},
|
||||
map[string]interface{}{"componet_name": "cmd", "componet_help": "cmd",
|
||||
"componet_tmpl": "componet", "componet_view": "Runtime", "componet_init": "",
|
||||
"componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "_route",
|
||||
"componet_args": []interface{}{}, "inputs": []interface{}{
|
||||
map[string]interface{}{"type": "text", "name": "pod", "imports": "pod"},
|
||||
map[string]interface{}{"type": "text", "name": "cmd", "value": "gg"},
|
||||
map[string]interface{}{"type": "select", "name": "sub", "values": []interface{}{"status", ""}},
|
||||
map[string]interface{}{"type": "button", "value": "执行"},
|
||||
},
|
||||
},
|
||||
map[string]interface{}{"componet_name": "cmd", "componet_help": "cmd",
|
||||
"componet_tmpl": "componet", "componet_view": "Runtime", "componet_init": "",
|
||||
"componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "_route",
|
||||
"componet_args": []interface{}{}, "inputs": []interface{}{
|
||||
map[string]interface{}{"type": "text", "name": "pod", "imports": "pod"},
|
||||
map[string]interface{}{"type": "text", "name": "cmd", "value": "gg"},
|
||||
map[string]interface{}{"type": "select", "name": "sub", "values": []interface{}{"status", ""}},
|
||||
map[string]interface{}{"type": "text", "name": "sub", "imports": "dir"},
|
||||
map[string]interface{}{"type": "text", "name": "sub", "imports": "branch"},
|
||||
map[string]interface{}{"type": "button", "value": "执行"},
|
||||
},
|
||||
},
|
||||
},
|
||||
}, Help: "组件列表"},
|
||||
},
|
||||
Commands: map[string]*ctx.Command{
|
||||
@ -192,13 +270,10 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
||||
|
||||
case "create":
|
||||
user := m.Conf("runtime", "user.route")
|
||||
if user == "" {
|
||||
m.Echo("error: no user.route")
|
||||
return
|
||||
}
|
||||
|
||||
name := kit.Select(m.Conf("runtime", "user.name"), arg, 1)
|
||||
work := kit.Select(m.Conf("runtime", "work.route"), arg, 2)
|
||||
m.Assert(user != "", "error: no user.route")
|
||||
m.Assert(name != "", "error: no user.name")
|
||||
|
||||
if n := m.Cmdx("ssh._route", work, "_check", "work", name, user); n != "" {
|
||||
m.Conf("runtime", "work.route", work)
|
||||
@ -259,6 +334,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
||||
m.Add("append", "view", value["componet_view"])
|
||||
m.Add("append", "init", m.Cmdx("nfs.load", path.Join("usr/librarys/plugin", kit.Format(value["componet_init"])), -1))
|
||||
m.Add("append", "inputs", kit.Format(value["inputs"]))
|
||||
m.Add("append", "exports", kit.Format(value["exports"]))
|
||||
})
|
||||
m.Table()
|
||||
}
|
||||
|
@ -327,6 +327,7 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心",
|
||||
m.Add("append", "view", msg.Append("view"))
|
||||
m.Add("append", "init", msg.Append("init"))
|
||||
m.Add("append", "inputs", msg.Append("inputs"))
|
||||
m.Add("append", "exports", msg.Append("exports"))
|
||||
})
|
||||
m.Table()
|
||||
return
|
||||
|
@ -1,6 +1,8 @@
|
||||
var page = Page({
|
||||
conf: {border: 4, layout: {header:30, river:180, action:180, source:60, storm:180, footer:30}},
|
||||
onlayout: function(event, sizes) {
|
||||
kit.isWindows && (document.body.style.overflow = "hidden")
|
||||
|
||||
var height = document.body.clientHeight-page.conf.border
|
||||
var width = document.body.clientWidth-page.conf.border
|
||||
page.conf.height = height
|
||||
@ -265,6 +267,7 @@ var page = Page({
|
||||
},
|
||||
}
|
||||
|
||||
pane.Stop = false
|
||||
pane.Show = function() {
|
||||
var cmds = ["brow", river, 0]
|
||||
output.innerHTML = "", pane.Times(1000, cmds, function(line, index, msg) {
|
||||
@ -383,6 +386,7 @@ var page = Page({
|
||||
},
|
||||
"最大": function(event) {
|
||||
(toggle = !toggle)? page.onlayout(event, page.conf.layout): page.onlayout(event, {river:0, action:-1, source:60})
|
||||
page.target.Stop = !toggle
|
||||
},
|
||||
"全屏": function(event) {
|
||||
page.onlayout(event, {header:0, footer:0, river:0, action: -1, storm:0})
|
||||
|
@ -138,7 +138,7 @@ fieldset pre code, fieldset code pre {
|
||||
color:white;
|
||||
font-size:14px;
|
||||
background-color:#272822;
|
||||
overflow:scroll;
|
||||
overflow:auto;
|
||||
padding:5px;
|
||||
border:solid 2px green;
|
||||
border-left:solid 4px green;
|
||||
|
@ -3,6 +3,7 @@ function Page(page) {
|
||||
var conf = {}
|
||||
var conf_cb = {}
|
||||
page.__proto__ = {
|
||||
sync: {},
|
||||
ID: function() {
|
||||
return id++
|
||||
},
|
||||
@ -87,7 +88,7 @@ function Page(page) {
|
||||
{text: [text.name+"("+text.help+")", "legend"]},
|
||||
{name: "option", view: ["option", "form"], data: {Run: cb}, list: [{type: "input", style: {"display": "none"}}]},
|
||||
{name: "output", view: ["output", "div"]},
|
||||
{script: "Plugin("+id+","+text.inputs+","+"[\""+(text.args||[]).join("\",\"")+"\"]"+","+(text.init||"")+")"},
|
||||
{script: "Plugin("+id+","+JSON.stringify(text)+","+"[\""+(text.args||[]).join("\",\"")+"\"]"+","+(text.init||"")+")"},
|
||||
]}]
|
||||
break
|
||||
}
|
||||
@ -342,7 +343,7 @@ function Page(page) {
|
||||
pane.Times = form.Times = function(time, cmds, cb) {
|
||||
timer && clearTimeout(timer)
|
||||
function loop() {
|
||||
ctx.Run(page, form.dataset, cmds, function(msg) {
|
||||
!pane.Stop && ctx.Run(page, form.dataset, cmds, function(msg) {
|
||||
ctx.Table(msg, function(line, index) {
|
||||
cb(line, index, msg)
|
||||
})
|
||||
@ -380,20 +381,26 @@ function Page(page) {
|
||||
}
|
||||
return page
|
||||
}
|
||||
function Plugin(field, inputs, args, plugin) {
|
||||
function Plugin(field, text, args, plugin) {
|
||||
var inputs = JSON.parse(text.inputs)
|
||||
var exports = JSON.parse(text.exports||'["",""]')
|
||||
var option = field.querySelector("form.option")
|
||||
var output = field.querySelector("div.output")
|
||||
|
||||
page.sync["plugin"+exports[0]] = page.Sync("plugin"+exports[0])
|
||||
|
||||
option.Runs = function(event) {
|
||||
var args = []
|
||||
option.querySelectorAll("input").forEach(function(item, index){
|
||||
option.querySelectorAll(".args").forEach(function(item, index){
|
||||
item.type == "text" && args.push(item.value)
|
||||
item.type == "select-one" && args.push(item.value)
|
||||
})
|
||||
option.Run(event, args.slice(1), function(msg) {
|
||||
option.Run(event, args, function(msg) {
|
||||
(option.ondaemon || function(msg) {
|
||||
output.innerHTML = "",
|
||||
msg.append? kit.AppendTable(kit.AppendChild(output, "table"), ctx.Table(msg), msg.append)
|
||||
:kit.AppendChild(output, [{type: "code", list: [{text: [msg.result.join(""), "pre"]}]}])
|
||||
msg.append? kit.OrderTable(kit.AppendTable(kit.AppendChild(output, "table"), ctx.Table(msg), msg.append), exports[1], function(event, value) {
|
||||
page.sync["plugin"+exports[0]].set(value)
|
||||
}) :kit.AppendChild(output, [{type: "code", list: [{text: [msg.result.join(""), "pre"]}]}])
|
||||
})(msg)
|
||||
})
|
||||
}
|
||||
@ -402,7 +409,85 @@ function Plugin(field, inputs, args, plugin) {
|
||||
page.plugin = field
|
||||
}
|
||||
|
||||
var total = 0
|
||||
field.Add = option.Add = function(item) {
|
||||
var index = total
|
||||
total += 1
|
||||
page.sync["plugin"+item.imports] || (page.sync["plugin"+item.imports] = page.Sync("plugin"+item.imports))
|
||||
item.imports && page.sync["plugin"+item.imports].change(function(value, old) {
|
||||
ui[item.name].value = value
|
||||
})
|
||||
|
||||
switch (item.type) {
|
||||
case "button":
|
||||
item.onclick = function(event) {
|
||||
plugin[item.click]? plugin[item.click](event, item, option, field): option.Runs(event)
|
||||
}
|
||||
break
|
||||
case "select":
|
||||
break
|
||||
default:
|
||||
item.onkeyup = function(event) {
|
||||
page.oninput(event, function(event) {
|
||||
switch (event.key) {
|
||||
case "i":
|
||||
var next = field.nextSibling;
|
||||
next && next.Select()
|
||||
break
|
||||
case "o":
|
||||
var prev = field.previousSibling;
|
||||
prev && prev.Select()
|
||||
break
|
||||
case "c":
|
||||
output.innerHTML = ""
|
||||
break
|
||||
case "r":
|
||||
output.innerHTML = ""
|
||||
case "j":
|
||||
run(event)
|
||||
break
|
||||
case "l":
|
||||
page.action.scrollTo(0, option.parentNode.offsetTop)
|
||||
break
|
||||
case "m":
|
||||
page.View(field.parentNode, "plugin", field.Meta, [], option.Run)
|
||||
event.stopPropagation()
|
||||
break
|
||||
case "b":
|
||||
option.Add({})
|
||||
break
|
||||
default:
|
||||
return false
|
||||
}
|
||||
return true
|
||||
})
|
||||
event.key == "Enter" && (index == total-1? option.Runs(event): event.target.parentNode.nextSibling.childNodes[1].focus())
|
||||
event.key == "Enter" && (index == total-2 && event.target.parentNode.nextSibling.childNodes[1].type == "button" ? option.Runs(event): event.target.parentNode.nextSibling.childNodes[1].focus())
|
||||
}
|
||||
}
|
||||
// , field.Select = function() {
|
||||
// // ui.last.childNodes[1].focus()
|
||||
// })
|
||||
|
||||
item.className = "args"
|
||||
var ui = kit.AppendChild(option, [{type: "div", list: [{type: "label", inner: item.label||""},
|
||||
item.type == "select"? {type: "select", name: item.name, data: {className: "args", onchange: function(event) {
|
||||
(index == total-1? option.Runs(event): event.target.parentNode.nextSibling.childNodes[1].focus());
|
||||
(index == total-2 && event.target.parentNode.nextSibling.childNodes[1].type == "button" ? option.Runs(event): event.target.parentNode.nextSibling.childNodes[1].focus())
|
||||
|
||||
}}, list: item.values.map(function(value) {
|
||||
return {type: "option", value: value, inner: value}
|
||||
})}: {type: "input", name: item.name, data: item}]}])
|
||||
}
|
||||
|
||||
inputs.map(function(item, index, inputs) {
|
||||
option.Add(item)
|
||||
})
|
||||
|
||||
/*
|
||||
var ui = kit.AppendChild(option, inputs.map(function(item, index, inputs) {
|
||||
|
||||
total += 1
|
||||
item.type == "button"? item.onclick = function(event) {
|
||||
plugin[item.click]? plugin[item.click](event, item, option, field): option.Runs(event)
|
||||
|
||||
@ -444,11 +529,13 @@ function Plugin(field, inputs, args, plugin) {
|
||||
return {type: "div", list: [{type: "label", inner: item.label||""}, {type: "input", name: item.name, data: item, value: args && args[index]}]}
|
||||
}))
|
||||
ui.last.childNodes[1].focus()
|
||||
*/
|
||||
|
||||
plugin = plugin || {}, plugin.__proto__ = {
|
||||
show: function() {},
|
||||
init: function() {},
|
||||
}
|
||||
plugin.init(page, page.action, field, option, output, ui)
|
||||
// plugin.init(page, page.action, field, option, output, ui)
|
||||
plugin.init(page, page.action, field, option, output)
|
||||
page[field.id] = plugin
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ kit = toolkit = {
|
||||
isMobile: navigator.userAgent.indexOf("Mobile") > -1,
|
||||
isWeiXin: navigator.userAgent.indexOf("MicroMessenger") > -1,
|
||||
isMacOSX: navigator.userAgent.indexOf("Mac OS X") > -1,
|
||||
isWindows: navigator.userAgent.indexOf("Windows") > -1,
|
||||
isIPhone: navigator.userAgent.indexOf("iPhone") > -1,
|
||||
isSpace: function(c) {
|
||||
return c == " " || c == "Enter"
|
||||
@ -340,6 +341,7 @@ kit = toolkit = {
|
||||
}
|
||||
})
|
||||
})
|
||||
return table
|
||||
},
|
||||
RangeTable: function(table, index, sort_asc) {
|
||||
var list = table.querySelectorAll("tr")
|
||||
@ -409,25 +411,24 @@ kit = toolkit = {
|
||||
},
|
||||
OrderTable: function(table, field, cb) {
|
||||
if (!table) {return}
|
||||
var kit = this
|
||||
table.onclick = function(event) {
|
||||
var target = event.target
|
||||
var dataset = target.dataset
|
||||
var nodes = target.parentElement.childNodes
|
||||
for (var i = 0; i < nodes.length; i++) {
|
||||
if (nodes[i] == target) {
|
||||
var head = target.parentElement.parentElement.querySelector("tr")
|
||||
target.parentElement.childNodes.forEach(function(item, i) {
|
||||
if (item != target) {
|
||||
return
|
||||
}
|
||||
if (target.tagName == "TH") {
|
||||
dataset["sort_asc"] = (dataset["sort_asc"] == "1") ? 0: 1
|
||||
kit.RangeTable(table, i, dataset["sort_asc"] == "1")
|
||||
} else if (target.tagName == "TD") {
|
||||
var tr = target.parentElement.parentElement.querySelector("tr")
|
||||
if (tr.childNodes[i].innerText.startsWith(field)) {
|
||||
typeof cb == "function" && cb(event)
|
||||
return
|
||||
}
|
||||
if (field && head.childNodes[i].innerText.startsWith(field)) {
|
||||
typeof cb == "function" && cb(event, item.innerText)
|
||||
}
|
||||
kit.CopyText()
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user