From 4eb56fd692fc7346d69e47ab23f699865b5eb1bf Mon Sep 17 00:00:00 2001 From: shaoying Date: Thu, 13 Jun 2019 09:33:11 +0800 Subject: [PATCH] opt plugin.example.js --- src/contexts/nfs/nfs.go | 59 ++++++------ usr/librarys/chat.js | 10 +-- usr/librarys/example.js | 193 ++++++++++++++++++++-------------------- 3 files changed, 131 insertions(+), 131 deletions(-) diff --git a/src/contexts/nfs/nfs.go b/src/contexts/nfs/nfs.go index b52cbf1b..76e33836 100644 --- a/src/contexts/nfs/nfs.go +++ b/src/contexts/nfs/nfs.go @@ -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 }}, diff --git a/usr/librarys/chat.js b/usr/librarys/chat.js index 37326f3d..65e4d7a7 100644 --- a/usr/librarys/chat.js +++ b/usr/librarys/chat.js @@ -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"]}, diff --git a/usr/librarys/example.js b/usr/librarys/example.js index 8fedb508..fce831ca 100644 --- a/usr/librarys/example.js +++ b/usr/librarys/example.js @@ -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 }