forked from x/ContextOS
opt ctx.Event
This commit is contained in:
parent
953aad1d53
commit
a1afe94027
10
etc/init.shy
10
etc/init.shy
@ -1,11 +1,11 @@
|
|||||||
~cli
|
~cli
|
||||||
config load var/tmp/runtime.json runtime
|
config load tmp/runtime.json runtime
|
||||||
~aaa
|
~aaa
|
||||||
config load var/tmp/short.json short
|
config load tmp/short.json short
|
||||||
config load var/tmp/auth.json auth
|
config load tmp/auth.json auth
|
||||||
~ssh
|
~ssh
|
||||||
config load var/data/work.json work
|
config load data/work.json work
|
||||||
config load var/data/flow.json flow
|
config load data/flow.json flow
|
||||||
|
|
||||||
~nfs
|
~nfs
|
||||||
source etc/common.shy
|
source etc/common.shy
|
||||||
|
@ -356,6 +356,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
|||||||
// 工作目录
|
// 工作目录
|
||||||
cmd.Dir = kit.Select(kit.Chains(conf, "dir"), m.Option("cmd_dir"))
|
cmd.Dir = kit.Select(kit.Chains(conf, "dir"), m.Option("cmd_dir"))
|
||||||
if cmd.Dir != "" {
|
if cmd.Dir != "" {
|
||||||
|
os.MkdirAll(cmd.Dir, 0777)
|
||||||
m.Log("info", "dir %v", cmd.Dir)
|
m.Log("info", "dir %v", cmd.Dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,5 +4,5 @@ var version = struct {
|
|||||||
host string
|
host string
|
||||||
self int
|
self int
|
||||||
}{
|
}{
|
||||||
"2019-09-25 12:54:59", "centos", 603,
|
"2019-09-26 17:44:10", "centos", 606,
|
||||||
}
|
}
|
||||||
|
@ -21,15 +21,17 @@ kit upgrade "升级" private "ssh._route" _ "cli.upgrade" \
|
|||||||
text "" name see imports plugin_see \
|
text "" name see imports plugin_see \
|
||||||
button "升级"
|
button "升级"
|
||||||
|
|
||||||
kit missyou "任务" private \
|
kit missyou "任务" private "ssh._route" _ "cli.missyou" \
|
||||||
|
text "" name pod imports plugin_pod action auto \
|
||||||
text "" name see imports plugin_see \
|
text "" name see imports plugin_see \
|
||||||
text "" name you view long \
|
text "" name you view long \
|
||||||
button "行动" action auto \
|
button "行动" action auto \
|
||||||
exports you "" you
|
exports you "" you
|
||||||
|
|
||||||
kit pod "设备" private "ssh._route" _ "ssh.remote" __ \
|
kit pod "设备" private "ssh._route" _ "ssh.remote" __ \
|
||||||
text "" name pod \
|
text "" name pod imports plugin_pod action auto \
|
||||||
button "查看" action auto \
|
button "查看" action auto \
|
||||||
|
button "返回" cb Last \
|
||||||
exports pod pod pod
|
exports pod pod pod
|
||||||
|
|
||||||
kit ctx "模块" private "ssh._route" _ context _ list __ \
|
kit ctx "模块" private "ssh._route" _ context _ list __ \
|
||||||
|
@ -174,6 +174,7 @@ var page = Page({check: true,
|
|||||||
initRiver: function(page, field, option, output) {
|
initRiver: function(page, field, option, output) {
|
||||||
return {
|
return {
|
||||||
Show: function(which) {var pane = field.Pane
|
Show: function(which) {var pane = field.Pane
|
||||||
|
ctx.Event(event, {}, {name: "river.show"})
|
||||||
output.innerHTML = "", pane.Update([], "text", ["nick", "count"], "key", which||ctx.Search("river")||true)
|
output.innerHTML = "", pane.Update([], "text", ["nick", "count"], "key", which||ctx.Search("river")||true)
|
||||||
},
|
},
|
||||||
Action: {
|
Action: {
|
||||||
@ -556,6 +557,7 @@ var page = Page({check: true,
|
|||||||
prev? prev.click(): output.lastChild.click()
|
prev? prev.click(): output.lastChild.click()
|
||||||
},
|
},
|
||||||
Show: function(which) {var pane = field.Pane
|
Show: function(which) {var pane = field.Pane
|
||||||
|
ctx.Event(event, {}, {name: "storm.show"})
|
||||||
pane.which.get("") == which && page.action.Pane.Show()
|
pane.which.get("") == which && page.action.Pane.Show()
|
||||||
output.innerHTML = "", pane.Update([river], "text", ["key", "count"], "key", which||ctx.Search("storm")||true)
|
output.innerHTML = "", pane.Update([river], "text", ["key", "count"], "key", which||ctx.Search("storm")||true)
|
||||||
},
|
},
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
ctx = context = {__proto__: kit,
|
ctx = context = {__proto__: kit,
|
||||||
Event: function(event, msg, proto) {
|
Event: function(event, msg, proto) {
|
||||||
if (event.msg) {return event.msg}
|
if (event.msg && !msg) {return event.msg}
|
||||||
|
|
||||||
event.msg = msg = msg || {}, proto = proto || {}, msg.__proto__ = proto, proto.__proto__ = {
|
event.msg = msg = msg || {}, proto = proto || {}, msg.__proto__ = proto, proto.__proto__ = {
|
||||||
Push: function(key, value) {
|
Push: function(key, value) {
|
||||||
msg.append || (msg.append = [])
|
msg.append || (msg.append = [])
|
||||||
@ -26,7 +27,7 @@ ctx = context = {__proto__: kit,
|
|||||||
return msg
|
return msg
|
||||||
},
|
},
|
||||||
Run: function(dataset, cmd, cb) {
|
Run: function(dataset, cmd, cb) {
|
||||||
var msg = ctx.Event(event)
|
var msg = ctx.Event(event||document.createEvent("Event"), null, {name: "ctx.run"})
|
||||||
|
|
||||||
var option = {"cmds": cmd}
|
var option = {"cmds": cmd}
|
||||||
msg.option && msg.option.forEach(function(item) {
|
msg.option && msg.option.forEach(function(item) {
|
||||||
@ -265,7 +266,8 @@ ctx = context = {__proto__: kit,
|
|||||||
xhr.setRequestHeader("Accept", "application/json")
|
xhr.setRequestHeader("Accept", "application/json")
|
||||||
xhr.send(args.join("&"))
|
xhr.send(args.join("&"))
|
||||||
},
|
},
|
||||||
WSS: function(cb, onerror, onclose) {
|
WSS: Wrap(function(cb, onerror, onclose) {
|
||||||
|
var meta = arguments.callee
|
||||||
var s = new WebSocket(location.protocol.replace("http", "ws")+"//"+location.host+"/wss?wssid="+(page.wssid||""))
|
var s = new WebSocket(location.protocol.replace("http", "ws")+"//"+location.host+"/wss?wssid="+(page.wssid||""))
|
||||||
s.onopen = function(event) {
|
s.onopen = function(event) {
|
||||||
kit.Log("wss", "open")
|
kit.Log("wss", "open")
|
||||||
@ -278,8 +280,12 @@ ctx = context = {__proto__: kit,
|
|||||||
var msg = {"result": [event.data]}
|
var msg = {"result": [event.data]}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
meta.order++
|
||||||
|
// Event入口 -1.0
|
||||||
msg = ctx.Event(event, msg, {
|
msg = ctx.Event(event, msg, {
|
||||||
reply: function(msg) {
|
name: meta.order,
|
||||||
|
Order: meta.order,
|
||||||
|
Reply: function(msg) {
|
||||||
kit.Log(["wss", "result"].concat(msg.result))
|
kit.Log(["wss", "result"].concat(msg.result))
|
||||||
delete(msg.event), s.send(JSON.stringify(msg))
|
delete(msg.event), s.send(JSON.stringify(msg))
|
||||||
},
|
},
|
||||||
@ -302,5 +308,5 @@ ctx = context = {__proto__: kit,
|
|||||||
typeof onclose == "function" && onclose(event)
|
typeof onclose == "function" && onclose(event)
|
||||||
}
|
}
|
||||||
return s
|
return s
|
||||||
},
|
}, {order: 0}),
|
||||||
}
|
}
|
||||||
|
@ -130,6 +130,8 @@ function Page(page) {
|
|||||||
var script = {}, record = ""
|
var script = {}, record = ""
|
||||||
page = Meta(document.body, page, {__proto__: ctx,
|
page = Meta(document.body, page, {__proto__: ctx,
|
||||||
onload: function() {
|
onload: function() {
|
||||||
|
// Event入口 0
|
||||||
|
ctx.Event(event, {}, {name: document.title})
|
||||||
if (page.check && !ctx.Cookie("sessid")) {
|
if (page.check && !ctx.Cookie("sessid")) {
|
||||||
// 用户登录
|
// 用户登录
|
||||||
document.querySelectorAll("body>fieldset.Login").forEach(function(field) {
|
document.querySelectorAll("body>fieldset.Login").forEach(function(field) {
|
||||||
@ -406,7 +408,7 @@ function Page(page) {
|
|||||||
WSS: function(cb, onerror, onclose) {
|
WSS: function(cb, onerror, onclose) {
|
||||||
return page.socket || (page.socket = ctx.WSS(cb || (function(m) {
|
return page.socket || (page.socket = ctx.WSS(cb || (function(m) {
|
||||||
if (m.detail) {
|
if (m.detail) {
|
||||||
page.action.Pane.Core(event, m, ["_cmd", m.detail], m.reply)
|
page.action.Pane.Core(event, m, ["_cmd", m.detail], m.Reply)
|
||||||
} else {
|
} else {
|
||||||
page.ontoast(m.result.join(""))
|
page.ontoast(m.result.join(""))
|
||||||
}
|
}
|
||||||
@ -547,7 +549,6 @@ function Pane(page, field) {
|
|||||||
var index = list.length, ui = pane.View(output, type, line, key, function(event, cmds, cbs) {
|
var index = list.length, ui = pane.View(output, type, line, key, function(event, cmds, cbs) {
|
||||||
(type != "plugin" && type != "field") && pane.Select(index, line[which])
|
(type != "plugin" && type != "field") && pane.Select(index, line[which])
|
||||||
page.script("record", [name, line[key[0]]])
|
page.script("record", [name, line[key[0]]])
|
||||||
ctx.Event(event, {}, {name: name})
|
|
||||||
typeof cb == "function" && cb(line, index, event, cmds, cbs)
|
typeof cb == "function" && cb(line, index, event, cmds, cbs)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -574,6 +575,8 @@ function Pane(page, field) {
|
|||||||
Select: function(index, key) {
|
Select: function(index, key) {
|
||||||
-1 < last && last < list.length && (kit.classList.del(list[last], "select"))
|
-1 < last && last < list.length && (kit.classList.del(list[last], "select"))
|
||||||
last = index, list[index] && (kit.classList.add(list[index], "select"))
|
last = index, list[index] && (kit.classList.add(list[index], "select"))
|
||||||
|
// Event入口 1.0
|
||||||
|
ctx.Event(event, {}, {name: name+"."+key})
|
||||||
key && pane.which.set(key)
|
key && pane.which.set(key)
|
||||||
},
|
},
|
||||||
clear: function() {
|
clear: function() {
|
||||||
@ -686,14 +689,14 @@ function Pane(page, field) {
|
|||||||
page.Sync(k).change(pane.Listen[k])
|
page.Sync(k).change(pane.Listen[k])
|
||||||
}
|
}
|
||||||
pane.Button && pane.Button.length > 0 && (kit.InsertChild(field, output, "div", pane.Button.map(function(value) {
|
pane.Button && pane.Button.length > 0 && (kit.InsertChild(field, output, "div", pane.Button.map(function(value) {
|
||||||
return typeof value == "object"? {className: value[0], select: [value.slice(1), function(value, event) {
|
function call(value, event) {
|
||||||
value = event.target.value
|
// Event入口 1.1
|
||||||
|
ctx.Event(event, {}, {name: name+"."+value})
|
||||||
page.script("record", [name, value])
|
page.script("record", [name, value])
|
||||||
typeof pane.Action == "function"? pane.Action(value, event): pane.Action[value](event, value)
|
typeof pane.Action == "function"? pane.Action(value, event): pane.Action[value](event, value)
|
||||||
}]}: value == ""? {view: ["space"]} :value == "br"? {type: "br"}: {button: [value, function(value, event) {
|
}
|
||||||
page.script("record", [name, value])
|
return typeof value == "object"? {className: value[0], select: [value.slice(1), call]}:
|
||||||
typeof pane.Action == "function"? pane.Action(value, event): pane.Action[value](event, value)
|
value == ""? {view: ["space"]} :value == "br"? {type: "br"}: {button: [value, call]}
|
||||||
}]}
|
|
||||||
})).className="action")
|
})).className="action")
|
||||||
option.onsubmit = function(event) {
|
option.onsubmit = function(event) {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
@ -718,7 +721,8 @@ function Plugin(page, pane, field, runs) {
|
|||||||
|
|
||||||
var history = []
|
var history = []
|
||||||
var run = function(event, cmds, cbs) {
|
var run = function(event, cmds, cbs) {
|
||||||
event.Plugin = plugin, runs(event, cmds, cbs)
|
ctx.Event(event, null, {name: name, Plugin: plugin})
|
||||||
|
runs(event, cmds, cbs)
|
||||||
}
|
}
|
||||||
var plugin = Meta(field, (field.Script && field.Script.init || function() {
|
var plugin = Meta(field, (field.Script && field.Script.init || function() {
|
||||||
})(run, field, option, output)||{}, {
|
})(run, field, option, output)||{}, {
|
||||||
@ -781,13 +785,11 @@ function Plugin(page, pane, field, runs) {
|
|||||||
(typeof item.imports == "object"? item.imports: typeof item.imports == "string"? [item.imports]: []).forEach(function(imports) {
|
(typeof item.imports == "object"? item.imports: typeof item.imports == "string"? [item.imports]: []).forEach(function(imports) {
|
||||||
page.Sync(imports).change(function(value) {
|
page.Sync(imports).change(function(value) {
|
||||||
history.push({target: action.target, value: action.target.value});
|
history.push({target: action.target, value: action.target.value});
|
||||||
(action.target.value = value) && item.action == "auto" && plugin.Runs(window.event)
|
(action.target.value = value) && item.action == "auto" && plugin.Runs(document.createEvent("Event"))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
item.type == "button" && item.action == "auto" && plugin.Runs(window.event, function() {
|
item.type == "button" && item.action == "auto" && action.target.click()
|
||||||
var td = output.querySelector("td")
|
|
||||||
td && td.click()
|
|
||||||
})
|
|
||||||
item.which = plugin.Sync(input.name)
|
item.which = plugin.Sync(input.name)
|
||||||
plugin.Inputs[input.name] = ui[input.name]
|
plugin.Inputs[input.name] = ui[input.name]
|
||||||
return action.target
|
return action.target
|
||||||
@ -979,9 +981,10 @@ function Plugin(page, pane, field, runs) {
|
|||||||
you: function(value, name, line) {
|
you: function(value, name, line) {
|
||||||
var event = window.event
|
var event = window.event
|
||||||
event.Plugin = plugin
|
event.Plugin = plugin
|
||||||
|
|
||||||
line.you && name == "status" && (line.status == "start"? function() {
|
line.you && name == "status" && (line.status == "start"? function() {
|
||||||
plugin.Delay(3000, event, line.you+" stop...") && field.Run(event, [line.you, "stop"])
|
plugin.Delay(3000, event, line.you+" stop...") && field.Run(event, [option.pod.value, line.you, "stop"])
|
||||||
}(): field.Run(event, [line.you], function(msg) {
|
}(): field.Run(event, [option.pod.value, line.you], function(msg) {
|
||||||
plugin.Delay(3000, event, line.you+" start...")
|
plugin.Delay(3000, event, line.you+" start...")
|
||||||
}))
|
}))
|
||||||
return name == "status" || line.status == "stop" ? undefined: line.you
|
return name == "status" || line.status == "stop" ? undefined: line.you
|
||||||
@ -999,8 +1002,8 @@ function Plugin(page, pane, field, runs) {
|
|||||||
},
|
},
|
||||||
onaction: {
|
onaction: {
|
||||||
onfocus: function(event, action, type, name, item) {
|
onfocus: function(event, action, type, name, item) {
|
||||||
page.input = event.target, plugin.Select(true)
|
plugin.Select(true)
|
||||||
plugin.which.set(name)
|
page.input = event.target, plugin.which.set(name)
|
||||||
},
|
},
|
||||||
onblur: function(event, action, type, name, item) {
|
onblur: function(event, action, type, name, item) {
|
||||||
item.which.set(action.target.value)
|
item.which.set(action.target.value)
|
||||||
@ -1009,7 +1012,8 @@ function Plugin(page, pane, field, runs) {
|
|||||||
onclick: function(event, action, type, name, item) {
|
onclick: function(event, action, type, name, item) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "button":
|
case "button":
|
||||||
ctx.Event(event, {}, {name: meta.name+"."+name, pane: pane, plugin: plugin, input: item})
|
// Event入口 2.0
|
||||||
|
ctx.Event(event, {}, {name: meta.name+"."+name})
|
||||||
|
|
||||||
action[item.cb]? action[item.cb](event, item, option, field):
|
action[item.cb]? action[item.cb](event, item, option, field):
|
||||||
plugin[item.cb]? plugin[item.cb](event, item, option, field): plugin.Check()
|
plugin[item.cb]? plugin[item.cb](event, item, option, field): plugin.Check()
|
||||||
@ -1025,25 +1029,7 @@ function Plugin(page, pane, field, runs) {
|
|||||||
type == "text" && (action.target.value = kit.History.get("txt", -1).data.trim())
|
type == "text" && (action.target.value = kit.History.get("txt", -1).data.trim())
|
||||||
},
|
},
|
||||||
onchange: function(event, action, type, name, item) {
|
onchange: function(event, action, type, name, item) {
|
||||||
type == "select" && plugin.Check(item.action == "auto"? undefined: action)
|
type == "select" && ctx.Event(event, {}, {name: meta.name+"."+name}) && plugin.Check(item.action == "auto"? undefined: action)
|
||||||
},
|
|
||||||
onkeyup: function(event, action, type, name, item) {
|
|
||||||
switch (event.key) {
|
|
||||||
case " ":
|
|
||||||
event.stopPropagation()
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
page.oninput(event, function(event) {
|
|
||||||
switch (event.key) {
|
|
||||||
case " ":
|
|
||||||
case "w":
|
|
||||||
break
|
|
||||||
default:
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
onkeydown: function(event, action, type, name, item) {
|
onkeydown: function(event, action, type, name, item) {
|
||||||
switch (event.key) {
|
switch (event.key) {
|
||||||
@ -1091,12 +1077,31 @@ function Plugin(page, pane, field, runs) {
|
|||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
if (item.type != "textarea" && event.key == "Enter") {
|
if (item.type != "textarea" && event.key == "Enter") {
|
||||||
|
// Event入口 2.1
|
||||||
ctx.Event(event, {}, {name: meta.name+"."+name, pane: pane, plugin: plugin, input: item})
|
ctx.Event(event, {}, {name: meta.name+"."+name, pane: pane, plugin: plugin, input: item})
|
||||||
item.which.set(action.target.value)
|
item.which.set(action.target.value)
|
||||||
history.push({target: action.target, value: action.target.value});
|
history.push({target: action.target, value: action.target.value});
|
||||||
plugin.Check(action.target)
|
plugin.Check(action.target)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
onkeyup: function(event, action, type, name, item) {
|
||||||
|
switch (event.key) {
|
||||||
|
case " ":
|
||||||
|
event.stopPropagation()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
page.oninput(event, function(event) {
|
||||||
|
switch (event.key) {
|
||||||
|
case " ":
|
||||||
|
case "w":
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
},
|
||||||
},
|
},
|
||||||
exports: JSON.parse(meta.exports||'["",""]'),
|
exports: JSON.parse(meta.exports||'["",""]'),
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user