From 4eb290d72cdabdfb07dddca994701c86aeca3e9c Mon Sep 17 00:00:00 2001 From: shaoying Date: Sun, 25 Aug 2019 17:52:19 +0800 Subject: [PATCH] add favor.note --- src/contexts/cli/version.go | 2 +- src/contexts/nfs/nfs.go | 16 +++++++++++++++- src/contexts/ssh/ssh.go | 1 + src/contexts/yac/yac.go | 14 +++++++++++--- src/examples/chat/chat.go | 1 + src/examples/wiki/wiki.go | 6 +++--- src/plugin/context/index.shy | 20 ++++++++++---------- src/plugin/favor/index.shy | 14 ++++++++++++++ usr/librarys/example.js | 36 +++++++++++++++++++++++++++--------- usr/librarys/toolkit.js | 6 +++--- 10 files changed, 86 insertions(+), 30 deletions(-) diff --git a/src/contexts/cli/version.go b/src/contexts/cli/version.go index 61cfa1bb..f6ea1ac2 100644 --- a/src/contexts/cli/version.go +++ b/src/contexts/cli/version.go @@ -4,5 +4,5 @@ var version = struct { host string self int }{ - "2019-08-24 17:10:37", "ZYB-20190522USI.centos", 402, + "2019-08-25 17:36:48", "mac", 429, } diff --git a/src/contexts/nfs/nfs.go b/src/contexts/nfs/nfs.go index 4b98a6ee..cc41ded3 100644 --- a/src/contexts/nfs/nfs.go +++ b/src/contexts/nfs/nfs.go @@ -619,6 +619,7 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心", return sed(m, arg[0], args) } + skip, find := false, false m.Confm("pwd", func(index int, value string) bool { // p := path.Join(value, m.Option("dir_root"), arg[0]) p := path.Join(value, arg[0]) @@ -650,12 +651,25 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心", m.Append("file", p) m.Append("size", s.Size()) m.Append("time", s.ModTime().Format(m.Conf("time", "format"))) + skip = true } + + find = true return true } return false }) + if !find && arg[0] != "" { + if strings.HasSuffix(arg[0], "/") { + m.Assert(os.MkdirAll(arg[0], 0777)) + m.Echo(arg[0]) + } else if f, p, e := kit.Create(arg[0]); m.Assert(e) { + f.Close() + m.Echo(p) + } + } + if m.Has("dir_sort") { m.Sort(m.Meta["dir_sort"][0], m.Meta["dir_sort"][1:]...) } @@ -664,7 +678,7 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心", for _, v := range m.Meta[m.Meta["append"][0]] { m.Echo(v).Echo(" ") } - } else { + } else if !skip { m.Table() } return diff --git a/src/contexts/ssh/ssh.go b/src/contexts/ssh/ssh.go index f23b21d3..bf3ac0aa 100644 --- a/src/contexts/ssh/ssh.go +++ b/src/contexts/ssh/ssh.go @@ -408,6 +408,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心", m.Push("init", "") } m.Push("inputs", kit.Format(value["inputs"])) + m.Push("feature", kit.Format(value["feature"])) m.Push("exports", kit.Format(value["exports"])) m.Push("display", kit.Format(value["display"])) }) diff --git a/src/contexts/yac/yac.go b/src/contexts/yac/yac.go index f3da9a90..e8c9037b 100644 --- a/src/contexts/yac/yac.go +++ b/src/contexts/yac/yac.go @@ -318,6 +318,7 @@ var Index = &ctx.Context{Name: "yac", Help: "语法中心", // 表达式语句 map[string]interface{}{"page": "op1", "hash": "op1", "word": []interface{}{"mul{", "-", "+", "}"}}, + map[string]interface{}{"page": "op2", "hash": "op2", "word": []interface{}{"mul{", "~", "!~", "}"}}, map[string]interface{}{"page": "op2", "hash": "op2", "word": []interface{}{"mul{", "+", "-", "*", "/", "%", "}"}}, map[string]interface{}{"page": "op2", "hash": "op2", "word": []interface{}{"mul{", "<", "<=", ">", ">=", "==", "!=", "}"}}, map[string]interface{}{"page": "val", "hash": "val", "word": []interface{}{"opt{", "op1", "}", "mul{", "num", "key", "str", "exe", "}"}}, @@ -354,7 +355,6 @@ var Index = &ctx.Context{Name: "yac", Help: "语法中心", map[string]interface{}{"page": "op1", "hash": "op1", "word": []interface{}{"mul{", "-z", "-n", "}"}}, map[string]interface{}{"page": "op1", "hash": "op1", "word": []interface{}{"mul{", "-e", "-f", "-d", "}"}}, map[string]interface{}{"page": "op2", "hash": "op2", "word": []interface{}{"mul{", ":=", "=", "+=", "}"}}, - map[string]interface{}{"page": "op2", "hash": "op2", "word": []interface{}{"mul{", "~", "!~", "}"}}, map[string]interface{}{"page": "exp", "hash": "exp", "word": []interface{}{"\\{", "rep{", "map", "}", "\\}"}}, map[string]interface{}{"page": "val", "hash": "val", "word": []interface{}{"opt{", "op1", "}", "(", "exp", ")"}}, @@ -374,6 +374,7 @@ var Index = &ctx.Context{Name: "yac", Help: "语法中心", "button": true, "select": true, "textarea": true, + "feature": true, "exports": true, }, Help: "控件类型"}, "exec": &ctx.Config{Name: "info", Value: map[string]interface{}{ @@ -770,7 +771,9 @@ var Index = &ctx.Context{Name: "yac", Help: "语法中心", } pre := map[string]int{ - "=": -1, + "=": -1, + "||": 0, + "==": 1, "~": 1, "+": 2, "-": 2, "*": 3, "/": 3, "%": 3, } @@ -1094,6 +1097,7 @@ var Index = &ctx.Context{Name: "yac", Help: "语法中心", m.Log("info", "_index: %v", arg) args := []interface{}{} inputs := []interface{}{} + feature := map[string]interface{}{} exports := []interface{}{} for i := 7; i < len(arg); i++ { if !m.Confs("input", arg[i]) { @@ -1106,7 +1110,10 @@ var Index = &ctx.Context{Name: "yac", Help: "语法中心", continue } args := arg[i : j+1] - if arg[i] == "exports" { + if arg[i] == "feature" { + feature[arg[i+1]] = arg[i+2] + + } else if arg[i] == "exports" { for k := 1; k < len(args); k += 1 { exports = append(exports, args[k]) } @@ -1150,6 +1157,7 @@ var Index = &ctx.Context{Name: "yac", Help: "语法中心", "componet_cmd": kit.Select("", arg, 6), "componet_args": args, "inputs": inputs, + "feature": feature, "exports": exports, }) return diff --git a/src/examples/chat/chat.go b/src/examples/chat/chat.go index 4757d094..d3632373 100644 --- a/src/examples/chat/chat.go +++ b/src/examples/chat/chat.go @@ -317,6 +317,7 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心", m.Push("inputs", msg.Append("inputs")) m.Push("exports", msg.Append("exports")) m.Push("display", msg.Append("display")) + m.Push("feature", msg.Append("feature")) }) m.Table() break diff --git a/src/examples/wiki/wiki.go b/src/examples/wiki/wiki.go index 07a11634..74f1c9da 100644 --- a/src/examples/wiki/wiki.go +++ b/src/examples/wiki/wiki.go @@ -5,7 +5,6 @@ import ( "contexts/ctx" "contexts/web" - "toolkit" "bytes" "html/template" @@ -47,16 +46,17 @@ var Index = &ctx.Context{Name: "wiki", Help: "文档中心", }, Help: "组件列表"}, "level": &ctx.Config{Name: "level", Value: "local/wiki/自然/编程", Help: "路由数量"}, + "class": &ctx.Config{Name: "class", Value: "", Help: "路由数量"}, "favor": &ctx.Config{Name: "favor", Value: "index.md", Help: "路由数量"}, }, Commands: map[string]*ctx.Command{ "tree": &ctx.Command{Name: "tree", Help: "目录", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { - m.Cmdy("nfs.dir", path.Join(m.Confx("level"), kit.Select(m.Option("class"), arg, 0)), + m.Cmdy("nfs.dir", path.Join(m.Confx("level"), m.Confx("class", arg, 0)), "time", "size", "line", "file", "dir_sort", "time", "time_r") return }}, "text": &ctx.Command{Name: "text", Help: "文章", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { - which := m.Cmdx("nfs.path", path.Join(m.Confx("level"), m.Option("class"), m.Confx("favor", arg, 0))) + which := m.Cmdx("nfs.path", path.Join(m.Confx("level"), m.Confx("class", arg, 1), m.Confx("favor", arg, 0))) buffer := bytes.NewBuffer([]byte{}) template.Must(template.ParseFiles(which)).Funcs(ctx.CGI).Execute(buffer, m) diff --git a/src/plugin/context/index.shy b/src/plugin/context/index.shy index 8c97c110..fda576b6 100644 --- a/src/plugin/context/index.shy +++ b/src/plugin/context/index.shy @@ -2,7 +2,7 @@ fun project "项目" "" "" \ private \ select "" values plugin values submit values review values trend values stat values init action auto \ - text "" imports plugin_see action auto \ + text "" name see imports plugin_see action auto \ button "执行" \ exports see name see @@ -11,7 +11,7 @@ end fun compile "编译" "" "" \ private \ - select "" values plugin values restart values windows values darwin values linux values self values all \ + select "" values plugin values restart values windows values darwin values linux values self values all action auto \ text "" name see imports plugin_see \ button "编译" @@ -29,7 +29,7 @@ end fun upgrade "升级" "" "" \ private \ text "" name pod imports plugin_pod \ - select "" values script values restart values plugin values bench values portal values system \ + select "" values script values restart values plugin values bench values portal values system action auto \ text "" name see imports plugin_see \ button "升级" @@ -38,8 +38,8 @@ end fun missyou "任务" "" "" \ private \ - text "" imports plugin_see \ - text "" view long \ + text "" name see imports plugin_see \ + text "" name you view long \ button "行动" action auto \ exports you "" you @@ -48,7 +48,7 @@ end fun pod "设备" "" "" \ private \ - text "" view long \ + text "" name pod view long \ button "行动" action auto \ exports pod pod @@ -69,7 +69,7 @@ fun cmd "命令" "" "" \ private \ text "" name pod imports plugin_pod \ text "nfs" name ctx imports plugin_ctx \ - text "pwd" \ + text "pwd" name cmd \ button "执行" copy ssh._route _ context _ command __ @@ -79,8 +79,8 @@ fun dir "目录" "" "" \ private \ text "" name pod imports plugin_pod action auto \ text "usr/script" name dir imports plugin_dir action auto view long \ - button "查看" action auto \ - button "回退" click Back \ + button "浏览" action auto \ + feature display "editor" \ exports dir "" dir copy ssh._route _ nfs.dir _ time size line path @@ -89,7 +89,7 @@ end fun git "版本" "" "" \ private \ text "" name pod imports plugin_pod action auto \ - select "" values diff values status commit values values log values init action auto \ + select "" values status values diff commit values values log values init action auto \ text "" name txt action auto \ button "查看" action auto diff --git a/src/plugin/favor/index.shy b/src/plugin/favor/index.shy index d80daf7a..46b0c9f6 100644 --- a/src/plugin/favor/index.shy +++ b/src/plugin/favor/index.shy @@ -71,6 +71,20 @@ fun sys "命令行" "" "" \ copy nfs.source system __ end +fun note "记事本" "" "" \ + public \ + text "" name tip imports plugin_tip view long action auto \ + button "创建" action auto \ + feature display inner \ + exports tip file tip + + if $1 == "" || $1 ~ ".*/$" + copy context wiki tree __ + else + copy context wiki text __ + end +end + fun hello world "" "" \ public \ textarea "" \ diff --git a/usr/librarys/example.js b/usr/librarys/example.js index 7f322923..5c9dd5e7 100644 --- a/usr/librarys/example.js +++ b/usr/librarys/example.js @@ -684,7 +684,11 @@ function Pane(page, field) { }; return page[name] = field, pane.Field = field, field.Pane = pane } -function Plugin(page, pane, field, run) { +function Plugin(page, pane, field, runs) { + var run = function(event, cmds, cbs) { + event.Plugin = plugin, runs(event, cmds, cbs) + } + var option = field.querySelector("form.option") var action = field.querySelector("div.action") var output = field.querySelector("div.output") @@ -693,7 +697,9 @@ function Plugin(page, pane, field, run) { var name = meta.name var args = meta.args || [] var display = JSON.parse(meta.display||'{}') + var feature = JSON.parse(meta.feature||'{}') var exports = JSON.parse(meta.exports||'["",""]') + var deal = (feature && feature.display) || "table" var plugin = Meta(field, (field.Script && field.Script.init || function() { })(run, field, option, output)||{}, { @@ -707,6 +713,8 @@ function Plugin(page, pane, field, run) { var count = kit.Selector(option, "args").length args && count < args.length && (item.value = value||args[count++]||item.value||"") + item.title = item.title || item.name || "" + item.placeholder = item.title name = item.name || "input" var input = {type: "input", name: name, data: item} switch (item.type) { @@ -725,7 +733,7 @@ function Plugin(page, pane, field, run) { break } - var ui = kit.AppendChild(option, [{view: [item.view||""], list: [{type: "label", inner: item.label||""}, input]}]) + var ui = kit.AppendChild(option, [{view: [item.view||""], data: {title: item.title}, list: [{type: "label", inner: item.label||""}, input]}]) var action = Meta(ui[name] || {}, item, plugin.onaction, plugin); (typeof item.imports == "object"? item.imports: typeof item.imports == "string"? [item.imports]: []).forEach(function(imports) { @@ -812,7 +820,7 @@ function Plugin(page, pane, field, run) { }, time) }, Check: function(target, cb) { - option.querySelectorAll(".args").forEach(function(item, index, list) { + plugin.Select(true), option.querySelectorAll(".args").forEach(function(item, index, list) { target == undefined && index == list.length-1 && plugin.Runs(window.event, cb) item == target && (index == list.length-1? plugin.Runs(window.event, cb): page.plugin == field && list[index+1].focus()) }) @@ -828,7 +836,7 @@ function Plugin(page, pane, field, run) { }, 1000) event.Plugin = plugin, run(event, args, function(msg) { page.footer.Pane.State("ncmd", kit.History.get("cmd").length) - plugin.msg = msg, plugin.display(display.deal, cb) + plugin.msg = msg, plugin.display(deal, cb) show = false, page.ontoast("") }) }, @@ -837,9 +845,17 @@ function Plugin(page, pane, field, run) { output.innerHTML = "" }, display: function(arg, cb) { - display.deal = arg, plugin.ondaemon[display.deal||"table"](plugin.msg, cb) + deal = arg, plugin.ondaemon[deal||"table"](plugin.msg, cb) }, ondaemon: { + inner: function(msg, cb) { + output.style.maxWidth = pane.target.clientWidth-20+"px" + output.style.maxHeight = pane.target.clientHeight-60+"px" + output.innerHTML = "", msg.append? kit.OrderTable(kit.AppendTable(kit.AppendChild(output, "table"), ctx.Table(msg), msg.append), exports[1], function(event, value, name, line) { + page.Sync("plugin_"+exports[0]).set(plugin.onexport[exports[2]||""](value, name, line)) + }): (output.innerHTML = msg.result.join("")) + typeof cb == "function" && cb(msg) + }, table: function(msg, cb) { output.innerHTML = "" !display.hide_append && msg.append && kit.OrderTable(kit.AppendTable(kit.AppendChild(output, "table"), ctx.Table(msg), msg.append), exports[1], function(event, value, name, line) { @@ -849,7 +865,7 @@ function Plugin(page, pane, field, run) { typeof cb == "function" && cb(msg) }, editor: function(msg, cb) { - (output.innerHTML = "", Editor(plugin, option, output, output.clientWidth-40, 400, 10, msg)) + (output.innerHTML = "", Editor(run, plugin, option, output, output.clientWidth-40, 400, 10, msg)) }, canvas: function(msg, cb) { typeof cb == "function" && !cb(msg) || (output.innerHTML = "", Canvas(plugin, option, output, pane.target.clientWidth-45, pane.target.clientHeight-175, 10, msg)) @@ -882,6 +898,9 @@ function Plugin(page, pane, field, run) { name != "path" && (value = line.path) return value }, + tip: function(value, name, line) { + return option.tip.value + value + }, }, onaction: { onfocus: function(event, action, type, name, item) { @@ -893,9 +912,8 @@ function Plugin(page, pane, field, run) { onclick: function(event, action, type, name, item) { switch (type) { case "button": - plugin.Select(true) action[item.click]? action[item.click](event, item, option, field): - plugin[item.click]? plugin[item.click](event, item, option, field): plugin.Runs(event) + plugin[item.click]? plugin[item.click](event, item, option, field): plugin.Check() break case "text": if (event.ctrlKey) { @@ -908,7 +926,7 @@ function Plugin(page, pane, field, run) { action.target.value = kit.History.get("txt", -1).data.trim() }, onchange: function(event, action, type, name, item) { - plugin.Check(action) + plugin.Check(item.action == "auto"? undefined: action) }, onkeyup: function(event, action, type, name, item) { switch (event.key) { diff --git a/usr/librarys/toolkit.js b/usr/librarys/toolkit.js index 47e317b1..3a03bf3c 100644 --- a/usr/librarys/toolkit.js +++ b/usr/librarys/toolkit.js @@ -733,7 +733,7 @@ kit = toolkit = { }, } -function Editor(plugin, option, output, width, height, space, msg) { +function Editor(run, plugin, option, output, width, height, space, msg) { exports = ["dir", "path", "dir"] msg.append && kit.OrderTable(kit.AppendTable(kit.AppendChild(output, "table"), ctx.Table(msg), msg.append), exports[1], function(event, value, name, line) { page.Sync("plugin_"+exports[0]).set(plugin.onexport[exports[2]||""](value, name, line)) @@ -747,10 +747,10 @@ function Editor(plugin, option, output, width, height, space, msg) { ], function(value, event) { switch (value) { case "追加": - field.Run(event, args.concat(["dir_sed", "add"])) + run(event, args.concat(["dir_sed", "add"])) break case "提交": - field.Run(event, args.concat(["dir_sed", "put"])) + run(event, args.concat(["dir_sed", "put"])) break case "取消": break