mirror of
https://shylinux.com/x/ContextOS
synced 2025-04-25 16:58:06 +08:00
opt plugin.example.js
This commit is contained in:
parent
e0db2ea8b6
commit
4eb56fd692
@ -1275,24 +1275,6 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
|
||||
return
|
||||
}},
|
||||
|
||||
"temp": &ctx.Command{Name: "temp data", Help: "查找文件路径", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
h, _ := kit.Hash("uniq")
|
||||
name := fmt.Sprintf("var/tmp/file/%s", h)
|
||||
|
||||
m.Assert(os.MkdirAll("var/tmp/file/", 0777))
|
||||
f, e := os.Create(name)
|
||||
m.Assert(e)
|
||||
defer f.Close()
|
||||
f.Write([]byte(arg[0]))
|
||||
|
||||
m.Echo(name)
|
||||
return
|
||||
}},
|
||||
"trash": &ctx.Command{Name: "trash file", Help: "查找文件路径", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
os.Remove(arg[0])
|
||||
return
|
||||
}},
|
||||
|
||||
"hash": &ctx.Command{Name: "hash filename", Help: "查找文件路径", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
dir, name := path.Split(arg[0])
|
||||
m.Append("dir", dir)
|
||||
@ -1310,6 +1292,21 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
|
||||
}
|
||||
return
|
||||
}},
|
||||
"path": &ctx.Command{Name: "path filename", Help: "查找文件路径", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
if len(arg) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
m.Confm("paths", func(index int, value string) bool {
|
||||
p := path.Join(value, arg[0])
|
||||
if _, e := os.Stat(p); e == nil {
|
||||
m.Echo(p)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
return
|
||||
}},
|
||||
"copy": &ctx.Command{Name: "copy to from", Help: "查找文件路径", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
dir, _ := path.Split(arg[0])
|
||||
m.Assert(os.MkdirAll(dir, 0777))
|
||||
@ -1330,19 +1327,21 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
|
||||
m.Echo(arg[0])
|
||||
return
|
||||
}},
|
||||
"path": &ctx.Command{Name: "path filename", Help: "查找文件路径", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
if len(arg) == 0 {
|
||||
return
|
||||
}
|
||||
"temp": &ctx.Command{Name: "temp data", Help: "查找文件路径", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
h, _ := kit.Hash("uniq")
|
||||
name := fmt.Sprintf("var/tmp/file/%s", h)
|
||||
|
||||
m.Confm("paths", func(index int, value string) bool {
|
||||
p := path.Join(value, arg[0])
|
||||
if _, e := os.Stat(p); e == nil {
|
||||
m.Echo(p)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
m.Assert(os.MkdirAll("var/tmp/file/", 0777))
|
||||
f, e := os.Create(name)
|
||||
m.Assert(e)
|
||||
defer f.Close()
|
||||
f.Write([]byte(arg[0]))
|
||||
|
||||
m.Echo(name)
|
||||
return
|
||||
}},
|
||||
"trash": &ctx.Command{Name: "trash file", Help: "查找文件路径", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
os.Remove(arg[0])
|
||||
return
|
||||
}},
|
||||
|
||||
|
@ -413,8 +413,8 @@ var page = Page({
|
||||
pane.which.set(""), river = value, pane.Show()
|
||||
},
|
||||
}
|
||||
pane.Show = function() {
|
||||
output.Update([river], "text", ["key", "count"], "key", ctx.Search("storm")||true)
|
||||
pane.Show = function(which) {
|
||||
output.Update([river], "text", ["key", "count"], "key", which||ctx.Search("storm")||true)
|
||||
}
|
||||
pane.Next = function() {
|
||||
var next = output.querySelector("div.item.select").nextSibling
|
||||
@ -502,8 +502,7 @@ var page = Page({
|
||||
|
||||
form.Run(cmd, function(msg) {
|
||||
pane.Show()
|
||||
page.storm.Show()
|
||||
page.storm.which.set(ui.name.value, true)
|
||||
page.storm.Show(ui.name.value)
|
||||
})
|
||||
}]}, {name: "list", view: ["list", "table"]},
|
||||
]}])
|
||||
@ -512,8 +511,7 @@ var page = Page({
|
||||
pane.ShowDialog() && (table.innerHTML = "", ui.name.value = "nice", form.Run([river], function(msg) {
|
||||
kit.AppendTable(table, ctx.Table(msg), ["key", "user.route"], function(value, key, pod, i, tr, event) {
|
||||
var old = table.querySelector("tr.select")
|
||||
tr.className = "select", old && (old.className = "normal")
|
||||
form.Run([river, pod.key], function(msg) {
|
||||
tr.className = "select", old && (old.className = "normal"), form.Run([river, pod.key], function(msg) {
|
||||
device.innerHTML = "", kit.AppendTable(device, ctx.Table(msg), ["key", "index", "name", "help"], function(value, key, com, i, tr, event) {
|
||||
var last = kit.AppendChild(ui.list, [{type: "tr", list: [
|
||||
{text: [com.key, "td"]}, {text: [com.index, "td"]}, {text: [com.name, "td"]}, {text: [com.help, "td"]},
|
||||
|
@ -401,114 +401,117 @@ function Plugin(field, tool, args, plugin) {
|
||||
})
|
||||
}
|
||||
|
||||
var total = 0
|
||||
var count = 0
|
||||
field.Check = option.Check = function(event, index) {
|
||||
index == total-1 || (index == total-2 && event.target.parentNode.nextSibling.childNodes[1].type == "button")?
|
||||
option.Runs(event): event.target.parentNode.nextSibling.childNodes[1].focus()
|
||||
}
|
||||
field.Clone = option.Clone = function() {
|
||||
page.View(field.parentNode, "plugin", field.Meta, [], option.Run)
|
||||
}
|
||||
field.Clear = option.Clear = function() {
|
||||
field.parentNode && field.parentNode.removeChild(field)
|
||||
}
|
||||
field.Remove = option.Remove = function(who) {
|
||||
who.parentNode && who.parentNode.removeChild(who)
|
||||
}
|
||||
field.Select = option.Select = function(who) {
|
||||
page.plugin = field
|
||||
page.footer.State(".", field.id)
|
||||
}
|
||||
field.Append = option.Append = function(item) {
|
||||
var index = total
|
||||
total += 1
|
||||
|
||||
item.onfocus = function(event) {
|
||||
page.plugin = field
|
||||
page.input = event.target
|
||||
page.footer.State(".", field.id)
|
||||
page.footer.State(":", index)
|
||||
}
|
||||
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.Append({})
|
||||
break
|
||||
default:
|
||||
return false
|
||||
}
|
||||
return true
|
||||
var total = 0, count = 0
|
||||
plugin = plugin || {}, plugin.__proto__ = {
|
||||
show: function() {},
|
||||
init: function() {},
|
||||
Clone: function() {
|
||||
field.Meta.args = kit.Selector(option, ".args", function(item, index) {
|
||||
return item.value
|
||||
})
|
||||
event.key == "Enter" && option.Check(event, index)
|
||||
}
|
||||
page.View(field.parentNode, "plugin", field.Meta, [], option.Run)
|
||||
},
|
||||
Clear: function() {
|
||||
field.parentNode && field.parentNode.removeChild(field)
|
||||
},
|
||||
Check: function(event, index) {
|
||||
index == total-1 || (index == total-2 && event.target.parentNode.nextSibling.childNodes[1].type == "button")?
|
||||
option.Runs(event): event.target.parentNode.nextSibling.childNodes[1].focus()
|
||||
},
|
||||
Remove: function(who) {
|
||||
who.parentNode && who.parentNode.removeChild(who)
|
||||
},
|
||||
Append: function(item, name) {
|
||||
var index = total
|
||||
total += 1
|
||||
name = name || item.name
|
||||
|
||||
var input = {type: "input", name: item.name, data: item}
|
||||
switch (item.type) {
|
||||
case "button":
|
||||
item.onclick = function(event) {
|
||||
plugin[item.click]? plugin[item.click](event, item, option, field): option.Runs(event)
|
||||
}
|
||||
break
|
||||
item.onfocus = function(event) {
|
||||
page.plugin = plugin
|
||||
page.input = event.target
|
||||
page.footer.State(".", field.id)
|
||||
page.footer.State(":", index)
|
||||
}
|
||||
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":
|
||||
plugin.Clone()
|
||||
break
|
||||
case "b":
|
||||
plugin.Append(item, "args"+total).focus()
|
||||
break
|
||||
default:
|
||||
return false
|
||||
}
|
||||
return true
|
||||
})
|
||||
event.key == "Enter" && plugin.Check(event, index)
|
||||
}
|
||||
|
||||
case "select":
|
||||
input = {type: "select", name: item.name, data: {className: "args", onchange: function(event) {
|
||||
option.Check(event, index)
|
||||
var input = {type: "input", name: name, data: item}
|
||||
switch (item.type) {
|
||||
case "button":
|
||||
item.onclick = function(event) {
|
||||
plugin[item.click]? plugin[item.click](event, item, option, field): option.Runs(event)
|
||||
}
|
||||
break
|
||||
|
||||
}}, list: item.values.map(function(value) {
|
||||
return {type: "option", value: value, inner: value}
|
||||
})}
|
||||
args && count < args.length && (item.value = args[count++])
|
||||
break
|
||||
case "select":
|
||||
input = {type: "select", name: name, data: {className: "args", onchange: function(event) {
|
||||
plugin.Check(event, index)
|
||||
|
||||
default:
|
||||
args && count < args.length && (item.value = args[count++])
|
||||
item.className = "args"
|
||||
}
|
||||
}}, list: item.values.map(function(value) {
|
||||
return {type: "option", value: value, inner: value}
|
||||
})}
|
||||
args && count < args.length && (item.value = args[count++])
|
||||
break
|
||||
|
||||
var ui = kit.AppendChild(option, [{type: "div", list: [{type: "label", inner: item.label||""}, input]}])
|
||||
default:
|
||||
args && count < args.length && (item.value = args[count++])
|
||||
item.className = "args"
|
||||
}
|
||||
|
||||
page.plugin = field
|
||||
page.input = ui[item.name]
|
||||
item.imports && page.Sync(item.imports).change(function(value, old) {
|
||||
ui[item.name].value = value
|
||||
})
|
||||
var ui = kit.AppendChild(option, [{type: "div", list: [{type: "label", inner: item.label||""}, input]}])
|
||||
|
||||
page.plugin = field
|
||||
page.input = ui[name]
|
||||
index == 0 && ui[name] && ui[name].focus && ui[name].focus()
|
||||
item.imports && page.Sync(item.imports).change(function(value, old) {
|
||||
ui[name].value = value
|
||||
})
|
||||
return ui[name]
|
||||
},
|
||||
Select: function() {
|
||||
page.plugin = field
|
||||
page.footer.State(".", field.id)
|
||||
},
|
||||
}
|
||||
|
||||
var inputs = JSON.parse(tool.inputs)
|
||||
inputs.map(function(item, index, inputs) {
|
||||
option.Append(item)
|
||||
plugin.Append(item)
|
||||
})
|
||||
|
||||
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)
|
||||
page[field.id] = plugin
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user