diff --git a/src/contexts/aaa/aaa.go b/src/contexts/aaa/aaa.go index d7121e8e..ad617fce 100644 --- a/src/contexts/aaa/aaa.go +++ b/src/contexts/aaa/aaa.go @@ -270,7 +270,6 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心", // 检查链接 if arg[i] == "check" { - m.Log("fuck", "waht %v", p) has := "false" m.Confm("auth", []string{p, "ship"}, func(k string, ship map[string]interface{}) { if i == len(arg)-2 && (ship["meta"] != arg[i+1] && k != arg[i+1]) { @@ -369,6 +368,9 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心", if i > len(arg)-1 { // 查看数据 m.Set("result").Cmdy("ctx.config", "auth", strings.Join([]string{p, "data"}, ".")) return + } else if i == len(arg)-1 { // 查看数据 + m.Set("result").Cmdy("ctx.config", "auth", strings.Join([]string{p, "data", arg[i]}, ".")) + return } else if arg[i] == "delete" { // 删除数据 m.Confm("auth", []string{s, "data"}, func(data map[string]interface{}) { for _, k := range arg[i+1:] { @@ -549,7 +551,6 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心", return case "user": // 查看用户 - m.Log("fuck", "what %v", arg) m.Cmdy("aaa.auth", sid, "ship", "username") case "current": @@ -775,8 +776,8 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心", // 生成证书 template := x509.Certificate{ - SerialNumber: big.NewInt(1), - IsCA: true, + SerialNumber: big.NewInt(1), + IsCA: true, BasicConstraintsValid: true, KeyUsage: x509.KeyUsageCertSign, Subject: pkix.Name{CommonName: kit.Format(common)}, diff --git a/src/contexts/ctx/ctx.go b/src/contexts/ctx/ctx.go index ebbddecf..e83a6552 100644 --- a/src/contexts/ctx/ctx.go +++ b/src/contexts/ctx/ctx.go @@ -1751,8 +1751,8 @@ func (m *Message) Confm(key string, args ...interface{}) map[string]interface{} } } case func(int, map[string]interface{}): - for i, v := range table { - if val, ok := v.(map[string]interface{}); ok { + for i := m.Optioni("page.begin"); i < len(table); i++ { + if val, ok := table[i].(map[string]interface{}); ok { fun(i, val) } } diff --git a/src/contexts/web/web.go b/src/contexts/web/web.go index e205a2eb..f9b2e4eb 100644 --- a/src/contexts/web/web.go +++ b/src/contexts/web/web.go @@ -925,8 +925,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", tmpl := web.Template if m.Confs("route", "template_debug") { tmpl = template.New("render").Funcs(ctx.CGI) - t, e := tmpl.ParseGlob(path.Join(m.Cap("directory"), m.Conf("route", "template_dir"), "/*.tmpl")) - m.Log("fuck", "what %v %v", e, t) + tmpl.ParseGlob(path.Join(m.Cap("directory"), m.Conf("route", "template_dir"), "/*.tmpl")) tmpl.ParseGlob(path.Join(m.Cap("directory"), m.Conf("route", "template_dir"), m.Cap("route"), "/*.tmpl")) } @@ -983,7 +982,6 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", } } } - msg.Log("fuck", "%s", msg.Option("componet_name")) // 添加设备 arg = arg[:0] diff --git a/src/examples/chat/chat.go b/src/examples/chat/chat.go index 40d836ea..928665ed 100644 --- a/src/examples/chat/chat.go +++ b/src/examples/chat/chat.go @@ -134,6 +134,10 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心", if m.Cmds("aaa.auth", "username", arg[0], "password", arg[1]) { m.Option("username", arg[0]) m.Copy(m.Cmd("aaa.user", "session", "select"), "result") + m.Option("sessid", m.Result(0)) + if !m.Cmds("aaa.auth", "username", arg[0], "data", "chat.default") && m.Option("username") != m.Conf("runtime", "work.name") { + m.Cmds("aaa.auth", "username", arg[0], "data", "chat.default", m.Spawn().Cmd(".ocean", "spawn", "", m.Option("username")+"@"+m.Conf("runtime", "work.name"))) + } } } } else if m.Options("sessid") { @@ -152,13 +156,16 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心", switch arg[0] { case "spawn": + arg = append(arg, m.Option("username")) arg = append(arg, m.Conf("runtime", "work.name")) h := kit.Select(kit.Hashs("uniq"), arg, 1) user := map[string]interface{}{} for _, v := range arg[3:] { u := m.Cmdx("ssh._route", m.Conf("runtime", "work.route"), "_check", "work", v) - user[v] = map[string]interface{}{"user": u} + if u != "" { + user[v] = map[string]interface{}{"user": u} + } } m.Conf("flow", h, map[string]interface{}{ @@ -209,18 +216,20 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心", } switch arg[0] { - case "flow": - if len(arg) == 2 { - m.Confm("flow", []string{arg[1], "text.list"}, func(index int, value map[string]interface{}) { - m.Add("append", "index", index) - m.Add("append", "type", value["type"]) - m.Add("append", "text", value["text"]) - }) - m.Table() - return - } + case "brow": + m.Option("page.begin", kit.Select("0", arg, 2)) + m.Confm("flow", []string{arg[1], "text.list"}, func(index int, value map[string]interface{}) { + m.Add("append", "index", index) + m.Add("append", "type", value["type"]) + m.Add("append", "text", value["text"]) + m.Add("append", "create_time", value["create_time"]) + m.Add("append", "create_user", value["create_user"]) + }) + m.Table() + return - if m.Conf("flow", []string{arg[1], "conf.route"}) != m.Conf("runtime", "node.route") && len(arg) == 4 { + case "flow": + if kit.Right(m.Conf("flow", []string{arg[1], "conf.route"})) && m.Conf("flow", []string{arg[1], "conf.route"}) != m.Conf("runtime", "node.route") && len(arg) == 4 { m.Cmdy("ssh._route", m.Conf("flow", []string{arg[1], "conf.route"}), "context", "chat", "river", "flow", arg[1], arg[2], arg[3]) m.Log("info", "upstream") @@ -236,6 +245,7 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心", count := m.Confi("flow", []string{arg[1], "text.count"}) + 1 m.Confi("flow", []string{arg[1], "text.count"}, count) + m.Append("create_user", m.Option("username")) m.Echo("%d", count) m.Option("username", m.Conf("runtime", "user.name")) diff --git a/usr/librarys/chat.css b/usr/librarys/chat.css index 73fc8e8a..2b5f0dee 100644 --- a/usr/librarys/chat.css +++ b/usr/librarys/chat.css @@ -11,6 +11,20 @@ fieldset.River { fieldset.Target div.output div.item:hover { background-color:lightgreen; } +fieldset.Target>div.output>div.item { + padding-top:6px; + clear:both; +} +fieldset.Target>div.output>div.item>div.text { + padding:6px; + float:left; +} +fieldset.Target>div.output>div.item>div.user { + border-right:solid 1px green; + border-bottom:solid 1px green; + float:left; + padding:6px; +} fieldset.Source div.output { padding:0; } diff --git a/usr/librarys/chat.js b/usr/librarys/chat.js index 5c1dd753..3fce9ee3 100644 --- a/usr/librarys/chat.js +++ b/usr/librarys/chat.js @@ -203,6 +203,7 @@ var page = Page({ return {"button": ["创建"], "action": pane.Action} }, initTarget: function(page, pane, form, output) { + output.DisplayUser = true var river = "" pane.Listen = { river: function(value, old) { @@ -211,8 +212,11 @@ var page = Page({ } pane.Show = function() { - page.footer.State("text", 0) - output.Update(["flow", river], "text", ["text"], "index", false, fun) + var cmds = ["brow", river, 0] + output.innerHTML = "", pane.Times(100, cmds, function(line, index, msg) { + output.Append("", line, ["text"], "index", fun) + cmds[2] = parseInt(line.index)+1 + }) } function fun(line, index, event, args, cbs) { @@ -222,8 +226,7 @@ var page = Page({ pane.Send = function(type, text, cb) { form.Run(["flow", river, type, text], function(msg) { - output.Append(type, {text:text, index: msg.result[0]}, ["text"], "index", fun) - page.footer.State("text", msg.result[0]) + // output.Append(type, {create_user: msg.create_user[0], text:text, index: msg.result[0]}, ["text"], "index", fun) typeof cb == "function" && cb() }) } @@ -291,7 +294,8 @@ var page = Page({ output.Update([river, storm], "plugin", ["node", "name"], "index", false, function(line, index, event, args, cbs) { event.shiftKey? page.target.Send("field", JSON.stringify({ name: line.name, view: line.view, init: line.init, - node: line.node, group: line.group, index: line.index, inputs: line.inputs, + node: line.node, group: line.group, index: line.index, + inputs: line.inputs, args: args, })): form.Run([river, storm, index].concat(args), function(msg) { event.ctrlKey && (msg.append && msg.append[0]? page.target.Send("table", JSON.stringify(ctx.Tables(msg))): diff --git a/usr/librarys/example.js b/usr/librarys/example.js index 67abf59f..1a5b52b5 100644 --- a/usr/librarys/example.js +++ b/usr/librarys/example.js @@ -52,13 +52,14 @@ function Page(page) { View: function(parent, type, line, key, cb) { var ui = {} var result = [] + var text = line switch (type) { case "icon": result = [{view: ["item", "div"], list: [{type: "img", data: {src: line[key[0]]}}, {}]}] break case "text": - result = [{view: ["item", "div", key.length>1? line[key[0]]+"("+line[key[1]]+")": (key.length>0? line[key[0]]: "null")], click: cb}] + result = [{text: [key.length>1? line[key[0]]+"("+line[key[1]]+")": (key.length>0? line[key[0]]: "null"), "span"], click: cb}] break case "code": @@ -76,20 +77,27 @@ function Page(page) { break case "field": - line = JSON.parse(line.text) + var text = JSON.parse(line.text) case "plugin": var id = "plugin"+page.ID() - result = [{view: [line.view, "fieldset"], data: {id: id}, list: [ - {text: [line.name, "legend"]}, + result = [{view: [text.view, "fieldset"], data: {id: id}, list: [ + {text: [text.name, "legend"]}, {name: "option", view: ["option", "form"], data: {Run: cb}, list: [{type: "input", style: {"display": "none"}}]}, {name: "output", view: ["output", "div"]}, - {script: "Plugin("+id+","+line.inputs+","+line.init+")"}, + {script: "Plugin("+id+","+text.inputs+","+"["+(text.args||"")+"]"+","+(text.init||"")+")"}, ]}] break } + if (parent.DisplayUser) { + ui = kit.AppendChild(parent, [{view: ["item"], list:[ + {view: ["user", "div", line.create_user]}, + {view: ["text"], list:result} + ]}]) + } else { + ui = kit.AppendChild(parent, [{view: ["item"], list:result}]) + } - ui = kit.AppendChild(parent, result) ui.last.Meta = line return ui }, @@ -315,6 +323,27 @@ function Page(page) { }) }) } + pane.Time = form.Time = function(time, cmds, cb) { + function loop() { + ctx.Run(page, form.dataset, cmds, cb) + setTimeout(loop, time) + } + setTimeout(loop, time) + } + + var timer = "" + pane.Times = form.Times = function(time, cmds, cb) { + timer && clearTimeout(timer) + function loop() { + ctx.Run(page, form.dataset, cmds, function(msg) { + ctx.Table(msg, function(line, index) { + cb(line, index, msg) + }) + }) + timer = setTimeout(loop, time) + } + timer = setTimeout(loop, time) + } form.onsubmit = function(event) { event.preventDefault() } @@ -344,7 +373,7 @@ function Page(page) { } return page } -function Plugin(field, inputs, plugin) { +function Plugin(field, inputs, args, plugin) { var option = field.querySelector("form.option") var output = field.querySelector("div.output") @@ -405,7 +434,7 @@ function Plugin(field, inputs, plugin) { }, field.Select = function() { ui.last.childNodes[1].focus() }) - return {type: "div", list: [{type: "label", inner: item.label||""}, {type: "input", name: item.name, data: item}]} + 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()